Exemple #1
0
        public Notification(string notificationId, string notificationType, string notificationTypeDescription, NotificationLogLevel logLevel, string message, object data)
        {
            NotificationId          = notificationId;
            NotificationType        = notificationType;
            NotificationDescription = notificationTypeDescription;
            LogLevel = logLevel.ToString();
            Message  = message;
            Data     = data;

            NotificationDate = DateTime.Now;
        }
Exemple #2
0
        /// <summary>
        /// Send notification message to active clients
        /// </summary>
        /// <param name="notificationType">Type of notification</param>
        /// <param name="logLevel">Log level (UI display)</param>
        /// <param name="message">Message to display</param>
        /// <param name="data">Additional details (custom class)</param>
        public string Notify(string notificationType, string notificationTypeDescription, NotificationLogLevel logLevel, string message, object data = null, string notificationId = null)
        {
            bool isUpdate = !string.IsNullOrEmpty(notificationId);

            notificationId = isUpdate ? notificationId : Guid.NewGuid().ToString();

            string userName        = this.UserIdentity.UserName;
            string domainName      = this.UserIdentity.DomainName;
            string environmentName = this.UserIdentity.EnvironmentName;

            Notification notification = new Notification(notificationId, notificationTypeDescription, notificationType, logLevel, message, data);

            lock (_notificationLock)
            {
                string notificationTag = string.Format("{0}|{1}|{2}", userName, domainName, environmentName);
                if (!_notifications.ContainsKey(notificationTag))
                {
                    _notifications.Add(notificationTag, new List <Notification>());
                }

                var notifications = _notifications[notificationTag];

                if (isUpdate)
                {
                    // Remove Existing Notification
                    var existingNotification = notifications.FirstOrDefault(n => n.NotificationId.Equals(notificationId));
                    notifications.Remove(existingNotification);
                }

                notifications.Add(notification);
            }

            foreach (var connectionInfo in _connectedSessions.Where(connection => connection.Equals(userName, domainName, environmentName)))
            {
                var context = GlobalHost.ConnectionManager.GetHubContext <MarkelHub>();
                context.Clients.Client(connectionInfo.ConnectionId).Notify(notification);
            }

            return(notificationId);
        }