예제 #1
0
        /// <summary>
        /// Get Email notification list
        /// </summary>
        /// <param name="notifyEmailAddressList"></param>
        /// <returns></returns>
        private List <INotifyObject> GetNotificationList(NotifyPagerAddressList notifyPagerAddressList, AlarmObject alarmObject)
        {
            List <INotifyObject> notifyList        = new List <INotifyObject>();
            NotificationStyle    notificationStyle = new NotificationStyle();

            foreach (NotifyPagerAddress notifyPagerAddress in notifyPagerAddressList)
            {
                /*Check for Notification Pager Address and exit the sending process, if NotificationPagerAddress object is NULL*/
                if (notifyPagerAddress != null)
                {
                    /*Get Notification Object*/
                    //if (notifyPagerAddress.DeliveryMethod == 1) // DeliveryMethod 0 = Modem 1 = SNPP
                    //{
                    /*Get SNPP notify settings*/
                    if (GetNotifySNPPObject(alarmObject, notifyPagerAddress) != null)
                    {
                        notifyList.Add(GetNotifySNPPObject(alarmObject, notifyPagerAddress));
                    }
                    //}
                }
                else
                {
                    /*Record notification if Email Address parameters are not supplied properly*/
                    notificationStyle.RecordNotification(ErrorMessages.PagerComposer_SNPPParmsNotSupplied, alarmObject.NotificationID, 0, NotifyStatus.FAIL, NotifyTypes.PAGER);
                }
            }
            return(notifyList);
        }
        /// <summary>
        /// Get Sms notification list
        /// </summary>
        /// <param name="notifySmsAddressList"></param>
        /// <returns></returns>
        private List <INotifyObject> GetNotificationList(NotifyMobileList notifyMobileList, AlarmObject alarmObject, GenStoreInfo genStoreInfo)
        {
            List <INotifyObject> notifyList        = new List <INotifyObject>();
            NotificationStyle    notificationStyle = new NotificationStyle();

            foreach (NotifyMobiles notifyMobiles in notifyMobileList)
            {
                /*Check for Notification Sms Address and exit the sending process, if NotificationSmsAddress object is NULL*/
                if (notifyMobiles != null)
                {
                    /*Get Notification Object*/
                    INotifyObject notifyObject = GetNotifyObject(alarmObject, genStoreInfo, notifyMobiles);

                    if (notifyObject.NotifierSettings["ToPhoneNumber"].ToStr() == string.Empty || notifyObject.NotifierSettings["COMSettings"].ToStr() == string.Empty)
                    {
                        LogBook.Write("Missing mobile number or COM Settings");
                        /*Record notification if Sms parameters are not supplied properly*/
                        notificationStyle.RecordNotification(ErrorMessages.SMSComposer_InvalidSettings, notifyObject.NotifierSettings["NotificationID"].ToInt(), 0, NotifyStatus.FAIL, NotifyTypes.SMS);
                    }
                    else
                    {
                        //Add notification object to array list
                        notifyList.Add(notifyObject);
                    }
                }
                else
                {
                    /*Record notification if Sms parameters are not supplied properly*/
                    notificationStyle.RecordNotification(ErrorMessages.SMSComposer_InvalidSettings, alarmObject.NotificationID, 0, NotifyStatus.FAIL, NotifyTypes.SMS);
                }
            }
            return(notifyList);
        }
예제 #3
0
 /// <summary>
 /// method to handle response received after invoking the Notify object
 /// </summary>
 /// <param name="response"></param>
 /// <param name="notifyObject"></param>
 public void Receive(NotifyComResponse response, INotifyObject notifyObject)
 {
     try
     {
         /*Check the response object*/
         if (response != null)
         {
             NotificationStyle notificationStyle = new NotificationStyle();
             if (response.IsError == false)
             {
                 /*Record notification information.*/
                 notificationStyle.RecordNotification(response.ResponseContent.ToStr(), notifyObject.NotifierSettings["NotificationID"].ToInt(), 0, response.IsSucceeded ? NotifyStatus.PASS : NotifyStatus.FAIL, NotifyTypes.SWITCH);
             }
             else
             {
                 notificationStyle.RecordNotification(response.ResponseContent.ToStr(), notifyObject.NotifierSettings["NotificationID"].ToInt(), 0, NotifyStatus.FAIL, NotifyTypes.SWITCH);
                 //Write Log
                 LogBook.Write(response.ResponseContent.ToString());
             }
         }
     }
     catch (Exception ex)
     {
         LogBook.Write(ex, "CooperAtkins.NotificationClient.NotificationComposer.SwitchNotificationComposer");
     }
 }
예제 #4
0
        /// <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);
        }
        /// <summary>
        /// Create Notification Object
        /// </summary>
        /// <param name="genStoreDAO"></param>
        /// <returns></returns>
        private NotifyObject GetNotifyObject(Interface.Alarm.AlarmObject alarmObject, GenStoreInfo genStoreInfo, NotifyMobiles notifyMobiles)
        {
            string            toPhoneNumber     = string.Empty;
            string            toName            = string.Empty;
            string            message           = string.Empty;
            NotificationStyle notificationStyle = new NotificationStyle();


            //*Initialize NotifyObject*//
            NotifyObject notifyObject = new NotifyObject();

            //*Mobile Number*//
            toPhoneNumber = notifyMobiles.MobileNumber;

            //*Mobile name*//
            toName = notifyMobiles.Name;

            //* Message *//
            message = 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);

            ///*Assigning values to notification object*/
            notifyObject.NotificationType = "SMS";

            ///*Assign values to Notification settings*/
            Hashtable notificationSettings = new Hashtable();

            notificationSettings.Add("COMPort", genStoreInfo.MobileCOMPort);
            notificationSettings.Add("COMSettings", genStoreInfo.MobileCOMSettings);
            notificationSettings.Add("PIN1", genStoreInfo.PIN1);
            notificationSettings.Add("PIN2", genStoreInfo.PIN2);
            notificationSettings.Add("ServiceCenterNumber", genStoreInfo.SMSProviderServiceCenter);
            notificationSettings.Add("ToPhoneNumber", toPhoneNumber);
            notificationSettings.Add("FrqBand", genStoreInfo.FrequencyBand);
            notificationSettings.Add("ToName", toName);
            notificationSettings.Add("NotificationID", alarmObject.NotificationID);
            notificationSettings.Add("AttemptCount", "0");
            notifyObject.NotifierSettings = notificationSettings;
            ///* Notification Data */
            notifyObject.NotificationData = message;

            return(notifyObject);
        }
예제 #6
0
        /// <summary>
        /// Get notification object
        /// </summary>
        /// <param name="alarmObject"></param>
        /// <returns></returns>
        private NotifyObject GetNotifyObject(AlarmObject alarmObject)
        {
            string       scriptArgs   = GetScriptArguments(alarmObject);
            string       errorMsg     = string.Empty;
            string       scriptName   = ConfigurationManager.AppSettings.Get("ScriptPath").ToStr();
            NotifyObject notifyObject = new NotifyObject();

            NotificationStyle notificationStyle = new NotificationStyle();

            /*Set Notification Type*/
            notifyObject.NotificationType = "Switch";

            /*Notification Data*/
            notifyObject.NotificationData = "";

            Hashtable notificationSettings = new Hashtable();

            /*Script Arguments*/
            notificationSettings.Add("ScriptArgs", scriptArgs);

            /*Script Name*/
            notificationSettings.Add("ScriptName", scriptName);

            /*Notification ID*/
            notificationSettings.Add("NotificationID", alarmObject.NotificationID);

            /*Notification Settings*/
            notifyObject.NotifierSettings = notificationSettings;

            if (scriptName == string.Empty)
            {
                errorMsg = string.Format(ErrorMessages.ScriptComposer_InvalidScriptFileName, scriptName);

                /*If the script file name is empty record notification.*/
                notificationStyle.RecordNotification(errorMsg, alarmObject.NotificationID, 0, NotifyStatus.FAIL, NotifyTypes.SCRIPT);

                /*Log error*/
                LogBook.Write(_logContent + " *** Skipping custom alert script - no script found");
            }
            else if (!File.Exists(scriptName)) /*Check weather the script file exist or not*/
            {
                errorMsg = string.Format(ErrorMessages.ScriptComposer_ScriptFileNotFound, scriptName);

                /*If file doesn't exist in the specified path record notification*/
                notificationStyle.RecordNotification(errorMsg, alarmObject.NotificationID, 0, NotifyStatus.FAIL, NotifyTypes.SCRIPT);

                /*Log if script file not found*/
                LogBook.Write(_logContent + " *** Skipping custom alert script - file not found: ");
            }

            return(notifyObject);
        }
예제 #7
0
        /// <summary>
        /// To Record IVRNotification.
        /// </summary>
        private void RecordIVRNotification(AlarmObject _alarmObject)
        {
            NotificationStyle notificationStyle = null;

            try
            {
                notificationStyle = new NotificationStyle();
                TTIvrNotifications tTIVRNotifications = new TTIvrNotifications()
                {
                    Action             = "C",
                    AlarmID            = _alarmObject.AlarmID,
                    LastAttemptTime    = DateTime.UtcNow,
                    Notification_RecID = _alarmObject.NotificationID,
                    TransID            = _alarmObject.TransID,
                    PersonName         = _alarmObject.PersonName,
                    NumAttempts        = 0,
                    PhoneNumber        = _alarmObject.IVRPhoneNumber,
                    UserID             = _alarmObject.IVRUserID,
                    QueueTime          = DateTime.UtcNow,
                    isInProcess        = 1,
                    ThreadID           = _alarmObject.ThreadID
                };

                tTIVRNotifications.Execute();

                _recID = tTIVRNotifications.RecID;



                if (tTIVRNotifications.PhoneNumber.Trim() != string.Empty)
                {
                    //write to TTNotifcationLog table
                    notificationStyle.RecordNotification("Queued for Voice: " + tTIVRNotifications.PersonName + " @ " + tTIVRNotifications.PhoneNumber, _alarmObject.NotificationID, _alarmObject.TransID, NotifyStatus.PASS, NotifyTypes.VOICE);
                    // INotifyObject notifyObject = GetNotifyObject(_alarmObject, _genStore);
                }
                else
                {
                    //write to TTNotifcationLog table
                    notificationStyle.RecordNotification("Phone number does not exists. Queue failed ", _alarmObject.NotificationID, _alarmObject.TransID, NotifyStatus.FAIL, NotifyTypes.VOICE);
                }
                LogBook.Write("IVRNotification has been ADDED for AlarmID[" + tTIVRNotifications.AlarmID + "] To User [+" + tTIVRNotifications.UserID + "] at [" + tTIVRNotifications.PhoneNumber + "]");
            }
            catch (Exception ex)
            {
                //write to TTNotifcationLog table
                notificationStyle.RecordNotification("Queued for Voice: " + _alarmObject.IVRPhoneNumber.ToStr() + " Failed", _alarmObject.NotificationID, _alarmObject.TransID, NotifyStatus.FAIL, NotifyTypes.VOICE);
                LogBook.Write(ex, "CooperAtkins.IVRNotification");
            }
        }
예제 #8
0
        /// <summary>
        /// Receive response and record notification
        /// </summary>
        /// <param name="response"></param>
        /// <param name="notifyObject"></param>
        public void Receive(NotifyComResponse response, INotifyObject notifyObject)
        {
            /*Create notification style object*/
            NotificationStyle notificationStyle = new NotificationStyle();

            /*Check the response object*/
            if (response != null)
            {
                /*Record notification information.*/
                notificationStyle.RecordNotification(response.ResponseContent.ToStr().Replace("127.0.0.1", "server"), notifyObject.NotifierSettings["NotificationID"].ToInt(), 0, (response.IsSucceeded ? NotifyStatus.PASS : NotifyStatus.FAIL), NotifyTypes.POPUP);

                /*Log if Popup sent*/
                LogBook.Write(_logContent + " Popup Response: " + response.ResponseContent.ToStr());
            }
        }
예제 #9
0
        /// <summary>
        /// Create Notification Object
        /// </summary>
        /// <param name="genStoreDAO"></param>
        /// <returns></returns>
        private NotifyObject GetNotifyObject(Interface.Alarm.AlarmObject alarmObject, GenStoreInfo genStoreInfo)
        {
            string PhoneNumber = string.Empty;
            string Name        = string.Empty;
            string CallerID    = string.Empty;

            NotificationStyle notificationStyle = new NotificationStyle();


            //*Initialize NotifyObject*//
            NotifyObject notifyObject = new NotifyObject();


            PhoneNumber = alarmObject.IVRPhoneNumber;
            Name        = alarmObject.PersonName;
            CallerID    = genStoreInfo.ToPhoneNumber;



            ///*Assigning values to notification object*/
            notifyObject.NotificationType = "Voice";

            ///*Assign values to Notification settings*/
            Hashtable notificationSettings = new Hashtable();

            notificationSettings.Add("PhoneNumber", PhoneNumber);

            notificationSettings.Add("PersonName", Name);
            notificationSettings.Add("NotificationID", alarmObject.NotificationID);
            notificationSettings.Add("TransactionID", alarmObject.TransID);
            notificationSettings.Add("TimeOutOfRange", alarmObject.TimeOutOfRange);
            notificationSettings.Add("Value", alarmObject.Value);
            notificationSettings.Add("DeviceName", alarmObject.ProbeName);
            notificationSettings.Add("isMissComm", alarmObject.IsMissCommNotification);
            notificationSettings.Add("GroupName", alarmObject.GroupName);
            notificationSettings.Add("AlarmTime", alarmObject.AlarmTime);
            notificationSettings.Add("Probe", alarmObject.Probe);
            notificationSettings.Add("FromNumber", CallerID);
            notificationSettings.Add("AlarmID", alarmObject.AlarmID);


            notifyObject.NotifierSettings = notificationSettings;


            return(notifyObject);
        }
예제 #10
0
        public void Receive(NotifyComResponse response, INotifyObject notifyObject)
        {
            NotificationStyle notificationStyle = new NotificationStyle();

            /*Write Log
             * Response received from Notification Engine*/
            LogBook.Write(_logContent + " Response received from Pager Notification Engine.");

            /*Check the response object*/
            if (response != null)
            {
                /*Record notification information.*/
                notificationStyle.RecordNotification(response.ResponseContent.ToStr(), notifyObject.NotifierSettings["NotificationID"].ToInt(), 0, (response.IsSucceeded ? NotifyStatus.PASS : NotifyStatus.FAIL), NotifyTypes.PAGER);

                /*Log response content*/
                LogBook.Write(_logContent + " Pager Response: " + response.ResponseContent.ToStr());
            }
        }
예제 #11
0
        /// <summary>
        /// Method to get the switch id based on Notify Profile ID
        /// </summary>
        /// <param name="notifyProfileID"></param>
        /// <param name="notificationID"></param>
        /// <returns></returns>
        private int GetSwitchNotifyID(int notifyProfileID, int notificationID)
        {
            NotificationProfile notificationProfile = new NotificationProfile();
            NotificationStyle   notificationStyle   = new NotificationStyle();

            try
            {
                notificationProfile.NotifyProfileID = notifyProfileID;
                notificationProfile.Execute();
                //if (notificationProfile.SwitchNotifyID == 0)
                //    notificationStyle.RecordNotification("Relay switch not configured for this notification", notificationID, NotifyStatus.FAIL, NotifyTypes.SWITCH);
            }
            catch (Exception ex)
            {
                LogBook.Write("   *** Error in GetSwitchNotifyID method:" + ex.Message);
            }
            return(notificationProfile.SwitchNotifyID);
        }
예제 #12
0
        public void Receive(NotifyComResponse response, INotifyObject notifyObject)
        {
            NotificationStyle notificationStyle = new NotificationStyle();

            /*Write Log
             * Response received from Notification Engine*/
            LogBook.Write(_logContent + " Response received from Script Notification Engine.");

            /*Check the response object*/
            if (response != null)
            {
                /*Record notification indicating that the script executed successfully*/
                notificationStyle.RecordNotification(response.ResponseContent.ToStr(), notifyObject.NotifierSettings["NotificationID"].ToInt(), 0, (response.IsSucceeded ? NotifyStatus.PASS : NotifyStatus.FAIL), NotifyTypes.SCRIPT);

                /*Log response content*/
                LogBook.Write(_logContent + " Script Response: " + response.ResponseContent.ToStr());
            }
        }
예제 #13
0
 /// <summary>
 /// Method to send the response received from the Invoking the Notification
 /// </summary>
 /// <param name="response"></param>
 /// <param name="notifyObject"></param>
 public void Receive(NotifyComResponse response, INotifyObject notifyObject)
 {
     /*Check the response object*/
     if (response != null && notifyObject.NotifierSettings["NotificationID"].ToInt() != 0)
     {
         NotificationStyle notificationStyle = new NotificationStyle();
         if (response.IsError == false)
         {
             /*Record notification information.*/
             notificationStyle.RecordNotification(response.ResponseContent.ToStr(), notifyObject.NotifierSettings["NotificationID"].ToInt(), 0, response.IsSucceeded ? NotifyStatus.PASS : NotifyStatus.FAIL, NotifyTypes.MSGBOARD);
             LogBook.Write("Notification sent to message board: " + notifyObject.NotifierSettings["IpAddress"]);
         }
         else
         {
             notificationStyle.RecordNotification(response.ResponseContent.ToStr(), notifyObject.NotifierSettings["NotificationID"].ToInt(), 0, NotifyStatus.FAIL, NotifyTypes.MSGBOARD);
             LogBook.Write("     *** Error sending message board notification to" + notifyObject.NotifierSettings["IpAddress"]);
             LogBook.Write("     *** Error :" + response.ResponseContent);
         }
     }
 }
예제 #14
0
        private int GetMessageBoardID(int notifyProfileID, int notificationID)
        {
            //get the message board id, to which the message has to be sent
            NotificationProfile notificationProfile = new NotificationProfile();
            NotificationStyle   notificationStyle   = new NotificationStyle();

            try
            {
                notificationProfile.NotifyProfileID = notifyProfileID;
                notificationProfile = notificationProfile.Execute();
                if (notificationProfile.MsgBoardNotifyID == 0)
                {
                    notificationStyle.RecordNotification("Message board not found", notificationID, 0, NotifyStatus.FAIL, NotifyTypes.MSGBOARD);
                }
            }
            catch (Exception ex)
            {
                LogBook.Write("     *** Error in GetMessageBoardID :" + ex.Message);
            }
            return(notificationProfile.MsgBoardNotifyID);
        }
        /// <summary>
        /// To Record IVRNotification.
        /// </summary>
        private void RecordIVRNotification()
        {
            NotificationStyle notificationStyle = null;

            try
            {
                notificationStyle = new NotificationStyle();
                TTIvrNotifications tTIVRNotifications = new TTIvrNotifications()
                {
                    Action             = "C",
                    AlarmID            = _alarmObject.AlarmID,
                    LastAttemptTime    = DateTime.UtcNow,
                    Notification_RecID = _alarmObject.NotificationID,
                    NumAttempts        = 1,
                    PhoneNumber        = _alarmObject.IVRPhoneNumber,
                    TransID            = _alarmObject.TransID,
                    PersonName         = _alarmObject.PersonName,
                    UserID             = _alarmObject.IVRUserID,
                    QueueTime          = DateTime.UtcNow
                };

                tTIVRNotifications.Execute();

                if (tTIVRNotifications.PhoneNumber.Trim() != string.Empty)
                {
                    notificationStyle.RecordNotification("Queued for Voice: " + tTIVRNotifications.PersonName + " @ " + tTIVRNotifications.PhoneNumber, _alarmObject.TransID, _alarmObject.NotificationID, NotifyStatus.PASS, NotifyTypes.VOICE);
                }
                else
                {
                    notificationStyle.RecordNotification("Phone number does not exists. Queue failed ", _alarmObject.TransID, _alarmObject.NotificationID, NotifyStatus.FAIL, NotifyTypes.VOICE);
                }
                LogBook.Write("IVRNotification has been inserted.");
            }
            catch (Exception ex)
            {
                notificationStyle.RecordNotification("Queued for Voice: " + _alarmObject.IVRPhoneNumber.ToStr() + " Failed", _alarmObject.TransID, _alarmObject.NotificationID, NotifyStatus.FAIL, NotifyTypes.VOICE);
                LogBook.Write(ex, "CooperAtkins.IVRNotification");
            }
        }
예제 #16
0
        /// <summary>
        /// Get Popup notification list
        /// </summary>
        /// <param name="notifyEmailAddressList"></param>
        /// <returns></returns>
        private List <INotifyObject> GetNotificationList(NotifyPopupAddressList notificationPopupAddressList, AlarmObject alarmObject, string popupMessage)
        {
            List <INotifyObject> notifyList        = new List <INotifyObject>();
            NotificationStyle    notificationStyle = new NotificationStyle();

            foreach (NotifyPopupAddress notifyPopupAddress in notificationPopupAddressList)
            {
                /*Check for Notification Popup Address and exit the sending process, if NotificationEmailAddress object is NULL*/
                if (notifyPopupAddress != null)
                {
                    /*Get Notification Object*/
                    INotifyObject notifyObject = GetNotifyObject(alarmObject, popupMessage, notifyPopupAddress);

                    //Add notification object to array list
                    notifyList.Add(notifyObject);
                }
                else
                {
                    /*Record notification if Popup Address parameters are not supplied properly*/
                    notificationStyle.RecordNotification("", alarmObject.NotificationID, 0, NotifyStatus.FAIL, NotifyTypes.POPUP);
                }
            }
            return(notifyList);
        }
        /// <summary>
        /// Receive notification response.
        /// </summary>
        /// <param name="response"></param>
        public void Receive(NotifyComResponse response, INotifyObject notifyObject)
        {
            NotificationStyle notificationStyle = new NotificationStyle();

            /*Check the response object*/
            if (response != null)
            {
                /*Record notification information.*/
                notificationStyle.RecordNotification(response.ResponseContent.ToStr(), notifyObject.NotifierSettings["NotificationID"].ToInt(), 0, (response.IsSucceeded ? NotifyStatus.PASS : NotifyStatus.FAIL), NotifyTypes.SMS);

                if (response.IsError == false)
                {
                    /*Log if sms send to particular to address*/
                    LogBook.Write("SMS sent to: " + notifyObject.NotifierSettings["ToPhoneNumber"].ToStr());
                }
                else
                {
                    /*Log when sending sms failed*/
                    LogBook.Write("Error has occurred while sending SMS");
                    /*Log response content*/
                    LogBook.Write(response.ResponseContent.ToStr());
                }
            }
        }
예제 #18
0
        /// <summary>
        /// Create Notification Object
        /// </summary>
        /// <param name="genStoreDAO"></param>
        /// <returns></returns>
        private NotifyObject GetNotifyObject(Interface.Alarm.AlarmObject alarmObject, GenStoreInfo genStoreInfo, NotifyEmailAddress notifyEmailAddress)
        {
            bool   isAlphaPager = false, isSSL = false, isTSL = false, isBodyHtml = false;
            int    bodyFormat = Common.FORMAT_TEXT, smtpPort = 0, timeOut = 15000;
            string subject = "", body = "", emailToAddress = "", emailFromAddress = "", name = "", fromName = "TempTrak Monitor";
            string defaultSubject = "", defaultBody = "", defaultPagerSubject = "", defaultPagerBody = "", notifyTree = "";
            Int16  alphaPager = 0;

            /*Initialize NotifyObject*/
            NotifyObject notifyObject = new NotifyObject();
            /*Initialize NotificationStyle*/

            NotificationStyle notificationStyle = new NotificationStyle();

            /*Set SSL and TLS flags*/
            isSSL = (genStoreInfo.SmtpFlags & 1) == 1 ? true : false;
            isTSL = (genStoreInfo.SmtpFlags & 2) == 2 ? true : false;

            /*Set default SMTP Port value*/
            if (genStoreInfo.SmtpPort.ToInt() == 0 || genStoreInfo.SmtpPort.ToInt() < 1 || genStoreInfo.SmtpPort.ToInt() > 32767)
            {
                /*Default SMTP port number*/
                smtpPort = 25;
                /*If SSL is enables set SMTP port to 465*/
                if (isSSL)
                {
                    smtpPort = 465;
                }
            }
            else
            {
                smtpPort = genStoreInfo.SmtpPort.ToInt();
            }

            /*Email Address*/
            emailToAddress = notifyEmailAddress.EmailAddress;

            /*Email notification name*/
            name = notifyEmailAddress.Name;

            /*Alpha Pager*/
            alphaPager = notifyEmailAddress.AlphaPager;

            /*Default Subject*/
            defaultSubject = notificationStyle.GetFormatString(alarmObject, 1, "EmailSubject");

            /*Default Body*/
            defaultBody = notificationStyle.GetFormatString(alarmObject, 1, "EmailBody");

            /*Default Pager Subject*/
            defaultPagerSubject = notificationStyle.GetFormatString(alarmObject, 1, "EmailSubjectPager");

            /*Default Pager Body*/
            defaultPagerBody = notificationStyle.GetFormatString(alarmObject, 1, "EmailBodyPager");

            /*Notification Tree*/
            notifyTree = notificationStyle.GetFormatString(alarmObject, 1, "NotifyTree");

            /*Default Pager Subject*/
            defaultPagerSubject = (defaultPagerSubject == string.Empty) ? defaultSubject : defaultPagerSubject;

            /*Default Pager Subject*/
            defaultPagerBody = (defaultPagerBody == string.Empty) ? defaultBody : defaultPagerBody;

            ///*Set Email Body and Subject format*/
            if (alphaPager == 0)
            {
                isAlphaPager = false;
                subject      = defaultSubject;
                if (body.ToStr() == string.Empty)
                {
                    if (alarmObject.AlarmType != AlarmType.COMMUNICATIONS && alarmObject.AlarmType != AlarmType.RESETCOMMUNICATIONS)
                    {
                        body = notificationStyle.GetEmailBody(alarmObject);
                    }
                    else
                    {
                        if (alarmObject.AlarmType == AlarmType.COMMUNICATIONS)
                        {
                            bodyFormat = Common.FORMAT_HTML;
                            body       = "<html><head><style>TH{font-family: Verdana,Arial;font-weight: bold;font-size: 10pt;background: #333333;color: white;}TD{font-family: Verdana,Arial;font-weight: normal;font-size: 10pt;}</style></head><body style='font-family: Verdana, Arial; font-size: 10pt;'><span style='font-weight: bold; font-size: 14pt; background: black; color: yellow;'>!!! Missed Communication !!!</span><br /><br /><br /><span style='font-weight: bold;'>Sensor Name: %%NAME%%</span><br>FactoryID: %%ID%%<br /><br /><table border='0' cellpadding='1' cellspacing='1'><tr><th align='left'>TYPE:</th><td>%%TYPE%%</td></tr><tr><th align='left'>GROUP:</th><td>%%GROUP%%</td></tr><tr><th align='left'>Time out of range:</th><td>%%TimeOutOfRange%%</td></tr></table></body></html>";
                        }
                        else
                        {
                            bodyFormat = Common.FORMAT_HTML;
                            body       = "<html><head><style>TH{font-family: Verdana,Arial;font-weight: bold;font-size: 10pt;background: #333333;color: white;}TD{font-family: Verdana,Arial;font-weight: normal;font-size: 10pt;}</style></head><body style='font-family: Verdana, Arial; font-size: 10pt;'><span style='font-weight: bold; font-size: 14pt; background: black; color: yellow;'>!!! Back In Sight/Connection Resumed !!!</span><br /><br /><br /><span style='font-weight: bold;'>Sensor Name: %%NAME%%</span><br>FactoryID: %%ID%%<br /><br /><table border='0' cellpadding='1' cellspacing='1'><tr><th align='left'>TYPE:</th><td>%%TYPE%%</td></tr><tr><th align='left'>GROUP:</th><td>%%GROUP%%</td></tr><tr><th align='left'>Time out of range:</th><td>%%TimeOutOfRange%%</td></tr></table></body></html>";
                        }
                    }

                    if (body.ToStr() == string.Empty)
                    {
                        body = defaultBody;
                    }
                    else
                    {
                        bodyFormat = Common.FORMAT_HTML;
                        if (defaultBody.ToStr() != string.Empty)
                        {
                            defaultBody = defaultBody.Replace("\\n", "<br>");
                            body        = body + "<BR></BR>" + defaultBody;
                        }
                    }

                    if (notifyTree.ToStr() != string.Empty)
                    {
                        notifyTree = notifyTree.Replace("\\n", "<br>");
                        body       = body + "<BR><BR><TABLE WIDTH=500 style='padding:5px;'><TR><TD><HR><H4>Alarm Notification Action(s)</H4></TD></TR><TR><TD style='border:1px dotted #000000;background:#99ffff;'>" + notifyTree + "</TD></TR></TABLE>";
                    }
                }
            }
            else /*Alpha pager*/
            {
                isAlphaPager = true;
                subject      = defaultPagerSubject;
                body         = defaultPagerBody.Replace("\\n", Environment.NewLine);
            }
            /*Assign default subject and body values*/
            subject = (subject == string.Empty) ? defaultSubject : subject;
            body    = (body.ToStr() == string.Empty) ? "" : body;


            /*commented on 02/28/2011 to display from email address properly*/
            /*Get a default "From" address*/
            //if (emailToAddress != string.Empty)
            //{
            //    foreach (string item in emailToAddress.ToStr().Split(','))
            //    {
            //        emailFromAddress = item;
            //        break;
            //    }
            //}

            emailFromAddress = genStoreInfo.FromAddress;

            /*Format Subject*/
            subject = notificationStyle.SubstituteFormatString(subject, alarmObject);

            /*Format Body*/
            body = notificationStyle.SubstituteFormatString(body, alarmObject);

            /*Body Format*/
            isBodyHtml = (bodyFormat == Common.FORMAT_HTML) ? true : false;

            /*In case of missed communication set the custom message*/
            if (alarmObject.IsMissCommNotification)
            {
                subject    = "Missed Communication"; //set the appropriate message
                body       = alarmObject.MissedCommSensorInfo;
                isBodyHtml = true;
            }

            /*Set Email From Name*/
            fromName = (genStoreInfo.FromName != string.Empty) ? genStoreInfo.FromName : fromName;

            /*Assigning values to notification object*/
            notifyObject.NotificationType = "EMAIL";

            /*Assign values to Notification settings*/
            Hashtable notificationSettings = new Hashtable();

            notificationSettings.Add("SMTPServer", genStoreInfo.SmtpServer);
            /*0=via SMTPGateway, 1=MX Direct*/
            notificationSettings.Add("SMTPSendMethod", genStoreInfo.SmtpSendMethod);
            notificationSettings.Add("SMTPAuthUserName", genStoreInfo.SmtpAuthUserName);
            notificationSettings.Add("SMTPAuthPassword", genStoreInfo.SmtpAuthPassword);
            notificationSettings.Add("SMPTAuthDomain", genStoreInfo.SmtpAuthDomain);
            notificationSettings.Add("SMTPAuthMethod", genStoreInfo.SMTPAuthMethod);
            notificationSettings.Add("SMTPFlags", genStoreInfo.SmtpFlags);
            /*Bitmask: Bit 1=Use SSL, 2=Use TLS*/
            notificationSettings.Add("IsSSL", isSSL);
            notificationSettings.Add("IsTLS", isTSL);
            notificationSettings.Add("SMTPPort", smtpPort);
            notificationSettings.Add("BodyFormat", bodyFormat);
            notificationSettings.Add("FromAddress", emailFromAddress);
            notificationSettings.Add("ToAddress", emailToAddress);
            notificationSettings.Add("Subject", subject);
            notificationSettings.Add("EmailToName", name);
            notificationSettings.Add("FromName", fromName);
            notificationSettings.Add("IsAlphaPager", isAlphaPager);
            notificationSettings.Add("IsBodyHTML", isBodyHtml);
            //notificationSettings.Add("ReadTimeOut", timeOut); //Default Time out value 15 Sec in old code
            notifyObject.NotifierSettings = notificationSettings;
            /* Notification Data */
            notifyObject.NotificationData = body;
            notifyObject.NotifierSettings.Add("NotificationID", alarmObject.NotificationID);

            return(notifyObject);
        }
예제 #19
0
        /// <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);
        }
예제 #20
0
        /// <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);
        }
        internal NotifyComResponse InvokeNotifyEngine(INotifyObject notifyObject, NotificationEndPointElement endpoint)
        {
            //Implement client INotifyReceiver for client and notification server communication.
            int    notifyClienttimeOutValue = 0;
            string senderType = "", endpointAddress;

            if (endpoint != null && !string.IsNullOrEmpty(endpoint.WType) && !string.IsNullOrEmpty(endpoint.EndpointAddress))
            {
                senderType               = endpoint.WType;
                endpointAddress          = endpoint.EndpointAddress;
                notifyClienttimeOutValue = endpoint.Timeout;
                LogBook.Write(notifyObject.NotificationType + " end point type is " + endpointAddress);
            }
            else
            {
                senderType               = Interface.Alarm.AlarmModuleConfiguration.Instance.Configuration.EndPoint.WType;
                endpointAddress          = Interface.Alarm.AlarmModuleConfiguration.Instance.Configuration.EndPoint.EndpointAddress;
                notifyClienttimeOutValue = Interface.Alarm.AlarmModuleConfiguration.Instance.Configuration.EndPoint.Timeout;
                LogBook.Write(notifyObject.NotificationType + " end point type is {embed}");
            }

            NotifyComResponse response = null;

            if (senderType == "{embed}")
            {
                _notifyReceiver = CommunicationAdapter.GetInstance();
                response        = _notifyReceiver.Execute(notifyObject);
            }
            else
            {
                //Invoke remote object
                INotificationChannelClient client = _notifyClientEnd.GetClient(senderType, endpointAddress);
                //client.EndPointAddress = endpoint.EndpointAddress;
                client.OnReceive((data, remEndpoint) =>
                {
                    try
                    {
                        response = NotifyComResponse.Create(data);
                    }
                    catch (Exception ex)
                    {
                        response                 = new NotifyComResponse();
                        response.IsSucceeded     = true;
                        response.IsError         = true;
                        response.ResponseContent = "Notification Failed, while receiving data from notification engine.";
                        LogBook.Write("Error has occurred while receiving data from notification engine (Exception Message:" + ex.Message + ") \n Received Data: " + data);
                    }
                });

                bool timeout   = false;
                long startTick = DateTime.Now.Ticks;
Label4Retry:

                try
                {
                    client.Send(notifyObject.GetXML());
                }
                catch (Exception ex)
                {
                    if (notifyClienttimeOutValue == 0 || notifyClienttimeOutValue >= ((DateTime.Now.Ticks - startTick) / TimeSpan.TicksPerMillisecond))
                    {
                        timeout = true;
                    }

                    if (!timeout)
                    {
                        goto Label4Retry;
                    }
                    else
                    {
                        StringBuilder sb = new StringBuilder();
                        sb.AppendLine("Notification Service - Error has occurred while connecting to the remote notification engine.");
                        sb.AppendLine("Remote endpoint:" + endpointAddress);
                        sb.AppendLine("NotificationType:" + notifyObject.NotificationType);
                        sb.AppendLine("Data:" + notifyObject.NotificationData);
                        sb.AppendLine("Technical Information:" + ex.Message + ". " + ex.StackTrace);
                        LogBook.Write(sb.ToString(), "Notification Client", ErrorSeverity.Critical);

                        response                 = new NotifyComResponse();
                        response.IsSucceeded     = false;
                        response.IsError         = true;
                        response.ResponseContent = "Failed, while connecting to notification engine.";
                        LogBook.Write("Error has occurred while connecting to the remote notification engine (Exception Message:" + ex.Message + ")");


                        //record notification

                        NotifyTypes notifyType;
                        Enum.TryParse <NotifyTypes>(notifyObject.NotificationType.Trim(), true, out notifyType);

                        NotificationStyle notificationStyle = new NotificationStyle();
                        notificationStyle.RecordNotification(sb.ToString(), 0, 0, response.IsSucceeded ? NotifyStatus.PASS : NotifyStatus.FAIL, notifyType);
                    }
                }
            }
            return(response);
        }
        public INotifyObject[] Compose(AlarmObject alarmObject)
        {
            GenStoreInfo         genStoreInfo      = null;
            NotifyMobileList     notifyMobileList  = null;
            List <INotifyObject> notifyList        = new List <INotifyObject>();
            NotificationStyle    notificationStyle = new NotificationStyle();

            LogBook.Write("Executing Compose method");


            /*Get GenStore Information*/
            genStoreInfo = GenStoreInfo.GetInstance();

            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.SmtpSendMethod != 0)
                    //if ((genStoreInfo.ToPhoneNumber == string.Empty && genStoreInfo.SmtpAuthDomain == string.Empty) && genStoreInfo.SmtpSendMethod == 0)
                    //{
                    //    /*SMTP server not defined*/
                    //    LogBook.Write("Error: No SMTP Server has been defined");

                    //    /*Record notification if SMTP parameters are not supplied properly*/
                    //    notificationStyle.RecordNotification(ErrorMessages.SmsComposer_SMTPParmsNotSupplied, _alarmObject.NotificationID, NotifyStatus.FAIL, NotifyTypes.SMS);

                    //}
                    //else
                    //{
                    LogBook.Write("Fetching notify Mobiles List");
                    /*Get all the sms addresses that are configured for notification*/
                    notifyMobileList = GetNotifyMoibilesList(alarmObject.NotifyProfileID);
                    LogBook.Write("Notify Mobile List Count: " + notifyMobileList.Count.ToString());
                    if (notifyMobileList.Count != 0)
                    {
                        LogBook.Write("Constructing notify list objects");
                        /*Construct a notification object for each sms number and add to the notification list*/
                        notifyList = GetNotificationList(notifyMobileList, alarmObject, genStoreInfo);


                        for (int index = notifyList.Count - 1; index >= 0; index--)
                        {
                            INotifyObject notifyObject = notifyList[index];
                            SmsHelper.SmsQueue.Add(notifyObject);
                            notifyList.Remove(notifyObject);
                            new NotificationStyle().RecordNotification("Sms queued: " + notifyObject.NotifierSettings["ToPhoneNumber"].ToStr(), notifyObject.NotifierSettings["NotificationID"].ToInt(), 0, NotifyStatus.STATUS, NotifyTypes.SMS);
                        }


                        LogBook.Write("Notify list objects count: " + notifyList.Count);
                    }
                    else
                    {
                        /*Log when we don't have sms address to notify*/
                        LogBook.Write("Error: Missing entry in NotifySms/Groups");
                    }
                    //}
                }
                else
                {
                    /*Record notification if genStore parameters are not supplied properly.*/
                    notificationStyle.RecordNotification(ErrorMessages.SMSComposer_InvalidSettings, alarmObject.NotificationID, 0, NotifyStatus.FAIL, NotifyTypes.SMS);

                    /*Log if genStore information is empty*/
                    LogBook.Write("Error:  Missing GenStores table record");
                }
            }
            catch (Exception ex)
            {
                /*Write exception log*/
                LogBook.Write(ex, "CooperAtkins.NotificationClient.NotificationComposer.SmsNotificationComposer");
            }

            /*Send notification list to notification engine*/
            return(notifyList.ToArray());
        }
예제 #23
0
        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>
        /// Returns true if the current operation succeeded.
        /// </summary>
        /// <param name="data"></param>
        /// <param name="settings"></param>
        /// <param name="notificationID"></param>
        /// <returns></returns>
        ///



        public static bool Send(string data, Hashtable settings, int notificationID, int ivrID, int alarmID, AlarmObject alarmObject)
        {
            bool   retValue      = false;
            bool   callConnected = false;
            string response      = string.Empty;
            string succeeded     = string.Empty;
            string error         = string.Empty;
            Int16  dailAttempts  = 1;
            string DigitsPressed = string.Empty;

            long QueueID = -1;

            int    TryCount                 = -1;
            bool   CallAnswered             = false;
            bool   Answered                 = false;
            bool   CallComplete             = false;
            string MachineDetection         = string.Empty;
            int    Duration                 = -1;
            string IVRServiceResponseText   = string.Empty;
            int    TTIVRNotifications_RecID = -1;


            NotifyObject      notifyObject      = new NotifyObject();
            NotifyComResponse notifyResponse    = new NotifyComResponse();
            NotifyComResponse notifyComResponse = new NotifyComResponse();

            notifyObject.NotificationType = "Voice";
            notifyObject.NotificationData = data;     //voice message to be played
            notifyObject.NotifierSettings = settings; //hash table of keys and values


            NotificationEndPointElement element;
            string vcElement1;
            string vcElement2;
            string vcElement3;
            string vcElement4;

            /* get end point for voice composer*/


            string method = NotificationClient.GetInstance().WhoAmI("Voice", out element);

            string arguments = null;

            LogBook.Write("Sending voice alert....");
            switch (method.ToLower())
            {
            case "cooperatkins.notificationclient.notifyengine.ivrnotificationcom":


                System.Diagnostics.Process process = new System.Diagnostics.Process();
                if (element == null)
                {
                    arguments = @"-m ""<notification ack='true'><notificationData><![CDATA[" + data + @"]]></notificationData><notificationType><![CDATA[Voice]]></notificationType><notificationSettings><PhoneNo><![CDATA[" + settings["PhoneNo"].ToStr() + @"]]></PhoneNo></notificationSettings></notification>"" ";
                }
                else
                {
                    arguments = @"-c " + element.EndpointAddress + @" -m ""<notification ack='true'><notificationData><![CDATA[" + data + @"]]></notificationData><notificationType><![CDATA[Voice]]></notificationType><notificationSettings><PhoneNo><![CDATA[" + settings["PhoneNo"].ToStr() + @"]]></PhoneNo></notificationSettings></notification>"" ";
                }

                while (!callConnected)
                {
                    IvrAlarmStatus ivrAlarmStatus = new IvrAlarmStatus();
                    try
                    {
                        LogBook.Write("Checking whether alarm is cleared or not");
                        ivrAlarmStatus.AlarmID        = alarmID;
                        ivrAlarmStatus.NotificationID = notificationID;
                        ivrAlarmStatus.StoreID        = GenStoreInfo.GetInstance().StoreID;
                        ivrAlarmStatus.Execute();
                    }
                    catch (Exception ex)
                    {
                        LogBook.Write(ex, "CooperAtkins.NotificationClient.NotificationComposer.IvrClientHelper", ErrorSeverity.High);
                    }
                    finally
                    {
                        ivrAlarmStatus.Dispose();
                    }

                    if (ivrAlarmStatus.IsAlarmClearedOrBackInRange)
                    {
                        break;
                    }

                    /*       analog modem use  */

                    process.StartInfo.UseShellExecute        = false;
                    process.StartInfo.RedirectStandardOutput = true;
                    //process.StartInfo.RedirectStandardError = true;
                    process.StartInfo.CreateNoWindow = true;
                    process.StartInfo.FileName       = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\Utility.exe";
                    //process.StartInfo.FileName = @"F:\DEV\CooperAtkins\CooperAtkins.NotificationEngine.Utility\bin\Debug\Utility.exe";
                    process.StartInfo.Arguments = arguments;
                    // process.StartInfo.WorkingDirectory = ;
                    process.Start();

                    process.WaitForExit();


                    response = process.StandardOutput.ReadToEnd();

                    callConnected = true;
                    if (response.ToLower().Contains("device initialization failed") || response.ToLower().Contains("invalid_device_id") || response.ToLower().Contains("dll_not_found") || response.ToLower().Contains("exception from hresult"))
                    {
                        callConnected = false;
                    }
                    /*     end  analog modem use  */
                }
                break;


            case "cooperatkins.notificationclient.notificationcomposer.cdyneivrnotificationcomposer":
                long     TransactionID = -1;
                DateTime StartTime;
                DateTime EndTime;
                long     AlarmID = -1;


                string CDYNE_ID      = GenStoreInfo.GetInstance().CDYNE_ACCOUNT;//NotificationClient.GetInstance().GetCustomVoiceSettings("CDyneID", out vcElement1);
                string CDYNE_RETRIES = NotificationClient.GetInstance().GetCustomVoiceSettings("CDyneRetries", out vcElement2);
                string CDYNE_VOICEID = NotificationClient.GetInstance().GetCustomVoiceSettings("CDyneVoiceID", out vcElement3);
                string CDYNE_VOLUME  = NotificationClient.GetInstance().GetCustomVoiceSettings("CDyneVolume", out vcElement4);

                notifyObject.NotifierSettings["CDYNE_ID"]      = CDYNE_ID;
                notifyObject.NotifierSettings["CDYNE_RETRIES"] = CDYNE_RETRIES;
                notifyObject.NotifierSettings["CDYNE_VOICEID"] = CDYNE_VOICEID;
                notifyObject.NotifierSettings["CDYNE_VOLUME"]  = CDYNE_VOLUME;
                NotificationStyle  notificationStyle        = new NotificationStyle();
                TTIvrNotifications tTIvrNotificationsObject = new TTIvrNotifications();
                callConnected = false;

                while (!callConnected)
                {
                    notifyComResponse.IsInProcess = true;
                    int QueryCall = 0;
                    int UnivError = 0;

                    //if (!alarmObject.IsFailsafeEscalationNotification)
                    //{
                    //IvrAlarmStatus ivrAlarmStatus = new IvrAlarmStatus();
                    //try
                    //{
                    //    LogBook.Write("Checking whether alarm is cleared or not");
                    //    ivrAlarmStatus.AlarmID = alarmID;
                    //    ivrAlarmStatus.NotificationID = notificationID;
                    //    ivrAlarmStatus.StoreID = GenStoreInfo.GetInstance().StoreID;
                    //    ivrAlarmStatus.Execute();
                    //}
                    //catch (Exception ex)
                    //{
                    //    LogBook.Write(ex, "CooperAtkins.NotificationClient.NotificationComposer.CDYNEIvrClientHelper", ErrorSeverity.High);
                    //}
                    //finally
                    //{
                    //    ivrAlarmStatus.Dispose();
                    //}

                    //12/9/15 comment start
                    //AlarmStatus alarmStatus = new AlarmStatus();
                    //try
                    //{
                    //    LogBook.Write("IVR Checking whether alarm [" + alarmObject.NotificationID + "] is cleared or not");
                    //    alarmStatus.NotificationID = alarmObject.NotificationID;
                    //    alarmStatus.StoreID = GenStoreInfo.GetInstance().StoreID;
                    //    alarmStatus.Execute();
                    //}
                    //catch (Exception ex)
                    //{
                    //    LogBook.Write(ex, "CooperAtkins.NotificationClient.Alarm.AlarmInitializer", ErrorSeverity.High);
                    //}
                    //finally
                    //{
                    //    alarmStatus.Dispose();
                    //12/9/15 comment end }

                    int threadID = notifyObject.NotifierSettings["ThreadID"].ToInt();

                    //12/9/15 comment start
                    //if (alarmStatus.IsAlarmClearedOrBackInRange)
                    //{
                    //    Answered = false;
                    //    callConnected = false;
                    //    notifyComResponse.IsSucceeded = false;
                    //    notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\n < Phone Call To " + notifyObject.NotifierSettings["PhoneNo"] + "[" + notifyObject.NotifierSettings["CallerName"] + "]" + " SUSPENDED (Attempt # " + dailAttempts + " of " + (CDYNE_RETRIES.ToInt() + 1) + ")";
                    //    notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\nALARM WAS CLEARED OR BACK IN RANGE";

                    //    LogBook.Write("CALL SUSPENDED To " + notifyObject.NotifierSettings["PhoneNo"] + IVRServiceResponseText + " for NotificationID: " + notificationID + " [CDyneTransID: " + TransactionID + "] ALARM WAS CLEARED OR SENSOR IS BACK IN RANGE");

                    //    notificationStyle.RecordNotification(notifyComResponse.ResponseContent.ToString(), notificationID, TransactionID.ToInt(), NotifyStatus.FAIL, NotifyTypes.VOICE);
                    //    UpdateIVRNotification(ivrID, false, false, dailAttempts, TransactionID, threadID);

                    //    break;

                    //12/9/15 comment end }


                    int totalCallAttempts = notifyObject.NotifierSettings["Attempts"].ToInt();

                    if ((totalCallAttempts + dailAttempts) > (CDYNE_RETRIES.ToInt() + 1))
                    //also if a notficicationId is in an alert progress state from another thread,
                    //fall into this code to break out OR if cleared or inprogress check to be sure
                    //we made contatc through our maximum attempts value
                    {
                        notifyComResponse.IsInProcess = false;
                        UpdateIVRNotification(ivrID, false, notifyComResponse.IsInProcess, dailAttempts, TransactionID, threadID);
                        break;
                    }
                    //}


                    UpdateIVRNotification(ivrID, false, true, (totalCallAttempts + dailAttempts), TransactionID, threadID);

                    try{
                        IVRProcessor maketheIVRCall = new IVRProcessor();
                        notifyResponse = maketheIVRCall.Invoke(notifyObject);
                        //  notifyComResponse = new NotifyComResponse();
                        TransactionID = notifyResponse.TransactionIDReturned;
                        //query for call result

                        Answered = false;
                        PhoneNotify pn2 = new PhoneNotify();
                        while (!Answered)
                        {
                            if (QueryCall == 0)        //on first call, wait 1 minute for call to complete before getting call results
                            {
                                System.Threading.Thread.Sleep(1 * 60 * 1000);
                            }
                            else
                            {
                                System.Threading.Thread.Sleep(5 * 1000);
                            }
                            NotifyReturn nr2 = pn2.GetQueueIDStatus(TransactionID);
                            MachineDetection       = nr2.MachineDetection;
                            DigitsPressed          = nr2.DigitsPressed;
                            CallAnswered           = nr2.CallAnswered;
                            CallComplete           = nr2.CallComplete;
                            IVRServiceResponseText = nr2.ResponseText;
                            Duration  = nr2.Duration;
                            StartTime = nr2.StartTime;
                            EndTime   = nr2.EndTime;
                            if (CallAnswered == true && DigitsPressed.Contains("*"))
                            {
                                Answered      = true;
                                callConnected = true;
                                notifyComResponse.IsSucceeded = true;
                                //notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\n < Phone Call To " + notifyObject.NotifierSettings["PhoneNo"] + "[" + notifyObject.NotifierSettings["CallerName"] + "]" + " Connected (Attempt # " + dailAttempts + " of " + (CDYNE_RETRIES.ToInt() + 1) + ")";
                                notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\n < Phone Call To " + notifyObject.NotifierSettings["PhoneNo"] + "[" + notifyObject.NotifierSettings["CallerName"] + "]" + " Connected.  ";
                                notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\nAcknowledgement received, " + "'" + DigitsPressed + "' pressed.";
                                notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\nCall Complete >";

                                LogBook.Write("Query Call State Try: " + (QueryCall + 1) + ": Phone Call " + (totalCallAttempts + dailAttempts) + " of " + (CDYNE_RETRIES.ToInt() + 1) + " To " + notifyObject.NotifierSettings["PhoneNo"] + " Answered and Digits: " + DigitsPressed + " were pressed: " + IVRServiceResponseText + " for NotificationID: " + notificationID + " [CDyneTransID: " + TransactionID + "]");
                                break;
                            }
                            else if (CallAnswered == true && !DigitsPressed.Contains("*") && MachineDetection == "HUMAN" && CallComplete)
                            {
                                Answered = true;
                                notifyComResponse.IsSucceeded = false;
                                //notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\n < Phone Call To " + notifyObject.NotifierSettings["PhoneNo"] + "[" + notifyObject.NotifierSettings["CallerName"] + "]" + " Connected (Attempt # " + dailAttempts + " of " + (CDYNE_RETRIES.ToInt() + 1) + ")";
                                notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\n < Phone Call To " + notifyObject.NotifierSettings["PhoneNo"] + "[" + notifyObject.NotifierSettings["CallerName"] + "]" + " Connected.  ";
                                notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\nNo Acknowledgement received, Digits Pressed: " + DigitsPressed + ">";
                                LogBook.Write("Query Call State Try: " + (QueryCall + 1) + ": Phone Call " + (totalCallAttempts + dailAttempts) + " of " + (CDYNE_RETRIES.ToInt() + 1) + " To " + notifyObject.NotifierSettings["PhoneNo"] + " Answered but no digits were pressed: " + IVRServiceResponseText + " for NotificationID: " + notificationID + " [CDyneTransID: " + TransactionID + "]");
                                break;
                            }
                            else if (CallAnswered == true && DigitsPressed == "" && MachineDetection == "HUMAN" && !CallComplete)
                            {
                                notifyComResponse.IsSucceeded = false;
                                //notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\n < Phone Call To " + notifyObject.NotifierSettings["PhoneNo"] + "[" + notifyObject.NotifierSettings["CallerName"] + "]" + " Connected (Attempt # " + dailAttempts + " of " + (CDYNE_RETRIES.ToInt() + 1) + ")";
                                notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\n < Phone Call To " + notifyObject.NotifierSettings["PhoneNo"] + "[" + notifyObject.NotifierSettings["CallerName"] + "]" + " Connected.  ";
                                notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\nNo Acknowledgement received >";
                                LogBook.Write("Query Call State Try: " + (QueryCall + 1) + ": Phone Call " + (totalCallAttempts + dailAttempts) + " of " + (CDYNE_RETRIES.ToInt() + 1) + " To " + notifyObject.NotifierSettings["PhoneNo"] + " Answered but no digits were pressed: " + IVRServiceResponseText + " for NotificationID: " + notificationID + " [CDyneTransID: " + TransactionID + "]");
                                QueryCall += 1;
                            }
                            else if (CallAnswered == true && DigitsPressed == "" && MachineDetection == "MACHINE")
                            {
                                Answered = false;
                                notifyComResponse.IsSucceeded = false;
                                //notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\n < Phone Call To " + notifyObject.NotifierSettings["PhoneNo"] +"["+ notifyObject.NotifierSettings["CallerName"]+"]"+ " Connected (Attempt # " + dailAttempts + " of " + (CDYNE_RETRIES.ToInt() + 1) + ")";
                                notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\n < Phone Call To " + notifyObject.NotifierSettings["PhoneNo"] + "[" + notifyObject.NotifierSettings["CallerName"] + "]" + " Connected.  ";
                                notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\nAnswering Machine Detected >";
                                LogBook.Write("Query Call State Try: " + (QueryCall + 1) + ": Phone Call " + (totalCallAttempts + dailAttempts) + " of " + (CDYNE_RETRIES.ToInt() + 1) + " To " + notifyObject.NotifierSettings["PhoneNo"] + " Answered by MACHINE: " + IVRServiceResponseText + " for NotificationID: " + notificationID + " [CDyneTransID: " + TransactionID + "]");
                                break;
                            }
                            else if (IVRServiceResponseText == "In Call/Ringing" || IVRServiceResponseText == "Queued" || IVRServiceResponseText == "Universal Error")
                            {
                                notifyComResponse.IsSucceeded = false;
                                notifyComResponse.IsError     = true;
                                //if (notifyComResponse.ResponseContent != null)
                                //{
                                //    if ((!notifyComResponse.ResponseContent.ToString().Contains("Call/Ringing (Attempt # " + dailAttempts)) &&
                                //        (!notifyComResponse.ResponseContent.ToString().Contains("Queued (Attempt # " + dailAttempts)) &&
                                //        (!notifyComResponse.ResponseContent.ToString().Contains("Universal Error  (Attempt # " + dailAttempts)))  //only add line if it has not already been logged for this dial attempt
                                //    {
                                //        notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\n < Phone Call To " + notifyObject.NotifierSettings["PhoneNo"] + "[" + notifyObject.NotifierSettings["CallerName"] + "] " + IVRServiceResponseText + " (Attempt # " + dailAttempts + " of " + (CDYNE_RETRIES.ToInt() + 1) + ") >";
                                //    }
                                //}
                                //else
                                //{
                                //    notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\n < Phone Call To " + notifyObject.NotifierSettings["PhoneNo"] + "[" + notifyObject.NotifierSettings["CallerName"] + "] " + IVRServiceResponseText + " (Attempt # " + dailAttempts + " of " + (CDYNE_RETRIES.ToInt() + 1) + ") >";
                                //}
                                //    notifyComResponse.ResponseContent = "";
                                LogBook.Write("Query Call State Try: " + (QueryCall + 1) + ": Phone Call " + (totalCallAttempts + dailAttempts) + " of " + (CDYNE_RETRIES.ToInt() + 1) + " To " + notifyObject.NotifierSettings["PhoneNo"] + " Current Status: " + IVRServiceResponseText + " for NotificationID: " + notificationID + " [CDyneTransID: " + TransactionID + "]");
                                if (IVRServiceResponseText == "Universal Error")
                                {
                                    UnivError += 1;        //if it continues to return Universl Error allow a way to get out
                                }
                                QueryCall += 1;
                            }
                            else
                            {
                                notifyComResponse.IsSucceeded = false;
                                if (notifyComResponse.ResponseContent != null)
                                {
                                    if (!notifyComResponse.ResponseContent.ToString().Contains("ERROR"))         //only add line if it has not already been logged
                                    {
                                        //notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\n < Phone Call To " + notifyObject.NotifierSettings["PhoneNo"] + "[" + notifyObject.NotifierSettings["CallerName"] + "]" + " ERROR: " + IVRServiceResponseText + " (Attempt # " + dailAttempts + " of " + (CDYNE_RETRIES.ToInt() + 1) + ") >";
                                        notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\n < Phone Call To " + notifyObject.NotifierSettings["PhoneNo"] + "[" + notifyObject.NotifierSettings["CallerName"] + "]" + " ERROR: " + IVRServiceResponseText + " >";
                                    }
                                }
                                else
                                {
                                    //notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\n < Phone Call To " + notifyObject.NotifierSettings["PhoneNo"] + "[" + notifyObject.NotifierSettings["CallerName"] + "]" + " ERROR: " + IVRServiceResponseText + " (Attempt # " + dailAttempts + " of " + (CDYNE_RETRIES.ToInt() + 1) + ") >";
                                    notifyComResponse.ResponseContent += "\r\n\r\n\r\n\r\n < Phone Call To " + notifyObject.NotifierSettings["PhoneNo"] + "[" + notifyObject.NotifierSettings["CallerName"] + "]" + " ERROR: " + IVRServiceResponseText + " >";
                                }
                                LogBook.Write("Query Call State Try: " + (QueryCall + 1) + ": Phone Call " + (totalCallAttempts + dailAttempts) + " of " + (CDYNE_RETRIES.ToInt() + 1) + " To " + notifyObject.NotifierSettings["PhoneNo"] + " Current Status: " + IVRServiceResponseText + " for NotificationID: " + notificationID + " [CDyneTransID: " + TransactionID + "]");
                                QueryCall += 1;
                            }
                            if (QueryCall > 2 || Answered || (UnivError > 10))
                            {
                                break;
                            }
                        }
                    }catch (Exception ex)
                    {
                        LogBook.Write(ex, "CooperAtkins.NotificationClient.NotificationComposer.CDYNEIvrClientHelper MAkeTheCall", ErrorSeverity.High);
                    }


                    if (!callConnected || !Answered)
                    {
                        //write to TTNotificationLog

                        if (notifyComResponse.ResponseContent != null)
                        {
                            if (notifyComResponse.ResponseContent.ToString() != "")
                            {
                                notificationStyle.RecordNotification(notifyComResponse.ResponseContent.ToString(), notificationID, TransactionID.ToInt(), NotifyStatus.FAIL, NotifyTypes.VOICE);
                            }
                        }
                        notifyComResponse.ResponseContent = "";

                        //write to TTIVRNotifications
                        UpdateIVRNotification(ivrID, notifyComResponse.IsSucceeded, notifyComResponse.IsInProcess, (totalCallAttempts + dailAttempts), TransactionID, threadID);
                        // System.Threading.Thread.Sleep(30 * 1000); //wait and try that number 1 more time before trying next person
                        dailAttempts += 1;
                        retValue      = false;
                        if (((totalCallAttempts + dailAttempts.ToInt())) > CDYNE_RETRIES.ToInt16() + 1)
                        {        //try each person X times from config
                            LogBook.Write("Exhausted  " + (CDYNE_RETRIES.ToInt()) + " Re-Try Attempts To: " + notifyObject.NotifierSettings["PhoneNo"] + " for NotificationID: " + notificationID + " [CDyneTransID: " + TransactionID + "]");
                            notifyComResponse.IsInProcess = false;

                            if (UnivError >= 10)         //reset call counter, so it will re-attempt to call person has CDyne never truly made a call
                            {                            //4th param in below function
                                UpdateIVRNotification(ivrID, notifyComResponse.IsSucceeded, notifyComResponse.IsInProcess, 0, TransactionID, threadID);
                            }
                            else
                            {
                                UpdateIVRNotification(ivrID, notifyComResponse.IsSucceeded, notifyComResponse.IsInProcess, (totalCallAttempts + dailAttempts), TransactionID, threadID);
                            }
                            retValue = false;
                            alarmObject.IVRSuccess = false;
                            break;
                        }
                        else
                        {
                            LogBook.Write("Trying Retry Call Attempt " + (totalCallAttempts + dailAttempts) + " of " + (CDYNE_RETRIES.ToInt() + 1) + " Attempts To: " + notifyObject.NotifierSettings["PhoneNo"] + " for NotificationID: " + notificationID);
                        }
                    }
                    else
                    {
                        LogBook.Write("Call Complete.  Alert Success during call " + (totalCallAttempts + dailAttempts) + " of " + (CDYNE_RETRIES.ToInt() + 1) + " attempts To: " + notifyObject.NotifierSettings["PhoneNo"] + " for NotificationID: " + notificationID + " [CDyneTransID: " + TransactionID + "]");
                        notifyComResponse.IsInProcess = false;
                        notificationStyle.RecordNotification(notifyComResponse.ResponseContent.ToString(), notificationID, TransactionID.ToInt(), NotifyStatus.PASS, NotifyTypes.VOICE);
                        notifyComResponse.ResponseContent = "";
                        UpdateIVRNotification(ivrID, notifyComResponse.IsSucceeded, notifyComResponse.IsInProcess, (totalCallAttempts + dailAttempts), TransactionID, threadID);
                        retValue = true;
                        alarmObject.IVRSuccess = true;
                    }
                }
                break;         //end call attempts

            default:
                break;
            }

            if (method.ToLower() == "cooperatkins.notificationserver.notifyengine.ivrnotificationcom")
            {
                NotificationStyle notificationStyle = new NotificationStyle();

                foreach (string responseLine in response.Split(new string[] { "\n" }, StringSplitOptions.None))
                {
                    if (responseLine.ToLower().Contains("succeeded"))
                    {
                        succeeded = responseLine.ToLower().Replace("succeeded :", string.Empty);
                    }
                    else if (responseLine.ToLower().Contains("error"))
                    {
                        error = responseLine.ToLower().Replace("error :", string.Empty);
                    }
                }


                LogBook.Write("ResponseContent:" + response + ", IsSucceeded:" + succeeded + ", IsError:" + error);


                /* record the notification information to the database. */
                if (succeeded == "no")
                {
                    notificationStyle.RecordNotification(response.Remove(0, 60).Replace("\n", "\r\n"), notificationID, 0, NotifyStatus.FAIL, NotifyTypes.VOICE);
                }
                else
                {
                    notificationStyle.RecordNotification(response.Remove(0, 60).Replace("\n", "\r\n"), notificationID, 0, NotifyStatus.PASS, NotifyTypes.VOICE);
                }


                retValue = succeeded == "yes";
            }

            return(retValue);
        }
예제 #25
0
        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());
        }
예제 #26
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());
        }