private void mailSuccess(string emailAddress, string excelFile) { MailMessage m = new MailMessage(); m.Subject = String.Format("File {0} processed successfully", excelFile); m.Body = String.Format("File {0} processed successfully on {1}", excelFile, DateTime.Now); m.To.Add(new MailAddress(emailAddress)); EmailDaemon d = new EmailDaemon(log); d.SendMail(emailAddress, m); }
private void mailFailure(string emailAddress, string excelFile, string message, string stackTrace) { MailMessage m = new MailMessage(); var body = String.Format("File {0} processing failed on {1}\nMessage:{2}\nStacktrace:{3}", excelFile, DateTime.Now, message, stackTrace); m.Subject = String.Format("File {0} failed to process", excelFile); m.To.Add(new MailAddress(emailAddress)); m.Body = body; EmailDaemon d = new EmailDaemon(log); d.SendMail(emailAddress, m); }
protected override void Process() { log.Info("Starting EDI outbound process"); var config = GetConfiguration(); using (var unit = GetUnitOfWork()) { var outboundMessages = (from o in unit.Scope.Repository <EdiOrderPost>().GetAllAsQueryable() where !o.Processed && (!o.ProcessedCount.HasValue || o.ProcessedCount.Value < 5) select o).ToList(); foreach (var message in outboundMessages) { message.Processed = true; var connectorRelation = unit.Scope.Repository <ConnectorRelation>().GetSingle(x => x.ConnectorRelationID == message.ConnectorRelationID); if (message.Type == "Excel") { XmlDocument doc = new XmlDocument(); doc.LoadXml(message.PostDocument); DataTable table = new DataTable("Acknowledgement"); table.Columns.Add("EDIIdentifier"); table.Columns.Add("CustomerOrderNumber"); table.Columns.Add("ItemNumber"); table.Columns.Add("QuantityOrdered"); table.Columns.Add("QuantityBackordered"); table.Columns.Add("QuantityCancelled"); table.Columns.Add("Price"); table.Columns.Add("Message"); using (XmlReader reader = new XmlNodeReader(doc)) { table.ReadXml(reader); } ExcelWriter writer = new ExcelWriter(); var path = Path.Combine(config.AppSettings.Settings["ExcelPath"].Value, message.Type + message.EdiBackendOrderID + "_" + message.DocumentCounter + ".xlsx"); writer.ToExcel(table, message.Type, message.EdiBackendOrderID, message.CustomerOrderID, message.DocumentCounter, path); EmailDaemon daemon = new EmailDaemon(log); daemon.AcknowledgementNotification(connectorRelation.Name, connectorRelation.OutboundOrderConfirmation, false, path); } else if (connectorRelation.ConnectorType.HasValue && connectorRelation.ConnectorType.Value == (int)Objects.Enumerations.EdiConnectorTypeEnum.FtpConnector) { try { string fileName = string.Format("{0}-{1}-{2}.xml", message.Type, message.EdiBackendOrderID, message.DocumentCounter); if (connectorRelation.UseFtp.HasValue && connectorRelation.UseFtp.Value) { XmlDocument doc = new XmlDocument(); doc.LoadXml(message.PostDocument); if (connectorRelation.FtpType.HasValue && connectorRelation.FtpType.Value == (int)FtpTypeEnum.Customer) { FtpManager manager = new FtpManager(connectorRelation.FtpAddress, string.Empty, connectorRelation.OutboundUsername, connectorRelation.FtpPass, false, true, log); using (Stream s = new MemoryStream()) { doc.Save(s); manager.Upload(s, fileName); } } else { string basePath = ConfigurationManager.AppSettings["ConcentratorFtpUserDir"]; string ftpPath = Path.Combine(basePath, connectorRelation.ConnectorRelationID.ToString()); if (!Directory.Exists(ftpPath)) { Directory.CreateDirectory(ftpPath); } doc.Save(Path.Combine(ftpPath, fileName)); } } } catch (Exception ex) { message.ErrorMessage = ex.Message; } } else if (connectorRelation.ConnectorType.HasValue && connectorRelation.ConnectorType.Value == (int)Objects.Enumerations.EdiConnectorTypeEnum.HttpConnector) { DateTime startTimePost = DateTime.Now; try { System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Ssl3; HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(message.PostDocumentUrl); request.Method = "POST"; ServicePointManager.ServerCertificateValidationCallback += delegate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return(true); }; XmlDocument doc = new XmlDocument(); string contentType = "text/xml"; string document = message.PostDocument; HttpOutboundPostState state = new HttpOutboundPostState(request, message.EdiOrderPostID, unit, startTimePost); byte[] byteData = UTF8Encoding.UTF8.GetBytes(document); state.Request.ContentType = contentType; state.Request.ContentLength = byteData.Length; using (Stream postStream = request.GetRequestStream()) { postStream.Write(byteData, 0, byteData.Length); } request.BeginGetResponse(HttpOutboundCallBack, state); } catch (Exception ex) { message.Processed = false; if (message.ProcessedCount.HasValue) { message.ProcessedCount++; } else { message.ProcessedCount = 1; } message.ErrorMessage = ex.Message; DateTime resDateTime = new DateTime(DateTime.Now.Ticks - startTimePost.Ticks); message.ResponseTime = resDateTime.Second; } finally { unit.Save(); } } else { message.ErrorMessage = "No ConnectionRelationSettings, skip outbound message"; } unit.Save(); } } log.Info("Finish EDI outbound process"); }
public EmailSender(EmailDaemon emailDaemon) { _emailDaemon = emailDaemon; }