Example #1
0
        private IEnumerable <Message> OnAppStarted(AppStarting arg)
        {
            var ongoingAlerts = _unitOfWork.AlertRepository.GetList().Where(a => a.Status != StatusType.Closed);

            _ongoingAlerts.AddRange(ongoingAlerts);

            return(JanelObserver.Success());
        }
Example #2
0
        private IEnumerable <Message> SendNotificationWithAcknowledge(DateTime sentDate, Person to, CommunicationType communicationType, string message, Notification notification, object source)
        {
            var communication = new Communication {
                SentOn = sentDate,
                SentTo = to,
                Type   = communicationType
            };

            if (notification == null)
            {
                var appUrl = ConfigurationManager.AppSettings["Website_Url"] ?? _contextAccessor?.HttpContext.Request.Host.Host;
                notification = new Notification {
                    Message = $"{message}\n\nClick here to take action {appUrl}",
                    Source  = source
                };

                _ongoingNotifications.Add(notification);
            }

            notification.MessagesSent.Add(communication);

            communication.IsSentSuccessfully = SendNotification(to, notification.Message, communication.Type);

            _janelUnitOfWork.NotificationRepository.Insert(notification);

            if (communication.IsSentSuccessfully)
            {
                return(JanelObserver.Success());
            }
            else
            {
                var error = $"Unable to send notification {notification.Id}";

                JanelObserver.EventManager.Dispatch(new ErrorOccurred(error));

                return(new List <Message> {
                    new Message {
                        Description = error, Succeeded = false
                    }
                });
            }
        }
Example #3
0
        private IEnumerable <Message> ValidateSentNotifications(TaskTimerElapsed arg)
        {
            var notificationsToRemove = new List <Notification>();

            foreach (var notification in _ongoingNotifications)
            {
                if (notification.MessagesSent.Last().SentOn.AddMinutes(3) >= _dateTimeManager.GetNow())
                {
                    //3 minutes elapsed. Need to do something
                    if (notification.MessagesSent.Count >= 3)
                    {
                        //Responsible never responded
                        notificationsToRemove.Add(notification);
                        JanelObserver.EventManager.Dispatch(new NotificationNotResponded(notification));
                    }
                    else
                    {
                        //Retry sending a message
                        var sendItTo = notification.MessagesSent.Last().SentTo;
                        var nbMessageSentToThisGuy = notification.MessagesSent.Where(m => m.SentTo == sendItTo).Count();

                        var communicationType = nbMessageSentToThisGuy <= sendItTo.PreferedCommunications.Count ?
                                                sendItTo.PreferedCommunications.ElementAt(nbMessageSentToThisGuy) :
                                                sendItTo.PreferedCommunications.Last();

                        SendNotificationWithAcknowledge(_dateTimeManager.GetNow(), sendItTo, communicationType, notification.Message, notification, null);

                        _janelUnitOfWork.NotificationRepository.Update(notification);
                    }
                }
            }

            if (notificationsToRemove.Any())
            {
                notificationsToRemove.ForEach(n => _ongoingNotifications.Remove(n));
            }

            return(JanelObserver.Success());
        }
Example #4
0
        private IEnumerable <Message> OnAlertNotResponded(NotificationNotResponded arg)
        {
            var alert = arg.Notification.Source as Alert;

            if (alert.Status == StatusType.Transferring)
            {
                //Tranfert failed. Message back to responsible
                var firstResponsible = alert.Actors.First();

                _notificationManager.SendNotification(firstResponsible, $"Alert cannot be transfered. {alert.Responsible.Name} did not respond", firstResponsible.PreferedCommunications.First());

                alert.Responsible = firstResponsible;
                alert.Status      = StatusType.New;
                alert.UpdatedAt   = _dateTimeManager.GetNow();

                _unitOfWork.AlertRepository.Update(alert);
            }
            else
            {
                EscalateAlert(alert);
            }

            return(JanelObserver.Success());
        }
Example #5
0
        private IEnumerable <Message> ValidatePendingAlerts(TaskTimerElapsed arg)
        {
            foreach (var alert in _ongoingAlerts)
            {
                switch (alert.Status)
                {
                case StatusType.Acknowledge:
                case StatusType.Fixed:
                case StatusType.Transferring:
                    if (alert.UpdatedAt.AddMinutes(60) >= _dateTimeManager.GetNow())
                    {
                        EscalateAlert(alert);
                    }
                    break;

                case StatusType.Escalated:
                    if (alert.UpdatedAt.AddMinutes(60) >= _dateTimeManager.GetNow())
                    {
                        //In Deep shit !
                        var newResponsible = _scheduleManager.GetNextPersonInCharge(alert.Responsible);

                        alert.Status       = StatusType.Transferring;
                        alert.Description += $"\n\nAlert were escalated but was still not responded.";
                        alert.UpdatedAt    = _dateTimeManager.GetNow();

                        _unitOfWork.AlertRepository.Update(alert);

                        JanelObserver.EventManager.Dispatch(new AlertChanged(alert, StatusType.Transferring.ToString()));
                        JanelObserver.EventManager.Dispatch(new AlertReceived(alert, newResponsible));
                    }
                    break;
                }
            }

            return(JanelObserver.Success());
        }
Example #6
0
        private IEnumerable <Message> Acknowledge(NotificationAcknowledge arg)
        {
            Acknowledge((Alert)arg.Notification.Source, arg.By);

            return(JanelObserver.Success());
        }