public static int MoveFilesToBackupFolder(DateTime finalizationTime, string primaryFileName) { //primaryFileName: OPG_AP.20181109.000002.39XML1480844455713905 , move 4 files string pdfFileName = primaryFileName.Replace("XML", "pdf"); string respFileName = primaryFileName + ".resp"; string respHFileName = primaryFileName + ".respH"; string dateSubfolder = finalizationTime.ToString("yyyyMMdd") + "\\"; if (!Directory.Exists(aribaExceptionsBackupFolder + dateSubfolder)) { Directory.CreateDirectory(aribaExceptionsBackupFolder + dateSubfolder); } try { File.Move(aribaExceptionsProcessFolder + primaryFileName, aribaExceptionsBackupFolder + dateSubfolder + primaryFileName); File.Move(aribaExceptionsProcessFolder + pdfFileName, aribaExceptionsBackupFolder + dateSubfolder + pdfFileName); File.Move(aribaExceptionsProcessFolder + respFileName, aribaExceptionsBackupFolder + dateSubfolder + respFileName); File.Move(aribaExceptionsProcessFolder + respHFileName, aribaExceptionsBackupFolder + dateSubfolder + respHFileName); } catch (Exception ex) { OdissLogger.Error($"MoveFilesToBackupFolder error: primaryFileName:{primaryFileName}, finalization time:{finalizationTime.ToShortDateString()}. {ex.ToString()}"); return(-1); } return(1); }
public static string GetPDFRootFolder() { string folder; using (var db = new Odiss_OPG_BaseEntities()) { var setting1 = db.Settings.SingleOrDefault(x => x.Name.ToLower() == "documentspath"); if (setting1 == null) { OdissLogger.Error($"There is no documentspath setting in database."); throw new Exception("No DocumentsPath settings."); } folder = setting1.Value; if (folder.IndexOf("\\") < 0) { OdissLogger.Error($"DocumentPath was not set correctly."); throw new Exception("DocumentPath was not set correctly."); } } if (folder.LastIndexOf("\\") != folder.Length - 1) { folder += "\\"; // add last back slash } return(folder); }
public static int GetDayExceptionList(DateTime finalizationTime, bool processDaysTillfinalizationTime, out List <GetAribaWaitingExceptionList_Result> processList) {//if processDaysTillfinalizationTime == true, it will process multiple dates from aribaExceptionsStartDate to finalizationTime, if not, only process one date: finalizationTime int year = finalizationTime.Year; int month = finalizationTime.Month; int day = finalizationTime.Day; DateTime exceptionStartDate; if (processDaysTillfinalizationTime) { exceptionStartDate = aribaExceptionsStartDate; } else { exceptionStartDate = finalizationTime; // only one day } try { using (var db = new Octacom_OICS_Entities()) { processList = db.GetAribaWaitingExceptionList(exceptionStartDate, finalizationTime).ToList(); return(1); } } catch (Exception ex) { OdissLogger.Error($"GetDayExceptionList from database error: {ex.ToString()}"); processList = null; return(-1); } }
public static AppSettingWithFields GetAppSettingsWithFields(Guid appId) { try { using (var db = new Odiss_OPG_BaseEntities()) { db.Configuration.LazyLoadingEnabled = false; var app = db.Applications.FirstOrDefault(x => x.ID == appId); if (app == null) { return(null); } var settings = new AppSettingWithFields(); settings.app = app; var fields = db.Fields.Where(x => x.IDApplication == appId).ToList(); foreach (var field1 in fields) { field1.Application = null; // remove it to avoid loop serialization } settings.fields = fields; return(settings); } } catch (Exception ex) { OdissLogger.Error($"GetAppSettingsWithFields error: {ex.ToString()}"); return(null); } }
public static int GetSenderFromvwEmail(string pureSourceImage, out string sender, out DateTime?receivedDate) { sender = ""; receivedDate = null; pureSourceImage = pureSourceImage.ToUpper(); try { using (var db = new OPG_EMAILEntities()) { db.Database.CommandTimeout = 180; var email = db.vw_Email.SingleOrDefault(x => x.ProcessFileName.ToUpper() == pureSourceImage); if (email == null) { OdissLogger.Info($"No record in vw_email with ProcessFileName = {pureSourceImage}"); } else { sender = email.Sender; receivedDate = email.RecievedDate; } } } catch (Exception ex) { OdissLogger.Error($"GetSenderFromEmail error:{ex.ToString()}"); return(-3); } return(1); }
public static int GetAribaExceptionSender(string primaryFileName, out string sender, out DateTime?receivedDate, out string sourceImage, out string originalFileName) // only if batch type is OPG-EMAIL, use this to get sender { sender = ""; originalFileName = ""; sourceImage = ""; receivedDate = null; try { using (var db = new Octacom_OICS_Entities()) { db.Database.CommandTimeout = 180; var ret = db.GetAribaExceptionSender(primaryFileName).FirstOrDefault(); if (ret != null) { sender = ret.Sender; receivedDate = ret.ReceivedDate; originalFileName = ret.Filename; sourceImage = ret.SourceImage; } } } catch (Exception ex) { OdissLogger.Error($"GetAribaExceptionSender error: {ex.ToString()}"); return(-1); } return(1); }
public void Start() { OdissLogger.Info("Starting Ariba Windows service..."); OdissLogger.SetExceptionEmailSubject("OPG Ariba Service threw exceptions, please check log file for more details."); if (ConfigurationManager.AppSettings["Test_Mode_Process_One_Day_When_Start_Service"].ToLower() == "true") { string dateStr = ConfigurationManager.AppSettings["Test_Mode_Date_To_Process_When_Start_Service"]; if (!string.IsNullOrWhiteSpace(dateStr)) { DateTime aDate; if (DateTime.TryParse(dateStr, out aDate)) { AribaServiceDailyProcess(aDate.AddDays(1), false); // the service will always process previous date, so add one day } } } // Create a timer with one minute interval. aTimer = new System.Timers.Timer(60000); // Hook up the Elapsed event for the timer. aTimer.Elapsed += CheckIfItsTimeToProcessExceptions; aTimer.AutoReset = true; aTimer.Enabled = true; OdissLogger.Info("Ariba Windows service started..."); OdissLogger.Info($"The service will process Ariba exceptions daily at hour:{aribaSerivceDailyProcessAtHour}, minute:{aribaSerivceDailyProcessAtMinute}, now is:{DateTime.Now.Hour}:{DateTime.Now.Minute}"); }
public static int GetAribaExceptionBatchType(string primaryFileName, out string batchType, out DateTime?finalizationTime, out string processMessage) { batchType = ""; finalizationTime = null; processMessage = ""; try { using (var db = new Octacom_OICS_Entities()) { db.Database.CommandTimeout = 180; var ret = db.GetAribaExceptionBatchType(primaryFileName).FirstOrDefault(); if (ret != null) { batchType = ret.BatchType; finalizationTime = ret.FinalizationTime; } } } catch (Exception ex) { processMessage = $"GetAribaExceptionBatchType error: {ex.ToString()}"; OdissLogger.Error(processMessage); return(-1); } return(1); }
public static int GeneratePDFFile(string primaryFileName, string originalPdfFileFolder, DateTime finalizationTime, out string directoryId, out string pdfFileName, out string processMessage) { string targetPDFBaseFolder = GetPDFRootFolder(); pdfFileName = ""; directoryId = ""; processMessage = ""; string pdfStorageFolder; int iret = DirLocation.PreparePDFFolderAndDirectoryId(targetPDFBaseFolder, finalizationTime, out directoryId, out pdfStorageFolder); if (iret != 1) { processMessage = $"Could not prepare directoryId and pdf storage folder: {primaryFileName}, {targetPDFBaseFolder}, {finalizationTime}"; OdissLogger.Error(processMessage); return(-1); } string pdfSourceFileName = primaryFileName.ToUpper().Replace("XML", "pdf"); pdfFileName = pdfSourceFileName + ".pdf"; string sourceFullName, storageFullName; sourceFullName = originalPdfFileFolder + pdfSourceFileName; storageFullName = pdfStorageFolder + pdfFileName; if (!File.Exists(sourceFullName)) { processMessage = $"Source pdf file:{sourceFullName} does not exist, primary file name: {primaryFileName}, finalization time: {finalizationTime.ToString()}"; OdissLogger.Error(processMessage); return(-2); } try { File.Copy(sourceFullName, storageFullName); } catch (Exception ex) { string details = ex.ToString(); processMessage = $"Could not copy pdf file, from {sourceFullName} to {storageFullName}. Details:{details}"; OdissLogger.Error(processMessage); if (details.IndexOf("already exists") > 0) { processMessage = "Pdf file exists, process continues."; return(0); } return(-3); } processMessage = ""; return(1); }
private static void CheckIfItsTimeToProcessExceptions(Object source, ElapsedEventArgs e) {// check every minute to see if it's time to process Ariba process. DateTime now = DateTime.Now; if (now.Hour == aribaSerivceDailyProcessAtHour && now.Minute == aribaSerivceDailyProcessAtMinute) { OdissLogger.Info($"It's time to process Ariba exceptions."); AribaServiceDailyProcess(now, true); } }
public void Stop() { stopRequested = true; OdissLogger.Info("Stopping Ariba Windows service..."); aTimer.Stop(); aTimer.Dispose(); Thread.Sleep(3000); OdissLogger.Info("Ariba Windows service stopped..."); }
public static DateTime GetAribaExceptionsStartDate() { string dateStr = ConfigurationManager.AppSettings["AribaExceptionsStartDate"]; DateTime aDate; if (!DateTime.TryParse(dateStr, out aDate)) { OdissLogger.Error($"AribaExceptionsStartDate is not a valid Datetime."); throw new Exception($"AribaExceptionsStartDate is not a valid Datetime."); } return(aDate); }
public static void AribaServiceDailyProcess(DateTime triggerTime, bool processDaysTillPreviousDay) {// if processDaysTillPreviousDay is true, then process multiple days, otherwise only process one day: previous day DateTime processEndDate = triggerTime.AddDays(-1); if (!processDaysTillPreviousDay) { OdissLogger.Info($"Start to process Ariba exceptions: one day only:{processEndDate.ToString("yyyy-MM-dd")}"); } else { OdissLogger.Info($"Start to process Ariba exceptions: from: {aribaExceptionsStartDate.ToShortDateString()} to:{processEndDate.ToShortDateString()}"); } ProcessAribaDayExceptions(processEndDate, processDaysTillPreviousDay); }
public static string GetAribaExceptionsBackupFolder() { string folder = ConfigurationManager.AppSettings["AribaExceptionsBackupFolder"]; if (string.IsNullOrWhiteSpace(folder)) { OdissLogger.Error("Please config AribaExceptionsBackupFolder."); throw new Exception("Please config AribaExceptionsBackupFolder."); } if (folder.LastIndexOf("\\") != folder.Length - 1) { folder += "\\"; // add last back slash } return(folder); }
public static string GetAribaExceptionsProcessFolder() // this folder is for all the files daily, no date folder as Yogesh suggested { string folder = ConfigurationManager.AppSettings["AribaExceptionsProcessFolder"]; if (string.IsNullOrWhiteSpace(folder)) { OdissLogger.Error("Please config AribaExceptionsProcessFolder."); throw new Exception("Please config AribaExceptionsProcessFolder."); } if (folder.LastIndexOf("\\") != folder.Length - 1) { folder += "\\"; // add last back slash } return(folder); }
public static int ParseOctacomExceptionXmlFile(string xmlFullPathName, out string batchType, out string exceptionCode, out tblGroup aGroup, out List <tblGroupLine> lines) { aGroup = new tblGroup(); lines = new List <tblGroupLine>(); XElement xml = XElement.Load(xmlFullPathName); IEnumerable <XElement> codes = from node1 in xml.Descendants("ExceptionCode") select node1; exceptionCode = (string)codes.First(); codes = from node1 in xml.Descendants("BatchType") select node1; batchType = (string)codes.First(); codes = from node1 in xml.Descendants("Document") select node1; codes = from node1 in xml.Descendants("ScanDate") select node1; DateTime scandate; if (DateTime.TryParse((string)codes.First(), out scandate)) { OdissLogger.Error($"Invalid scan date: {(string)codes.First()}"); } aGroup.ScanDate = scandate; IEnumerable <XElement> fields = from nodes in xml.Descendants("Field") select nodes; string invoiceNumber = (string)fields.Where(x => (string)x.Attribute("Type") == "invoicenumber").First(); string ponumber = (string)fields.Where(x => (string)x.Attribute("Type") == "invoiceordernumber").First(); string utility = (string)fields.Where(x => (string)x.Attribute("Type") == "utility").First(); string strTotalAmount = (string)fields.Where(x => (string)x.Attribute("Type") == "invoicetotalvatincludedamount").First(); aGroup.InvoiceNo = invoiceNumber; aGroup.ExceptionCode = exceptionCode; aGroup.PONumber = ponumber; aGroup.Utility = utility; aGroup.TotalAmount = decimal.Parse(strTotalAmount); return(1); }
public static int ProcessAribaDayExceptionList(DateTime aDate, List <GetAribaWaitingExceptionList_Result> processList) { string filename, processMessage; foreach (var process1 in processList) { if (stopRequested) { return(0); } filename = process1.PrimaryFileName; try { int iret = ProcessPrimaryFile(process1.FinalizationTime.Value, process1.PrimaryFileName, out processMessage); if (iret == 1) // if all right, then move files to backup folder { MoveFilesToBackupFolder(process1.FinalizationTime.Value, process1.PrimaryFileName); } // insert into AribaProcessedException table, so it wont pricess it next time AribaProcessedException processed1 = new AribaProcessedException(); processed1.OICSConnectorProcessId = process1.OICSConnectorProcessId; processed1.ProcessedDate = DateTime.Now; processed1.ServiceState = iret; processed1.ServiceDetails = processMessage; using (var db = new Octacom_OICS_Entities()) { db.Entry(processed1).State = System.Data.Entity.EntityState.Added; db.SaveChanges(); } } catch (Exception ex) { OdissLogger.Error($"Error occurred when process {filename}: {ex.ToString()}"); } } OdissLogger.Info($"Ariba service processed {processList.Count} exception records."); return(1); }
public static int GetAribaSerivceDailyProcessAtMinute() { string strMinute = ConfigurationManager.AppSettings["AribaSerivceDailyProcessAtMinute"]; if (string.IsNullOrWhiteSpace(strMinute)) { OdissLogger.Error("Please config AribaSerivceDailyProcessAtMinute."); throw new Exception("Please config AribaSerivceDailyProcessAtMinute."); } int minute; if (!int.TryParse(strMinute, out minute) || minute > 59 || minute < 0) { OdissLogger.Error($"AribaSerivceDailyProcessAtMinute is not a valid minute number:{strMinute}."); throw new Exception($"AribaSerivceDailyProcessAtMinute is not a valid minute number:{strMinute}."); } return(minute); }
public static int GetAribaSerivceDailyProcessAtHour() { string strHour = ConfigurationManager.AppSettings["AribaSerivceDailyProcessAtHour"]; if (string.IsNullOrWhiteSpace(strHour)) { OdissLogger.Error("Please config AribaSerivceDailyProcessAtHour."); throw new Exception("Please config AribaSerivceDailyProcessAtHour."); } int hour; if (!int.TryParse(strHour, out hour) || hour > 23 || hour < 0) { OdissLogger.Error($"AribaSerivceDailyProcessAtHour is not a valid hour number:{strHour}."); throw new Exception($"AribaSerivceDailyProcessAtHour is not a valid hour number:{strHour}."); } return(hour); }
public static int ProcessAribaDayExceptions(DateTime aDate, bool processDaysTillPreviousDay) { List <GetAribaWaitingExceptionList_Result> processList; int iret = GetDayExceptionList(aDate, processDaysTillPreviousDay, out processList); if (iret != 1) { return(iret); } if (processList != null && processList.Count > 0) { if (processDaysTillPreviousDay) { OdissLogger.Info($"Found {processList.Count} exception records in OICSConnectorProcess table which FinalizationTime between {aribaExceptionsStartDate.ToString("yyyy-MM-dd")} and {aDate.ToString("yyyy-MM-dd")} and HasErrors is true. Processing started."); } else { OdissLogger.Info($"Found {processList.Count} exception records in OICSConnectorProcess table which FinalizationTime is {aDate.ToString("yyyy-MM-dd")} and HasErrors is true. Processing started."); } ProcessAribaDayExceptionList(aDate, processList); } else { if (processDaysTillPreviousDay) { OdissLogger.Info($"There is no unprocessed exception record between {aribaExceptionsStartDate.ToString("yyyy-MM-dd")} and {aDate.ToString("yyyy-MM-dd")}."); } else { OdissLogger.Info($"There is no unprocessed exception record for date:{aDate.ToString("yyyy-MM-dd")}."); } } return(1); }
public string SendInvoice(DateTime processDate, string xmlFullFileName) { // xmlFullFileName: something like: E:\bak\OPG_SAMPLE_DATA\Octacom_Exceptions\2018_11_16\OPG_AP.20181115.000002.21.XML int iret; OdissLogger.SetExceptionEmailSubject("OPG Web Service threw exceptions, please check log file for more details."); try { iret = OctaExceptionHelper.ProcessOctacomException(processDate, xmlFullFileName); } catch (Exception ex) { OdissLogger.Error($"SendInvoice error: {ex.ToString()}"); iret = -11; } if (iret == 1) { return("OK."); } else { return("Error code:" + iret); } }
public static int ProcessOctacomException(DateTime processDate, string xmlFullFileName) { if (!File.Exists(xmlFullFileName)) { OdissLogger.Error($"Xml source file does not exist: xmlFullFileName"); return(-1); } string errorCode, batchType; tblGroup aGroup; List <tblGroupLine> lines; int iret = ParseOctacomExceptionXmlFile(xmlFullFileName, out batchType, out errorCode, out aGroup, out lines); if (iret != 1) { OdissLogger.Error($"Parse {xmlFullFileName} error. Return code:{iret}"); return(-2); } if (errorCode == "E000") { OdissLogger.Info($"Error code is E000, no further process. File path: {xmlFullFileName} "); return(1); } int ind = xmlFullFileName.LastIndexOf("\\"); string sourceFolder = xmlFullFileName.Substring(0, ind + 1); // with back slash at the end string xmlFileName = xmlFullFileName.Substring(ind + 1); string pdfFileName = errorCode + "_" + xmlFileName.ToUpper().Replace(".XML", ".PDF"); // error code like: E002 if (!File.Exists(sourceFolder + pdfFileName)) { OdissLogger.Error($"Pdf file does not exist: {pdfFileName} at folder: {sourceFolder}"); return(-3); } string pdfStorageFolder, directoryId; string targetPDFBaseFolder = GetPDFRootFolder(); iret = DirLocation.PreparePDFFolderAndDirectoryId(targetPDFBaseFolder, processDate, out directoryId, out pdfStorageFolder); if (iret != 1) { OdissLogger.Error($"Could not prepare directoryId and pdf storage folder: {xmlFileName}, {targetPDFBaseFolder}, {processDate}"); return(-4); } if (batchType == "OPG-EMAIL") { string sender; DateTime?receivedDate; string shortProcessFileName = xmlFileName.ToUpper().Replace(".XML", ""); //OPG_AP.20181115.000002.03 iret = GetSenderFromvwEmail(shortProcessFileName, out sender, out receivedDate); if (iret == 1) { aGroup.Sender = sender; aGroup.ReceivedDate = receivedDate; } aGroup.Source = "EMAIL"; } else { aGroup.Source = "SCAN"; } try { File.Copy(sourceFolder + pdfFileName, pdfStorageFolder + pdfFileName); } catch (Exception ex) { string details = ex.ToString(); OdissLogger.Error($"Copy file error: from{sourceFolder + pdfFileName} to {pdfStorageFolder + pdfFileName}. Info:{details}"); if (details.IndexOf("already exists") < 0)// ignore file exists error { return(-5); } } aGroup.DocType = "Octacom"; aGroup.Filename = pdfFileName; aGroup.DirectoryID = directoryId; aGroup.GUID = Guid.NewGuid(); aGroup.ProcessFilename = xmlFileName; aGroup.I_CaptureDate = DateTime.Now; TblGroupHelper.AddTblGroup(aGroup); return(1); }
public static int ParseOctacomExceptionXmlFile(string xmlFullPathName, out string batchType, out string exceptionCode, out string pureSourceImage, out tblGroup aGroup, out List <tblGroupLine> lines) { // \\datacap-srv\opg_ap\IMAGES\SCAN\0007_OP_201811200045_001.TIF pureSourceImage:OP_201811200045 aGroup = new tblGroup(); lines = new List <tblGroupLine>(); XElement xml = XElement.Load(xmlFullPathName); IEnumerable <XElement> codes = from node1 in xml.Descendants("ExceptionCode") select node1; exceptionCode = (string)codes.First(); codes = from node1 in xml.Descendants("BatchType") select node1; batchType = (string)codes.First(); codes = from node1 in xml.Descendants("SourceImage") select node1; pureSourceImage = (string)codes.First(); int ind = pureSourceImage.LastIndexOf("\\"); if (ind > 0) { pureSourceImage = pureSourceImage.Substring(ind + 1); pureSourceImage = pureSourceImage.Substring(5, 15); } codes = from node1 in xml.Descendants("Document") select node1; codes = from node1 in xml.Descendants("ScanDate") select node1; string scanDateStr = (string)codes.First(); DateTime scandate = new DateTime(1970, 1, 1); //12/20/2018 try { int year = int.Parse(scanDateStr.Substring(6)); int month = int.Parse(scanDateStr.Substring(0, 2)); int day = int.Parse(scanDateStr.Substring(3, 2)); scandate = new DateTime(year, month, day); } catch (Exception ex) { OdissLogger.Error($"Invalid scan date: {(string)codes.First()}"); } aGroup.ScanDate = scandate; IEnumerable <XElement> fields = from nodes in xml.Descendants("Field") select nodes; string invoiceNumber = (string)fields.Where(x => (string)x.Attribute("Type") == "invoicenumber").First(); string ponumber = (string)fields.Where(x => (string)x.Attribute("Type") == "invoiceordernumber").First(); string utility = (string)fields.Where(x => (string)x.Attribute("Type") == "utility").First(); string strTotalAmount = (string)fields.Where(x => (string)x.Attribute("Type") == "invoicetotalvatincludedamount").First(); aGroup.InvoiceNo = invoiceNumber; aGroup.ExceptionCode = exceptionCode; aGroup.PONumber = ponumber; aGroup.Utility = utility; aGroup.TotalAmount = decimal.Parse(strTotalAmount); return(1); }
public static int ProcessOctacomException(DateTime processDate, string xmlFullFileName) { if (!File.Exists(xmlFullFileName)) { OdissLogger.Error($"Xml source file does not exist: {xmlFullFileName}"); return(-1); } string errorCode, batchType, pureSoureImage; tblGroup aGroup; List <tblGroupLine> lines; int iret = ParseOctacomExceptionXmlFile(xmlFullFileName, out batchType, out errorCode, out pureSoureImage, out aGroup, out lines); if (iret != 1) { OdissLogger.Error($"Parse {xmlFullFileName} error. Return code:{iret}"); return(-2); } if (errorCode == "E000") { OdissLogger.Info($"Error code is E000, no further process. File path: {xmlFullFileName} "); return(1); } int ind = xmlFullFileName.LastIndexOf("\\"); string sourceFolder = xmlFullFileName.Substring(0, ind + 1); // with back slash at the end string xmlFileName = xmlFullFileName.Substring(ind + 1); string pdfFileName = errorCode + "_" + xmlFileName.ToUpper().Replace(".XML", ".PDF"); // error code like: E002 if (!File.Exists(sourceFolder + pdfFileName)) { OdissLogger.Error($"Pdf file does not exist: {pdfFileName} at folder: {sourceFolder}"); return(-3); } string pdfStorageFolder, directoryId; string targetPDFBaseFolder = GetPDFRootFolder(); iret = DirLocation.PreparePDFFolderAndDirectoryId(targetPDFBaseFolder, processDate, out directoryId, out pdfStorageFolder); if (iret != 1) { OdissLogger.Error($"Could not prepare directoryId and pdf storage folder: {xmlFileName}, {targetPDFBaseFolder}, {processDate}"); return(-4); } if (batchType == "OPG-EMAIL") { string sender; DateTime?receivedDate; string shortProcessFileName = xmlFileName.ToUpper().Replace(".XML", ""); //OPG_AP.20181115.000002.03 iret = GetSenderFromvwEmail(pureSoureImage, out sender, out receivedDate); if (iret == 1) { aGroup.Sender = sender; aGroup.ReceivedDate = receivedDate; } aGroup.Source = "EMAIL"; } else { aGroup.Source = "SCAN"; } try { File.Copy(sourceFolder + pdfFileName, pdfStorageFolder + pdfFileName); File.Delete(sourceFolder + pdfFileName); // delete pdf file as Yogesh requested File.Delete(xmlFullFileName); // delete xml file OdissLogger.Info($"File: {sourceFolder + pdfFileName} and {xmlFullFileName} have been deleted."); } catch (Exception ex) { string details = ex.ToString(); if (details.IndexOf("already exists") < 0)// ignore file exists error { OdissLogger.Error($"Copy file error: from {sourceFolder + pdfFileName} to {pdfStorageFolder + pdfFileName}. Info:{details}"); return(-5); } else { //File.Delete(sourceFolder + pdfFileName); // delete pdf file as Yogesh requested //File.Delete(xmlFullFileName); // delete xml file OdissLogger.Info($"{xmlFullFileName} has been processed previously."); } } aGroup.OctProcessFilename = pureSoureImage; aGroup.DocType = "Octacom"; aGroup.Filename = pdfFileName; aGroup.DirectoryID = directoryId; aGroup.GUID = Guid.NewGuid(); aGroup.XMLFile = xmlFileName; aGroup.I_CaptureDate = DateTime.Now; //check if process file name has been added, if added no more process using (var db = new Odiss_OPG_BaseEntities()) { var group1 = db.tblGroups.FirstOrDefault(x => x.XMLFile == xmlFileName); if (group1 != null) { OdissLogger.Info($"XML file:{xmlFileName} has been processed. The group record will be updated, the original record is: " + JsonConvert.SerializeObject(group1, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore })); group1.Filename = pdfFileName; group1.DirectoryID = directoryId; group1.I_CaptureDate = DateTime.Now; group1.DocType = "Octacom"; db.Entry(group1).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } else { TblGroupHelper.AddTblGroup(aGroup); } } return(1); }
public static int ParseAribaPrimaryXMLFile(string sourceFullFolder, string primaryFileName, DateTime finalizationTime, out tblGroup group, out List <tblGroupLine> groupLines, out string processMessage) { group = new tblGroup(); groupLines = new List <tblGroupLine>(); processMessage = ""; if (!File.Exists($"{sourceFullFolder}{primaryFileName}")) { processMessage = $"Primary XML file: { sourceFullFolder}{ primaryFileName} does not exist."; OdissLogger.Error(processMessage); return(-1); } XmlDocument doc = new XmlDocument(); doc.Load($"{sourceFullFolder}{primaryFileName}"); XmlNode invoiceDetailRequest = doc.SelectSingleNode("/cXML/Request/InvoiceDetailRequest"); XmlNode requestHeader = invoiceDetailRequest.SelectSingleNode("InvoiceDetailRequestHeader"); string invoiceID = requestHeader.Attributes["invoiceID"].Value; group.InvoiceNo = invoiceID; XmlNode nodeGrossAmount = invoiceDetailRequest.SelectSingleNode("InvoiceDetailSummary/GrossAmount"); string strGrossAmount = nodeGrossAmount.SelectSingleNode("Money").InnerText; decimal grossAmount; if (!decimal.TryParse(strGrossAmount, out grossAmount)) { processMessage = $"File:{sourceFullFolder}{primaryFileName} has invalid GrossAmount:{strGrossAmount}"; OdissLogger.Error(processMessage); return(-2); } group.TotalAmount = grossAmount; group.GUID = Guid.NewGuid(); group.I_CaptureDate = DateTime.Now; XmlNodeList invoiceDetailOrders = invoiceDetailRequest.SelectSingleNode("InvoiceDetailOrder").SelectNodes("InvoiceDetailItem"); XmlNode nodeInvoiceDetailOrderInfo = invoiceDetailRequest.SelectSingleNode("InvoiceDetailOrder/InvoiceDetailOrderInfo/MasterAgreementIDInfo"); string PONumber = nodeInvoiceDetailOrderInfo.Attributes["agreementID"].Value; group.PONumber = PONumber; foreach (XmlNode item in invoiceDetailOrders) { string uom = item.SelectSingleNode("UnitOfMeasure").InnerText; string unitPrice = item.SelectSingleNode("UnitPrice/Money").InnerText; string quantity = item.Attributes["quantity"].Value; string strLineNumber = item.Attributes["invoiceLineNumber"].Value; tblGroupLine aline = new tblGroupLine(); aline.UOM = uom; aline.Qty = int.Parse(quantity); aline.UnitPrice = decimal.Parse(unitPrice); aline.Guid = Guid.NewGuid(); aline.ReferenceId = group.GUID; aline.InvoiceLineNumber = int.Parse(strLineNumber); groupLines.Add(aline); } return(1); }