Пример #1
0
        /// <summary>
        /// Check for sensor type Units Of Measure
        /// </summary>
        /// <param name="alarmObject"></param>
        /// <returns></returns>
        private string GetSensorTypeUOM(Interface.Alarm.AlarmObject alarmObject)
        {
            string         sensorType = "", sensorTypeUOM = "";
            SensorTypeInfo sensorTypeInfo = null;

            sensorType = alarmObject.SensorType.ToStr().Trim().ToUpper();
            if (AlarmHelper.IsTempSensor(sensorType))
            {
                sensorTypeUOM = (alarmObject.IsCelsius) ? "C" : "F";
            }
            else if (sensorType.IndexOf("HUMI") >= 0)
            {
                sensorTypeUOM = "%RH";
            }
            else if (AlarmHelper.IsContactSensor(sensorType))
            {
                sensorTypeUOM = "";
            }
            else if (sensorType.Length > 0)
            {
                sensorTypeInfo = AlarmHelper.GetSensorTypeInfo(sensorType);
                if (sensorTypeInfo != null)
                {
                    sensorTypeUOM  = sensorTypeInfo.UOM;
                    sensorTypeInfo = null;
                }
            }
            return(sensorTypeUOM);
        }
Пример #2
0
        /// <summary>
        /// Get Pager Notification Address List
        /// </summary>
        /// <param name="alarmObject"></param>
        /// <returns></returns>
        private NotifyPagerAddressList GetPagerAddressList(Interface.Alarm.AlarmObject alarmObject)
        {
            NotifyPagerAddressList notifyPagerAddressList = null;

            try
            {
                /*Fetch Email Address list based on Notification Profile ID*/
                notifyPagerAddressList = new NotifyPagerAddressList();
                Criteria criteria = new Criteria();
                criteria.ID = GetPagerNotificationID(alarmObject.NotifyProfileID);//Replace with
                notifyPagerAddressList.Load(criteria);
            }
            catch (Exception ex)
            {
                /*Debug Object values for reference*/
                LogBook.Debug(notifyPagerAddressList, this);

                /*Write exception log*/
                LogBook.Write(_logContent + " Error has occurred while fetching pager address list from 'GenNotifyPagers' table", ex, "CooperAtkins.NotificationClient.NotificationComposer.PagerNotificationComposer");
            }
            finally
            {
                notifyPagerAddressList.Dispose();
            }
            return(notifyPagerAddressList);
        }
Пример #3
0
        /// <summary>
        /// Get FormatID
        /// </summary>
        /// <param name="alarmObject"></param>
        /// <param name="formatType"></param>
        /// <param name="action"></param>
        /// <returns></returns>
        private int GetFormatID(Interface.Alarm.AlarmObject alarmObject, string formatType, int action)
        {
            int sensorFormatID = 0;
            SensorFormatString sensorFormatString = null;

            try
            {
                sensorFormatString            = new SensorFormatString();
                sensorFormatString.UTID       = alarmObject.UTID;
                sensorFormatString.Probe      = alarmObject.Probe;
                sensorFormatString.FormatType = formatType;
                sensorFormatString.Action     = action;

                sensorFormatString.Execute(sensorFormatString);
                sensorFormatID = sensorFormatString.SensorFormatID;
            }
            catch (Exception ex)
            {
                /*Debug Object values for reference*/
                LogBook.Debug(sensorFormatString, this);

                /*Write exception log*/
                LogBook.Write("Error has occurred while retrieving SensorFormatID", ex, "CooperAtkins.NotificationClient.NotificationComposer.Notification");
            }
            finally
            {
                sensorFormatString.Dispose();
            }
            return(sensorFormatID);
        }
Пример #4
0
        /// <summary>
        /// Get Notification E-Mail Address list based on Notification Profile ID
        /// </summary>
        /// <param name="alarmObject"></param>
        /// <returns></returns>
        private NotifyEmailAddressList GetNotifyEmailAddressList(Interface.Alarm.AlarmObject alarmObject)
        {
            NotifyEmailAddressList notifyEmailAddressList = null;

            try
            {
                /*Create NotifyEmailAddressList object*/
                notifyEmailAddressList = new NotifyEmailAddressList();
                /*Create Criteria object*/
                Criteria criteria = new Criteria();
                /*Get the Email notificationId and assign to criteria.ID*/
                criteria.ID = GetEmailNotificationID(alarmObject.NotifyProfileID);
                /*Gets list of notification email addresses*/
                notifyEmailAddressList.Load(criteria);
            }
            catch (Exception ex)
            {
                /*Debug Object values for reference*/
                LogBook.Debug(notifyEmailAddressList, this);

                /*Write exception log*/
                LogBook.Write(_logContent + " Error has occurred while fetching email address list from 'GenNotifyEmails' table", ex, "CooperAtkins.NotificationClient.NotificationComposer.EmailNotificationComposer");
            }
            finally
            {
                notifyEmailAddressList.Dispose();
            }
            return(notifyEmailAddressList);
        }
        /// <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>
        /// 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);
        }
Пример #7
0
        /// <summary>
        /// Get E-Mail body
        /// </summary>
        /// <param name="alarmObject"></param>
        /// <returns></returns>
        public string GetEmailBody(Interface.Alarm.AlarmObject alarmObject)
        {
            string emilBodyStr = "";
            string iUOM = "", sUOM = "", sURL = "";

            string[] alarmVals = new string[5];

            //Set Alarm values
            alarmVals = FormatSensorValues(alarmObject);
            if (alarmVals.Length >= 4)
            {
                sUOM = alarmVals[3];
                iUOM = alarmVals[4];
            }

            //sURL--> Set local host name //Pending

            /*Get Email Body*/
            using (DataAccess.EmailBody emailBody = new DataAccess.EmailBody())
            {
                emailBody.EmailFormat       = 0; //1=Text, 2=HTML, 0=Default (HTML)
                emailBody.UTID              = alarmObject.UTID;
                emailBody.Probe             = alarmObject.Probe;
                emailBody.LogTime           = (DateTime?)alarmObject.AlarmTime.MinDateToDateTime();
                emailBody.TzOffset          = Convert.ToDecimal(Common.TzOffset() / 60);
                emailBody.SensorReading     = alarmObject.Value;
                emailBody.AlarmStartTime    = (DateTime?)alarmObject.AlarmStartTime.MinDateToDateTime();
                emailBody.AlarmProfileRecID = 0;
                emailBody.ThresholdMins     = alarmObject.CurrentAlarmMinutes;
                emailBody.CondThresholdMins = alarmObject.Threshold.ToInt();
                emailBody.CondMinValue      = alarmObject.AlarmMinValue.ToDecimal();
                emailBody.CondMaxValue      = alarmObject.AlarmMaxValue.ToDecimal();
                emailBody.IncludeHistory    = 0;            //NULL in VB
                emailBody.ValuesUOM         = iUOM.ToInt(); //-- 0 = Unknown / None,9 = Celsius,31  = Fahrenheit
                emailBody.HTMLlink          = sURL;
                emailBody.Severity          = alarmObject.Severity;

                /*Execute*/
                emailBody.Execute(emailBody);
                /*E-Mail Body*/
                emilBodyStr = emailBody.Body;
            }
            return(emilBodyStr);
        }
Пример #8
0
        /// <summary>
        /// Format the sensor values
        /// </summary>
        /// <param name="alarmObject"></param>
        /// <returns></returns>
        private string FormatCurrentSensorValue(Interface.Alarm.AlarmObject alarmObject, SensorCurrentStatus sensorCurrentStatus)
        {
            //Define local variables
            string sValue;
            int    nDecimals;

            sValue    = sensorCurrentStatus.CurrentValue.ToStr();
            nDecimals = 1;

            switch (((alarmObject.SensorType.ToStr() != string.Empty) && (alarmObject.SensorType.ToStr().Length >= 4)) ? alarmObject.SensorType.Substring(0, 4) : "")
            {
            case "TEMP":
            case "THER":
                if (alarmObject.IsCelsius)
                {
                    sValue = Common.FahrenheitToCelsius(alarmObject.Value.ToStr());
                }

                nDecimals = 1;
                break;

            case "CONT":
            case "SECU":
                sValue    = GetContactStateString(alarmObject.UTID, alarmObject.Probe, alarmObject.Value.ToDecimal(), 1);  //Language = 1
                nDecimals = 0;
                break;

            //case "NAFE": //NAFEM Protocol Device Sensor
            //    int index = 0;
            //    foreach (string value in alarmObject.SensorType.Split(':'))
            //    {
            //        aParts[index] = value;
            //        index++;
            //        if (index == 4)
            //            break;
            //    }
            //    dUOM = 0;
            //    if (aParts[1] != "")
            //        dUOM = aParts[1].ToDecimal();
            //    if (dUOM == Measure.UOMBitMask.ToDecimal())
            //    {
            //        sUOM = "";
            //        sValue = GetContactStateString(alarmObject.UTID, alarmObject.Probe, alarmObject.Value.ToDecimal(), 1); //Language = 1
            //    }
            //    else
            //        sUOM = NAFEMuom2DisplayString(dUOM);
            //    if (dUOM == Measure.UOMcelsius.ToDecimal())
            //    {
            //        sValue = Common.FahrenheitToCelsius(alarmObject.Value.ToStr());
            //        sMin = Common.FahrenheitToCelsius(alarmObject.AlarmMinValue.ToStr());
            //        sMax = Common.FahrenheitToCelsius(alarmObject.AlarmMaxValue.ToStr());
            //    }
            //    nDecimals = 1;
            //    iUOM = dUOM;
            //    break;
            case "HUMI":
                nDecimals = 1;
                break;

            case "V5":
            case "V10":
                break;

            default:
                nDecimals = GetSensorTypeDecimals(alarmObject.SensorType);
                break;
            }

            /* Contact sensor will give the value as "Opened or Closed", before casting the to double, check the value type.*/
            double outValue;

            if (double.TryParse(sValue, out outValue))
            {
                if (sValue != "")
                {
                    sValue = Microsoft.VisualBasic.Strings.FormatNumber(Double.Parse(sValue), nDecimals);
                }
            }

            return(sValue);
        }
Пример #9
0
        /// <summary>
        /// Format the sensor values
        /// </summary>
        /// <param name="alarmObject"></param>
        /// <returns></returns>
        private string[] FormatSensorValues(Interface.Alarm.AlarmObject alarmObject)
        {
            string[] aValues = new string[5];

            //Define local variables
            string  sValue, sMin, sMax, sUOM;
            decimal iUOM, dUOM;
            int     nDecimals;

            string[] aParts = new string[5];

            //Assign variables
            sUOM      = "";
            sValue    = alarmObject.DisplayValue.ToStr();
            sMin      = alarmObject.AlarmMinValue.ToStr();
            sMax      = alarmObject.AlarmMaxValue.ToStr();
            iUOM      = 0;
            nDecimals = 1;

            switch (((alarmObject.SensorType.ToStr() != string.Empty) && (alarmObject.SensorType.ToStr().Length >= 4)) ? alarmObject.SensorType.Substring(0, 4) : "")
            {
            case "TEMP":
            case "THER":
                sUOM = (alarmObject.IsCelsius) ? "C" : "F";
                if (alarmObject.IsCelsius)
                {
                    sValue = Common.FahrenheitToCelsius(alarmObject.Value.ToStr());
                    sMin   = Common.FahrenheitToCelsius(alarmObject.AlarmMinValue.ToStr());
                    sMax   = Common.FahrenheitToCelsius(alarmObject.AlarmMaxValue.ToStr());
                    iUOM   = Measure.UOMcelsius.ToInt();
                }
                else
                {
                    iUOM = Measure.UOMfahrenheit.ToInt();
                }
                nDecimals = 1;
                break;

            case "CONT":
            case "SECU":
                sValue    = GetContactStateString(alarmObject.UTID, alarmObject.Probe, alarmObject.Value.ToDecimal(), 1);  //Language = 1
                nDecimals = 0;
                break;

            case "NAFE":     //NAFEM Protocol Device Sensor
                int index = 0;
                foreach (string value in alarmObject.SensorType.Split(':'))
                {
                    aParts[index] = value;
                    index++;
                    if (index == 4)
                    {
                        break;
                    }
                }
                dUOM = 0;
                if (aParts[1] != "")
                {
                    dUOM = aParts[1].ToDecimal();
                }
                if (dUOM == Measure.UOMBitMask.ToDecimal())
                {
                    sUOM   = "";
                    sValue = GetContactStateString(alarmObject.UTID, alarmObject.Probe, alarmObject.Value.ToDecimal(), 1);     //Language = 1
                }
                else
                {
                    sUOM = NAFEMuom2DisplayString(dUOM);
                }
                if (dUOM == Measure.UOMcelsius.ToDecimal())
                {
                    sValue = Common.FahrenheitToCelsius(alarmObject.Value.ToStr());
                    sMin   = Common.FahrenheitToCelsius(alarmObject.AlarmMinValue.ToStr());
                    sMax   = Common.FahrenheitToCelsius(alarmObject.AlarmMaxValue.ToStr());
                }
                nDecimals = 1;
                iUOM      = dUOM;
                break;

            case "HUMI":
                sUOM      = "%RH";
                nDecimals = 1;
                break;

            case "V5":
            case "V10":
                sUOM = "Volts";
                break;

            default:
                sUOM      = GetSensorTypeUOM(alarmObject);
                nDecimals = GetSensorTypeDecimals(alarmObject.SensorType);
                break;
            }

            /* Contact sensor will give the value as "Opened or Closed", before casting the to double, check the value type.*/
            double outValue;

            if (double.TryParse(sValue, out outValue))
            {
                if (sValue != "")
                {
                    sValue = Microsoft.VisualBasic.Strings.FormatNumber(Double.Parse(sValue), nDecimals);
                    sMin   = (sMin != "") ? Microsoft.VisualBasic.Strings.FormatNumber(Double.Parse(sMin), nDecimals) : "";
                    sMax   = (sMax != "") ? Microsoft.VisualBasic.Strings.FormatNumber(Double.Parse(sMax), nDecimals) : "";
                }
            }

            //sValue, sMin, sMax, sUOM, iUOM

            aValues[0] = sValue;
            aValues[1] = sMin;
            aValues[2] = sMax;
            aValues[3] = sUOM;
            aValues[4] = iUOM.ToStr();
            return(aValues);
        }
Пример #10
0
        /// <summary>
        /// Get format string
        /// </summary>
        /// <param name="formatString"></param>
        /// <param name="alarmObject"></param>
        /// <returns></returns>
        public string SubstituteFormatString(string formatString, Interface.Alarm.AlarmObject alarmObject)
        {
            string  temperatureReading = "Reading OK", sUCOM = "", sValue;
            decimal dMin, dMax;

            string[] aValues = new string[4];

            /*Set Alarm Values*/
            //Check for contact sensor
            if (AlarmHelper.IsContactSensor(alarmObject.SensorType))
            {
                temperatureReading = (alarmObject.Value == 0) ? "CLOSED" : "OPEN";
            }
            else
            {
                temperatureReading = (alarmObject.Value < alarmObject.AlarmMinValue) ? "LOW" : "HIGH";
            }

            dMin   = alarmObject.AlarmMinValue;
            dMax   = alarmObject.AlarmMaxValue;
            sValue = alarmObject.DisplayValue;
            sUCOM  = "";


            if (alarmObject.AlarmType == AlarmType.COMMUNICATIONS)
            {
                sValue = alarmObject.CurrentAlarmMinutes.ToString();
            }
            else
            {
                aValues = FormatSensorValues(alarmObject);
                if (aValues.Length >= 3)
                {
                    sValue = aValues[0];
                    dMin   = aValues[1].ToDecimal();
                    dMax   = aValues[2].ToDecimal();
                    sUCOM  = aValues[3];
                }
            }

            //Substitute values for format string
            //formatString = formatString.Replace("\\n", Environment.NewLine);
            //formatString = formatString.Replace("\\n", "\\n");
            //formatString = formatString.Replace("\n", Environment.NewLine);
            formatString = Microsoft.VisualBasic.Strings.Replace(formatString, "%%ID%%", FormatFactoryID(alarmObject.FactoryID), 1, -1, Constants.vbTextCompare);
            formatString = Microsoft.VisualBasic.Strings.Replace(formatString, "%%NAME%%", alarmObject.ProbeName, 1, -1, Constants.vbTextCompare);
            formatString = Microsoft.VisualBasic.Strings.Replace(formatString, "%%NAME2%%", alarmObject.ProbeName2, 1, -1, Constants.vbTextCompare);
            formatString = Microsoft.VisualBasic.Strings.Replace(formatString, "%%TYPE%%", (alarmObject.AlarmType == AlarmType.COMMUNICATIONS.ToInt16()) ? alarmObject.SensorClass : alarmObject.SensorType, 1, -1, Constants.vbTextCompare);
            formatString = Microsoft.VisualBasic.Strings.Replace(formatString, "%%VALUE%%", sValue, 1, -1, Constants.vbTextCompare);
            formatString = Microsoft.VisualBasic.Strings.Replace(formatString, "%%MIN%%", dMin.ToStr(), 1, -1, Constants.vbTextCompare);
            formatString = Microsoft.VisualBasic.Strings.Replace(formatString, "%%MAX%%", dMax.ToStr(), 1, -1, Constants.vbTextCompare);
            formatString = Microsoft.VisualBasic.Strings.Replace(formatString, "%%UOM%%", sUCOM.ToStr(), 1, -1, Constants.vbTextCompare);
            formatString = Microsoft.VisualBasic.Strings.Replace(formatString, "%%TIME%%", alarmObject.AlarmTime.ToLocalTime().ToString(), 1, -1, Constants.vbTextCompare);
            formatString = Microsoft.VisualBasic.Strings.Replace(formatString, "%%GMTTIME%%", alarmObject.AlarmTime.ToStr(), 1, -1, Constants.vbTextCompare);
            formatString = Microsoft.VisualBasic.Strings.Replace(formatString, "%%NOW%%", DateTime.Now.ToStr(), 1, -1, Constants.vbTextCompare);
            formatString = Microsoft.VisualBasic.Strings.Replace(formatString, "%%GROUP%%", alarmObject.GroupName, 1, -1, Constants.vbTextCompare);
            formatString = Microsoft.VisualBasic.Strings.Replace(formatString, "%%HOTCOLD%%", temperatureReading, 1, -1, Constants.vbTextCompare);
            formatString = Microsoft.VisualBasic.Strings.Replace(formatString, "%%CORF%%", (alarmObject.IsCelsius) ? "C" : "F", 1, -1, Constants.vbTextCompare);
            formatString = Microsoft.VisualBasic.Strings.Replace(formatString, "%%THRESHOLD%%", alarmObject.Threshold.ToStr(), 1, -1, Constants.vbTextCompare);
            formatString = Microsoft.VisualBasic.Strings.Replace(formatString, "%%THRESHOLDMINS%%", alarmObject.CondThresholdMins.ToStr(), 1, -1, Constants.vbTextCompare);
            formatString = Microsoft.VisualBasic.Strings.Replace(formatString, "%%TimeOutOfRange%%", Common.FormatMinutes(GetCurrentMinInAlarm(alarmObject)), 1, -1, Constants.vbTextCompare);
            formatString = Microsoft.VisualBasic.Strings.Replace(formatString, "%%AlarmStartTime%%", alarmObject.AlarmStartTime.ToLocalTime().ToString(), 1, -1, Constants.vbTextCompare);
            formatString = Microsoft.VisualBasic.Strings.Replace(formatString, "%%ESCALATION%%", (alarmObject.IsEscalationNotification ? "** ESCALATION NOTIFICATION **" : ((alarmObject.IsFailsafeEscalationNotification) ? "** FAILSAFE ESCALATION NOTIFICATION **" : "")), 1, -1, Constants.vbTextCompare);
            formatString = Microsoft.VisualBasic.Strings.Replace(formatString, "%%SEVERITY%%", alarmObject.Severity.ToStr(), 1, -1, Constants.vbTextCompare);
            // Does this put in the actual current value?
            if (formatString != null)
            {
                if (formatString.Contains("%%CURRENTVALUE%%", StringComparison.OrdinalIgnoreCase))
                {
                    // Need to hit datbase for current values

                    SensorCurrentStatus sensorCurrentStatus = new SensorCurrentStatus();
                    try
                    {
                        LogBook.Write("Getting current value and time for sensor");
                        sensorCurrentStatus.UTID  = alarmObject.UTID;
                        sensorCurrentStatus.Probe = alarmObject.Probe;
                        sensorCurrentStatus.Execute();
                    }
                    catch (Exception ex)
                    {
                        LogBook.Write(ex, "CooperAtkins.NotificationClient.NotificationComposer.NotificationStyle", ErrorSeverity.High);
                    }
                    finally
                    {
                        sensorCurrentStatus.Dispose();
                    }
                    formatString = Microsoft.VisualBasic.Strings.Replace(formatString, "%%CURRENTVALUE%%", sensorCurrentStatus.CurrentValue.ToStr(), 1, -1, Constants.vbTextCompare);
                    formatString = Microsoft.VisualBasic.Strings.Replace(formatString, "%%CURRENTVALUETIME%%", sensorCurrentStatus.CurrentTime.ToLocalTime().ToString(), 1, -1, Constants.vbTextCompare);
                }
            }



            return(formatString);
        }
Пример #11
0
        /// <summary>
        /// Get Format String
        /// </summary>
        /// <param name="alarmObject"></param>
        /// <param name="languageID"></param>
        /// <param name="formatType"></param>
        /// <returns></returns>
        public string GetFormatString(Interface.Alarm.AlarmObject alarmObject, int languageID, string formatType)
        {
            string sensorType = "", frmtstring = "";
            int    i = 0, formatID = 0;

            //Sensor Type
            sensorType = (alarmObject.AlarmType == AlarmType.COMMUNICATIONS ? "MISS" : alarmObject.SensorType);
            try
            {
                while ((sensorType != "" && i < 2))
                {
                    if (i > 0)
                    {
                        sensorType = "";
                    }
                    //Get Sensor FomratID
                    while (true)
                    {
                        //Individual message format
                        formatID = GetFormatID(alarmObject, formatType, 1);
                        if (formatID != 0)
                        {
                            break;
                        }
                        //Next, check for Group default message format...
                        formatID = GetFormatID(alarmObject, formatType, 2);
                        if (formatID != 0)
                        {
                            break;
                        }
                        //Finally, get default message format...
                        formatID = GetFormatID(alarmObject, formatType, 3);
                        break;
                    }
                    if (formatID != 0)
                    {
                        //Get Sensor format string.
                        using (FormatString formatString = new FormatString())
                        {
                            formatString.FormatID   = formatID;
                            formatString.LanguageID = languageID;
                            formatString.SensorType = sensorType;
                            formatString.Execute(formatString);
                            frmtstring = formatString.ComposeString;
                            if (frmtstring.ToStr() != "")
                            {
                                break;
                            }
                        }
                    }
                    i = i + 1;
                }
            }
            catch (Exception ex)
            {
                /*Write Log*/
                LogBook.Write("Error occurred getting the format string.", ex, "CooperAtkins.NotificationClient.NotificationComposer.NotificationStyle");
            }

            //If FormatString is empty set default value.
            if (frmtstring.ToStr() == string.Empty)
            {
                frmtstring = GetDefaultFormatString(alarmObject, languageID, formatType);
            }
            else
            {
                return(frmtstring);
            }

            return(frmtstring);
        }
Пример #12
0
        /// <summary>
        /// Get default format string
        /// </summary>
        /// <param name="alarmObject"></param>
        /// <param name="languageID"></param>
        /// <param name="formatType"></param>
        /// <returns></returns>
        private string GetDefaultFormatString(Interface.Alarm.AlarmObject alarmObject, int languageID, string formatType)
        {
            string formatString = "";

            if (alarmObject.AlarmType == AlarmType.COMMUNICATIONS)
            {
                formatString = "MISSED COMM: %%TYPE%% %%NAME%% In %%GROUP%% (%%TimeOutOfRange%%)";
            }
            else if (AlarmHelper.IsContactSensor(alarmObject.SensorType))
            {
                //Check logic for vbTextCompare in c#

                /*Body Pager*/
                if (formatType.IndexOf("BodyPager") >= 0)
                {
                    formatString = "";
                }

                /*Notify Tree*/
                else if (formatType.IndexOf("NotifyTree") >= 0)
                {
                    formatString = "";
                }

                /*Email Body*/
                else if (formatType.IndexOf("EmailBody") >= 0)
                {
                    formatString = "";
                }

                /*Pager Subject*/
                else if (formatType.IndexOf("SubjectPager") >= 0)
                {
                    formatString = "TempTrak ALERT - %%NAME%% In %%GROUP%%: %%VALUE%% (%%THRESHOLDMINS%%)";
                }

                /*Email Subject*/
                else if (formatType.IndexOf("EmailSubject") >= 0)
                {
                    formatString = "TempTrak ALERT - %%NAME%% In %%GROUP%%: %%VALUE%% (%%THRESHOLDMINS%%)";
                }

                /*Net send*/
                else if (formatType.IndexOf("NetSend") >= 0)
                {
                    formatString = "!! TEMP TRAK ALERT !!\n%%NAME%% In %%GROUP%%: %%VALUE%% (%%THRESHOLDMINS%%)";
                }

                /*Popup*/
                else if (formatType.IndexOf("Popup") >= 0)
                {
                    formatString = "!! TEMP TRAK ALERT !!\n%%NAME%% In %%GROUP%%: %%VALUE%% (%%THRESHOLDMINS%%)";
                }

                /*Message Board*/
                else if (formatType.IndexOf("Board") >= 0)
                {
                    formatString = "WARNING: %%NAME%% In %%GROUP%%: at %%VALUE%% (%%THRESHOLDMINS%%)";
                }

                /*Default*/
                else
                {
                    formatString = "TempTrak ALERT - %%NAME%% In %%GROUP%%: %%VALUE%% (%%THRESHOLDMINS%%)";
                }
            }
            else
            {
                /*Pager Body*/
                if (formatType.IndexOf("BodyPager") >= 0)
                {
                    formatString = "";
                }

                /*Notify Tree*/
                else if (formatType.IndexOf("NotifyTree") >= 0)
                {
                    formatString = "";
                }

                /*Email Body*/
                else if (formatType.IndexOf("EmailBody") >= 0)
                {
                    formatString = "";
                }

                /*Pager Subject*/
                else if (formatType.IndexOf("SubjectPager") >= 0)
                {
                    formatString = "TempTrak ALERT - %%NAME%% In %%GROUP%% at %%VALUE%% (%%MIN%%-%%MAX%%)";
                }

                /*Email Subject*/
                else if (formatType.IndexOf("EmailSubject") >= 0)
                {
                    formatString = "TempTrak ALERT - %%NAME%% In %%GROUP%%: at %%VALUE%% (Normal Range %%MIN%%-%%MAX%%)";
                }

                /*Net send*/
                else if (formatType.IndexOf("NetSend") >= 0)
                {
                    formatString = "!! TEMP TRAK ALERT !!\n%%NAME%% In %%GROUP%%: at %%VALUE%% (Normal Range %%MIN%%-%%MAX%%)";
                }

                /*Popup*/
                else if (formatType.IndexOf("Popup") >= 0)
                {
                    formatString = "!! TEMP TRAK ALERT !!\n%%NAME%% In %%GROUP%%: at %%VALUE%% (Normal Range %%MIN%%-%%MAX%%)";
                }

                /*Message Board*/
                else if (formatType.IndexOf("Board") >= 0)
                {
                    formatString = "WARNING: %%NAME%% In %%GROUP%%: at %%VALUE%% (Range %%MIN%%-%%MAX%%)";
                }

                /*Default*/
                else
                {
                    formatString = "TempTrak ALERT - %%NAME%% In %%GROUP%%: at %%VALUE%% (Range %%MIN%%-%%MAX%%)";
                }
            }
            return(formatString);
        }
Пример #13
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);
        }
Пример #14
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);
        }