示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        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);
        }
示例#4
0
        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);
        }
示例#5
0
        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);
        }
示例#6
0
        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();
                }
            }
        }
示例#7
0
        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);
        }
示例#9
0
        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);
        }
示例#10
0
        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);
        }