示例#1
0
        public JsonResult DeleteTemplate(String virtualPath)
        {
            bool retJsonBool           = false;
            DocumentsOperations docOps = new DocumentsOperations();

            if (docOps.GetFileByVirtualPath(virtualPath) != null)
            {
                DCEOperations dceOps = new DCEOperations();
                Guid          fileID = dceOps.GetFileIDFromTemplateByVirtualPath(virtualPath);
                if (fileID != Guid.Empty)
                {
                    dceOps.DeleteUploadedTemplateKeywords(fileID);
                    dceOps.DeleteUploadedTemplates(virtualPath);
                    docOps.DeleteFile(virtualPath);
                    String physicalPath = UtilityOperations.GetServerMapPath(virtualPath);
                    physicalPath = DecodePath(physicalPath);
                    if (System.IO.File.Exists(physicalPath))
                    {
                        System.IO.File.Delete(physicalPath);
                    }
                    retJsonBool = true;
                }
            }
            return(new JsonResult()
            {
                Data = retJsonBool
            });
        }
示例#2
0
文件: FileModel.cs 项目: qiugs/dms
        public FileModel(String virtualPath, String userPath)
        {
            Name        = virtualPath;
            FullPath    = Encode("\\");
            Category    = new Category(FileType.DiscRoot);
            VirtualPath = virtualPath;
            String physicalPath = UtilityOperations.GetServerMapPath(virtualPath);

            CurrentFolderFiles = GetFoldersAndFiles(physicalPath);
            IsFolder           = true;
            if (String.Equals(virtualPath, UtilityOperations.GetDockerCommonFolderPath()))
            {
                IsCommonFolder = true;
            }
            if (String.Equals(virtualPath, UtilityOperations.GetDockerRootPath() + userPath))
            {
                IsRootDir         = true;
                parentVirtualPath = virtualPath;
            }
            else
            {
                IsRootDir         = false;
                parentVirtualPath = UtilityOperations.GetVirtualPath(Directory.GetParent(physicalPath).FullName);
            }
        }
示例#3
0
        public ActionResult DocClassification(HttpPostedFileBase file)
        {
            DocClassification docCls = new DocClassification();

            try {
                String physicalPath = "";
                if (file.ContentLength > 0)
                {
                    String fileHashName = (DateTime.Now).ToString("yyyyMMddHHmmssffff") + file.FileName;
                    physicalPath = DecodePath(
                        Path.Combine(
                            UtilityOperations.GetServerMapPath(
                                UtilityOperations.GetDCEDockerRootPath()) + "\\_temp",
                            Path.GetFileName(fileHashName)));
                    file.SaveAs(physicalPath);
                    String   varet        = (new DocumentsOperations()).IdentifyDocumentType(physicalPath);
                    FileInfo uploadedFile = new FileInfo(physicalPath);
                    docCls.DocClassifiedOutcome += "<input hidden id=\"UploadedFileName\" value=\"" + uploadedFile.Name + "\"/>";
                    docCls.DocClassifiedOutcome += "<span>File Name : " + (uploadedFile.Name).Substring(18) + "</span><br/>";
                    docCls.DocClassifiedOutcome += "<span>Document Type : " + varet + "</span><br/>";
                    docCls.DocClassifiedOutcome += "<span>File Uploaded @ : " + uploadedFile.CreationTime + "</span><br/>";
                }
                else
                {
                    docCls.DocClassifiedMsg = "Error - Please attach the file ...";
                }
            } catch (Exception ex) {
                docCls.DocClassifiedMsg = "Error - File upload failed! " + ex.Message;
            }

            return(View(docCls));
        }
示例#4
0
        public JsonResult Upload(String virtualPath)
        {
            String jsonRet = "";

            if (String.IsNullOrEmpty(virtualPath) || virtualPath == "/")
            {
                virtualPath = UtilityOperations.GetDockerRootPath(Server);
            }
            String userName = HttpContext.User.Identity.Name;

            foreach (String file in Request.Files)
            {
                var fileContent  = Request.Files[file];
                var fileNiceName = Request.Form["fileNiceName"];
                var fileDesc     = Request.Form["fileDesc"];
                if (fileContent != null && fileContent.ContentLength > 0)
                {
                    String filePath            = Path.Combine(UtilityOperations.GetServerMapPath(virtualPath), Path.GetFileName(fileContent.FileName));
                    DocumentsOperations docOps = new DocumentsOperations();
                    //docOps.InsertFile(fileContent.FileName, virtualPath, fileNiceName, fileDesc);
                    docOps.InsertFileEncodeFileName(fileContent.FileName, virtualPath + "/" + fileContent.FileName, fileNiceName, fileDesc, userName, false);
                    fileContent.SaveAs(filePath);
                    jsonRet = "Uploaded";
                }
            }
            return(new JsonResult()
            {
                Data = jsonRet
            });
        }
示例#5
0
        public JsonResult OCRThisFile(String virtualPath)
        {
            String        physicalPath  = UtilityOperations.DecodePath(UtilityOperations.GetServerMapPath(virtualPath), Server);
            SingleFileOCR singleFileOCR = new SingleFileOCR(physicalPath);
            String        retVal        = singleFileOCR.StartOCR();

            if (!retVal.StartsWith("ERROR"))
            {
                DocumentsOperations docOps = new DocumentsOperations();
                var    file       = docOps.GetFileByVirtualPath(virtualPath);
                String oriFileExt = (new System.IO.FileInfo(physicalPath)).Extension;
                String retFileExt = (new System.IO.FileInfo(retVal)).Extension;
                retFileExt = retVal.Substring(retVal.Length - (retFileExt.Length + 4));
                docOps.InsertFileEncodeFileName(file.Name.Replace(oriFileExt, retFileExt), file.VirtualPath.Replace(oriFileExt, retFileExt), "", "OCR Performed @ " + DateTime.Now, HttpContext.User.Identity.Name, false);
                docOps.InsertFileBeenOCR(docOps.GetFileIDByVirtualPath(file.VirtualPath.Replace(oriFileExt, retFileExt)), docOps.IdentifyDocumentType(retVal));
                return(new JsonResult()
                {
                    Data = ""
                });
            }
            return(new JsonResult()
            {
                Data = retVal
            });
        }
示例#6
0
        public JsonResult UploadTemplate()
        {
            String retJsonMsg = String.Empty;

            foreach (String file in Request.Files)
            {
                var        fileContent  = Request.Files[file];
                var        docType      = Request.Form["DocType"];
                var        docDesc      = Request.Form["DocDesc"];
                var        skipPages    = Request.Form["SkipPages"];
                List <int> pagesToSkill = new List <int>();
                if (skipPages.Length > 0)
                {
                    List <String> skippages = skipPages.Split(',').ToList();
                    foreach (String skip in skippages)
                    {
                        int  number;
                        bool retInt = int.TryParse(skip, out number);
                        if (retInt)
                        {
                            pagesToSkill.Add(number);
                        }
                        else
                        {
                            retJsonMsg = "ERROR - Skip page value [" + skip + "] is not a number!"; break;
                        }
                    }
                }
                if (fileContent != null && fileContent.ContentLength > 0 && String.IsNullOrEmpty(retJsonMsg))
                {
                    String virtualPath         = UtilityOperations.GetDCEDockerRootPath();
                    String physicalPath        = DecodePath(Path.Combine(UtilityOperations.GetServerMapPath(virtualPath), Path.GetFileName(fileContent.FileName)));
                    String userName            = HttpContext.User.Identity.Name;
                    DocumentsOperations docOps = new DocumentsOperations();
                    if (docOps.GetFileByVirtualPath(virtualPath + "/" + fileContent.FileName) == null)
                    {
                        System.IO.Directory.CreateDirectory(UtilityOperations.GetServerMapPath(virtualPath));
                        fileContent.SaveAs(physicalPath);
                        docOps.InsertFileEncodeFileName(fileContent.FileName, virtualPath + "/" + fileContent.FileName, "_DCEDockerFile", docDesc, userName, false);
                        DCEOperations dceOps = new DCEOperations();
                        dceOps.InsertTemplate(virtualPath + "/" + fileContent.FileName, docType, docDesc, userName);
                        List <String> retStrArr = GetPDFContents(physicalPath, pagesToSkill);
                        dceOps.InsertOCRContents(fileContent.FileName, retStrArr[0], retStrArr[1]);
                    }
                    else
                    {
                        retJsonMsg = "ERROR - The file already eixsts.";
                    }
                }
            }
            return(new JsonResult()
            {
                Data = retJsonMsg
            });
        }
示例#7
0
        public void DownloadFile(String virtualPath, String userID)
        {
            String physicalPath = UtilityOperations.GetServerMapPath(virtualPath);

            physicalPath = UtilityOperations.DecodePath(physicalPath, Server);
            List <String> archives = new List <String>();

            archives.Add(physicalPath);
            RecordFileDownload(virtualPath, userID);
            UtilityOperations.DownloadFiles(archives, this.HttpContext.ApplicationInstance.Context);
        }
示例#8
0
        public ActionResult CommonFolderMgt(CommonFolderManagement cfm, String submit, String tableSelectedFolder)
        {
            DocumentsOperations docOps = new DocumentsOperations();
            String virtualPath = "", physicalPath = "", folderPath = "";

            switch (submit)
            {
            case "Create":
                virtualPath  = UtilityOperations.GetDockerCommonFolderPath();
                physicalPath = UtilityOperations.GetServerMapPath(virtualPath);
                folderPath   = Path.Combine(UtilityOperations.DecodePath(physicalPath, Server), cfm.FolderName);
                if (folderPath != "\\")
                {
                    if (!Directory.Exists(folderPath))
                    {
                        docOps.InsertNewFolder(virtualPath, folderPath, HttpContext.User.Identity.Name, cfm.FolderName);
                    }
                    else
                    {
                        TempData["CommonFolderMgtErrorMsg"] = "Warning - Folder already existed.";
                    }
                }
                break;

            case "Edit":
                return(RedirectToAction("EditCommonFolder", new { virtualPath = tableSelectedFolder }));

            case "Delete":
                physicalPath = UtilityOperations.DecodePath(UtilityOperations.GetServerMapPath(tableSelectedFolder), Server);
                FileAttributes attr = System.IO.File.GetAttributes(physicalPath);
                if (Directory.Exists(physicalPath))
                {
                    if (docOps.GetFilesStartsWithVirtualPath(tableSelectedFolder) != null)
                    {
                        docOps.DeleteFile(tableSelectedFolder);
                    }
                    Directory.Delete(physicalPath, true);
                }
                else
                {
                    TempData["CommonFolderMgtErrorMsg"] = "Warning - Folder not exist in the system.";
                }
                break;
            }
            return(RedirectToAction("CommonFolderMgt"));
        }
示例#9
0
        public JsonResult DeleteFile(String virtualPath)
        {
            bool retJsonBool = false;

            if (virtualPath.Length > 1)
            {
                String physicalPath = UtilityOperations.GetServerMapPath(virtualPath);
                physicalPath = UtilityOperations.DecodePath(physicalPath, Server);
                FileAttributes attr = System.IO.File.GetAttributes(physicalPath);
                if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
                {
                    if (Directory.Exists(physicalPath))
                    {
                        DocumentsOperations docOps = new DocumentsOperations();
                        if (docOps.GetFilesStartsWithVirtualPath(virtualPath) != null)
                        {
                            docOps.DeleteFile(virtualPath);
                        }
                        Directory.Delete(physicalPath, true);
                        retJsonBool = true;
                    }
                }
                else
                {
                    if (System.IO.File.Exists(physicalPath))
                    {
                        DocumentsOperations docOps = new DocumentsOperations();
                        if (docOps.GetFileByVirtualPath(virtualPath) != null)
                        {
                            docOps.DeleteFile(virtualPath);
                        }
                        System.IO.File.Delete(physicalPath);
                        retJsonBool = true;
                    }
                }
            }
            return(new JsonResult()
            {
                Data = retJsonBool
            });
        }
示例#10
0
        public JsonResult Rename()
        {
            var            virtualPath   = Request.Form["virtualPath"];
            var            newName       = Request.Form["newName"];
            var            oldName       = Request.Form["oldName"];
            String         decodePath    = UtilityOperations.DecodePath(UtilityOperations.GetServerMapPath(virtualPath), Server);
            String         newDecodePath = decodePath.Replace(oldName, newName);
            String         retJsonMsg    = "";
            FileAttributes attr          = System.IO.File.GetAttributes(decodePath);

            if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
            {
                if (System.IO.Directory.Exists(decodePath))
                {
                    System.IO.Directory.Move(decodePath, decodePath.Replace(oldName, newName));
                    retJsonMsg += " DirRenamed";
                }
            }
            else
            {
                if (System.IO.File.Exists(decodePath))
                {
                    System.IO.File.Move(decodePath, decodePath.Replace(oldName, newName));
                    retJsonMsg += " FileRenamed";
                }
            }
            DocumentsOperations docOps = new DocumentsOperations();

            if (docOps.GetFileByVirtualPath(virtualPath) != null)
            {
                docOps.RenameFile(newName, virtualPath, virtualPath.Replace(oldName, newName));
                retJsonMsg += " DBRenamed";
            }
            return(new JsonResult()
            {
                Data = retJsonMsg
            });
        }
示例#11
0
        public JsonResult CreateNewFolder(String virtualPath, String userName, String folderName)
        {
            String physicalPath = UtilityOperations.GetServerMapPath(virtualPath);
            String decodePath   = UtilityOperations.DecodePath(physicalPath, Server);
            String folderPath   = Path.Combine(decodePath, folderName);
            String retJsonMsg   = "";

            if (folderPath != "\\")
            {
                if (!Directory.Exists(folderPath))
                {
                    DocumentsOperations docOps = new DocumentsOperations();
                    docOps.InsertNewFolder(virtualPath, folderPath, userName, folderName);
                }
                else
                {
                    retJsonMsg += "Folder name already exists. Please enter a different folder name";
                }
            }
            return(new JsonResult()
            {
                Data = retJsonMsg
            });
        }
示例#12
0
文件: FileModel.cs 项目: qiugs/dms
        public FileModel GetFolderOrFile(String virtualPath)
        {
            String physicalPath = UtilityOperations.GetServerMapPath(virtualPath);

            if (!string.IsNullOrEmpty(physicalPath))
            {
                physicalPath = Decode(physicalPath);
            }
            DocumentsOperations docOps    = new DocumentsOperations();
            FileModel           fileModel = null;

            try {
                FileAttributes attr = System.IO.File.GetAttributes(physicalPath);
                if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
                {
                    DirectoryInfo di = new DirectoryInfo(physicalPath);
                    fileModel = new FileModel(di);
                    RMA_Docker.Models.File dbFile = docOps.GetFileByVirtualPath(UtilityOperations.GetVirtualPath(physicalPath));
                    if (dbFile != null)
                    {
                        fileModel.Description        = dbFile.Description;
                        fileModel.NiceNameOrAreaName = dbFile.NiceNameOrAreaName;
                        fileModel.UploadedDT         = dbFile.DateTimeUploaded;
                        fileModel.VirtualPath        = dbFile.VirtualPath;
                    }
                }
                else
                {
                    FileInfo fi = new FileInfo(physicalPath);
                    fileModel = new FileModel(fi);
                    var dbFile = docOps.GetFileByVirtualPath(UtilityOperations.GetVirtualPath(physicalPath));
                    if (dbFile != null)
                    {
                        fileModel.Description        = dbFile.Description;
                        fileModel.NiceNameOrAreaName = dbFile.NiceNameOrAreaName;
                        fileModel.UploadedDT         = dbFile.DateTimeUploaded;
                        fileModel.VirtualPath        = dbFile.VirtualPath;
                        var fileOCR = docOps.GetFileBeenOCR(dbFile.ID);
                        if (fileOCR != null)
                        {
                            fileModel.IsOCR      = true;
                            fileModel.AllowToOCR = false;
                            fileModel.OcrDocType = fileOCR.DocumentType;
                        }
                        else
                        {
                            fileModel.IsOCR      = false;
                            fileModel.AllowToOCR = false;
                            if (docOps.IsFileBeenOCRByFileName(dbFile.Name.Replace(".pdf", "_ocr.pdf")))
                            {
                                fileModel.AllowToOCR = false;
                            }
                            else
                            {
                                fileModel.AllowToOCR = ((new DCEOperations()).GetFileExtensionsAllowToOCR()
                                                        .Select(fileExt => fileExt.FileExtension.ToLower()))
                                                       .Contains(fileModel.Extension.ToLower());
                            }
                            fileModel.OcrDocType = "";
                        }
                    }
                }
            } catch (Exception) { }
            fileModel.parentVirtualPath = virtualPath;
            return(fileModel);
        }