public void SendNotification(IEnumerable <Guid> users, Notification.Entity.SignalR.Notification notification) { try { LogBusiness.Info(string.Format("[NotificationHub] SendNotification (connectionId: {0})", Context.ConnectionId)); if (users == null || !users.Any()) { LogBusiness.Warn(string.Format("[NotificationHub] SendNotification - Listagem de usuários vazia (connectionId: {0})", Context.ConnectionId)); return; } if (notification == null) { LogBusiness.Warn(string.Format("[NotificationHub] SendNotification - Notificação vazia (connectionId: {0})", Context.ConnectionId)); return; } foreach (var user in users) { LogBusiness.Debug(string.Format("[NotificationHub] SendNotification - Notificação ({0}) enviada para o usuário ({1})", notification.Id, user)); Clients.Group(user.ToString()).ReceiveNotification(notification); } } catch (Exception exc) { LogBusiness.Error(exc); throw; } }
public override Task OnDisconnected(bool stopCalled) { try { LogBusiness.Info(string.Format("[NotificationHub] OnDisconnected (connectionId: {0})", Context.ConnectionId)); var principal = this.Context.User as ClaimsPrincipal; var getUserId = from c in principal.Identities.First().Claims where c.Type == CLAIM_USERID select c.Value;//.FirstOrDefault(); var userId = getUserId.FirstOrDefault(); if (userId != null) { LogBusiness.Debug(string.Format("[NotificationHub] Grupo ({0}) removido (connectionId: {1})", userId, Context.ConnectionId)); Groups.Remove(Context.ConnectionId, userId.ToString()); } return(base.OnDisconnected(stopCalled)); } catch (Exception exc) { LogBusiness.Error(exc); throw; } }
public static void SendNotification(IEnumerable <Guid> users, Guid notificationId) { try { var notif = NotificationBusiness.GetById(notificationId); if (notif == null) { LogBusiness.Warn(string.Format("[SignalRClientBusiness] SendNotification - Notificação não encontrada ({0})", notificationId)); return; } if ((notif.DateStartNotification > DateTime.Now.Date) || (notif.DateEndNotification != null && DateTime.Now.Date > notif.DateEndNotification)) { LogBusiness.Info(string.Format("[SignalRClientBusiness] SendNotification - Notificação fora do período programado ({0})", notificationId)); return; } var notifP = new Notification.Entity.SignalR.Notification() { Id = notif.Id, Title = notif.Title, Message = notif.Message }; var hubConnection = new HubConnection(UrlSignalRServer); var hub = hubConnection.CreateHubProxy("notificationHub"); hubConnection.Headers.Add("Authorization", "Basic " + Base64Encode(UserCredentialSignalRServer, PasswordCredentialSignalRServer)); hubConnection.Start().Wait(); int i = 0; int total = users.Count(); while (i < total) { var ltU = users.Skip(i).Take(1000).ToList(); LogBusiness.Debug(string.Format("[SignalRClientBusiness] SendNotification - Enviando... ({0}-{1})", i, ltU.Count)); hub.Invoke("SendNotification", ltU, notifP).Wait(); i += 1000; } hubConnection.Stop(); } catch (Exception exc) { LogBusiness.Error(exc); throw; } }
private void LoadUrlIdenityServerConfiguration() { try { urlIdentityServer = ConfigurationManager.AppSettings["urlIdentityServer"]; scopesIdentityServer = ConfigurationManager.AppSettings["scopesIdentityServer"]; LogBusiness.Debug(string.Format("Configuração de Identity: Url({0}), Scope({1})", urlIdentityServer, scopesIdentityServer)); } catch (Exception exc) { LogBusiness.Error(exc); } }
private void LoadLogConfiguration() { try { bool value; var config = ConfigurationManager.AppSettings[LogBusiness.ConfigIsEnabledDebug]; if (config != null && bool.TryParse(config, out value)) { LogBusiness.IsEnabledDebug = value; } config = ConfigurationManager.AppSettings[LogBusiness.ConfigIsEnabledInfo]; if (config != null && bool.TryParse(config, out value)) { LogBusiness.IsEnabledInfo = value; } config = ConfigurationManager.AppSettings[LogBusiness.ConfigIsEnabledWarn]; if (config != null && bool.TryParse(config, out value)) { LogBusiness.IsEnabledWarn = value; } config = ConfigurationManager.AppSettings[LogBusiness.ConfigIsEnabledError]; if (config != null && bool.TryParse(config, out value)) { LogBusiness.IsEnabledError = value; } LogBusiness.Debug( string.Format("Configuração de Log: Debug({0}), Info({1}), Warn({2}), Error({3})", LogBusiness.IsEnabledDebug, LogBusiness.IsEnabledInfo, LogBusiness.IsEnabledWarn, LogBusiness.IsEnabledError)); } catch (Exception exc) { LogBusiness.Error(exc); } }
private void LoadSignalRServerConfiguration() { try { var config = ConfigurationManager.AppSettings[SignalRClientBusiness.CONFIG_URLSIGNALRSERVERHUB]; if (config != null) { SignalRClientBusiness.UrlSignalRServer = config; LogBusiness.Debug(string.Format("Configuração de SignalRServer: Url({0})", SignalRClientBusiness.UrlSignalRServer)); } else { LogBusiness.Warn("Configuração de UrlSignalRServerHub não encontrada."); } SignalRClientBusiness.UserCredentialSignalRServer = ConfigurationManager.AppSettings[Business.Signal.SignalRClientBusiness.CONFIG_USERCREDENTIALSIGNALRSERVER]; SignalRClientBusiness.PasswordCredentialSignalRServer = ConfigurationManager.AppSettings[Business.Signal.SignalRClientBusiness.CONFIG_PASSWORDCREDENTIALSIGNALRSERVER]; } catch (Exception exc) { LogBusiness.Error(exc); } }