< Summary

Information
Class: Services.SignalRServices.NotificationService
Assembly: Services
File(s): /home/runner/work/Studio2Prod/Studio2Prod/AppRepository/SignalRServices/NotificationService.cs
Line coverage
39%
Covered lines: 9
Uncovered lines: 14
Coverable lines: 23
Total lines: 55
Line coverage: 39.1%
Branch coverage
0%
Covered branches: 0
Total branches: 2
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Initialize(...)100%11100%
NotifyAllAsync()100%210%
NotifyAsync()100%11100%
NotifyUsersAsync()0%3228.57%
NotifySystemAsync()100%210%

File(s)

/home/runner/work/Studio2Prod/Studio2Prod/AppRepository/SignalRServices/NotificationService.cs

#LineLine coverage
 1using System.Text.Json;
 2using Microsoft.AspNetCore.SignalR;
 3
 4namespace Services.SignalRServices;
 5
 6public static class NotificationService
 7{
 8    private static IHubContext<NotificationHub>? _hubContext;
 9
 10    public static void Initialize(IHubContext<NotificationHub> hubContext)
 11    {
 212        _hubContext = hubContext;
 213    }
 14
 15    public static async Task NotifyAllAsync(string message)
 16    {
 017        if (_hubContext == null)
 018            throw new InvalidOperationException("NotificationService не инициализирован.");
 19
 020        await _hubContext.Clients.All.SendAsync("PopupNotification", message);
 021    }
 22
 23    public static async Task NotifyAsync(string source, string color, string text, string icon = "fa-circle-info")
 24    {
 1425        if (_hubContext == null)
 926            throw new InvalidOperationException("NotificationService не инициализирован.");
 27
 528        var payload = JsonSerializer.Serialize(new { source, color, icon, text });
 529        await _hubContext.Clients.All.SendAsync("PopupNotification", payload);
 130    }
 31
 32    public static async Task NotifyUsersAsync(IEnumerable<string> userIds, string source, string color, string text, str
 33    {
 30534        if (_hubContext == null)
 30535            throw new InvalidOperationException("NotificationService не инициализирован.");
 36
 037        var recipients = userIds.Where(x => !string.IsNullOrWhiteSpace(x)).Distinct().ToArray();
 038        if (recipients.Length == 0)
 039            return;
 040        var payload = JsonSerializer.Serialize(new { source, color, icon, text });
 041        await _hubContext.Clients.Users(recipients).SendAsync("PopupNotification", payload);
 042    }
 43
 44    /// <summary>
 45    /// Отправляет системное уведомление всем активным пользователям через SignalR
 46    /// Используется для важных системных сообщений, которые должны отображаться в модальном окне
 47    /// </summary>
 48    public static async Task NotifySystemAsync(string message)
 49    {
 050        if (_hubContext == null)
 051            throw new InvalidOperationException("NotificationService не инициализирован.");
 52
 053        await _hubContext.Clients.All.SendAsync("SystemNotification", message);
 054    }
 55}