Exemple #1
0
        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);
            }
        }
Exemple #2
0
        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 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);
            }
        }
Exemple #5
0
        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 }));
            }
        }
Exemple #7
0
        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);
        }