public PartialViewResult SendMessage(Message message) { var success = true; if (!(CaptchaChecker.CheckCaptcha(Request) || (!checkMessage(message)))) { success = false; } if (success) { var mailMessage = new MailMessage(); mailMessage.From = new MailAddress("*****@*****.**"); mailMessage.To.Add(WebConfigurationManager.AppSettings["email_to"]); mailMessage.Subject = "New message from AK investing techs"; mailMessage.IsBodyHtml = true; var bld = new StringBuilder(); bld.AppendFormat("<b>Name:</b> {0}", message.Name); bld.AppendLine("<br>"); bld.AppendFormat("<b>Email:</b> {0}", message.EMail); bld.AppendLine("<br>"); bld.AppendFormat("<b>Phone:</b> {0}", message.Phone); bld.AppendLine("<br>"); bld.AppendLine(message.Content.Replace(Environment.NewLine, "<br>")); mailMessage.Body = bld.ToString(); var client = new SmtpClient("localhost", 25); try { client.Send(mailMessage); } catch { success = false; } } var status = new RequestStatusMessage() { Result = success ? string.Format("Thank you, {0}. Your message has been sent.", message.Name) : "Error! Invalid data.", IsSuccess = success }; return(PartialView(status)); }
public void GetSystemStatus(out SystemStatus status) { // Log.Info("GetSystemStatus"); Message message = new RequestStatusMessage(); ManualResetEvent waitHandle = new ManualResetEvent(false); SystemStatusMessage response = null; SystemStatusReceived action = delegate(SystemStatusMessage msg) { response = msg; waitHandle.Set(); }; try { SystemStatusEvent += action; for (int i = 0; i < 5; i++) { SendMessage(message); if (waitHandle.WaitOne(5000)) // change here { waitHandle.Reset(); if (response != null) { status = response.Status; // Log.Info("GetSystemStatus:{0}",status); return; } } } // Log.Warn("GetSystemStatus;Timeout"); throw new TimeoutException(); } catch (Exception ex) { // Log.Error("GetSystemStatus;Exception:{0}",ex.ToString()); LastException = ex; throw; } finally { SystemStatusEvent -= action; } }