Exemplo n.º 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);
         }
     }
 }
Exemplo n.º 2
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);
                    }
                }
        }
Exemplo n.º 3
0
 public abstract Task CopyTo(DirectoryViewModel targetDirectory, CancellationToken ct, IProgress <double> progress);
Exemplo n.º 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);
        }
 public override async Task CopyTo(DirectoryViewModel targetDirectory, CancellationToken ct, IProgress<double> progress)
 {
     var resultFileSystemFullName = Path.Combine(targetDirectory.FullName, this.Name);
     Directory.CreateDirectory(resultFileSystemFullName);
 }