/// <summary> /// Get Pager Notification Address List /// </summary> /// <param name="alarmObject"></param> /// <returns></returns> private NotifyPagerAddressList GetPagerAddressList(Interface.Alarm.AlarmObject alarmObject) { NotifyPagerAddressList notifyPagerAddressList = null; try { /*Fetch Email Address list based on Notification Profile ID*/ notifyPagerAddressList = new NotifyPagerAddressList(); Criteria criteria = new Criteria(); criteria.ID = GetPagerNotificationID(alarmObject.NotifyProfileID);//Replace with notifyPagerAddressList.Load(criteria); } catch (Exception ex) { /*Debug Object values for reference*/ LogBook.Debug(notifyPagerAddressList, this); /*Write exception log*/ LogBook.Write(_logContent + " Error has occurred while fetching pager address list from 'GenNotifyPagers' table", ex, "CooperAtkins.NotificationClient.NotificationComposer.PagerNotificationComposer"); } finally { notifyPagerAddressList.Dispose(); } return(notifyPagerAddressList); }
/// <summary> /// Get Notification E-Mail Address list based on Notification Profile ID /// </summary> /// <param name="alarmObject"></param> /// <returns></returns> private NotifyMobileList GetNotifyMoibilesList(int notifyProfileID) { NotifyMobileList notifyMobileList = null; try { LogBook.Write("Fetching Mobile notify ID list"); /*Create NotifySmsAddressList object*/ notifyMobileList = new NotifyMobileList(); /*Create Criteria object*/ Criteria criteria = new Criteria(); /*Get the Sms notificationId and assign to criteria.ID*/ criteria.ID = GetMobileNotificationID(notifyProfileID); /*Gets list of notification sms addresses*/ notifyMobileList.Load(criteria); LogBook.Write("Notify Mobile ID list count: " + notifyMobileList.Count); } catch (Exception ex) { /*Debug Object values for reference*/ LogBook.Debug(notifyMobileList, this); /*Write exception log*/ LogBook.Write("Error has occurred while fetching mobile numbers list from 'GenNotifySms' table", ex, "CooperAtkins.NotificationClient.NotificationComposer.SMSNotificationComposer"); } finally { notifyMobileList.Dispose(); } return(notifyMobileList); }
public NotifyComResponse Invoke(INotifyObject notifyObject) { NotifyComResponse response; ScriptHelper client = new ScriptHelper(notifyObject); /*Log * Notification data received from email notification composer * Executing Script...*/ LogBook.Write("Notification data received from Script Notification Composer"); LogBook.Write("Executing Script"); try { /* sending notification.*/ response = client.Send(); /*Log : Sending response to Script Notification Composer */ LogBook.Write("Sending response to Script Notification Composer"); } catch (Exception ex) { response = new NotifyComResponse(); response.IsSucceeded = false; response.IsError = true; //response.ResponseContent = ex.Message + "\n" + ex.StackTrace; /*Debug Object values for reference*/ LogBook.Debug(response, this); /*Write exception log*/ LogBook.Write(ex, "CooperAtkins.NotificationServer.NotifyEngine.ScriptNotifyCom"); } return(response); }
/// <summary> /// Get Pager Notification ID /// </summary> /// <param name="notifyProfileID"></param> /// <returns></returns> private int GetPagerNotificationID(int notifyProfileID) { NotificationProfile notificationProfile = null; int pagerNotificationID = 0; try { notificationProfile = new NotificationProfile(); notificationProfile.NotifyProfileID = notifyProfileID; notificationProfile = notificationProfile.Execute(); pagerNotificationID = notificationProfile.PagerNotifyID; } catch (Exception ex) { /*Debug Object values for reference*/ LogBook.Debug(notificationProfile, this); /*Write exception log*/ LogBook.Write(_logContent + " Error has occurred while fetching PagerNotifyID ", ex, "CooperAtkins.NotificationClient.NotificationComposer.PagerNotificationComposer"); } finally { notificationProfile.Dispose(); } return(pagerNotificationID); }
public NotifyComResponse Invoke(INotifyObject notifyObject) { NotifyComResponse response; EmailClient client = new EmailClient(notifyObject); /*Log * Notification data received from email notification composer * Sending Email...*/ LogBook.Write("Notification data received from Email Notification Composer"); LogBook.Write("Sending Email notification to: " + notifyObject.NotifierSettings["ToAddress"].ToStr()); try { response = client.Send(); /*Log : Sending response to Email Notification Composer */ LogBook.Write("Sending response to Email Notification Composer"); } catch (Exception ex) { response = new NotifyComResponse(); response.IsSucceeded = false; response.IsError = true; //response.ResponseContent = ex.Message + "\n" + ex.StackTrace; /*Debug Object values for reference*/ LogBook.Debug(response, this); /*Write exception log*/ LogBook.Write(ex, "CooperAtkins.NotificationServer.NotifyEngine.INotifyCom"); } return(response); }
/// <summary> /// Get missed communication sensor list /// </summary> /// <returns></returns> private MissedCommunicationList GetMissedCommunicationList() { MissedCommunicationList missedCommunicationList = null; try { /*Create MissedCommunicationList instance*/ missedCommunicationList = new MissedCommunicationList(); /*Create empty Criteria object*/ Criteria criteria = new Criteria(); /*Execute to get the missed communication list*/ missedCommunicationList = missedCommunicationList.Load(criteria); } catch (Exception ex) { /*Debug Object values for reference*/ LogBook.Debug(missedCommunicationList, this); /*Write exception log*/ LogBook.Write("Error has occurred while fetching missed communication data.", ex, "CooperAtkins.NotificationClient.NotificationComposer"); } finally { missedCommunicationList.Dispose(); } return(missedCommunicationList); }
public INotifyObject[] Compose(AlarmObject alarmObject) { NotifyPagerAddressList notifyPagerAddressList = null; List <INotifyObject> notifyObjectList = null; if (alarmObject.IsMissCommNotification) { _logContent = "Missed Communication"; } else { _logContent = "SensorID: " + alarmObject.UTID.ToStr() + " SensorAlarmID: " + alarmObject.SensorAlarmID.ToStr(); } /*Write Log: * Started Pager Notification * Reached Pager Notification Composer*/ LogBook.Write("*** Started Composing Pager Notification for " + _logContent + "***"); try { /*Get Pager Address List*/ notifyPagerAddressList = GetPagerAddressList(alarmObject); LogBook.Debug("NotifyPagerAddressList count: " + notifyPagerAddressList.Count.ToStr()); /*Get notification List*/ notifyObjectList = GetNotificationList(notifyPagerAddressList, alarmObject); LogBook.Debug("NotifyObjectList count: " + notifyObjectList.Count.ToStr()); } catch (Exception ex) { /*Write exception log*/ if (_logContent.Trim() != string.Empty) { LogBook.Write(_logContent); } LogBook.Write(ex, "CooperAtkins.NotificationClient.NotificationComposer.PagerNotificationComposer"); } if (notifyObjectList.Count > 0) { /*Write Log * Sending Pager notification data to Notification Engine*/ LogBook.Write(_logContent + " Sending notification data to Pager Notification Engine."); } for (int index = notifyObjectList.Count - 1; index >= 0; index--) { INotifyObject notifyObject = notifyObjectList[index]; /*if the pager type is digital then add it to the queue, removing from the current list (queue will be processed separately)*/ if (notifyObject.NotifierSettings["DeliveryMethod"].ToInt() != 1) { DigitalPagerHelper.DigitalPagerQueue.Add(notifyObject); notifyObjectList.Remove(notifyObject); new NotificationStyle().RecordNotification("Page queued: " + notifyObject.NotifierSettings["ToAddress"].ToStr() + ", Message:" + notifyObject.NotifierSettings["PagerMessage"].ToStr(), notifyObject.NotifierSettings["NotificationID"].ToInt(), 0, NotifyStatus.STATUS, NotifyTypes.PAGER); } } return(notifyObjectList.ToArray()); }
/// <summary> /// Send Popup message /// </summary> /// <returns></returns> public NotifyComResponse Send() { NotifyComResponse notifyComResponse = new NotifyComResponse(); try { /*Send Pop up using UDP Client*/ NetworkClient networkClient = new NetworkClient(); networkClient.UdpClient(_remoteHost, _remotePort, _alertMessage); /*Record notify response*/ notifyComResponse.IsError = false; notifyComResponse.IsSucceeded = true; notifyComResponse.ResponseContent = "Popup message sent to [" + _addressBookName + "] " + _remoteHost; } catch (Exception ex) { /*Log remote port,host*/ /*Record notify response*/ notifyComResponse.IsError = true; notifyComResponse.IsSucceeded = false; notifyComResponse.ResponseContent = "Popup message to [" + _addressBookName + "] " + _remoteHost + " Failed."; /*Debug Object values for reference*/ LogBook.Debug(notifyComResponse, this); /*Write exception log*/ LogBook.Write("Error has occurred while sending popup to ." + _remoteHost, ex, "CooperAtkins.NotificationServer.NotifyEngine.POPUP.PopupClient"); } return(notifyComResponse); }
/// <summary> /// Record notification results in the database /// </summary> /// <param name="logText"></param> /// <param name="notificationID"></param> /// <param name="status"></param> /// <param name="notificationType"></param> public void RecordNotification(string logText, int notificationID, int transactionID, NotifyStatus status, NotifyTypes notificationType) { RecordNotification recordNotification = null; try { recordNotification = new RecordNotification(); /*Error or Notification response is recorded*/ recordNotification.LogText = logText; recordNotification.NotificationID = notificationID; recordNotification.TransID = transactionID; recordNotification.Status = status; recordNotification.NotifyType = notificationType; recordNotification.Execute(); } catch (Exception ex) { /*Debug Object values for reference*/ LogBook.Debug(recordNotification, this); /*Write exception log*/ LogBook.Write("Error has occurred while inserting record notification parameters into 'ttNotificationLog' table", ex, "CooperAtkins.NotificationClient.NotificationComposer.EmailNotificationComposer"); } finally { recordNotification.Dispose(); } }
/// <summary> /// Get FormatID /// </summary> /// <param name="alarmObject"></param> /// <param name="formatType"></param> /// <param name="action"></param> /// <returns></returns> private int GetFormatID(Interface.Alarm.AlarmObject alarmObject, string formatType, int action) { int sensorFormatID = 0; SensorFormatString sensorFormatString = null; try { sensorFormatString = new SensorFormatString(); sensorFormatString.UTID = alarmObject.UTID; sensorFormatString.Probe = alarmObject.Probe; sensorFormatString.FormatType = formatType; sensorFormatString.Action = action; sensorFormatString.Execute(sensorFormatString); sensorFormatID = sensorFormatString.SensorFormatID; } catch (Exception ex) { /*Debug Object values for reference*/ LogBook.Debug(sensorFormatString, this); /*Write exception log*/ LogBook.Write("Error has occurred while retrieving SensorFormatID", ex, "CooperAtkins.NotificationClient.NotificationComposer.Notification"); } finally { sensorFormatString.Dispose(); } return(sensorFormatID); }
/// <summary> /// Get active notification profile ids /// </summary> /// <returns></returns> private NotificationProfile GetActiveNotificationProfile(int storeID) { NotificationProfile notificationProfile = null; try { notificationProfile = new NotificationProfile(); notificationProfile.NotifyProfileID = _notifyProfileID; notificationProfile.StoreID = storeID; notificationProfile = notificationProfile.Execute(); } catch (Exception ex) { /*Debug Object values for reference*/ LogBook.Debug(notificationProfile, this); /*Write exception log*/ LogBook.Write("Error has occurred while fetching notification profile Ids ", ex, "CooperAtkins.NotificationClient.NotificationComposer.NotificationEligibility"); } finally { notificationProfile.Dispose(); } return(notificationProfile); }
public EmailClient(INotifyObject notifyObject) { try { /*Set Email parameters*/ _smtpServer = notifyObject.NotifierSettings["SMTPServer"].ToStr(); _sendMethod = notifyObject.NotifierSettings["SMTPSendMethod"].ToInt(); _fromAddress = notifyObject.NotifierSettings["FromAddress"].ToStr(); _toAddress = notifyObject.NotifierSettings["ToAddress"].ToStr(); _fromName = notifyObject.NotifierSettings["FromName"].ToStr(); _smtpPort = notifyObject.NotifierSettings["SMTPPort"].ToInt(); _subject = notifyObject.NotifierSettings["Subject"].ToStr(); _smtpAuthUserName = notifyObject.NotifierSettings["SMTPAuthUserName"].ToStr(); _smtpAuthPassword = notifyObject.NotifierSettings["SMTPAuthPassword"].ToStr(); _smtpAuthDomain = notifyObject.NotifierSettings["SMPTAuthDomain"].ToStr(); _smtpAuthMethod = notifyObject.NotifierSettings["SMTPAuthMethod"].ToStr(); _isSSL = notifyObject.NotifierSettings["IsSSL"].ToBoolean(); _isTLS = notifyObject.NotifierSettings["IsTLS"].ToBoolean(); _emailToName = notifyObject.NotifierSettings["EmailToName"].ToStr(); _readTimeOut = notifyObject.NotifierSettings["ReadTimeOut"].ToInt(); _isBodyHTML = notifyObject.NotifierSettings["IsBodyHTML"].ToBoolean(); _isAlphaPager = notifyObject.NotifierSettings["IsAlphaPager"].ToBoolean(); _body = notifyObject.NotificationData.ToStr(); } catch (Exception ex) { /*Debug Object values for reference*/ LogBook.Debug(notifyObject, this); /*Write exception log*/ LogBook.Write("Error has occurred while retrieving values from notification settings", ex, "CooperAtkins.NotificationServer.NotifyEngine.Email.EmailClient"); } }
/// <summary> /// Get E-mail Notification ID /// </summary> /// <param name="notifyProfileID"></param> /// <returns></returns> private int GetEmailNotificationID(int notifyProfileID) { NotificationProfile notificationProfile = null; int emailNotificationID = 0; try { /*Create NotificationProfile instance*/ notificationProfile = new NotificationProfile(); /*Send criteria notifyProfileID to get the Notification ID*/ notificationProfile.NotifyProfileID = notifyProfileID; /*Execute*/ notificationProfile = notificationProfile.Execute(); /*Assign the EmailNotifyID to local variable emailNotificationID*/ emailNotificationID = notificationProfile.EmailNotifyID; } catch (Exception ex) { /*Debug Object values for reference*/ LogBook.Debug(notificationProfile, this); /*Write exception log*/ LogBook.Write("Error has occurred while fetching EmailNotifyID ", ex, "CooperAtkins.NotificationClient.NotificationComposer.EmailNotificationComposer"); } finally { /*Dispose the notificationProfile object*/ notificationProfile.Dispose(); } return(emailNotificationID); }
public NotifyComResponse Invoke(INotifyObject notifyObject) { NotifyComResponse response; POPUP.PopupClient client = new POPUP.PopupClient(notifyObject); /*Log * Notification data received from Pager notification composer * Sending Pager...*/ LogBook.Write("Notification data received from Popup Notification Composer"); LogBook.Write("Sending Popup notification to: " + notifyObject.NotifierSettings["RemoteHost"].ToStr()); try { /*sending notification.*/ response = client.Send(); /*Log : Sending response to Email Notification Composer */ LogBook.Write("Sending response to Popup Notification Composer"); } catch (Exception ex) { response = new NotifyComResponse(); response.IsSucceeded = true; response.IsError = false; /*Debug Object values for reference*/ LogBook.Debug(response, this); /*Write exception log*/ LogBook.Write(ex, "CooperAtkins.NotificationServer.NotifyEngine.PopupNotifyCom"); } return(response); }
/// <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> /// Send Script for execution /// </summary> /// <returns></returns> public NotifyComResponse Send() { NotifyComResponse notifyComResponse = new NotifyComResponse(); try { /*log that script started*/ LogBook.Write("Notification Script Started"); Process process = new Process(); process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; process.StartInfo.Arguments = _scriptArguments; process.StartInfo.FileName = _scriptName; try { process.Start(); /*Record notify response*/ notifyComResponse.IsError = false; notifyComResponse.IsSucceeded = true; notifyComResponse.ResponseContent = "Script executed successfully."; } catch (Exception ex) { /*Record notify response*/ notifyComResponse.IsError = true; notifyComResponse.IsSucceeded = false; notifyComResponse.ResponseContent = "Script execution failed"; /*Debug Object values for reference*/ LogBook.Debug(notifyComResponse, this); /*Write exception log*/ LogBook.Write("Error has occurred while running the script.", ex, "CooperAtkins.NotificationServer.NotifyEngine.ScriptHelper"); } } catch (Exception ex) { /*Record notify response*/ notifyComResponse.IsError = true; notifyComResponse.IsSucceeded = false; notifyComResponse.ResponseContent = "Script execution failed"; /*Debug Object values for reference*/ LogBook.Debug(notifyComResponse, this); /*Write exception log*/ LogBook.Write("Error has occurred while preparing script settings.", ex, "CooperAtkins.NotificationServer.NotifyEngine.Script.ScriptHelper"); } return(notifyComResponse); }
public ScriptHelper(INotifyObject notifyObject) { try { /* get settings information.*/ _scriptName = notifyObject.NotifierSettings["ScriptName"].ToStr(); _scriptArguments = notifyObject.NotifierSettings["ScriptArgs"].ToStr(); } catch (Exception ex) { /*Debug Object values for reference*/ LogBook.Debug(notifyObject, this); /*Write exception log*/ LogBook.Write("Error has occurred while retrieving values from notification settings", ex, "CooperAtkins.NotificationServer.NotifyEngine.Script.ScriptClient"); } }
public NotifyComResponse Invoke(INotifyObject notifyObject) { NotifyComResponse response = null; PagerHelper client = new PagerHelper(notifyObject); /*Log * Notification data received from Pager notification composer * Sending Pager...*/ LogBook.Write("Notification data received from Pager Notification Composer"); LogBook.Write("Sending Pager notification to: " + notifyObject.NotifierSettings["ToAddress"].ToStr()); try { int waitingSecs = 0; response = client.Send(notifyObject); while (!client.ProcessCompleted) { Thread.Sleep(1 * 1000); waitingSecs++; if (waitingSecs > 120) { client.Message += "\r\nNo response from last 120 seconds, terminating the process"; response.IsError = true; break; } } if (notifyObject.NotifierSettings["DeliveryMethod"].ToInt() != 1) { response.ResponseContent = client.Message; } /*Log : Sending response to Email Notification Composer */ LogBook.Write("Sending response to Pager Notification Composer"); } catch (Exception ex) { /*Debug Object values for reference*/ LogBook.Debug(response, this); /*Write exception log*/ LogBook.Write(ex, "CooperAtkins.NotificationServer.NotifyEngine.INotifyCom"); } return(response); }
static void CWay2callDriver_OnNativeDeviceEvent(ushort DeviceID, uint Event, uint EventData, uint EventDataEx, byte[] pEventBuffer) { /* hang up the call if it raises call busy or disconnected event. */ if (w2cDrv.Device[DeviceID].EventDescription(Event, EventData).ToString().ToLower().Contains("busy")) { WriteLog("Call is Busy"); WriteLog("Hanging Up"); Hangup(); } else if (w2cDrv.Device[DeviceID].EventDescription(Event, EventData).ToString().ToLower().Contains("disconnected")) { WriteLog("disconnected"); WriteLog("Hanging Up"); Hangup(); } LogBook.Debug("DeviceID: " + DeviceID + ", Event:" + w2cDrv.Device[DeviceID].EventDescription(Event, EventData).ToString()); }
public PopupClient(INotifyObject notifyObject) { try { /* get remote popup settings. */ _remoteHost = notifyObject.NotifierSettings["RemoteHost"].ToStr(); _remotePort = notifyObject.NotifierSettings["RemotePort"].ToInt(); _addressBookName = notifyObject.NotifierSettings["Name"].ToStr(); _alertMessage = notifyObject.NotificationData.ToStr(); } catch (Exception ex) { /*Debug Object values for reference*/ LogBook.Debug(notifyObject, this); /*Write exception log*/ LogBook.Write("Error has occurred while retrieving values from notification settings", ex, "CooperAtkins.NotificationServer.NotifyEngine.POPUP.PopupClient"); } }
public PagerHelper(INotifyObject notifyObject) { try { _snppServer = notifyObject.NotifierSettings["SNPPServer"].ToStr(); _snppPort = notifyObject.NotifierSettings["SNPPPort"].ToInt(); _pagerSubject = notifyObject.NotifierSettings["PagerSubject"].ToStr(); _pagerToAddress = notifyObject.NotifierSettings["ToAddress"].ToStr(); _name = notifyObject.NotifierSettings["Name"].ToStr(); _pagerBody = notifyObject.NotificationData.ToStr(); } catch (Exception ex) { /*Debug Object values for reference*/ LogBook.Debug(notifyObject, this); /*Write exception log*/ LogBook.Write("Error has occurred while retrieving values from notification settings", ex, "CooperAtkins.NotificationServer.NotifyEngine.PagerHelper"); } }
/// <summary> /// Get contact state string /// </summary> /// <returns></returns> private string GetContactStateString(string utid, int probe, decimal state, int language) { string contactStateString = ""; ContactState contactState = null; try { contactState = new ContactState(); contactState.UTID = utid; contactState.Probe = probe; contactState.contactState = state; contactState.LanguageID = language; contactState.Execute(contactState); contactStateString = contactState.contactStateString; } catch (Exception ex) { /*Debug Object values for reference*/ LogBook.Debug(contactState, this); /*Write exception log*/ LogBook.Write("Error has occurred while retrieving contactStateString", ex, "CooperAtkins.NotificationClient.NotificationComposer.Notification"); } finally { contactState.Dispose(); } //Set default string if contact string doesn't exist if (contactStateString == string.Empty && state == 0) { contactStateString = "Closed"; } else if (contactStateString == string.Empty) { contactStateString = "Open"; } return(contactStateString); }
public NotifyComResponse Send() { notifyComResponse = new NotifyComResponse(); try { /*Send notification to Pager using SNPP Server*/ try { //snnpObj = new KTGUtil.SNPP(); using (SNPPWrapper snppObj = new SNPPWrapper()) { /*SNPP Host*/ snppObj.Host = _snppServer; /*SNPP Port Number*/ snppObj.Port = _snppPort; /*Subject*/ snppObj.Subject = _pagerSubject; /*Body*/ snppObj.Body = _pagerBody; /*Pager To Address*/ snppObj.SendTo = _pagerToAddress; /*Send information to pager*/ int res = snppObj.Send(); ProcessCompleted = true; if (res == 0) { /*Record notify response*/ notifyComResponse.IsError = false; notifyComResponse.IsSucceeded = true; notifyComResponse.ResponseContent = "Page to [" + _name + "] " + _pagerToAddress + ", sent successfully."; } else { notifyComResponse.IsError = true; notifyComResponse.IsSucceeded = false; notifyComResponse.ResponseContent = "Page to [" + _name + "] " + _pagerToAddress + ", Error:." + snppObj.LastErrorText; } } } catch (Exception ex) { /*Record notify response*/ notifyComResponse.IsError = true; notifyComResponse.IsSucceeded = false; notifyComResponse.ResponseContent = "Page to [" + _name + "] " + _pagerToAddress + ", Failed."; Message += "Page to [" + _name + "] " + _pagerToAddress + ", Failed (" + ex.Message + ")."; ProcessCompleted = true; /*Debug Object values for reference*/ LogBook.Debug(notifyComResponse, this); /*Write exception log*/ LogBook.Write("Error has occurred while sending pager to ." + _pagerToAddress, ex, "CooperAtkins.NotificationServer.NotifyEngine.PagerHelper"); } } catch (Exception ex) { /*Record notify response*/ notifyComResponse.IsError = true; notifyComResponse.IsSucceeded = true; notifyComResponse.ResponseContent = "Page to [" + _name + "] " + _pagerToAddress + ", Failed."; Message += "Page to [" + _name + "] " + _pagerToAddress + ", Failed (" + ex.Message + ")."; ProcessCompleted = true; /*Debug Object values for reference*/ LogBook.Debug(notifyComResponse, this); /*Write exception log*/ LogBook.Write("Error has occurred while preparing SNPP setting.", ex, "CooperAtkins.NotificationServer.NotifyEngine.PagerHelper"); } return(notifyComResponse); }
/// <summary> /// Send Mail /// </summary> /// <returns></returns> public NotifyComResponse Send(INotifyObject notifyObject) { notifyComResponse = new NotifyComResponse(); try { _snppServer = notifyObject.NotifierSettings["SNPPServer"].ToStr(); _snppPort = notifyObject.NotifierSettings["SNPPPort"].ToInt(); _pagerSubject = notifyObject.NotifierSettings["PagerSubject"].ToStr(); _pagerToAddress = notifyObject.NotifierSettings["ToAddress"].ToStr(); _name = notifyObject.NotifierSettings["Name"].ToStr(); _pagerBody = notifyObject.NotificationData.ToStr(); /*Send notification to Pager using SNPP Server*/ try { if (notifyObject.NotifierSettings["DeliveryMethod"].ToInt() != 1) { string phone = notifyObject.NotifierSettings["ToAddress"].ToStr(); int pagerDelay = notifyObject.NotifierSettings["PagerDelay"].ToInt(); string pagerMessage = notifyObject.NotifierSettings["PagerMessage"].ToStr(); string comPortId = notifyObject.NotifierSettings["PagerComPort"].ToStr(); Int16 attemptCount = notifyObject.NotifierSettings["AttemptCount"].ToInt16(); attemptCount++; notifyObject.NotifierSettings["AttemptCount"] = attemptCount; notifyObject.NotifierSettings["LastSentTime"] = DateTime.Now; Message = " Attempt: " + attemptCount.ToString(); sendPageTime = DateTime.Now; /* * "2400,n,8,1" * 1st baud rate * 2nd parity * 3rd data bits * 4th stop bit*/ IOPort.ComSettings comSettings = new IOPort.ComSettings(); comSettings.BaudRate = 2400; comSettings.ParityBit = System.IO.Ports.Parity.Even; comSettings.DataBits = 8; comSettings.StopBit = System.IO.Ports.StopBits.One; int n = 0; //COMcmds[n++] = "1~+~.1"; //COMcmds[n++] = ".3~+~.1"; //COMcmds[n++] = ".3~+~.1"; //COMcmds[n++] = ".5~ATH~3"; // Hang-up if connected COMcmds[n++] = ".5~ATH~3"; // Hang-up if connected COMcmds[n++] = ".5~ATZ~3"; // Reset modem COMcmds[n++] = ".5~ATL0M0~3"; // Disable modem speaker / sounds COMcmds[n++] = ".5~ATE0~3"; //Turn off echoing if (notifyObject.NotifierSettings["COMportInitString"].ToStr().Length > 0) { COMcmds[n++] = ".5~" + notifyObject.NotifierSettings["COMportInitString"].ToStr() + "~1"; } //If Len(InitString) Then COMcmds[n] = ".5~" & InitString & "~1"; COMcmds[n++] = ".5~ATDT" + phone + new System.Text.StringBuilder().Append(',', pagerDelay).ToString() + pagerMessage + "~40"; //COMcmds[n++] = "0~+~.1"; //COMcmds[n++] = ".3~+~.1"; //COMcmds[n++] = ".3~+~.1"; COMcmds[n++] = ".5~ATH~3"; nCOMcmds = n; comPort = new IOPort();//for COMM port //ping the com port comPort.Handshake("COM" + comPortId, comSettings, DataRecieveFromCom); SendCommand(); } else { //snnpObj = new KTGUtil.SNPP(); using (SNPPWrapper snppObj = new SNPPWrapper()) { /*SNPP Host*/ snppObj.Host = _snppServer; /*SNPP Port Number*/ snppObj.Port = _snppPort; /*Subject*/ snppObj.Subject = _pagerSubject; /*Body*/ snppObj.Body = _pagerBody; /*Pager To Address*/ snppObj.SendTo = _pagerToAddress; /*Send information to pager*/ int res = snppObj.Send(); ProcessCompleted = true; if (res == 0) { /*Record notify response*/ notifyComResponse.IsError = false; notifyComResponse.IsSucceeded = true; notifyComResponse.ResponseContent = "Page to [" + _name + "] " + _pagerToAddress + ", sent successfully."; } else { notifyComResponse.IsError = true; notifyComResponse.IsSucceeded = false; notifyComResponse.ResponseContent = "Page to [" + _name + "] " + _pagerToAddress + ", Error:." + snppObj.LastErrorText; } } } } catch (Exception ex) { /*Record notify response*/ notifyComResponse.IsError = true; notifyComResponse.IsSucceeded = false; notifyComResponse.ResponseContent = "Page to [" + _name + "] " + _pagerToAddress + ", Failed."; Message += "Page to [" + _name + "] " + _pagerToAddress + ", Failed (" + ex.Message + ")."; ProcessCompleted = true; /*Debug Object values for reference*/ LogBook.Debug(notifyComResponse, this); /*Write exception log*/ LogBook.Write("Error has occurred while sending pager to ." + _pagerToAddress, ex, "CooperAtkins.NotificationServer.NotifyEngine.PagerHelper"); } } catch (Exception ex) { /*Record notify response*/ notifyComResponse.IsError = true; notifyComResponse.IsSucceeded = true; notifyComResponse.ResponseContent = "Page to [" + _name + "] " + _pagerToAddress + ", Failed."; Message += "Page to [" + _name + "] " + _pagerToAddress + ", Failed (" + ex.Message + ")."; ProcessCompleted = true; /*Debug Object values for reference*/ LogBook.Debug(notifyComResponse, this); /*Write exception log*/ LogBook.Write("Error has occurred while preparing SNPP setting.", ex, "CooperAtkins.NotificationServer.NotifyEngine.PagerHelper"); } return(notifyComResponse); }
/// <summary> /// Send Mail /// </summary> /// <returns></returns> public NotifyComResponse Send() { NotifyComResponse notifyComResponse = new NotifyComResponse(); try { try { MailAddress ma = new MailAddress(_fromAddress); } catch (FormatException ex) { // invalid from mail address, set it to [email protected] LogBook.Write("The format for the from email address (" + _fromAddress + ") is incorrect. [email protected] will be used instead."); _fromAddress = "*****@*****.**"; } SmtpClient ss = new SmtpClient(_smtpServer, _smtpPort); MailMessage mm = new MailMessage(_fromAddress, _toAddress, _subject, _body); CDO.Message message = new CDO.Message(); /*Create Mail Message Object*/ MailMessage mailObj = new MailMessage(); /*Email from address*/ mailObj.From = new MailAddress(_fromAddress, _fromName); /*Email to address*/ mailObj.To.Add(new MailAddress(_toAddress)); /*Email subject*/ mailObj.Subject = _subject; /*Email Body Encoding*/ mailObj.BodyEncoding = Encoding.Default; /*Email Body*/ mailObj.Body = _body; /*Body format (HTML/Text)*/ mailObj.IsBodyHtml = _isBodyHTML; /*Via SMTP Gateway (i.e. your local Exchange Server)-> SmtpSendMethod = 0*/ /*Via Direct Domain SMTP Connection w/DNS MX Lookup-> SmtpSendMethod = 1*/ /*When SmtpSendMethod = 1 we are sending via local host instead of using SMTP settings*/ SmtpClient smtpClientObj = null; if (_sendMethod == 1) { //Send message string domain = mailObj.To[0].Address.Substring(mailObj.To[0].Address.IndexOf('@') + 1); //To Do :need to check for MX record existence before you send. Left intentionally for you. string mxRecord = SendSMTP.DnsLookUp.GetMXRecords(domain)[0]; smtpClientObj = new SmtpClient(mxRecord); } else { if (_isTLS == true && _isSSL == false) { ss.EnableSsl = true; ss.Timeout = 20000; ss.DeliveryMethod = SmtpDeliveryMethod.Network; ss.UseDefaultCredentials = false; ss.Credentials = new NetworkCredential(_smtpAuthUserName, _smtpAuthPassword); mm.BodyEncoding = UTF8Encoding.UTF8; mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure; mm.IsBodyHtml = _isBodyHTML; } else { CDO.IConfiguration configuration = message.Configuration; ADODB.Fields fields = configuration.Fields; ADODB.Field field = fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"]; field.Value = _smtpServer; field = fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"]; field.Value = _smtpPort; field = fields["http://schemas.microsoft.com/cdo/configuration/sendusing"]; field.Value = CDO.CdoSendUsing.cdoSendUsingPort; field = fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"]; if (_smtpAuthMethod == "" || _smtpAuthMethod.ToUpper() == "NONE") { field.Value = CDO.CdoProtocolsAuthentication.cdoAnonymous; } else if (_smtpAuthMethod.ToUpper() == "NTLM") { field.Value = CDO.CdoProtocolsAuthentication.cdoNTLM; } else { field.Value = CDO.CdoProtocolsAuthentication.cdoBasic; } field = fields["http://schemas.microsoft.com/cdo/configuration/sendusername"]; field.Value = _smtpAuthUserName; field = fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"]; field.Value = _smtpAuthPassword; field = fields["http://schemas.microsoft.com/cdo/configuration/smtpusessl"]; field.Value = _isSSL; field = fields["http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"]; field.Value = 10; fields.Update(); message.From = @"""" + _fromName + @""" <" + _fromAddress + ">";; message.To = _toAddress; message.Subject = _subject; if (_isBodyHTML) { message.HTMLBody = _body; } else { message.TextBody = _body; } } } try { if (_sendMethod == 1) { smtpClientObj.Send(mailObj); } else { /*Send Mail*/ if (_isTLS == true && _isSSL == false) { ss.Send(mm); } else { message.Send(); } } /*Record notify response*/ notifyComResponse.IsError = false; notifyComResponse.IsSucceeded = true; notifyComResponse.ResponseContent = "Email sent to: " + "[" + _emailToName + "]" + _toAddress + ((_isAlphaPager) ? " (ALPHA PAGER) " : ""); } catch (Exception ex) { /*Record notify response*/ notifyComResponse.IsError = true; notifyComResponse.IsSucceeded = false; notifyComResponse.ResponseContent = "Email to: " + "[" + _emailToName + "]" + _toAddress + ((_isAlphaPager) ? " (ALPHA PAGER) " : "") + " Failed " + ex.Message; /*Debug Object values for reference*/ LogBook.Debug(notifyComResponse, this); /*Write exception log*/ LogBook.Write("Error has occurred while sending email to ." + _emailToName, ex, "CooperAtkins.NotificationServer.NotifyEngine.Email.EmailClient"); } finally { // Added on 2/19/2012 // Srinivas Rao Eranti // Added try catch to release the message object try { Marshal.FinalReleaseComObject(message); // GC.SuppressFinalize(message); } catch { } } } catch (Exception ex) { /*Record notify response*/ notifyComResponse.IsError = true; notifyComResponse.IsSucceeded = false; notifyComResponse.ResponseContent = "Email to: " + "[" + _emailToName + "]" + _toAddress + ((_isAlphaPager) ? "(ALPHA PAGER)" : "") + " Failed " + ex.Message; /*Debug Object values for reference*/ LogBook.Debug(notifyComResponse, this); /*Write exception log*/ LogBook.Write("Error has occurred while preparing SMTP setting.", ex, "CooperAtkins.NotificationServer.NotifyEngine.Email.EmailClient"); } return(notifyComResponse); }
/// <summary> /// Get Notification settings for SNPP /// </summary> /// <param name="alarmObject"></param> /// <param name="notifyPagerAddress"></param> /// <returns></returns> private NotifyObject GetNotifySNPPObject(Interface.Alarm.AlarmObject alarmObject, NotifyPagerAddress notifyPagerAddress) { string snppServer = "", defaultPagerSubject = "", defaultPagerBody = "", defaultSubject = "", defaultBody = ""; string subject = "", body = "", toAddress = ""; int snppPort = 0; int pagerDelay = 0; string pagerMessage = string.Empty; /*Create Notification Style object*/ NotificationStyle notificationStyle = new NotificationStyle(); /*Create notification object */ NotifyObject notifyObject = new NotifyObject(); /*Set Notification Type*/ notifyObject.NotificationType = "Pager"; /*Create hashtable for notification settings*/ Hashtable notificationSettings = new Hashtable(); /*Set Default pager subject*/ defaultPagerSubject = notificationStyle.GetFormatString(alarmObject, 1, "EmailSubjectPager"); /*Set default pager body*/ defaultPagerBody = notificationStyle.GetFormatString(alarmObject, 1, "EmailBodyPager"); /*Set default subject*/ defaultSubject = notificationStyle.GetFormatString(alarmObject, 1, "EmailSubject"); /*Set default body*/ defaultBody = notificationStyle.GetFormatString(alarmObject, 1, "EmailBody"); /*If default pager subject is empty set default subject as default pager subject*/ defaultPagerSubject = (defaultPagerSubject == string.Empty) ? defaultSubject : defaultPagerSubject; /*If default pager body is empty set default body as default pager body*/ defaultPagerBody = (defaultPagerBody == string.Empty) ? defaultBody : defaultPagerBody; /*Set Email Body and Subject format*/ subject = defaultPagerSubject; body = defaultPagerBody; subject = notificationStyle.SubstituteFormatString(subject, alarmObject); body = notificationStyle.SubstituteFormatString(body, alarmObject); /*Pager Body as notification data*/ /*If pager body is empty assign the default pager body from alarm object*/ /*Check this logic in old application*/ /*In case of missed communication assign the custom body and subject*/ if (alarmObject.IsMissCommNotification || body == string.Empty) { body = alarmObject.PagerMessage; } notificationSettings.Add("DeliveryMethod", notifyPagerAddress.DeliveryMethod); /*Get SNPP settings from GenStores*/ GenStoreInfo genStoreInfo = null; /*Get GenStore Information*/ genStoreInfo = GenStoreInfo.GetInstance(); snppServer = genStoreInfo.SNPPServer; snppPort = genStoreInfo.SNPPPort; /*Set PhoneNumber to Pager destination field*/ toAddress = notifyPagerAddress.PhoneNumber; /*Pager Subject*/ notificationSettings.Add("PagerSubject", subject); notificationSettings.Add("Name", notifyPagerAddress.PagerName); /*Pager Destination Address*/ notificationSettings.Add("ToAddress", toAddress); /* if the delivery type is modem*/ if (notifyPagerAddress.DeliveryMethod != 1) { pagerDelay = notifyPagerAddress.PagerDelay; if (alarmObject.PagerMessage.Trim() != string.Empty) { pagerMessage = alarmObject.PagerMessage; } else { pagerMessage = notifyPagerAddress.PagerMessage; } pagerMessage = notificationStyle.SubstituteFormatString(pagerMessage, alarmObject); notificationSettings.Add("PagerDelay", pagerDelay); notificationSettings.Add("PagerMessage", pagerMessage); notificationSettings.Add("AttemptCount", "0"); notificationSettings.Add("LastSentTime", DateTime.Now); } notificationSettings.Add("PagerComPort", genStoreInfo.PagerComPort); notificationSettings.Add("COMportInitString", genStoreInfo.ComPortInitStr); LogBook.Debug("SNPP Server: " + snppServer); LogBook.Debug("SNPP Port: " + snppPort); notificationSettings.Add("NotificationID", alarmObject.NotificationID); if (notifyPagerAddress.DeliveryMethod == 1) { if (snppServer != string.Empty) { /*Set Default SNPP port if not assigned*/ snppPort = (snppPort < 1 || snppPort > 32767) ? 444 : snppPort; /*If pager destination address is empty record notification as fail*/ if (toAddress != string.Empty) { /*SNPP Server or Host*/ notificationSettings.Add("SNPPServer", genStoreInfo.SNPPServer); /*SNPP Port Number*/ notificationSettings.Add("SNPPPort", snppPort); } else { notificationStyle.RecordNotification(ErrorMessages.PagerComposer_SNPPToAddressNotSupplied, alarmObject.NotificationID, 0, NotifyStatus.FAIL, NotifyTypes.PAGER); /*Exit and return empty notification object*/ return(null); } } else { /*Record notification if SNPP settings are not supplied properly*/ notificationStyle.RecordNotification(ErrorMessages.PagerComposer_SNPPParmsNotSupplied, alarmObject.NotificationID, 0, NotifyStatus.FAIL, NotifyTypes.PAGER); /*Exit and return empty notification object*/ return(null); } } /*Set notification setting to notification object*/ notifyObject.NotifierSettings = notificationSettings; /*Pager body*/ notifyObject.NotificationData = body; return(notifyObject); }