Ejemplo n.º 1
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);
        }