コード例 #1
0
 public override async Task CopyTo(DirectoryViewModel targetDirectory, CancellationToken ct, IProgress<double> progress)
 {
     var resultFileSystemFullName = Path.Combine(targetDirectory.FullName, this.Name);
     using (FileStream sourceStream =
         new FileStream(this.FullName, FileMode.Open, FileAccess.Read, FileShare.Read, BufferSize, useAsync: true))
     using (FileStream targetStream =
         new FileStream(resultFileSystemFullName, FileMode.CreateNew, FileAccess.Write, FileShare.None, BufferSize, useAsync: true))
     {
         double totalBytesRead = 0;
         byte[] buffer = new byte[BufferSize];
         int bytesRead = 0;
         while ((bytesRead = await sourceStream.ReadAsync(buffer, 0, buffer.Length, ct)) != 0)
         {
             totalBytesRead += bytesRead;
             await targetStream.WriteAsync(buffer, 0, bytesRead, ct);
             progress?.Report(totalBytesRead / sourceStream.Length);
         }
     }
 }
コード例 #2
0
ファイル: FileViewModel.cs プロジェクト: marvel16/MyCommander
        public override async Task CopyTo(DirectoryViewModel targetDirectory, CancellationToken ct, IProgress <double> progress)
        {
            var resultFileSystemFullName = Path.Combine(targetDirectory.FullName, this.Name);

            using (FileStream sourceStream =
                       new FileStream(this.FullName, FileMode.Open, FileAccess.Read, FileShare.Read, BufferSize, useAsync: true))
                using (FileStream targetStream =
                           new FileStream(resultFileSystemFullName, FileMode.CreateNew, FileAccess.Write, FileShare.None, BufferSize, useAsync: true))
                {
                    double totalBytesRead = 0;
                    byte[] buffer         = new byte[BufferSize];
                    int    bytesRead      = 0;
                    while ((bytesRead = await sourceStream.ReadAsync(buffer, 0, buffer.Length, ct)) != 0)
                    {
                        totalBytesRead += bytesRead;
                        await targetStream.WriteAsync(buffer, 0, bytesRead, ct);

                        progress?.Report(totalBytesRead / sourceStream.Length);
                    }
                }
        }
コード例 #3
0
 public abstract Task CopyTo(DirectoryViewModel targetDirectory, CancellationToken ct, IProgress <double> progress);
コード例 #4
0
        public override async Task CopyTo(DirectoryViewModel targetDirectory, CancellationToken ct, IProgress <double> progress)
        {
            var resultFileSystemFullName = Path.Combine(targetDirectory.FullName, this.Name);

            Directory.CreateDirectory(resultFileSystemFullName);
        }
コード例 #5
0
 public override async Task CopyTo(DirectoryViewModel targetDirectory, CancellationToken ct, IProgress<double> progress)
 {
     var resultFileSystemFullName = Path.Combine(targetDirectory.FullName, this.Name);
     Directory.CreateDirectory(resultFileSystemFullName);
 }