Exemplo n.º 1
0
        /// <summary>
        /// Constructor using file move info and overwrite indicator</summary>
        /// <param name="type">File move type (Delete, Move, or Copy)</param>
        /// <param name="sourcePath">Source path</param>
        /// <param name="destinationPath">Destination path, or null if deleting</param>
        /// <param name="allowOverwrites">If true, files at destination path may be overwritten</param>
        public FileMoveInfo(FileMoveType type, string sourcePath, string destinationPath, bool allowOverwrites)
        {
            if (sourcePath == null)
            {
                throw new ArgumentNullException("sourcePath");
            }
            if (destinationPath == null && type != FileMoveType.Delete)
            {
                throw new ArgumentNullException("destinationPath");
            }

            // make sure that source and destination path are either both directories or both files
            if (sourcePath != null &&
                destinationPath != null)
            {
                if (string.IsNullOrEmpty(Path.GetFileName(sourcePath)) !=
                    string.IsNullOrEmpty(Path.GetFileName(destinationPath)))
                {
                    throw new InvalidOperationException("source and destination paths must both be directories or files");
                }
            }

            Type            = type;
            SourcePath      = sourcePath;
            DestinationPath = destinationPath;

            m_allowOverwrites = allowOverwrites;
        }
Exemplo n.º 2
0
 internal async Task <bool> MoveAsync(FileMoveType moveType)
 {
     if (!IsMoving && ValidatePaths())
     {
         IsMoving = true;
         try
         {
             return(await _progressFileMover.MoveFile(_sourcePath, _destinationPath, moveType, ProgressCallback));
         }
         finally
         {
             IsMoving = false;
         }
     }
     return(false);
 }
Exemplo n.º 3
0
        /// <summary>
        /// Moves a file from the source path to the destination path, calling hte progress callback to update the progress and check if it should cancel the move
        /// </summary>
        /// <param name="sourcePath"></param>
        /// <param name="destinationPath"></param>
        /// <param name="progressCallback">A method to be called to update progress and also set cancelled on the event args if the move should be cancelled</param>
        /// <returns></returns>
        /// <exception cref="ArgumentException">If source or destination path is null or empty</exception>
        /// <exception cref="ArgumentException">If progressCallback is null</exception>
        public async Task <bool> MoveFile(string sourcePath, string destinationPath, FileMoveType moveType, Action <FileMoveProgressArgs> progressCallback)
        {
            if (string.IsNullOrWhiteSpace(sourcePath))
            {
                throw new ArgumentException("sourcePath cannot be null or empty");
            }
            if (string.IsNullOrWhiteSpace(destinationPath))
            {
                throw new ArgumentException("destinationPath cannot be null or empty");
            }
            if (progressCallback == null)
            {
                throw new ArgumentNullException("progressCallback");
            }

            ProgressCallback = progressCallback;

            _totalFileSize = new FileInfo(sourcePath).Length;

            SuccessDescriptor success;

            switch (moveType)
            {
            case FileMoveType.Move:
                success = await StartFileMove(sourcePath, destinationPath);

                break;

            case FileMoveType.Copy:
                success = await StartFileCopy(sourcePath, destinationPath);

                break;

            default:
                throw new NotImplementedException($"File Move Type not implemenented. {moveType.ToString()}");
            }

            HandleResult(sourcePath, success);
            return(success.IsSuccess);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Constructor using file move info and overwrite indicator</summary>
        /// <param name="type">File move type (Delete, Move, or Copy)</param>
        /// <param name="sourcePath">Source path</param>
        /// <param name="destinationPath">Destination path, or null if deleting</param>
        /// <param name="allowOverwrites">If true, files at destination path may be overwritten</param>
        public FileMoveInfo(FileMoveType type, string sourcePath, string destinationPath, bool allowOverwrites)
        {
            if (sourcePath == null)
                throw new ArgumentNullException("sourcePath");
            if (destinationPath == null && type != FileMoveType.Delete)
                throw new ArgumentNullException("destinationPath");

            // make sure that source and destination path are either both directories or both files
            if (sourcePath != null &&
                destinationPath != null)
            {
                if (string.IsNullOrEmpty(Path.GetFileName(sourcePath)) !=
                    string.IsNullOrEmpty(Path.GetFileName(destinationPath)))
                {
                    throw new InvalidOperationException("source and destination paths must both be directories or files");
                }
            }

            Type = type;
            SourcePath = sourcePath;
            DestinationPath = destinationPath;

            m_allowOverwrites = allowOverwrites;
        }
Exemplo n.º 5
0
 /// <summary>
 /// Constructor using file move info</summary>
 /// <param name="type">File move type (Delete, Move, or Copy)</param>
 /// <param name="sourcePath">Source path</param>
 /// <param name="destinationPath">Destination path, or null if deleting</param>
 public FileMoveInfo(FileMoveType type, string sourcePath, string destinationPath)
     : this(type, sourcePath, destinationPath, false)
 {
 }
Exemplo n.º 6
0
 /// <summary>
 /// Constructor using file move info</summary>
 /// <param name="type">File move type (Delete, Move, or Copy)</param>
 /// <param name="sourcePath">Source path</param>
 /// <param name="destinationPath">Destination path, or null if deleting</param>
 public FileMoveInfo(FileMoveType type, string sourcePath, string destinationPath)
     : this(type, sourcePath, destinationPath, false)
 {
 }