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 ArchiveDoc(Guid appId, Guid docId, string referenceNo, string notes) { try { using (var db = new Odiss_OPG_BaseEntities()) { var doc = db.tblGroups.SingleOrDefault(x => x.GUID == docId); if (doc == null) { return(0); } doc.Archived = 1; doc.ReferenceNo = referenceNo; doc.ArchiveComment = notes; doc.ArchivedDate = DateTime.Now; doc.Status = "Archive"; db.Entry(doc).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); //audit doc.tblDirectory = new tblDirectory(); // remove self reference loop doc.tblGroupLines = new List <tblGroupLine>(); // Library.Audit.Save(AuditTypeEnum.ArchiveDocument, appId, doc); } } catch (Exception ex) { OdissLogger.Error($"Archive doc error:{ex.ToString()}"); return(-1); } 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); } }
static Dictionary <string, bool> pdfDayFolderExists = new Dictionary <string, bool>(); // key:20181101 --> true public static int PreparePDFFolderAndDirectoryId(string baseFolder, DateTime receivedDate, out string directoryId, out string pdfStorageFolder) { //the new directoryId will always in this format: 20181101 lock (_threadlock) // avoid to create same location id and directoryid { string volume = receivedDate.ToString("yyyy"); string dictKey = receivedDate.ToString("yyyyMMdd"); if (directoryIdDict.ContainsKey(dictKey)) { pdfStorageFolder = baseFolder + volume + "\\" + dictKey + "\\"; directoryId = directoryIdDict[dictKey]; return(1); } using (var db = new Odiss_OPG_BaseEntities()) { var directory = db.tblDirectories.SingleOrDefault(x => x.DirectoryID == dictKey); // the dictionaryId is like: 20181101 if (directory != null) // created previously { directoryId = dictKey; directoryIdDict.Add(dictKey, dictKey); // saved in dictionary, so we dont need to check db again and again pdfStorageFolder = baseFolder + volume + "\\" + dictKey + "\\"; return(1); } //need to create new directory //first prepare folder PrepareFolder(baseFolder, receivedDate); // insert records into tblLocation and tblDirectory table var loc1 = new tblLocation(); loc1.LocationId = dictKey; loc1.Volume = volume; loc1.RPath = baseFolder; var dir1 = new tblDirectory(); dir1.DirectoryID = dictKey; dir1.LocationID = dictKey; dir1.Directory = dictKey; db.Entry(loc1).State = EntityState.Added; db.Entry(dir1).State = EntityState.Added; db.SaveChanges(); directoryIdDict.Add(dictKey, dictKey); // saved in dictionary, so we dont need to check db again and again directoryId = dictKey; pdfStorageFolder = baseFolder + volume + "\\" + dictKey + "\\"; } return(1); } }
public void TestMoveResubmitDocPDF() { using (var db = new Odiss_OPG_BaseEntities()) { var doc = db.tblGroups.SingleOrDefault(x => x.GUID == new Guid("2D90B70D-0353-432D-B1AB-03D61F2B87AB")); int iret = DocHelper.MoveResubmitDocPDF(doc); Assert.AreEqual(iret, 1); } }
public static Guid AddGroupLine(tblGroupLine aGroupLine) { using (var db = new Odiss_OPG_BaseEntities()) { if (aGroupLine.Guid == Guid.Empty) { aGroupLine.Guid = Guid.NewGuid(); } db.Entry(aGroupLine).State = EntityState.Added; db.SaveChanges(); return(aGroupLine.Guid); } }
public static Guid AddTblGroup(tblGroup aGroup) { using (var db = new Odiss_OPG_BaseEntities()) { if (aGroup.GUID == Guid.Empty) { aGroup.GUID = Guid.NewGuid(); } db.Entry(aGroup).State = EntityState.Added; db.SaveChanges(); return(aGroup.GUID); } }
public IHttpActionResult Get(Guid?id) { if (!id.HasValue) { return(NotFound()); } using (var ctx = new Odiss_OPG_BaseEntities()) { var group = ctx.tblGroups.FirstOrDefault(x => x.GUID == id); group.tblDirectory = new tblDirectory(); group.lineItems = group.tblGroupLines; var json = JsonConvert.SerializeObject(group, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); return(Ok(group)); }; }
public static int ResubmitDoc(Guid appId, Guid docId, string notes) { try { using (var db = new Odiss_OPG_BaseEntities()) { var doc = db.tblGroups.SingleOrDefault(x => x.GUID == docId); if (doc == null) { return(0); } //remove file first int iret = MoveResubmitDocPDF(doc); if (iret < 0) { return(iret); } doc.Archived = 2; // Resubmitted doc.ArchivedDate = DateTime.Now; doc.ArchiveComment = notes; doc.Status = "Resubmit"; db.Entry(doc).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); //audit doc.tblDirectory = new tblDirectory(); // remove self reference loop Library.Audit.Save(AuditTypeEnum.EditProperties, appId, doc); } } catch (Exception ex) { OdissLogger.Error($"ResubmitDoc doc error:{ex.ToString()}"); return(-1); } return(1); }
public IHttpActionResult Upsert([FromBody] tblGroup document) { try { using (var ctx = new Odiss_OPG_BaseEntities()) { var existing = ctx.tblGroups.SingleOrDefault(x => x.GUID == document.GUID); document.tblGroupLines = document.lineItems; foreach (var item in document.tblGroupLines) { if (item.Guid == Guid.Empty) { item.Guid = Guid.NewGuid(); } } if (existing != null) { ctx.Entry(existing).State = System.Data.Entity.EntityState.Detached; ctx.UpdateGraph(document, map => map.OwnedCollection(x => x.tblGroupLines)); } else { ctx.tblGroups.Add(document); } ctx.SaveChanges(); } return(Ok(new { status = 1, obj = document })); } catch (Exception ex) { return(Ok(new { status = -1, obj = ex })); } }
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 MoveResubmitDocPDF(tblGroup doc) { string pdfStorageRoot = ""; // ConfigurationManager.AppSettings["PDFRootFolder"]; using (var db = new Odiss_OPG_BaseEntities()) { var setting1 = db.Settings.FirstOrDefault(x => x.Name.ToLower() == "documentspath"); if (setting1 == null) { OdissLogger.Error($"DocumentsPath was not set."); return(-1); } if (setting1.Value.IndexOf("\\") < 0) { OdissLogger.Error($"DocumentsPath was not set correctly."); return(-2); } pdfStorageRoot = setting1.Value; } if (pdfStorageRoot.LastIndexOf("\\") != pdfStorageRoot.Length - 1) { pdfStorageRoot += "\\"; // add last back slash } string resubmitPDFRootFolder = GetResubmitPDFRootFolder(); string directoryId = doc.DirectoryID; string year = directoryId.Substring(0, 4); string fileName = doc.Filename; string sourceFile = $"{pdfStorageRoot}{year}\\{directoryId}\\{fileName}"; string destFolder = $"{resubmitPDFRootFolder}{year}\\{directoryId}"; if (!Directory.Exists(destFolder)) { Directory.CreateDirectory(destFolder); } string destFile = $"{destFolder}\\{fileName}"; try { File.Copy(sourceFile, destFile); //File.Delete(sourceFile); // dont delete for now, since tblGroup table record still there } catch (Exception ex) { string details = ex.ToString(); if (details.IndexOf("already exist") > -1) { return(0); } OdissLogger.Error($"MoveResubmitDocPDF error: {details}"); return(-3); } return(1); }