Exemple #1
0
 public static void Copy(string sourceFileName, string destFileName)
 {
     if (_provider == null)
     {
         File.Copy(sourceFileName, destFileName);
     }
     else
     {
         _provider.Copy(sourceFileName, destFileName);
     }
 }
        private async Task SafeMoveFile(string source, string dest, string temp, bool copy)
        {
            string swapPath = null;

            try {
                if (copy)
                {
                    await _fileService.Copy(source, temp);
                }
                else
                {
                    await Task.Run(() => _fileService.Move(source, temp));
                }

                if (_fileService.FileExists(dest))
                {
                    swapPath = PathUtil.GetTempFilePath(dest);
                    _fileService.Move(dest, swapPath);
                }

                _fileService.Move(temp, dest);
            }
            finally {
                if (_fileService.FileExists(temp))
                {
                    _fileService.Delete(temp);
                }
                if (swapPath != null && _fileService.FileExists(swapPath) && _fileService.FileExists(dest))
                {
                    _fileService.Delete(swapPath);
                }
            }
        }
        private async Task SafeMoveFile(IFileInfo source, IFileInfo destination, string temp, bool copy)
        {
            IFileInfo swapInfo = null;
            IFileInfo tempInfo = _fileService.GetFile(temp);

            try {
                if (copy)
                {
                    await _fileService.Copy(source, tempInfo);
                }
                else
                {
                    await Task.Run(() => _fileService.Move(source, tempInfo));
                }

                if (destination.Exists)
                {
                    swapInfo = _fileService.GetFile(PathUtil.GetTempFilePath(destination.Path));
                    _fileService.Move(destination, swapInfo);
                }

                _fileService.Move(tempInfo, destination);
            }
            finally {
                // Refresh
                tempInfo = _fileService.GetFile(temp);
                if (swapInfo != null)
                {
                    swapInfo    = _fileService.GetFile(swapInfo.Path);
                    destination = _fileService.GetFile(destination.Path);
                }

                if (tempInfo.Exists)
                {
                    _fileService.Delete(tempInfo);
                }

                if (swapInfo != null && swapInfo.Exists && destination.Exists)
                {
                    _fileService.Delete(swapInfo);
                }
            }
        }
 public Task Copy(IFileInfo source, IFileInfo destination)
 {
     return(_next.Copy(source, destination));
 }