Advertisement
HenX

SignalR

Dec 8th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.80 KB | None | 0 0
  1.  public static class NotificationsControl
  2.     {
  3.         private static NotificationsManager _notificationsManager = new NotificationsManager(HttpContext.Current);
  4.  
  5.         internal static void AddHubId(HttpContextBase context, string hubid)
  6.         {
  7.             try
  8.             {                
  9.                 List<UserToHub> _listeners = context.Cache["Suzct_NotificationsListeners"] as List<UserToHub> ?? new List<UserToHub>();
  10.  
  11.                 if (!_listeners.Any(m => m.hubid == hubid) && context.User != null && context.User.Identity.IsAuthenticated)
  12.                 {
  13.                     _listeners.Add(new UserToHub() {
  14.                         hubid = hubid,
  15.                         username = context.User.Identity.Name,
  16.                         browser = context.Request.Browser.Browser,
  17.                         ipaddress = context.Request.UserHostAddress
  18.                     });
  19.  
  20.                     context.Cache["Suzct_NotificationsListeners"] = _listeners;
  21.  
  22.                     ListenersDebugOutput(context);
  23.                 }
  24.             }
  25.             catch (Exception e)
  26.             {
  27.                 LogWriter.InsertException(e, HttpContext.Current.User);
  28.             }
  29.         }
  30.  
  31.         internal static void RemoveHubId(HttpContextBase context, string hubId)
  32.         {
  33.             try
  34.             {
  35.                 List<UserToHub> _listeners = context.Cache["Suzct_NotificationsListeners"] as List<UserToHub> ?? new List<UserToHub>();
  36.  
  37.                 _listeners.RemoveAll(m => m.hubid == hubId);
  38.  
  39.                 context.Cache["Suzct_NotificationsListeners"] = _listeners;
  40.  
  41.                 ListenersDebugOutput(context);
  42.             }
  43.             catch (Exception e)
  44.             {
  45.                 LogWriter.InsertException(e, HttpContext.Current.User);
  46.             }
  47.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement