public static int Execute(QuickMediaSorterProjectTriggerAction action, FileInfo fileInfo) { QuickMediaSorterProjectTriggerAction rolebackAction = new QuickMediaSorterProjectTriggerAction(); int step = 0; switch (action.ActionTypeEnum) { case ObjectModel.ActionType.None: break; case ObjectModel.ActionType.Next: step = 1; break; case ObjectModel.ActionType.Previous: step = -1; break; case ObjectModel.ActionType.Delete: step = 1; fileInfo.Delete(); break; case ObjectModel.ActionType.Copy: List <string> l = new List <string>() { fileInfo.FullName }; ShellFileOperation.CopyItems(l, action.FullPathFolder); //fileInfo.CopyTo(PathHelper.GetFullPath(action.FullPathFolder, fileInfo.Name)); step = 1; break; case ObjectModel.ActionType.Move: List <string> l1 = new List <string>() { fileInfo.FullName }; ShellFileOperation.MoveItems(l1, action.FullPathFolder); //fileInfo.MoveTo(PathHelper.GetFullPath(action.FullPathFolder, fileInfo.Name)); step = 1; break; default: throw new ArgumentOutOfRangeException(); } return(step); }
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."); } }