public void Error(string key, Exception e) { if (!dataCounter.ContainsKey(key)) { dataCounter.Add(key, new Counter() { Success = 0, Error = 0 }); } ++((Counter)dataCounter[key]).Error; LogProcess.Error(e, string.Empty); }
public Recipient(string name, string address) { if (Regex.IsMatch(address, @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$")) { this.Name = name; this.Address = address; } else { Exception e = new FormatException(); LogProcess.Error(e, address); throw e; } }
public void Process() { if (processing || this.smtpServer == null) { return; } lock (lockObj) { processing = true; } QueueProcess queueProcess = new QueueProcess(); int blockSleep = Convert.ToInt32(ConfigurationManager.AppSettings["BlockSleep"]); ClickOnceDMLib.Structs.Queue queue = queueProcess.GetQueue(); if (queue != null) { InitSMTPServer(); LogProcess.Info("In-Process Start"); ILog log = new LogCounter(); // log interface foreach (Recipient recipient in queue.RecipientData) { long baseTick = DateTime.Now.Ticks; var smtp = from s1 in this.smtpServer orderby s1.Weight ascending select s1; SMTPServer serverInfo = smtp.First(); SendMailProcess sendMailProcess = new SendMailProcess(log); sendMailProcess.SetHostAndPort(serverInfo.Host, serverInfo.Port); MailAddress mailAddress = null; try { mailAddress = new MailAddress(recipient.Address.Trim(), recipient.Name); } catch (Exception ex) { LogProcess.Error(ex); continue; } if (mailAddress != null) { sendMailProcess.Send( new MailAddress(queue.TicketData.SenderAddress, queue.TicketData.SenderName), new MailAddress[] { mailAddress }, queue.TicketData.Subject, queue.TicketData.Body ); serverInfo.SetWeight(TimeSpan.FromTicks(DateTime.Now.Ticks - baseTick).Milliseconds); } } log.Flush(); // write log LogProcess.Info("In-Process End"); Thread.Sleep(blockSleep); } processing = false; }