/// <summary> /// Get Notification E-Mail Address list based on Notification Profile ID /// </summary> /// <param name="alarmObject"></param> /// <returns></returns> private NotifyEmailAddressList GetNotifyEmailAddressList(int notifyProfileID) { NotifyEmailAddressList notifyEmailAddressList = null; try { /*Create NotifyEmailAddressList object*/ notifyEmailAddressList = new NotifyEmailAddressList(); /*Create Criteria object*/ Criteria criteria = new Criteria(); /*Get the Email notificationId and assign to criteria.ID*/ criteria.ID = GetEmailNotificationID(notifyProfileID); /*Gets list of notification email addresses*/ notifyEmailAddressList.Load(criteria); } catch (Exception ex) { /*Debug Object values for reference*/ LogBook.Debug(notifyEmailAddressList, this); /*Write exception log*/ LogBook.Write("Error has occurred while fetching email address list from 'GenNotifyEmails' table", ex, "CooperAtkins.NotificationClient.NotificationComposer.EmailNotificationComposer"); } finally { notifyEmailAddressList.Dispose(); } return(notifyEmailAddressList); }
/// <summary> /// Get Email notification list /// </summary> /// <param name="notifyEmailAddressList"></param> /// <returns></returns> private List <INotifyObject> GetNotificationList(NotifyEmailAddressList notifyEmailAddressList, AlarmObject alarmObject, GenStoreInfo genStoreInfo) { List <INotifyObject> notifyList = new List <INotifyObject>(); NotificationStyle notificationStyle = new NotificationStyle(); foreach (NotifyEmailAddress notifyEmailAddress in notifyEmailAddressList) { /*Check for Notification Email Address and exit the sending process, if NotificationEmailAddress object is NULL*/ if (notifyEmailAddress != null) { /*Get Notification Object*/ INotifyObject notifyObject = GetNotifyObject(alarmObject, genStoreInfo, notifyEmailAddress); if (notifyObject.NotifierSettings["FromAddress"].ToStr() == string.Empty || notifyObject.NotifierSettings["ToAddress"].ToStr() == string.Empty) { /*Record notification if Email (To/From) Address parameters are not supplied properly*/ notificationStyle.RecordNotification(ErrorMessages.EmailComposer_InvalidEmailAddress, alarmObject.NotificationID, 0, NotifyStatus.FAIL, NotifyTypes.EMAIL); } else { //Add notification object to array list notifyList.Add(notifyObject); } } else { /*Record notification if Email Address parameters are not supplied properly*/ notificationStyle.RecordNotification(ErrorMessages.EmailComposer_EmailParamsNotSupplied, alarmObject.NotificationID, 0, NotifyStatus.FAIL, NotifyTypes.EMAIL); } } return(notifyList); }
public INotifyObject[] Compose(AlarmObject alarmObject) { GenStoreInfo genStoreInfo = null; NotifyEmailAddressList notifyEmailAddressList = null; List <INotifyObject> notifyList = new List <INotifyObject>(); NotificationStyle notificationStyle = new NotificationStyle(); /*Get GenStore Information*/ genStoreInfo = GenStoreInfo.GetInstance(); if (alarmObject.IsMissCommNotification) { _logContent = "Missed Communication"; } else { _logContent = "SensorID: " + alarmObject.UTID.ToStr() + " SensorAlarmID: " + alarmObject.SensorAlarmID.ToStr(); } /*Write Log: * Started Email Notification * Reached Email Notification Composer*/ LogBook.Write("*** Started Composing E-Mail Notification for " + _logContent + "***"); try { //If there's no record in the database, Execute method will return null if (genStoreInfo != null) { /*Record notification if SMTP settings are not supplied properly*/ if ((genStoreInfo.SmtpServer.ToStr() == string.Empty && genStoreInfo.SmtpAuthDomain == string.Empty) && genStoreInfo.SmtpSendMethod == 0) { /*SMTP server not defined*/ LogBook.Write(_logContent + " Error: No SMTP Server has been defined."); /*Record notification if SMTP parameters are not supplied properly*/ notificationStyle.RecordNotification(ErrorMessages.EmailComposer_SMTPParmsNotSupplied, alarmObject.NotificationID, 0, NotifyStatus.FAIL, NotifyTypes.EMAIL); } else { /*Get all the email addresses that are configured for notification*/ notifyEmailAddressList = GetNotifyEmailAddressList(alarmObject); if (notifyEmailAddressList.Count != 0) { /*Construct a notification object for each email address and add to the notification list*/ notifyList = GetNotificationList(notifyEmailAddressList, alarmObject, genStoreInfo); LogBook.Write("Email Notification count: " + notifyList.Count.ToString()); } else { /*Log when we don't have Email address to notify*/ LogBook.Write(_logContent + " Error: Missing entry in NotifyEmails/Groups."); } } } else { /*Record notification if genStore parameters are not supplied properly.*/ notificationStyle.RecordNotification(ErrorMessages.EmailComposer_GenStoreInvalid, alarmObject.NotificationID, 0, NotifyStatus.FAIL, NotifyTypes.EMAIL); /*Log if genStore information is empty*/ LogBook.Write(_logContent + " Error: Missing GenStores table record."); } } catch (Exception ex) { /*Write exception log*/ //LogBook.Write(_logContent + " " + ex); LogBook.Write(_logContent + " Error: ", ex, "CooperAtkins.NotificationClient.NotificationComposer.EmailNotificationComposer"); //, "CooperAtkins.NotificationClient.NotificationComposer.EmailNotificationComposer"); } //if (notifyList.Count > 0) /*Write Log * Sending Email notification data to Notification Engine*/ LogBook.Write(_logContent + " Sending notification data to Email Notification Engine."); /*Send notification list to notification engine*/ return(notifyList.ToArray()); }