/// <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;
        }
Пример #2
0
        public bool SendMail(AlertEntity alert)
        {
            bool status = false;
            string strStatus = string.Empty;

            try
            {
                if (alert.ServerInfo != null)
                {

                    System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient(alert.ServerInfo.ServerName);


                    System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
                    message.IsBodyHtml = alert.MessageGroup.IsBodyHtml;
                    message.From = new System.Net.Mail.MailAddress(alert.MessageGroup.FromAddress);
                    message.BodyEncoding = System.Text.Encoding.ASCII;

                    if (!string.IsNullOrEmpty(alert.ServerInfo.Port))
                    {
                        int portAddress = 0;

                        if (int.TryParse(alert.ServerInfo.Port, out portAddress))
                        {
                            mailClient.Port = portAddress;
                        }
                    }


                    mailClient.EnableSsl = alert.ServerInfo.EnableSSL;

                    if (!string.IsNullOrEmpty(alert.ServerInfo.UserID) && !string.IsNullOrEmpty(alert.ServerInfo.Password))
                    {
                        mailClient.UseDefaultCredentials = false;
                        mailClient.Credentials = new System.Net.NetworkCredential(alert.ServerInfo.UserID,
                            SiteLicensingCryptoHelper.Decrypt(alert.ServerInfo.Password, "B411y51T"));
                    }

                    if (!string.IsNullOrEmpty(alert.ServerInfo.PickupFolder))
                    {
                        if (!System.IO.Directory.Exists(alert.ServerInfo.PickupFolder))
                        {
                            System.IO.Directory.CreateDirectory(alert.ServerInfo.PickupFolder);

                        }
                        mailClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.SpecifiedPickupDirectory;
                        mailClient.PickupDirectoryLocation = alert.ServerInfo.PickupFolder;

                    }

                    LogManager.WriteLog("Started Processing", LogManager.enumLogLevel.Info);

                    string[] ToList = alert.MessageGroup.ToList.Split(';');
                    string[] ccList = alert.MessageGroup.CCList.Split(';');
                    string[] bccList = alert.MessageGroup.BCCList.Split(';');
                    if (ToList != null)
                    {
                        for (int index = 0; index < ToList.Length; index++)
                        {
                            if (!string.IsNullOrEmpty(ToList[index]))
                                message.To.Add(ToList[index]);
                        }

                        for (int index = 0; index < ccList.Length; index++)
                        {
                            if (!string.IsNullOrEmpty(ccList[index]))
                                message.CC.Add(ccList[index]);
                        }

                        for (int index = 0; index < bccList.Length; index++)
                        {
                            if (!string.IsNullOrEmpty(bccList[index]))
                                message.Bcc.Add(bccList[index]);
                        }


                        message.Body = alert.MessageGroup.MsgContent;
                        message.Subject = alert.MessageGroup.Subject;
                        if (!string.IsNullOrEmpty(alert.MessageGroup.AttachementPath))
                        {
                            alert.MessageGroup.AttachmentType = alert.MessageGroup.AttachmentType.Replace("*yyyyMMdd", "*" + DateTime.Today.AddDays(-1).ToString("yyyyMMdd"));
                            string[] files = Directory.GetFiles(alert.MessageGroup.AttachementPath, alert.MessageGroup.AttachmentType, SearchOption.AllDirectories);

                            LogManager.WriteLog("Adding Attachments Processing", LogManager.enumLogLevel.Info);
                            foreach (string sourceFile in files)
                            {
                                message.Attachments.Add(new System.Net.Mail.Attachment(sourceFile));
                            }
                            LogManager.WriteLog("Adding Attachments Completed", LogManager.enumLogLevel.Info);
                        }
                        mailClient.Send(message);
                        LogManager.WriteLog("Message Sent", LogManager.enumLogLevel.Info);
                        status = true;
                        strStatus = "Email Message Sent Successfully";

                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.Publish(ex);
                status = false;
            }

           
            return status;
        }
Пример #3
0
        public bool SendMail(AlertEntity alert)
        {
            bool   status    = false;
            string strStatus = string.Empty;

            try
            {
                if (alert.ServerInfo != null)
                {
                    System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient(alert.ServerInfo.ServerName);


                    System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
                    message.IsBodyHtml   = alert.MessageGroup.IsBodyHtml;
                    message.From         = new System.Net.Mail.MailAddress(alert.MessageGroup.FromAddress);
                    message.BodyEncoding = System.Text.Encoding.ASCII;

                    if (!string.IsNullOrEmpty(alert.ServerInfo.Port))
                    {
                        int portAddress = 0;

                        if (int.TryParse(alert.ServerInfo.Port, out portAddress))
                        {
                            mailClient.Port = portAddress;
                        }
                    }


                    mailClient.EnableSsl = alert.ServerInfo.EnableSSL;

                    if (!string.IsNullOrEmpty(alert.ServerInfo.UserID) && !string.IsNullOrEmpty(alert.ServerInfo.Password))
                    {
                        mailClient.UseDefaultCredentials = false;
                        mailClient.Credentials           = new System.Net.NetworkCredential(alert.ServerInfo.UserID,
                                                                                            SiteLicensingCryptoHelper.Decrypt(alert.ServerInfo.Password, "B411y51T"));
                    }

                    if (!string.IsNullOrEmpty(alert.ServerInfo.PickupFolder))
                    {
                        if (!System.IO.Directory.Exists(alert.ServerInfo.PickupFolder))
                        {
                            System.IO.Directory.CreateDirectory(alert.ServerInfo.PickupFolder);
                        }
                        mailClient.DeliveryMethod          = System.Net.Mail.SmtpDeliveryMethod.SpecifiedPickupDirectory;
                        mailClient.PickupDirectoryLocation = alert.ServerInfo.PickupFolder;
                    }

                    LogManager.WriteLog("Started Processing", LogManager.enumLogLevel.Info);

                    string[] ToList  = alert.MessageGroup.ToList.Split(';');
                    string[] ccList  = alert.MessageGroup.CCList.Split(';');
                    string[] bccList = alert.MessageGroup.BCCList.Split(';');
                    if (ToList != null)
                    {
                        for (int index = 0; index < ToList.Length; index++)
                        {
                            if (!string.IsNullOrEmpty(ToList[index]))
                            {
                                message.To.Add(ToList[index]);
                            }
                        }

                        for (int index = 0; index < ccList.Length; index++)
                        {
                            if (!string.IsNullOrEmpty(ccList[index]))
                            {
                                message.CC.Add(ccList[index]);
                            }
                        }

                        for (int index = 0; index < bccList.Length; index++)
                        {
                            if (!string.IsNullOrEmpty(bccList[index]))
                            {
                                message.Bcc.Add(bccList[index]);
                            }
                        }


                        message.Body    = alert.MessageGroup.MsgContent;
                        message.Subject = alert.MessageGroup.Subject;
                        if (!string.IsNullOrEmpty(alert.MessageGroup.AttachementPath))
                        {
                            alert.MessageGroup.AttachmentType = alert.MessageGroup.AttachmentType.Replace("*yyyyMMdd", "*" + DateTime.Today.AddDays(-1).ToString("yyyyMMdd"));
                            string[] files = Directory.GetFiles(alert.MessageGroup.AttachementPath, alert.MessageGroup.AttachmentType, SearchOption.AllDirectories);

                            LogManager.WriteLog("Adding Attachments Processing", LogManager.enumLogLevel.Info);
                            foreach (string sourceFile in files)
                            {
                                message.Attachments.Add(new System.Net.Mail.Attachment(sourceFile));
                            }
                            LogManager.WriteLog("Adding Attachments Completed", LogManager.enumLogLevel.Info);
                        }
                        mailClient.Send(message);
                        LogManager.WriteLog("Message Sent", LogManager.enumLogLevel.Info);
                        status    = true;
                        strStatus = "Email Message Sent Successfully";
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.Publish(ex);
                status = false;
            }


            return(status);
        }
Пример #4
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);
        }