Пример #1
0
            /// <summary>
            /// this is the code that executes in the spawned thread
            /// </summary>
            private static void ThreadHandler()
            {
                EmailClient  smtp = new EmailClient();
                EmailMessage mail = new EmailMessage();

                mail.To   = Settings.EmailTo;
                mail.From = Settings.EmailFrom;

                if (_blnHaveException)
                {
                    mail.Subject = "Handled Exception notification - " + _strExceptionType;
                }
                else
                {
                    mail.Subject = "HandledExceptionManager notification";
                }
                mail.Body = _strEmailBody;
                //-- try to send email, but we don't care if it succeeds (for now)
                try
                {
                    smtp.SendMail(mail);
                }
                catch (Exception e)
                {
                    Debug.WriteLine("** SMTP email failed to send!");
                    Debug.WriteLine("** " + e.Message);
                }
            }
Пример #2
0
        public async Task <bool> SendEmailReminderNotificationsForWorkorderTemplates(UserViewModel user, string projectName, DateTime projectPlanedStartDate)
        {
            EmailClient emailClient = new EmailClient();

            var PostData = new EmailRequest
            {
                Email = new Email
                {
                    Cc          = new List <string>(),
                    Params      = new string[] { user.Name, projectName, projectPlanedStartDate.ToLocalTime().ToString() },
                    Subject     = "SERVICEORDER NOTIFICATION",
                    To          = new string[] { user.Email },
                    Attachments = new List <string[]>()
                },
                Type = EMailTypeEnum.SERVICEORDER_TEMPLATE_REMINDER_NOTIFICATION
            };

            string json = JsonConvert.SerializeObject(PostData, Formatting.Indented);

            var buffer      = Encoding.UTF8.GetBytes(json);
            var byteContent = new ByteArrayContent(buffer);

            byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            return(await emailClient.SendMail(byteContent));
        }
Пример #3
0
 private void Application_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
 {
     //if (this.DoHandle)
     //{
     //    //Handling the exception within the UnhandledExcpeiton handler.
     //    DAL.logger.Log(e.Exception + Environment.NewLine , MessageType.Error);
     //    e.Handled = true;
     //}
     //else
     //{
     //If you do not set e.Handled to true, the application will close due to crash.
     EmailClient.SendMail(e.Exception.ToString());
     DAL.logger.Log(e.Exception + Environment.NewLine, MessageType.Error);
     MessageBox.Show("Application is going to close! ", "Uncaught Exception");
     e.Handled = true;
     //}
 }
Пример #4
0
            //--
            //-- this is the code that executes in the spawned thread
            //--
            private static void ThreadHandler()
            {
                EmailClient  objMail        = new EmailClient();
                EmailMessage objMailMessage = new EmailMessage();

                objMailMessage.To      = Settings.EmailTo;
                objMailMessage.From    = Settings.EmailFrom;
                objMailMessage.Subject = "Unhandled Exception notification - " + _strExceptionType;
                objMailMessage.Body    = _strException;
                if (Settings.TakeScreenshot & Settings.EmailScreenshot)
                {
                    objMailMessage.AttachmentPath = _strScreenshotFullPath;
                }
                try
                {
                    // call SendMail method in SimpleMail class
                    objMail.SendMail(objMailMessage);
                }
                catch (Exception)
                {
                    //-- don't do anything; sometimes SMTP isn't available, which generates an exception
                    //-- and an exception in the unhandled exception manager.. is bad news.
                }
            }
Пример #5
0
        private void DoValidate()
        {
            RedisServer redis = new RedisServer(ConfigurationManager.Get("redisHost"), 6379, ConfigurationManager.Get("redisPassword"));

            string key = "locker-validate-" + Name;

            try
            {
                if (SpiderContext.Validations == null)
                {
                    return;
                }

                var validations = SpiderContext.Validations.GetValidations();

                if (validations != null && validations.Count > 0)
                {
                    foreach (var validation in validations)
                    {
                        validation.CheckArguments();
                    }
                }

                if (redis != null)
                {
                    while (!redis.LockTake(key, "0", TimeSpan.FromMinutes(10)))
                    {
                        Thread.Sleep(1000);
                    }
                }

                var  lockerValue          = redis?.HashGet(ValidateStatusName, Name);
                bool needInitStartRequest = lockerValue != "validate finished";

                if (needInitStartRequest)
                {
                    Logger.Info("开始数据验证 ...");

                    if (validations != null && validations.Count > 0)
                    {
                        MailBodyBuilder builder = new MailBodyBuilder(Name, SpiderContext.Validations.Corporation);
                        foreach (var validation in validations)
                        {
                            builder.AddValidateResult(validation.Validate());
                        }
                        string mailBody = builder.Build();

                        using (EmailClient client = new EmailClient(SpiderContext.Validations.EmailSmtpServer, SpiderContext.Validations.EmailUser, SpiderContext.Validations.EmailPassword, SpiderContext.Validations.EmailSmtpPort))
                        {
                            client.SendMail(new EmaillMessage($"{Name} " + "validation report", mailBody, SpiderContext.Validations.EmailTo)
                            {
                                IsHtml = true
                            });
                        }
                    }
                }
                else
                {
                    Logger.Info("有其他线程执行了数据验证.");
                }

                if (needInitStartRequest)
                {
                    redis?.HashSet(ValidateStatusName, Name, "validate finished");
                }
            }
            catch (Exception e)
            {
                Logger.Error(e.Message, e);
            }
            finally
            {
                redis?.LockRelease(key, 0);
            }
        }