Пример #1
0
        public IResult <Result.InternalTypes.Void> RenameFile(string basePath, string oldName, string newName)
        {
            var oldPathResult = _pathManager.Combine(basePath, oldName);

            if (!oldPathResult.IsSuccess)
            {
                return(new FailureResult(oldPathResult.Exception));
            }

            var newPathResult = _pathManager.Combine(basePath, newName);

            if (!newPathResult.IsSuccess)
            {
                return(new FailureResult(newPathResult.Exception));
            }

            try
            {
                ValidateNameLength(newPathResult.Data);
                Directory.Move(oldPathResult.Data, newPathResult.Data);

                return(new SuccessResult());
            }
            catch (Exception e)
            {
                return(new FailureResult(e));
            }
        }
        public async Task <IResult <Folder> > Search(string nameToSearch, int page)
        {
            var homePathResult = _pathManager.Combine(_configuration.HomeFolderPath, _configuration.HomeFolderName);

            if (!homePathResult.IsSuccess)
            {
                return(new FailureResult <Folder>(homePathResult.Exception));
            }

            var homeFolderResult = _folderProvider.GetFolder(homePathResult.Data);

            if (!homeFolderResult.IsSuccess)
            {
                return(new FailureResult <Folder>(homeFolderResult.Exception));
            }

            var loadSearchResults = await homeFolderResult.Data.LoadSearchPageAsync(nameToSearch, page);

            if (!loadSearchResults.IsSuccess)
            {
                return(new FailureResult <Folder>(loadSearchResults.Exception));
            }

            return(new SuccessResult <Folder>(homeFolderResult.Data));
        }
Пример #3
0
        public void DirectoryCopy(string sourceDirName, string destDirName, bool copySubDirs)
        {
            if (destDirName.StartsWith(sourceDirName))
            {
                throw new Exception("Could not copy parent folder into child folder. This will cause infinite recursive copy");
            }

            // Get the subdirectories for the specified directory.
            DirectoryInfo dir = new DirectoryInfo(sourceDirName);

            if (!dir.Exists)
            {
                throw new DirectoryNotFoundException(
                          "Source directory does not exist or could not be found: "
                          + sourceDirName);
            }

            DirectoryInfo[] dirs = dir.GetDirectories();
            // If the destination directory doesn't exist, create it.
            if (!Directory.Exists(destDirName))
            {
                Directory.CreateDirectory(destDirName);
            }

            // Get the files in the directory and copy them to the new location.
            var files = dir.GetFiles();

            foreach (var file in files)
            {
                string temppath = _pathManager.Combine(destDirName, file.Name);
                file.CopyTo(temppath, false);
            }

            // If copying subdirectories, copy them and their contents to new location.
            if (!copySubDirs)
            {
                return;
            }
            foreach (DirectoryInfo subdir in dirs)
            {
                string temppath = _pathManager.Combine(destDirName, subdir.Name);
                DirectoryCopy(subdir.FullName, temppath, true);
            }
        }
Пример #4
0
        private string GetFullPath(string relativePath)
        {
            var fullPathResult = PathManager.Combine(Configuration.HomeFolderPath, relativePath);

            if (!fullPathResult.IsSuccess)
            {
                throw new ArgumentException($"Could not create full path from '{Configuration.BaseFolderPath}' and '{relativePath}'", fullPathResult.Exception);
            }

            return(fullPathResult.Data);
        }
Пример #5
0
        public void CreateFile(int requestId, ITmpFile file)
        {
            //Synchronization starts here and end in the folder content manager in CreateFile
            _concurrentManager.AcquireSynchronization(new List <IFolderContent>()
            {
                new FolderContent(file.Name, file.Path, file.Type)
            });

            _requestIdToFiles[requestId] = file;
            if (string.IsNullOrEmpty(file.TmpCreationPath))
            {
                file.TmpCreationPath = _pathManager.Combine(_pathManager.GetTempPath(), Guid.NewGuid().ToString());
            }

            if (_requestIdToBinaryWriter.ContainsKey(requestId))
            {
                var writer = _requestIdToBinaryWriter[requestId];
                writer.Close();
            }

            _requestIdToBinaryWriter[requestId] = new BinaryWriter(_fileManager.Create(file.TmpCreationPath));
        }