public void Execute() { foreach (var kv in _mapping) { CopyEventArgs e = new CopyEventArgs(kv.Value); CopyFilesInfo copyFilesInfo = kv.Value; string fullPath = PathHelper.GetFullPath(kv.Key, true); copyFilesInfo.SetStart(); OnCopyStatusChanged?.Invoke(this, e); try { Debug.Print("Copying {0} files to {1}", copyFilesInfo.FileList.Count(), fullPath); if (ShellFileOperation.CopyItems(copyFilesInfo.FileList, fullPath)) { copyFilesInfo.SetFinished(); } else { copyFilesInfo.SetCancelled(); } } catch (Exception ex) { copyFilesInfo.SetError(ex); throw; } OnCopyStatusChanged?.Invoke(this, e); if (copyFilesInfo.Status == COPY_STATUS.CANCELLED) { break; } } try { Debug.Print($"Moving all files to backup ({PathHelper.AppPath("backup")})"); string backupPath = PathHelper.GetFullPath(PathHelper.AppPath("backup"), false); ShellFileOperation.DeleteCompletelySilent(backupPath); ShellFileOperation.MoveItems(_dicFiles.Keys.ToList(), PathHelper.GetFullPath(backupPath, true)); } catch (Exception ex) { ErrorHandler.Handle(ex, "Error while backing up the files after the main operation has finished."); } }
public void Run() { foreach (FolderCleanerConfigTaskDestination dst in _task.Destination) { foreach (var kv in dst.Mapping) { // get the full path and CREATE it if not exists string fullPath = PathHelper.GetFullPath(dst.Path, kv.Key, true); CopyFilesInfo info = kv.Value; // The operation is done on a banch of files at once! if (dst.Move) { Debug.Print("Moving {0} files to {1}", info.FileList.Count(), fullPath); ShellFileOperation.MoveItems(info.FileList, fullPath); } else { Debug.Print("Copying {0} files to {1}", info.FileList.Count(), fullPath); ShellFileOperation.CopyItems(info.FileList, fullPath); } } } }
public CopyEventArgs(CopyFilesInfo info) { Info = info; }