public static int ProcessPrimaryFile(DateTime finalizationTime, string primaryFileName, out string processMessage) { string directoryId, pdfFileName; processMessage = ""; int iret = GeneratePDFFile(primaryFileName, aribaExceptionsProcessFolder, finalizationTime, out directoryId, out pdfFileName, out processMessage); if (iret < 0) // if 0, means file alread created. { return(iret); } tblGroup aGroup; List <tblGroupLine> grouplines; iret = ParseAribaPrimaryXMLFile(aribaExceptionsProcessFolder, primaryFileName, finalizationTime, out aGroup, out grouplines, out processMessage); if (iret < 1) { return(iret); } string batchType, sender, originalFileName, sourceImage; DateTime?fTime, receivedDate; iret = GetAribaExceptionBatchType(primaryFileName, out batchType, out fTime, out processMessage); if (iret == 1) { if (batchType == "OPG-EMAIL")// get sender from db { iret = GetAribaExceptionSender(primaryFileName, out sender, out receivedDate, out sourceImage, out originalFileName); if (iret == 1) { aGroup.Sender = sender; aGroup.ReceivedDate = receivedDate; aGroup.OriginalFilename = originalFileName; aGroup.SourceImage = sourceImage; aGroup.Source = "EMAIL"; } } else { aGroup.Source = "SCAN"; } } string respXmlFileName = primaryFileName + ".resp"; string statusCode, statusText, statusMessage; iret = ParseRespXMLFile($"{aribaExceptionsProcessFolder}{respXmlFileName}", out statusCode, out statusText, out statusMessage); aGroup.DirectoryID = directoryId; aGroup.Filename = pdfFileName; aGroup.ScanDate = finalizationTime; aGroup.ProcessFilename = primaryFileName.Substring(0, primaryFileName.IndexOf("XML")); aGroup.AribaExceptionCode = statusCode; aGroup.AribaExceptionReason = statusMessage; aGroup.DocType = "Ariba"; aGroup.I_CaptureDate = DateTime.Now; //next save to table TblGroupHelper.AddTblGroup(aGroup); foreach (var line in grouplines) { TblGroupHelper.AddGroupLine(line); } processMessage = ""; 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 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); }