protected override Task <IListWithErrorDictionary <CopiedFile> > CopySpecificAsync(CancellationToken token)
        {
            return(Task.Run <IListWithErrorDictionary <CopiedFile> >(async() => {
                var copiedFileList = new ListWithErrorDictionary <CopiedFile>();
                var selectedFiles = Model.Items.Where(x => x.IsSelected).ToList();
                MaxProgressBarValue = selectedFiles.Count;
                Progress = 0;
                var index = 0;
                while (index < selectedFiles.Count && !token.IsCancellationRequested)
                {
                    Progress++;
                    var file = selectedFiles[index];
                    try
                    {
                        using (var fileStream = File.Open(file.Path, FileMode.Open))
                        {
                            var destinationFilePath = Path.Combine(Model.DestinationPath, file.Name);
                            using (var destinationStream = File.Create(destinationFilePath))
                            {
                                await fileStream.CopyToAsync(destinationStream, 81920, token);
                            }
                        }
                        copiedFileList.Add(new CopiedFile(file.Name, file.Size, DateTime.Now));
                    }
                    catch (Exception exc) when(exc is UnauthorizedAccessException || exc is IOException)
                    {
                        copiedFileList.AddError(file.Path, exc.Message);
                    } //swallow unauthorizedaccessexceptions
                    index++;
                }

                return copiedFileList;
            }));
        }
示例#2
0
 protected override Task <IListWithErrorDictionary <CopiedFile> > CopySpecificAsync(CancellationToken token)
 {
     return(Task.Run <IListWithErrorDictionary <CopiedFile> >(async() => {
         var copiedList = new ListWithErrorDictionary <CopiedFile>();
         var selectedItems = Model.Items.Where(x => x.IsSelected).ToList();
         Progress = 0;
         MaxProgressBarValue = selectedItems.Count;
         foreach (var file in selectedItems)
         {
             token.ThrowIfCancellationRequested();
             Progress++;
             await _folderCopier.DirectoryCopyAsync(file.Path, Model.DestinationPath, token);
             copiedList.Add(new CopiedFile(file.Path, file.Size, DateTime.Now));
         }
         return copiedList;
     }));
 }