Ejemplo n.º 1
0
 private void DoWork()
 {
     try
     {
         CurrentAction = "Discovery";
         DoStatus(true);
         List <FileJob> jobs = Discover(sourcefolders, target);
         while (jobs.Count > 0)
         {
             this.TotalItems    = jobs.Count;
             this.TotalProgress = jobs.Sum(j => j.TotalProgress);
             DoStatus(true);
             if (CheckCancel())
             {
                 return;
             }
             var results = RunJobs(jobs).Where(r => !r.Success).ToList();
             jobs = results.Select(r => r.Job).ToList();
             if (CheckCancel() || results.Count == 0)
             {
                 return;
             }
             if (results.Any(r => r.IsOverWriteError))
             {
                 var err    = results.Where(r => r.IsOverWriteError).Select(r => r.Job).ToList();
                 var method = ShowOverwriteDialog(err);
                 jobs.ForEach(j => j.ExistsAction = method);
             }
             if (results.Any(r => !r.IsOverWriteError))
             {
                 var err    = results.Where(r => !r.IsOverWriteError).ToList();
                 var method = OptionGui.GetChoiceResult($"{err.Count}/{TotalItems} jobs errored, do you want to retry?",
                                                        $"The following files failed to copy:{Environment.NewLine}{string.Join(Environment.NewLine, err.Select(e => $"{e.Job.Source.OriginalPath}: {e.Reason}"))}",
                                                        new[] { RetryAction.Retry, RetryAction.Skip });
                 if (method != RetryAction.Retry)
                 {
                     return;
                 }
             }
         }
     }
     catch (Exception e)
     {
         CopyExtension.Logger.Log(this, e);
         CurrentAction = "Errored";
         CurrentName   = $"{e.GetType().Name}: {e.Message}";
         DoStatus(true);
         IsPaused = true;
         CheckCancel();
     }
     finally
     {
         IsDone = true;
         DoComplete();
     }
 }
Ejemplo n.º 2
0
 private ExistsAction ShowOverwriteDialog(IEnumerable <FileJob> items)
 {
     return(OptionGui.GetChoiceResult($"{items.Count()}/{TotalItems} files already exist, do you want to retry?",
                                      $"The following files already exist:{Environment.NewLine}{string.Join(Environment.NewLine, items.Select(e => $"{e.Source.OriginalPath} to {e.Target.OriginalPath}"))}",
                                      new[] { ExistsAction.Overwrite, ExistsAction.OverwriteFix, ExistsAction.Rename, ExistsAction.Skip }));
 }