public INotifyObject[] Compose(AlarmObject alarmObject) { NotifyPopupAddressList notificationPopupAddressList = null; string popupMessage = ""; /*Notify List*/ List <INotifyObject> notifyList = new List <INotifyObject>(); /*Initialize NotifySettings*/ NotificationStyle notificationStyle = new NotificationStyle(); if (alarmObject.IsMissCommNotification) { _logContent = "Missed Communication"; } else { _logContent = "SensorID: " + alarmObject.UTID.ToStr() + " SensorAlarmID: " + alarmObject.SensorAlarmID.ToStr(); } /*Check whether server popup or remote popup*/ if (alarmObject.IsServerPopup) { /*Write Log: * Started Server popup Notification * Reached Server popup Notification Composer*/ LogBook.Write("*** Started Composing Server popup Notification for " + _logContent + "***"); /*Get custom message for missed communication*/ if (alarmObject.IsMissCommNotification) { popupMessage = "Missed Communication" + " [" + alarmObject.MissedCommSensorCount + "] sensors"; } else { /*Get popup message*/ popupMessage = notificationStyle.GetFormatString(alarmObject, 1, "Popup"); /*Substitute message parameters*/ popupMessage = notificationStyle.SubstituteFormatString(popupMessage, alarmObject); } /*Server popup*/ NotifyPopupAddress notifyPopupAddress = new NotifyPopupAddress(); notifyPopupAddress.NetSendTo = ConfigurationManager.AppSettings.Get("NetSendTo").ToStr(); notifyPopupAddress.Name = ConfigurationManager.AppSettings.Get("NetSendFromName").ToStr(); /*Get Notification Object*/ INotifyObject notifyObject = GetNotifyObject(alarmObject, popupMessage, notifyPopupAddress); if (notifyList.Count > 0) { /*Write Log * Sending Server Popup notification data to Notification Engine*/ LogBook.Write(_logContent + " Sending notification data to Server Popup Notification Engine."); } notifyList.Add(notifyObject); } else { /*Write Log: * Started Server popup Notification * Reached Server popup Notification Composer*/ LogBook.Write("*** Started Composing Remote popup Notification for " + _logContent + "***"); /*Get custom message for missed communication*/ if (alarmObject.IsMissCommNotification) { popupMessage = "Missed Communication" + " [" + alarmObject.MissedCommSensorCount + "] sensors"; } else { /*Get NetSend message*/ popupMessage = notificationStyle.GetFormatString(alarmObject, 1, "NetSend"); /*Notification Tree*/ string notifyTree = notificationStyle.GetFormatString(alarmObject, 1, "NotifyTree"); /*Format Subject*/ string netSendMsg = notificationStyle.SubstituteFormatString(popupMessage, alarmObject); popupMessage = netSendMsg; /*Format Notify Tree*/ string netTreeMsg = notificationStyle.SubstituteFormatString(notifyTree, alarmObject); notifyTree = netTreeMsg; if (notifyTree != string.Empty) { popupMessage = popupMessage + "%%NOTIFYTREE%%" + notifyTree; } } /*Get Notification Popup Address List*/ notificationPopupAddressList = GetNotifyPopupAddressList(alarmObject); if (notificationPopupAddressList.Count != 0) { /*Get Popup Notification list*/ notifyList = GetNotificationList(notificationPopupAddressList, alarmObject, popupMessage); } else { /*Log when we don't have Popup address to notify*/ LogBook.Write(_logContent + " Error: Missing entry in NotifyEmails/Groups"); } if (notifyList.Count > 0) { /*Write Log * Sending Remote Popup notification data to Notification Engine*/ LogBook.Write(_logContent + " Sending notification data to Remote Popup Notification Engine."); } } return(notifyList.ToArray()); }
/// <summary> /// /// </summary> /// <param name="alarmObject"></param> /// <returns></returns> private NotifyObject GetNotifyObject(AlarmObject alarmObject, string popupMessage, NotifyPopupAddress notifyPopupAddress) { string alertTime = "", location = "", temperatureReading = "", notificationData = ""; /*Initialize NotifyObject*/ NotifyObject notifyObject = new NotifyObject(); /*Notification settings*/ NotificationStyle notificationStyle = new NotificationStyle(); /*Alert Time*/ alertTime = alarmObject.AlarmTime.ToLocalTime().ToString(); //Common.LocalTimeToUTC(alarmObject.AlarmTime, Common.TZ_OFFSET).ToStr(); alertTime = (alertTime == string.Empty ? DateTime.Now.ToStr() : alertTime); /*Location*/ location = alarmObject.ProbeName.ToStr() + (alarmObject.GroupName.ToStr() != string.Empty ? ("(" + alarmObject.GroupName + ")") : ""); /*HOT COLD*/ //Check for contact sensor if (AlarmHelper.IsContactSensor(alarmObject.SensorType)) { temperatureReading = (alarmObject.Value == 0) ? "CLOSED" : "OPEN"; } else { temperatureReading = (alarmObject.Value < alarmObject.AlarmMinValue) ? "LOW" : "HIGH"; } /*Building the alert message data*/ notificationData = "<alert><msg>" + HtmlEncode(popupMessage) + "</msg>" + "<time_local>" + HtmlEncode(alertTime) + "</time_local>" + "<time_gmt>" + HtmlEncode(alarmObject.AlarmTime.ToStr()) + "</time_gmt>" + "<loc>" + HtmlEncode((alarmObject.GroupName.ToStr())) + "</loc>" + "<name>" + HtmlEncode((alarmObject.ProbeName.ToStr())) + "</name>" + "<type>" + HtmlEncode((alarmObject.SensorType.ToStr())) + "</type>" + "<class>" + HtmlEncode((alarmObject.SensorClass.ToStr())) + "</class>" + "<alertType>" + HtmlEncode((temperatureReading)) + "</alertType>" + "</alert>"; string temp = "00000000"; int strLength = temp.Length - notificationData.Length.ToString().Length; notificationData = temp.Substring(0, strLength) + notificationData.Length + notificationData; /*Assign values to Notification settings*/ Hashtable notificationSettings = new Hashtable(); /*Remote Port*/ notificationSettings.Add("RemotePort", ConfigurationManager.AppSettings["PortNumber"]); /*Remote Host*/ notificationSettings.Add("RemoteHost", notifyPopupAddress.NetSendTo); /*Name that was configured in temp trak application*/ notificationSettings.Add("Name", notifyPopupAddress.Name); /*Notification ID*/ notificationSettings.Add("NotificationID", alarmObject.NotificationID); /*Notification settings*/ notifyObject.NotifierSettings = notificationSettings; /*Pop up message*/ notifyObject.NotificationData = notificationData; /*Set Notification Type*/ notifyObject.NotificationType = (alarmObject.IsServerPopup) ? "ServerPopup" : "RemotePopup"; return(notifyObject); }