Exemplo n.º 1
0
 public async Task Notice(MessageType messageType, string title, string message, string username = null)
 {
     await Task.Run(() =>
     {
         var dyn = new
         {
             type = messageType.Description(),
             title,
             message
         };
         if (!string.IsNullOrWhiteSpace(username))
         {
             //Singlecast notice
             username = UserNameAdapter.Adapt(username);
             Logger.Info("send notice to " + username);
             Context.Clients.Group(username).addNoticeToPage(dyn);
         }
         else
         {
             //Multicast notice
             Logger.Info("multicast notice send");
             Context.Clients.All.addNoticeToPage(dyn);
         }
     });
 }
Exemplo n.º 2
0
 public DtoApprover GetCurrentApproverByLogin(string employeeLogin, bool isAdmin = false)
 {
     employeeLogin = UserNameAdapter.Adapt(employeeLogin);
     if (string.IsNullOrWhiteSpace(employeeLogin))
     {
         return(null);
     }
     using (var db = new KadrDataContext())
     {
         var idEmployee =
             db.Employees.FirstOrDefault(w => w.EmployeeLogin.ToLower() == employeeLogin.ToLower());
         return(idEmployee != null?DtoClassConstructor.DtoApprover(db, idEmployee.id, isAdmin) :
                    DtoClassConstructor.DtoApproverIfNullAndAdmin(db, isAdmin));
     }
 }
Exemplo n.º 3
0
 public override Task OnConnected()
 {
     try
     {
         var name         = UserNameAdapter.Adapt(base.Context.User.Identity.Name);
         var connectionId = base.Context.ConnectionId;
         _userNameAndConnectionId.Add(connectionId, name);
         Groups.Add(base.Context.ConnectionId, name);
         Logger.Info("connect as " + name);
     }
     catch (System.Exception ex)
     {
         Logger.Error(ex);
     }
     return(base.OnConnected());
 }
Exemplo n.º 4
0
 public override Task OnReconnected()
 {
     try
     {
         var connectionId = base.Context.ConnectionId;
         var name         = _userNameAndConnectionId.FirstOrDefault(f => f.Key == connectionId).Value;
         if (string.IsNullOrWhiteSpace(name))
         {
             Groups.Remove(base.Context.ConnectionId, name);
             Logger.Info("disconnect as " + name);
             name = UserNameAdapter.Adapt(base.Context.User.Identity.Name);
             _userNameAndConnectionId.Add(connectionId, name);
             Groups.Add(base.Context.ConnectionId, name);
         }
         Logger.Info("reconnect as " + name);
     }
     catch (System.Exception ex)
     {
         Logger.Error(ex);
     }
     return(base.OnReconnected());
 }