public static bool RenameProject(ProjectArgs args, IBasicPanel <Project> control, ref string message) { string path = Path.Combine(control.FSWorker.WorkDirectory, args.RenamedArgs.From); ComplexTransaction transaction = new ComplexTransaction(); transaction.AddOperation(() => TransactionDirectory.CopyDirectory(path, Path.Combine(control.FSWorker.WorkDirectory, args.RenamedArgs.To)), () => { if (!TransactionDirectory.RemoveDirectory( Path.Combine(control.FSWorker.WorkDirectory, args.RenamedArgs.To))) { Transaction.Current.Rollback(); } }); transaction.AddOperation(() => { TransactionDirectory.RemoveDirectory(path); }, new List <string> { path }); transaction.AddOperation(() => { TransactionFile.DeleteFiles( new FileArgs( new List <string> { Path.Combine(control.FSWorker.WorkDirectory, args.RenamedArgs.To, args.RenamedArgs.From + ProjectExtension) }, args.RenamedArgs.From, Happened.Deleted, (b, s, arg) => { })); }, new List <string> { Path.Combine(control.FSWorker.WorkDirectory, args.RenamedArgs.To, args.RenamedArgs.From + ProjectExtension) }); transaction.DoOperation(); return(Save(control.Save(args.RenamedArgs.To, control.SaveItemManager.DoSave(args)), Path.Combine(control.FSWorker.WorkDirectory, args.RenamedArgs.To, args.RenamedArgs.To + ProjectExtension), ref message)); }
private bool DoParseAndDo(FileSystemTask task, ref string message) { if (task.IsFolder == true) { var args = task.Args as ProjectArgs; if (args == null) { message = "Invalid cast"; return(false); } RenamedArgs renamedArgs = args.RenamedArgs; if (renamedArgs != null) { return(BrowseSystem.RenameProject(args, Control, ref message)); } return(Do(args.Happened, true, args, ref message)); } else if (task.IsFolder == false) { bool resposne = true; var args = task.Args as FileArgs; if (args == null) { message = "Invalid cast"; return(false); } RenamedArgs renamedArgs = args.RenamedArgs; if (renamedArgs != null) { string path = Path.Combine(task.Path, "Files"); ComplexTransaction transaction = new ComplexTransaction(); transaction.AddOperation(() => RenameFile(Path.Combine(path, renamedArgs.From + BrowseSystem.Extension), Path.Combine(path, renamedArgs.To + BrowseSystem.Extension)), () => RenameFile(Path.Combine(path, renamedArgs.To + BrowseSystem.Extension), Path.Combine(path, renamedArgs.From + BrowseSystem.Extension))); if (File.Exists(Path.Combine(path, renamedArgs.From + NoteExtension))) { transaction.AddOperation( () => RenameFile(Path.Combine(path, renamedArgs.From + NoteExtension), Path.Combine(path, renamedArgs.To + NoteExtension)), () => RenameFile(Path.Combine(path, renamedArgs.To + NoteExtension), Path.Combine(path, renamedArgs.From + NoteExtension))); } transaction.DoOperation(); return(File.Exists(Path.Combine(path, renamedArgs.To + BrowseSystem.Extension))); //bool res = TransactionFile.MoveFile( // Path.Combine(path, renamedArgs.From + BrowseSystem.Extension), Path.Combine(path, renamedArgs.To + BrowseSystem.Extension), // ref message); //if(!File.Exists(Path.Combine(path, renamedArgs.From + NoteExtension))) { return res; } // res &= TransactionFile.MoveFile( // Path.Combine(path, renamedArgs.From + NoteExtension), // Path.Combine(path, renamedArgs.To + NoteExtension), // ref message); // renamedArgs = new RenamedArgs(Path.Combine(path, renamedArgs.From + BrowseSystem.Extension), Path.Combine(path, renamedArgs.To + BrowseSystem.Extension), renamedArgs.Callback); // return res; } resposne = Do(args.Happened, false, args, ref message); return(resposne); } message = "Invalid parameter"; return(false); }