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 }); }
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 }); }
public ActionResult EditCommonFolder(String virtualPath) { DocumentsOperations docOps = new DocumentsOperations(); var file = docOps.GetFileByVirtualPath(virtualPath); CommonFolderAssignment cfa = new CommonFolderAssignment { FolderName = file.Name, CreatedAt = file.DateTimeUploaded.ToString(), VirtualPath = file.VirtualPath, UsersName = docOps.GetUsersNameByFileID(file.ID), RolesName = docOps.GetRolesNameByFileID(file.ID) }; MembershipUserCollection allUsers = Membership.GetAllUsers(); List <String> excludedUsers = new List <String>(); foreach (MembershipUser user in allUsers) { if (!cfa.UsersName.Contains(user.UserName)) { excludedUsers.Add(user.UserName); } } cfa.ExcludedUsers = excludedUsers; cfa.ExcludedRoles = Roles.GetAllRoles().Except(cfa.RolesName).ToList(); return(View(cfa)); }
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 }); }
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 }); }
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 }); }
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); }
public static IList <FileModel> GetFoldersAndFiles(string path) { List <FileModel> resultFile = new List <FileModel>(); List <FileModel> resultFolder = new List <FileModel>(); if (string.IsNullOrEmpty(path)) { return(GetRootDirectories()); } else { path = Decode(path); } DocumentsOperations docOps = new DocumentsOperations(); try { foreach (string file in Directory.GetFiles(path, "*", SearchOption.TopDirectoryOnly)) { FileInfo fi = new FileInfo(file); FileModel newFileModel = new FileModel(fi); var dbFile = docOps.GetFileByVirtualPath(UtilityOperations.GetVirtualPath(file)); if (dbFile != null) { newFileModel.Description = dbFile.Description; newFileModel.NiceNameOrAreaName = dbFile.NiceNameOrAreaName; newFileModel.UploadedDT = dbFile.DateTimeUploaded; newFileModel.VirtualPath = dbFile.VirtualPath; var fileOCR = docOps.GetFileBeenOCR(dbFile.ID); if (fileOCR != null) { newFileModel.IsOCR = true; newFileModel.AllowToOCR = false; newFileModel.OcrDocType = fileOCR.DocumentType; } else { newFileModel.IsOCR = false; newFileModel.AllowToOCR = false; if (docOps.IsFileBeenOCRByFileName(dbFile.Name.Replace(".pdf", "_ocr.pdf"))) { newFileModel.AllowToOCR = false; } else { newFileModel.AllowToOCR = ((new DCEOperations()).GetFileExtensionsAllowToOCR() .Select(fileExt => fileExt.FileExtension.ToLower())) .Contains(newFileModel.Extension.ToLower()); } newFileModel.OcrDocType = ""; } } resultFile.Add(newFileModel); } foreach (string dir in Directory.GetDirectories(path, "*", SearchOption.TopDirectoryOnly)) { DirectoryInfo di = new DirectoryInfo(dir); FileModel newFileModel = new FileModel(di); String getVirtualPath = UtilityOperations.GetVirtualPath(dir); RMA_Docker.Models.File dbFile = docOps.GetFileByVirtualPath(getVirtualPath); if (dbFile != null) { newFileModel.Description = dbFile.Description; newFileModel.NiceNameOrAreaName = dbFile.NiceNameOrAreaName; newFileModel.UploadedDT = dbFile.DateTimeUploaded; newFileModel.VirtualPath = dbFile.VirtualPath; } resultFolder.Add(newFileModel); } resultFile.Sort((a, b) => { var name1 = a.Name; var name2 = b.Name; if (a.Category.Value == FileType.Folder) { name1 = " " + name1; } if (b.Category.Value == FileType.Folder) { name2 = " " + name2; } return(name1.CompareTo(name2)); }); resultFolder.AddRange(resultFile); } catch (Exception) { } return(resultFolder); }