public FileExplorerResponse Remove(string[] names, string path) { FileExplorerResponse DeleteResponse = new FileExplorerResponse(); try { string physicalPath = GetPath(path); List <FileAccessRules> FilesPermission = new List <FileAccessRules>(); for (int i = 0; i < names.Length; i++) { FileAccessRules permission = GetFilePermission(physicalPath, names[i], IsFile(CombineRelativePath(path, names[i]))); if (!permission.Read || !permission.Edit) { throw new ArgumentException("'" + path + names[i] + "' is not accessible. Access is denied."); } FilesPermission.Add(permission); } DeleteResponse = FileExplorerOperations.Remove(names, path); var items = DeleteResponse.files.ToArray(); for (int i = 0; i < items.Length; i++) { items[i].permission = FilesPermission[i]; } DeleteResponse.files = items; return(DeleteResponse); } catch (Exception e) { DeleteResponse.error = e.GetType().FullName + ", " + e.Message; return(DeleteResponse); } }
public FileExplorerResponse Paste(string sourceDir, string backupDir, string[] names, string option, IEnumerable <CommonFileDetails> commonFiles) { FileExplorerResponse PasteResponse = new FileExplorerResponse(); try { string phyPath = GetPath(sourceDir); for (int i = 0; i < names.Length; i++) { FileAccessRules FilePermission = GetFilePermission(phyPath, names[i], IsFile(CombineRelativePath(sourceDir, names[i]))); if (!FilePermission.Read || !FilePermission.Copy) { throw new ArgumentException("'" + sourceDir + names[i] + "' is not accessible. Access is denied."); } } FileAccessRules PathPermission = GetPathPermission(backupDir); if (!PathPermission.Read || !PathPermission.EditContents) { throw new ArgumentException("'" + backupDir + "' is not accessible. Access is denied."); } PasteResponse = FileExplorerOperations.Paste(sourceDir, backupDir, names, option, commonFiles); PasteResponse.files = SetPermission(backupDir, PasteResponse.files); return(PasteResponse); } catch (Exception e) { PasteResponse.error = e.GetType().FullName + ", " + e.Message; return(PasteResponse); } }
public FileAccessRules UpdateFileRules(FileAccessRules filePermission, AccessRule fileRule) { filePermission.Copy = HasPermission(fileRule.Copy); filePermission.Download = HasPermission(fileRule.Download); filePermission.Edit = HasPermission(fileRule.Edit); filePermission.Read = HasPermission(fileRule.Read); return(filePermission); }
public FileAccessRules UpdateFolderRules(FileAccessRules filePermission, AccessRule folderRule) { filePermission.Copy = HasPermission(folderRule.Copy); filePermission.Edit = HasPermission(folderRule.Edit); filePermission.EditContents = HasPermission(folderRule.EditContents); filePermission.Read = HasPermission(folderRule.Read); filePermission.Upload = HasPermission(folderRule.Upload); return(filePermission); }
public void Upload(HttpFileCollection files, string path) { FileAccessRules PathPermission = GetPathPermission(path); if (!PathPermission.Read || !PathPermission.Upload) { throw new ArgumentNullException("'" + path + "' is not accessible. Access is denied."); } FileExplorerOperations.Upload(files, path); }
public void Download(string path, string[] names) { string physicalPath = GetPath(path); for (int i = 0; i < names.Length; i++) { FileAccessRules FilePermission = GetFilePermission(physicalPath, names[i], true); if (!FilePermission.Read || !FilePermission.Download) { throw new ArgumentNullException("'" + path + names[i] + "' is not accessible. Access is denied."); } } FileExplorerOperations.Download(path, names); }
public FileExplorerResponse NewFolder(string path, string name) { FileExplorerResponse CreateResponse = new FileExplorerResponse(); try { FileAccessRules PathPermission = GetPathPermission(path); if (!PathPermission.Read || !PathPermission.EditContents) { throw new ArgumentException("'" + path + "' is not accessible. Access is denied."); } CreateResponse = FileExplorerOperations.NewFolder(path, name); CreateResponse.files = SetPermission(path, CreateResponse.files); return(CreateResponse); } catch (Exception e) { CreateResponse.error = e.GetType().FullName + ", " + e.Message; return(CreateResponse); } }
public FileExplorerResponse Rename(string path, string oldName, string newName, IEnumerable <CommonFileDetails> commonFiles) { FileExplorerResponse RenameResponse = new FileExplorerResponse(); try { FileAccessRules FilePermission = GetFilePermission(GetPath(path), oldName, IsFile(CombineRelativePath(path, oldName))); if (!FilePermission.Read || !FilePermission.Edit) { throw new ArgumentException("'" + path + oldName + "' is not accessible. Access is denied."); } RenameResponse = FileExplorerOperations.Rename(path, oldName, newName, commonFiles); RenameResponse.files = SetPermission(path, RenameResponse.files); return(RenameResponse); } catch (Exception e) { RenameResponse.error = e.GetType().FullName + ", " + e.Message; return(RenameResponse); } }
public FileExplorerResponse Search(string path, string filter, string searchString, bool caseSensitive) { FileExplorerResponse SearchResponse = new FileExplorerResponse(); try { string physicalPath = GetPath(path); FileAccessRules RootPermission = GetPathPermission(path); if (!RootPermission.Read) { throw new ArgumentException("'" + path + "' is not accessible. Access is denied."); } SearchResponse = FileExplorerOperations.Search(path, filter, searchString, caseSensitive); var items = SearchResponse.files.ToArray(); for (int i = 0; i < items.Length; i++) { FileAccessRules PathPermission = GetPathPermission(path + items[i].filterPath.Replace("\\", "/")); if (!PathPermission.Read) { items = items.Where((val, idx) => idx != i).ToArray(); i--; continue; } items[i].permission = GetFilePermission(physicalPath + items[i].filterPath, items[i].name, items[i].isFile); if (items[i].isFile) { items[i].permission.EditContents = PathPermission.EditContents; items[i].permission.Upload = PathPermission.Upload; } } SearchResponse.files = items; return(SearchResponse); } catch (Exception e) { SearchResponse.error = e.GetType().FullName + ", " + e.Message; return(SearchResponse); } }
public FileAccessRules GetFilePermission(string location, string name, bool isFile) { FileAccessRules FilePermission = new FileAccessRules(); if (isFile) { string nameExtension = Path.GetExtension(name).ToLower(); foreach (AccessRule fileRule in AccessRules.Rules) { if (!string.IsNullOrEmpty(fileRule.Path) && Path.HasExtension(fileRule.Path) && (fileRule.Role == null || fileRule.Role == AccessRules.Role)) { var pathExtension = Path.GetExtension(fileRule.Path).ToLower(); if (fileRule.Path.IndexOf("*.*") > -1) { string parentPath = fileRule.Path.Substring(0, fileRule.Path.IndexOf("*.*")); if (location.IndexOf(GetPath(AccessRules.RootPath + parentPath)) == 0 || parentPath == "") { FilePermission = UpdateFileRules(FilePermission, fileRule); } } else if (fileRule.Path.IndexOf("*.") > -1) { string parentPath = fileRule.Path.Substring(0, fileRule.Path.IndexOf("*.")); if ((GetPath(AccessRules.RootPath + parentPath) == location || parentPath == "") && nameExtension == pathExtension) { FilePermission = UpdateFileRules(FilePermission, fileRule); } } else if (GetPath(AccessRules.RootPath + fileRule.Path) == (location + name)) { FilePermission = UpdateFileRules(FilePermission, fileRule); } } } return(FilePermission); } else { foreach (AccessRule folderRule in AccessRules.Rules) { if (folderRule.Path != null && !Path.HasExtension(folderRule.Path) && (folderRule.Role == null || folderRule.Role == AccessRules.Role)) { if (folderRule.Path.IndexOf("*") > -1) { string parentPath = folderRule.Path.Substring(0, folderRule.Path.IndexOf("*")); if ((location + name).IndexOf(GetPath(AccessRules.RootPath + parentPath)) == 0 || parentPath == "") { FilePermission = UpdateFolderRules(FilePermission, folderRule); } } else if (GetPath(AccessRules.RootPath + folderRule.Path) == (location + name) || GetPath(AccessRules.RootPath + folderRule.Path) == (location + name + "\\")) { FilePermission = UpdateFolderRules(FilePermission, folderRule); } else if ((location + name).IndexOf(GetPath(AccessRules.RootPath + folderRule.Path)) == 0) { FilePermission.Edit = HasPermission(folderRule.EditContents); FilePermission.EditContents = HasPermission(folderRule.EditContents); } } } FilePermission.Download = false; return(FilePermission); } }