Exemple #1
0
        private void GetServerDetails()
        {
            if (Convert.ToBoolean(AlertEngine.GetSetting("IsEmailAlertEnabled")))
            {
                LogManager.WriteLog("Initialize", LogManager.enumLogLevel.Info);
                EmailAlertInputs input = new EmailAlertInputs();

                grpEmailSubscribers = input.GetEmailSubScribers();

                serverDetails = AlertEngine.GetMailServer();
            }
        }
        /// <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;
        }
Exemple #3
0
        /// <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);
        }