/// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public bool ProcessEmailAlertData()
        {
            List<rsp_GetSiteListResult> lstSites = null;
            string sSendMail = string.Empty;

            using (DataHelper context = new DataHelper(DatabaseHelper.GetConnectionString()))
            {
                context.GetSetting(0, "SendMailFromEnterprise", "false", ref sSendMail);

                if (Convert.ToBoolean(sSendMail))
                {
                    lstSites = context.GetSiteList().ToList();

                    LogManager.WriteLog("Count" + lstSites.Count.ToString(), LogManager.enumLogLevel.Info);
                    if (lstSites != null && lstSites.Count > 0)
                    {
                        foreach (rsp_GetSiteListResult site in lstSites)
                        {
                            LogManager.WriteLog("Spawning New Thread", LogManager.enumLogLevel.Info);
                            LogManager.WriteLog("SITE CODE :" + site.SITE_CODE, LogManager.enumLogLevel.Info);
                            workerThread = new Thread((ProcessWorkerThread)) { Name = site.SITE_CODE };
                            workerThread.Start(site.SITE_CODE);
                            // workerThread.Start("1002");
                            workerThread.Priority = ThreadPriority.Normal;
                        }
                        // ProcessWorkerThread("1002");
                    }
                }
                else
                    ProcessWorkerThread(string.Empty);
            }
            return true;
        }
        /// <summary>
        /// get teh list of email subscribers for sending alerts.
        /// </summary>
        /// <returns></returns>
        public Dictionary<string, MailMessageGroup> GetEmailSubScribers()
        {
             Dictionary<string ,MailMessageGroup> dEmailConfigurations = null;
             try
             {
                 using (DataHelper context = new DataHelper(DatabaseHelper.GetConnectionString()))
                 {
                     List<EmailSubscriberDetailsResult> subscribers = context.GetEmailAlertSubscribers(string.Empty).ToList();

                     dEmailConfigurations = (from s in subscribers
                                             group s by s into g
                                             select new // Selection criteria
                                             {
                                                 key = g.Key.TypeName,
                                                 val = new MailMessageGroup
                                                 {
                                                     FromAddress = g.Key.FromMail,
                                                     ToList = g.Key.ToMail,
                                                     CCList = g.Key.CCMail,
                                                     BCCList = g.Key.BCCMail,
                                                     Encoding = System.Text.Encoding.ASCII.ToString(),
                                                     Subject = g.Key.SUBJECT
                                                 }
                                             }).ToDictionary(k => k.key, v => v.val);

                 }
             }
             catch (Exception ex)
             { ExceptionManager.Publish(ex); }
             finally
             { }
            return dEmailConfigurations;
        }
예제 #3
0
 public bool CheckAndUpdateNewCalendar(int MinDays)
 {
     LogManager.WriteLog("AC - > inside CheckAndUpdateNewCalendar method", LogManager.enumLogLevel.Info);
     try
     {
         bool result = true;
         using (DataHelper context = new DataHelper(DatabaseHelper.GetConnectionString()))
         {
             result = Convert.ToBoolean(context.CheckAndUpdateNewCalendar(MinDays));
         }
         return result;
     }
     catch (Exception ex)
     {
         ExceptionManager.Publish(ex);
         return false;
     }
 }
        /// <summary>
        /// process alerts for each site.
        /// </summary>
        /// <param name="siteCode"></param>
        /// <param name="recordsCount"></param>
        /// <returns></returns>
        private bool ProcessRecordsForSite(string siteCode, int perItemprocessInterval)
        {
            // declare.
            int? iRecord = 0;
            bool bResult = false;
            string strResult = string.Empty;
            AlertEntity entity = null;
            AlertEngine engine = new AlertEngine();

            List<UnprocessedRecordsForEmailAlertResult> lstUnprocessedAlerts = null;
            //process started.
           // LogManager.WriteLog("Called for site(s) : " + siteCode, LogManager.enumLogLevel.Info);
            int recordsCount = Convert.ToInt32(ConfigManager.Read("RecordCounttoprocess"));

            try
            {
                //Get all unprocessed email alerts.
                using (DataHelper context = new DataHelper(DatabaseHelper.GetConnectionString()))
                {
                    lstUnprocessedAlerts = context.GetUnprocessedRecordsForEmailAlert(siteCode, recordsCount).ToList();
                }

                //Check if there any records to process.
                if (lstUnprocessedAlerts != null && lstUnprocessedAlerts.Count > 0)
                {
                    int count = lstUnprocessedAlerts.Count;

                    LogManager.WriteLog(string.Format(":::> Processing {0:D} Items for Site : {1}  on Thread : {2}.",
                        count, siteCode, Thread.CurrentThread.ManagedThreadId), LogManager.enumLogLevel.Info);

                    //Process each alert.
                    foreach (UnprocessedRecordsForEmailAlertResult alert in lstUnprocessedAlerts)
                    {
                        try
                        {
								GetServerDetails();
                                entity = new AlertEntity();

                                if (grpEmailSubscribers == null) return false;

                                foreach (KeyValuePair<string, MailMessageGroup> keys in grpEmailSubscribers)
                                {
                                    if (keys.Key == alert.AlertType_Name)
                                    {
                                        entity.Name = keys.Key;
                                        entity.MessageGroup = keys.Value;
                                        entity.MessageGroup.MsgContent = "Site Code: " + alert.EMD_SiteCode + "Site Name: "+ alert.SiteName +"---->  Alert Message: " +  alert.EMD_Content ;

                                        if (serverDetails != null) entity.ServerInfo = serverDetails;
                                        bResult = engine.SendMail(entity);
                                    }
                                }
                           
                        }
                        catch (Exception ex)
                        {
                            ExceptionManager.Publish(ex); bResult = false; strResult = ex.Message;
                        }
                        finally
                        {
                            //Update the process status.
                            using (DataHelper context = new DataHelper(DatabaseHelper.GetConnectionString()))
                            {
                                if (bResult)
                                {
                                    //if successfull.
                                    context.UpdateEmailAlertHistoryStatus(
                                        Convert.ToInt32(alert.EMD_ID), strResult, 100);
                                    bResult = true;
                                }
                                else
                                {
                                    //if failure
                                    context.UpdateEmailAlertHistoryStatus(
                                        Convert.ToInt32(alert.EMD_ID), strResult, -1);
                                    bResult = false;
                                }
                            }

                        }
                    }

                }

            }
            catch (Exception ex)
            { ExceptionManager.Publish(ex); }
            return iRecord == 0 ? true : false;
        }
예제 #5
0
        /// <summary>
        /// get setting value from setting table.
        /// </summary>
        /// <param name="SettingName"></param>
        /// <returns></returns>
        public static string GetSetting(string SettingName)
        {
            string strSetting = string.Empty;

            try
            {

                using (DataHelper context = new DataHelper(DatabaseHelper.GetConnectionString()))
                {
                    context.GetSetting(0, SettingName, string.Empty, ref strSetting);
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.Publish(ex);
            }
            return strSetting;
        }
예제 #6
0
        public static MailServer GetMailServer()
        {
            MailServer lMailServer = null;
            try
            {
                using (DataHelper context = new DataHelper(DatabaseHelper.GetConnectionString()))
                {
                    MailServerInfoResult lServer = context.GetMailServerInfo().ToList().First();

                    lMailServer = (
                                    new MailServer
                                    {
                                        EnableSSL = (bool)lServer.EnableSSL,
                                        Password = lServer.PWD,
                                        Port = lServer.Port.ToString(),
                                        ServerName = lServer.ServerName,
                                        UserID = lServer.UID

                                    });

                }
            }
            catch (Exception ex)
            {
                ExceptionManager.Publish(ex);
                lMailServer = new MailServer();
            }

            return lMailServer;
        }