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); } }
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); }