private static ResultObject DeleteStorageSpaceFolderInternal(int storageSpaceId, int storageSpaceFolderId) { var result = TaskManager.StartResultTask <IntResult>("STORAGE_SPACES", "DELETE_STORAGE_SPACE_FOLDER"); try { if (storageSpaceId < 0) { throw new ArgumentException("Storage Space iD must be greater than 0"); } var storage = GetStorageSpaceById(storageSpaceId); if (storage == null) { throw new Exception(string.Format("Storage space with id={0} not found", storageSpaceId)); } var storageFolder = GetStorageSpaceFolderById(storageSpaceFolderId); if (storageFolder == null) { throw new Exception(string.Format("Storage Space folder with id={0} not found", storageSpaceFolderId)); } var ss = GetStorageSpaceService(storage.ServiceId); if (storageFolder.IsShared) { ss.RemoveShare(storageFolder.Path); } ss.DeleteFolder(storageFolder.Path); DataProvider.RemoveStorageSpaceFolder(storageSpaceFolderId); } catch (Exception exception) { TaskManager.WriteError(exception); result.AddError("Error removing Storage Space folder", exception); if (result.Value > 0) { DataProvider.RemoveStorageSpaceFolder(result.Value); } } finally { if (!result.IsSuccess) { TaskManager.CompleteResultTask(result); } else { TaskManager.CompleteResultTask(); } } return(result); }
private static ResultObject RemoveStorageSpaceLevelInternal(int id) { var result = TaskManager.StartResultTask <ResultObject>("STORAGE_SPACES", "REMOVE_STORAGE_SPACE_LEVEL"); try { if (id < 1) { throw new ArgumentException("Id must be greater than 0"); } DataProvider.RemoveStorageSpaceLevel(id); } catch (Exception exception) { TaskManager.WriteError(exception); result.AddError("Error removing Storage Space Level", exception); } finally { if (!result.IsSuccess) { TaskManager.CompleteResultTask(result); } else { TaskManager.CompleteResultTask(); } } return(result); }
public ResultObject DeleteFolders(int itemId) { var result = TaskManager.StartResultTask <ResultObject>("ORGANIZATION_FOLDERS", "DELETE_ALL_FOLDERS"); try { foreach (var storageSpaceFolderType in Enum.GetValues(typeof(StorageSpaceFolderTypes))) { DeleteFolders(itemId, storageSpaceFolderType.ToString()); } } catch (Exception exception) { TaskManager.WriteError(exception); result.AddError("Error deleting organization folders", exception); } finally { if (!result.IsSuccess) { TaskManager.CompleteResultTask(result); } else { TaskManager.CompleteResultTask(); } } return(result); }
private static IntResult FindBestStorageSpaceServiceInternal(IStorageSpaceSelector selector, string groupName, long quotaSizeBytes) { var result = TaskManager.StartResultTask <IntResult>("STORAGE_SPACES", "FIND_BEST_STORAGE_SPACE_SERVICE"); try { var bestStorage = selector.FindBest(groupName, quotaSizeBytes); result.Value = bestStorage.Id; } catch (Exception exception) { TaskManager.WriteError(exception); result.AddError("Error finding best Storage Space", exception); } finally { if (!result.IsSuccess) { TaskManager.CompleteResultTask(result); } else { TaskManager.CompleteResultTask(); } } return(result); }
public ResultObject DeleteFolders(int itemId, string type) { var result = TaskManager.StartResultTask <ResultObject>("ORGANIZATION_FOLDERS", "DELETE_FOLDERS_BY_TYPE"); try { var folders = GetFolders(itemId, type); foreach (var folder in folders) { DeleteFolder(itemId, folder.Id); } } catch (Exception exception) { TaskManager.WriteError(exception); result.AddError("Error deleting organization folders", exception); } finally { if (!result.IsSuccess) { TaskManager.CompleteResultTask(result); } else { TaskManager.CompleteResultTask(); } } return(result); }
private static IntResult SaveStorageSpaceInternal(StorageSpace space, bool isShared = false) { var result = TaskManager.StartResultTask <IntResult>("STORAGE_SPACES", "SAVE_STORAGE_SPACE"); try { if (space == null) { throw new ArgumentNullException("space"); } var ss = GetStorageSpaceService(space.ServiceId); if (isShared) { var share = ShareStorageSpaceFolderInternal(space.Id, space.Path, space.Name); space.IsShared = true; space.UncPath = share.UncPath; } if (space.Id > 0) { DataProvider.UpdateStorageSpace(space); TaskManager.Write("Updating Storage Space with id = {0}", space.Id.ToString(CultureInfo.InvariantCulture)); result.Value = space.Id; } else { result.Value = DataProvider.InsertStorageSpace(space); TaskManager.Write("Inserting new Storage Space, obtained id = {0}", space.Id.ToString(CultureInfo.InvariantCulture)); space.Id = result.Value; } ss.UpdateStorageSettings(space.Path, space.FsrmQuotaSizeBytes, space.FsrmQuotaType); } catch (Exception exception) { TaskManager.WriteError(exception); result.AddError("Error saving Storage Space", exception); } finally { if (!result.IsSuccess) { TaskManager.CompleteResultTask(result); } else { TaskManager.CompleteResultTask(); } } return(result); }
private static IntResult SaveStorageSpaceLevelInternal(StorageSpaceLevel level, List <ResourceGroupInfo> groups) { var result = TaskManager.StartResultTask <IntResult>("STORAGE_SPACES", "SAVE_STORAGE_SPACE_LEVEL"); try { if (level == null) { throw new ArgumentNullException("level"); } if (level.Id > 0) { DataProvider.UpdateStorageSpaceLevel(level); TaskManager.Write("Updating Storage Space Level with id = {0}", level.Id.ToString(CultureInfo.InvariantCulture)); result.Value = level.Id; } else { result.Value = DataProvider.InsertStorageSpaceLevel(level); TaskManager.Write("Inserting new Storage Space Level, obtained id = {0}", level.Id.ToString(CultureInfo.InvariantCulture)); level.Id = result.Value; } var resultGroup = SaveLevelResourceGroups(result.Value, groups); if (!resultGroup.IsSuccess) { throw new Exception("Error saving resource groups"); } } catch (Exception exception) { TaskManager.WriteError(exception); result.AddError("Error saving Storage Space Level", exception); } finally { if (!result.IsSuccess) { TaskManager.CompleteResultTask(result); } else { TaskManager.CompleteResultTask(); } } return(result); }
private static ResultObject RenameFolderInternal(int storageSpaceId, int folderId, string organizationId, string group, string fullPath, string newName) { var result = TaskManager.StartResultTask <ResultObject>("STORAGE_SPACES", "RENAME_FOLDER"); try { if (storageSpaceId < 0) { throw new ArgumentException("Storage Space iD must be greater than 0"); } var storage = GetStorageSpaceById(storageSpaceId); if (storage == null) { throw new Exception(string.Format("Storage space with id={0} not found", storageSpaceId)); } var ss = GetStorageSpaceService(storage.ServiceId); ss.RemoveShare(fullPath); ss.RenameFolder(fullPath, newName); var newPath = Path.Combine(Directory.GetParent(fullPath).ToString(), newName); var shareName = GenerateShareName(organizationId, newName); var share = ShareStorageSpaceFolderInternal(storageSpaceId, newPath, shareName); var folder = GetStorageSpaceFolderById(folderId); StorageSpacesController.UpdateStorageSpaceFolder(storageSpaceId, folderId, organizationId, group, newName, share.UncPath, folder.FsrmQuotaSizeBytes, folder.FsrmQuotaType); } catch (Exception exception) { TaskManager.WriteError(exception); result.AddError("Error during folder rename", exception); } finally { if (!result.IsSuccess) { TaskManager.CompleteResultTask(result); } else { TaskManager.CompleteResultTask(); } } return(result); }
private static ResultObject SetStorageSpaceFolderQuotaInternal(int storageSpaceId, int storageSpaceFolderId, long quotaInBytes, QuotaType quotaType) { var result = TaskManager.StartResultTask <IntResult>("STORAGE_SPACES", "SET_STORAGE_SPACE_FOLDER_QUOTA"); try { if (storageSpaceId < 0) { throw new ArgumentException("Storage Space iD must be greater than 0"); } var storage = GetStorageSpaceById(storageSpaceId); if (storage == null) { throw new Exception(string.Format("Storage space with id={0} not found", storageSpaceId)); } var storageFolder = GetStorageSpaceFolderById(storageSpaceFolderId); if (storageFolder == null) { throw new Exception(string.Format("Storage Space folder with id={0} not found", storageSpaceFolderId)); } SetFolderQuota(storageSpaceId, storageFolder.Path, quotaInBytes, quotaType); DataProvider.UpdateStorageSpaceFolder(storageSpaceFolderId, storageFolder.Name, storageSpaceId, storageFolder.Path, storageFolder.UncPath, storageFolder.IsShared, quotaType, quotaInBytes); } catch (Exception exception) { TaskManager.WriteError(exception); result.AddError("Error removing Storage Space folder", exception); if (result.Value > 0) { DataProvider.RemoveStorageSpaceFolder(result.Value); } } finally { if (!result.IsSuccess) { TaskManager.CompleteResultTask(result); } else { TaskManager.CompleteResultTask(); } } return(result); }
private static IntResult CreateStorageSpaceFolderInternal(int storageSpaceId, string groupName, string organizationId, string folderName, long quotaInBytes, QuotaType quotaType) { var result = TaskManager.StartResultTask <IntResult>("STORAGE_SPACES", "CREATE_STORAGE_SPACE_FOLDER"); try { var storageSpace = StorageSpacesController.GetStorageSpaceById(storageSpaceId); if (storageSpace == null) { throw new Exception(string.Format("Storage space with id={0} not found", storageSpaceId)); } var ss = GetStorageSpaceService(storageSpace.ServiceId); var fullPath = CreateFilePath(storageSpace.Path, organizationId, groupName, folderName); ss.CreateFolder(fullPath); var shareName = GenerateShareName(organizationId, folderName); var share = ShareStorageSpaceFolderInternal(storageSpace.Id, fullPath, shareName); ss.UpdateFolderQuota(fullPath, quotaInBytes, quotaType); result.Value = DataProvider.CreateStorageSpaceFolder(folderName, storageSpace.Id, fullPath, share.UncPath, true, quotaType, quotaInBytes); } catch (Exception exception) { TaskManager.WriteError(exception); result.AddError("Error creating Storage Space folder", exception); if (result.Value > 0) { DataProvider.RemoveStorageSpaceFolder(result.Value); } } finally { if (!result.IsSuccess) { TaskManager.CompleteResultTask(result); } else { TaskManager.CompleteResultTask(); } } return(result); }
private static ResultObject SetFolderNtfsPermissionsInternal(int storageSpaceId, string fullPath, UserPermission[] permissions, bool isProtected, bool preserveInheritance) { var result = TaskManager.StartResultTask <IntResult>("STORAGE_SPACES", "SET_NTFS_PERMISSIONS_ON_FOLDER"); try { if (storageSpaceId < 0) { throw new ArgumentException("Storage Space iD must be greater than 0"); } var storage = GetStorageSpaceById(storageSpaceId); if (storage == null) { throw new Exception(string.Format("Storage space with id={0} not found", storageSpaceId)); } var ss = GetStorageSpaceService(storage.ServiceId); ss.SetFolderNtfsPermissions(fullPath, permissions, isProtected, preserveInheritance); } catch (Exception exception) { TaskManager.WriteError(exception); result.AddError("Error setting NTFS permissions on Storage Space folder", exception); if (result.Value > 0) { DataProvider.RemoveStorageSpaceFolder(result.Value); } } finally { if (!result.IsSuccess) { TaskManager.CompleteResultTask(result); } else { TaskManager.CompleteResultTask(); } } return(result); }
private static ResultObject UpdateStorageSpaceFolderInternal(int storageSpaceId, int storageSpaceFolderId, string organizationId, string groupName, string folderName, string uncPath, long quotaInBytes, QuotaType quotaType) { var result = TaskManager.StartResultTask <ResultObject>("STORAGE_SPACES", "UPDATE_STORAGE_SPACE_FOLDER"); try { var storageSpace = StorageSpacesController.GetStorageSpaceById(storageSpaceId); if (storageSpace == null) { throw new Exception(string.Format("Storage space with id={0} not found", storageSpaceId)); } var ss = StorageSpacesController.GetStorageSpaceService(storageSpace.ServiceId); var fullPath = CreateFilePath(storageSpace.Path, organizationId, groupName, folderName); if (quotaInBytes > 0) { ss.UpdateFolderQuota(fullPath, quotaInBytes, quotaType); } DataProvider.UpdateStorageSpaceFolder(storageSpaceFolderId, folderName, storageSpace.Id, fullPath, uncPath, false, quotaType, quotaInBytes); } catch (Exception exception) { TaskManager.WriteError(exception); result.AddError("Error removing Storage Space", exception); } finally { if (!result.IsSuccess) { TaskManager.CompleteResultTask(result); } else { TaskManager.CompleteResultTask(); } } return(result); }
private static StorageSpaceFolderShare ShareStorageSpaceFolderInternal(int storageSpaceId, string fullPath, string shareName) { var result = TaskManager.StartResultTask <ResultObject>("STORAGE_SPACES", "SHARE_STORAGE_SPACE_FOLDER"); try { var storageSpace = StorageSpacesController.GetStorageSpaceById(storageSpaceId); if (storageSpace == null) { throw new Exception(string.Format("Storage space with id={0} not found", storageSpaceId)); } var ss = StorageSpacesController.GetStorageSpaceService(storageSpace.ServiceId); var share = ss.ShareFolder(fullPath, shareName); if (share == null) { throw new Exception("Error sharin folder"); } return(share); } catch (Exception exception) { result.AddError("Error sharing Storage Space folder", exception); throw TaskManager.WriteError(exception); } finally { if (!result.IsSuccess) { TaskManager.CompleteResultTask(result); } else { TaskManager.CompleteResultTask(); } } }
private static BoolResult StorageSpaceFileOrFolderExistInternal(int storageSpaceId, string fullPath) { var result = TaskManager.StartResultTask <BoolResult>("STORAGE_SPACES", "FOLDER_OR_FOLDER_EXIST"); try { if (storageSpaceId < 0) { throw new ArgumentException("Storage Space iD must be greater than 0"); } var storage = GetStorageSpaceById(storageSpaceId); if (storage == null) { throw new Exception(string.Format("Storage space with id={0} not found", storageSpaceId)); } var ss = GetStorageSpaceService(storage.ServiceId); result.Value = ss.FileOrDirectoryExist(fullPath); } catch (Exception exception) { TaskManager.WriteError(exception); result.AddError("Error during folder exist check", exception); } finally { if (!result.IsSuccess) { TaskManager.CompleteResultTask(result); } else { TaskManager.CompleteResultTask(); } } return(result); }
public ResultObject DeleteFolder(int itemId, int folderId) { var result = TaskManager.StartResultTask <ResultObject>("ORGANIZATION_FOLDERS", "DELETE_FOLDER"); try { var folder = StorageSpacesController.GetStorageSpaceFolderById(folderId); if (folder == null) { throw new Exception("Folder not found"); } DataProvider.DeleteOrganizationStoragSpacesFolder(folderId); var deletionResult = StorageSpacesController.DeleteStorageSpaceFolder(folder.StorageSpaceId, folder.Id); if (deletionResult.IsSuccess == false) { throw new Exception(string.Join(";", deletionResult.ErrorCodes)); } } catch (Exception exception) { TaskManager.WriteError(exception); result.AddError("Error deleting organization folder", exception); } finally { if (!result.IsSuccess) { TaskManager.CompleteResultTask(result); } else { TaskManager.CompleteResultTask(); } } return(result); }
private static ResultObject SaveLevelResourceGroupsInternal(int levelId, IEnumerable <ResourceGroupInfo> newGroups) { var result = TaskManager.StartResultTask <ResultObject>("STORAGE_SPACES", "REMOVE_STORAGE_SPACE_LEVEL"); try { if (levelId < 1) { throw new ArgumentException("Level Id must be greater than 0"); } DataProvider.RemoveStorageSpaceLevelResourceGroups(levelId); if (newGroups != null) { foreach (var newGroup in newGroups) { DataProvider.AddStorageSpaceLevelResourceGroup(levelId, newGroup.GroupId); } } } catch (Exception exception) { TaskManager.WriteError(exception); result.AddError("Error saving Storage Space Level Resource Groups", exception); } finally { if (!result.IsSuccess) { TaskManager.CompleteResultTask(result); } else { TaskManager.CompleteResultTask(); } } return(result); }
private static ResultObject RemoveStorageSpaceInternal(int id) { var result = TaskManager.StartResultTask <ResultObject>("STORAGE_SPACES", "REMOVE_STORAGE_SPACE"); try { if (id < 1) { throw new ArgumentException("Id must be greater than 0"); } var storage = GetStorageSpaceByIdInternal(id); var ss = GetStorageSpaceService(storage.ServiceId); ss.ClearStorageSettings(storage.Path, storage.UncPath); DataProvider.RemoveStorageSpace(id); } catch (Exception exception) { TaskManager.WriteError(exception); result.AddError("Error removing Storage Space", exception); } finally { if (!result.IsSuccess) { TaskManager.CompleteResultTask(result); } else { TaskManager.CompleteResultTask(); } } return(result); }