Ejemplo n.º 1
0
        static void AlarmChecker(Ram_Info ws1)
        {
            try
            {

                if (AlarmCount > ws1.AlarmValue && AlarmStatus == 0)
                {

                    try
                    {
                        AlarmFormatter(ws1);
                    }
                    catch (Exception ex)
                    {

                        LogUtil.WriteLog(LogLevel.ERROR, ex.Message + " " + ex.StackTrace + Environment.NewLine + "**** " + "Date:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                    }

                    if (ws1.isFtpUploadEnable)
                    {
                        FTPHandler ftpUploader = new FTPHandler();
                        ftpUploader.Upload(ws1.AlarmFilePath, ws1.FtpFileName);
                    }

                    if (ws1.isMailSendEnable)
                    {
                        string[] mailingList1 = ws1.ReceiverList.Split('#');
                        foreach (string mailAdress in mailingList1)
                        {
                            Mailer cs = new Mailer();
                            cs.EmailSubject = String.Format(ws1.ClubName + "/" + ws1.Name, ws1.ClubName);
                            cs.EmailBody = "Server-IP: " + ws1.ServerIpAddress + "\n" + "Project Name:  " + ws1.ClubName + "\n" + ws1.MessageStopped + "%" + ws1.AlarmPercentage + "\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                            cs.IsHtmlMail = false;
                            cs.EmailTo = mailAdress;
                            cs.SmtpServerPort = SMTP_PORT;
                            cs.SenderEmailAddress = SMTP_USER;
                            cs.SenderEmailPassword = SMTP_PASS;
                            cs.EnableSsl = true;
                            cs.SmtpServerName = SMTP_HOST;
                            Mailer.SendSingleEmail(cs);
                            cs = null;

                        }

                    }

                    if (ws1.isSmsSendEnable)
                    {

                        try
                        {

                            string[] arrSmsList = ws1.SmsList.Split('#');
                            foreach (string Msisdn in arrSmsList)
                            {
                                DataAccessLayer _objDataAccessLayer = new DataAccessLayer();
                                _objDataAccessLayer.SendMessage(ws1.ServiceCode, Msisdn, String.Format("{0} - {1}", ws1.ClubName, ws1.MessageStopped + "\n" + "Server-IP: " + ws1.ServerIpAddress + "\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
                            }
                        }
                        catch (Exception exSms)
                        {
                            LogUtil.WriteLog(LogLevel.ERROR, exSms.Message + " " + exSms.StackTrace + Environment.NewLine + "**** " + "Date:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                        }
                    }
                    AlarmStatus = 1;

                }

                else if (AlarmCount == 0 && AlarmStatus == 1)
                {

                    AlarmStatus = 0;
                    AlarmCount = 0;

                    try
                    {
                        AlarmFormatter(ws1);
                    }
                    catch (Exception ex)
                    {

                        LogUtil.WriteLog(LogLevel.ERROR, ex.Message + " " + ex.StackTrace + Environment.NewLine + "**** " + "Date:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                    }

                    if (ws1.isFtpUploadEnable)
                    {
                        FTPHandler ftpUploader = new FTPHandler();
                        ftpUploader.Upload(ws1.AlarmFilePath, ws1.FtpFileName);
                    }

                    if (ws1.isSmsSendEnable)
                    {

                        try
                        {

                            string[] arrSmsList = ws1.SmsList.Split('#');
                            foreach (string Msisdn in arrSmsList)
                            {
                                DataAccessLayer _objDataAccessLayer = new DataAccessLayer();
                                _objDataAccessLayer.SendMessage(ws1.ServiceCode, Msisdn, String.Format("{0} - {1}", ws1.ClubName, ws1.MessageStarted + "\n" + "Server-IP: " + ws1.ServerIpAddress + "\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
                            }
                        }
                        catch (Exception exSms)
                        {
                            LogUtil.WriteLog(LogLevel.ERROR, exSms.Message + " " + exSms.StackTrace + Environment.NewLine + "**** " + "Date:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                        }
                    }

                    if (ws1.isMailSendEnable)
                    {
                        string[] mailingList = ws1.ReceiverList.Split('#');
                        foreach (string mailAdress in mailingList)
                        {
                            Mailer cs = new Mailer();
                            cs.EmailSubject = String.Format(ws1.ClubName + "/" + ws1.Name, ws1.ClubName);
                            cs.EmailBody = "Server-IP: " + ws1.ServerIpAddress + "\n" + "Project Name:  " + ws1.ClubName + "\n" + ws1.MessageStarted + "%" + ws1.AlarmPercentage + "\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                            cs.IsHtmlMail = false;
                            cs.EmailTo = mailAdress;
                            cs.SmtpServerPort = SMTP_PORT;
                            cs.SenderEmailAddress = SMTP_USER;
                            cs.SenderEmailPassword = SMTP_PASS;
                            cs.EnableSsl = true;
                            cs.SmtpServerName = SMTP_HOST;
                            Mailer.SendSingleEmail(cs);
                            cs = null;
                        }

                    }
                }
                else
                {
                    Console.WriteLine("Normal");
                }
            }

            catch (Exception ex)
            {

                LogUtil.WriteLog(LogLevel.ERROR, ex.Message + " " + ex.StackTrace + Environment.NewLine + "**** " + "Date:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
            }
        }
Ejemplo n.º 2
0
        protected override void OnStart(string[] args)
        {
            try
            {

                #region serviceVariables

                string ServiceStarterMessage = ConfigurationManager.AppSettings.Get("ServiceStarterMessage");
                string ClubName = ConfigurationManager.AppSettings.Get("ClubName");
                string AppName = ConfigurationManager.AppSettings.Get("ApplicationName");
                int StartSleepTime = Convert.ToInt32(ConfigurationManager.AppSettings.Get("StartSleepTime"));
                string ServiceStarterMailinglist = ConfigurationManager.AppSettings.Get("ServiceStarterMailinglist");
                string ServerIP = ConfigurationManager.AppSettings.Get("ServerIP");

                string SMTP_HOST = ConfigurationManager.AppSettings.Get("SMTP_HOST");
                string SMTP_PORT = ConfigurationManager.AppSettings.Get("SMTP_PORT");
                string SMTP_USER = ConfigurationManager.AppSettings.Get("SMTP_USER");
                string SMTP_PASS = ConfigurationManager.AppSettings.Get("SMTP_PASS");
                bool isSSLEnabled = Convert.ToBoolean(ConfigurationManager.AppSettings.Get("SMTP_SSL_ENABLE"));

                #endregion
                try
                {
                    #region SendMailFirstToAuthorized
                    string[] mailingList = ServiceStarterMailinglist.Split('#');
                    foreach (string Receievers in mailingList)
                    {

                        Mailer cs = new Mailer();
                        cs.EmailSubject = ClubName + "/" + AppName + " windows service has started:  " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ClubName;
                        cs.EmailBody = "Server IP:" + ServerIP + Environment.NewLine + "Project Name:" + ClubName + Environment.NewLine + ServiceStarterMessage + Environment.NewLine + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                        cs.IsHtmlMail = false;
                        cs.EmailTo = Receievers;
                        cs.SmtpServerPort = SMTP_PORT;
                        cs.SenderEmailAddress = SMTP_USER;
                        cs.SenderEmailPassword = SMTP_PASS;
                        cs.EnableSsl = true;
                        cs.SmtpServerName = SMTP_HOST;
                        Mailer.SendSingleEmail(cs);
                        cs = null;
                    }
                    #endregion

                    LogUtil.WriteLog(LogLevel.INFO, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + AppName + " has started, sleeping for " + StartSleepTime.ToString() + " miliseconds before starting threads");
                    Thread.Sleep(StartSleepTime);
                    LogUtil.WriteLog(LogLevel.INFO, "Sleep ended, starting to process threads");

                    Thread alarmChecker = new Thread(new ThreadStart((new AlarmMonitor()).Start));
                    alarmChecker.Name = "Alarm Monitor";
                    alarmChecker.Start();

                }
                catch (Exception ex)
                {
                    LogUtil.WriteLog(LogLevel.ERROR, String.Format("MESSAGE: {0} *** STACK TRACE: {1}", ex.Message, ex.StackTrace));
                }

            }
            catch (Exception ex)
            {

                LogUtil.WriteLog(LogLevel.ERROR, String.Format("MESSAGE: {0} *** STACK TRACE: {1}", ex.Message, ex.StackTrace));
            }
        }