Пример #1
0
        private void AddNotificationToList(AlarmObject alarmObject)
        {
            var list = from info in PreviousNotificationsList
                       where info.SensorAlarmID == alarmObject.SensorAlarmID && info.NotifyProfileID == alarmObject.NotifyProfileID
                       select info;

            /*if the same message board is exists for this sensor, do not add this board information*/
            if (list.Count() > 0)
            {
                return;
            }

            PreviousNotifications previousNotifications = new PreviousNotifications()
            {
                NotificationID  = alarmObject.NotificationID,
                NotifyProfileID = alarmObject.NotifyProfileID,
                SensorAlarmID   = alarmObject.SensorAlarmID,
            };

            PreviousNotificationsList.Add(previousNotifications);
        }
Пример #2
0
        public INotifyObject[] Compose(AlarmObject alarmObject)
        {
            List <INotifyObject> notifyList = null;

            try
            {
                notifyList = new List <INotifyObject>();
                LogBook.Write("Executing compose method");

                //if the dynamic notification is already cleared , no need to send to Notify objects list to notify engine
                if (alarmObject.IsDynamicNotificationClearProcessStarted == true)
                {
                    return(new List <INotifyObject>().ToArray());
                }
                //if IsDynamicNotificationCleared is true we need to set the below flag in order skip notifications
                //received from any escalations while the clear process is going on
                if (alarmObject.IsDynamicNotificationCleared)
                {
                    alarmObject.IsDynamicNotificationClearProcessStarted = true;
                }

                //to store the message
                string message = string.Empty;



                LogBook.Write("Formatting the message");
                //create instance of notification style to generate format strings, parse it
                NotificationStyle notificationStyle = new NotificationStyle();

                //get the message from the alarm object
                message = alarmObject.Value == null ? string.Empty : alarmObject.Value.ToString();

                //if message length is greater than zero, get the format string for the message
                if (message.Length > 0)
                {
                    message = notificationStyle.GetFormatString(alarmObject, 1, "MessageBoard");
                }

                //replace line breaks with spaces
                message = message.Replace("\\n", " ");

                //substitute actual values for the format strings using the alarm object
                message = notificationStyle.SubstituteFormatString(message, alarmObject);

                LogBook.Write("Completed message formatting");

                //to format the message for missed communications
                if (alarmObject.IsMissCommNotification == true)
                {
                    LogBook.Write("Constructing missed comm message");
                    message = "Missed Communication" + " [" + alarmObject.MissedCommSensorCount + "] sensors";
                }

                if (alarmObject.IsDynamicNotificationCleared)
                {
                    var prvNotificationList = from info in PreviousNotificationsList
                                              where info.SensorAlarmID == alarmObject.SensorAlarmID
                                              select info;
                    CurrentClearedBoards = string.Empty;
                    for (int index = prvNotificationList.Count() - 1; index >= 0; index--)
                    {
                        PreviousNotifications info = prvNotificationList.ToList <PreviousNotifications>()[index];
                        alarmObject.NotificationID  = info.NotificationID;
                        alarmObject.NotifyProfileID = info.NotifyProfileID;

                        PreapreMessage(alarmObject, message, ref notifyList);
                        PreviousNotificationsList.Remove(info);
                    }
                }
                else
                {
                    if (!alarmObject.SetServerTime)
                    {
                        AddNotificationToList(alarmObject);
                    }
                    PreapreMessage(alarmObject, message, ref notifyList);
                }
            }
            catch (Exception ex)
            {
                LogBook.Write(ex, " CooperAtkins.NotificationClient.NotificationComposer.MsgBrdNotificationComposer");
            }

            return(notifyList.ToArray());
        }