public Task <string> CopyFileAsync(string srcFolderName, string srcFileName, string destFolderName,
                                           string destFileName, IAccessCondition destAccessCondition)
        {
            if (srcFolderName == null)
            {
                throw new ArgumentNullException(nameof(srcFolderName));
            }

            if (srcFileName == null)
            {
                throw new ArgumentNullException(nameof(srcFileName));
            }

            if (destFolderName == null)
            {
                throw new ArgumentNullException(nameof(destFolderName));
            }

            if (destFileName == null)
            {
                throw new ArgumentNullException(nameof(destFileName));
            }

            var srcFilePath  = buildPath(srcFolderName, srcFileName);
            var destFilePath = buildPath(destFolderName, destFileName);

            _fileSystemService.CreateDirectory(Path.GetDirectoryName(destFilePath));

            if (!_fileSystemService.FileExists(srcFilePath))
            {
                throw new InvalidOperationException("Could not copy because source file does not exists");
            }

            if (_fileSystemService.FileExists(destFilePath))
            {
                throw new InvalidOperationException("Could not copy because destination file already exists");
            }

            try
            {
                _fileSystemService.Copy(srcFilePath, destFilePath, overwrite: false);
            }
            catch (IOException e)
            {
                throw new InvalidOperationException("Could not copy because destination file already exists", e);
            }

            return(Task.FromResult <string>(null));
        }
Ejemplo n.º 2
0
        private void SaveToDisk()
        {
            try
            {
                IEnumerable <string> settings = _settings.Select(s => string.Format("{0} {1}", s.Key, s.Value));
                string text = string.Join("\n", settings);

                string backupFile = $"{_settingsFilePath}.bak";
                _fileSystemService.Copy(_settingsFilePath, backupFile);

                _fileSystemService.Write(_settingsFilePath, text);
            }
            catch (Exception ex)
            {
                _windowService.Alert("Failed to Save settings!", ex.ToString());
            }
        }
Ejemplo n.º 3
0
        public Task <string> CopyFileAsync(
            string srcFolderName,
            string srcFileName,
            string destFolderName,
            string destFileName,
            IAccessCondition destAccessCondition)
        {
            if (srcFolderName == null)
            {
                throw new ArgumentNullException(nameof(srcFolderName));
            }

            if (srcFileName == null)
            {
                throw new ArgumentNullException(nameof(srcFileName));
            }

            if (destFolderName == null)
            {
                throw new ArgumentNullException(nameof(destFolderName));
            }

            if (destFileName == null)
            {
                throw new ArgumentNullException(nameof(destFileName));
            }

            var srcFilePath  = BuildPath(_configuration.FileStorageDirectory, srcFolderName, srcFileName);
            var destFilePath = BuildPath(_configuration.FileStorageDirectory, destFolderName, destFileName);

            _fileSystemService.CreateDirectory(Path.GetDirectoryName(destFilePath));

            try
            {
                _fileSystemService.Copy(srcFilePath, destFilePath, overwrite: false);
            }
            catch (IOException e)
            {
                throw new FileAlreadyExistsException("Could not copy because destination file already exists", e);
            }

            return(Task.FromResult <string>(null));
        }