public override CommandResult Run() { var count = 0; string msg; using (var cs = new ContextSwitcher(Context, Path)) { if (cs.Result.Status != CommandStatus.Success) return cs.Result; var inspector = new ItemInspector(Context.CurrentItem); count = inspector.CountDescendants(); var parent = Context.CurrentItem.Parent; if (NoRecycle) { Context.CurrentItem.Delete(); msg = "Deleted"; } else { Context.CurrentItem.Recycle(); msg = "Recycled"; } if (Path.Length == 0) Context.CurrentItem = parent; } return new CommandResult(CommandStatus.Success, string.Format(msg + " {0} {1}", count, count == 1 ? "item" : "items")); }
public override CommandResult Run() { if (string.IsNullOrEmpty(TargetPath)) return new CommandResult(CommandStatus.Failure, Constants.Messages.MissingRequiredParameter.FormatWith("targetPath")); // Evaulate the target path var evalTargetPath = PathParser.EvaluatePath(Context, TargetPath); Item parent = null; using (var targetSwitcher = new ContextSwitcher(Context, evalTargetPath)) { if (targetSwitcher.Result.Status != CommandStatus.Success) return targetSwitcher.Result; parent = Context.CurrentItem; if (parent == null) return new CommandResult(CommandStatus.Failure, "Failed to find the target path '" + TargetPath + "'"); } int count = 0; Item movedItem = null; using (var sourceSwitcher = new ContextSwitcher(Context, Path)) { if (sourceSwitcher.Result.Status != CommandStatus.Success) return sourceSwitcher.Result; // Now perform the move string sourceName = Context.CurrentItem.Name; if (parent.Database == Context.CurrentItem.Database) Context.CurrentItem.MoveTo(parent); else { string xml = Context.CurrentItem.GetOuterXml(true); parent.Paste(xml, false, PasteMode.Overwrite); // Now the item has been copied, delete the original var deleteCommand = new DeleteItem(); deleteCommand.Initialise(Context, Formatter); deleteCommand.Path = Context.CurrentItem.Paths.FullPath; deleteCommand.Run(); } movedItem = parent.Children[Context.CurrentItem.ID]; if(movedItem == null) movedItem = parent.Children[sourceName]; if (movedItem != null) { var inspector = new ItemInspector(movedItem); count = inspector.CountDescendants(); } } if (movedItem == null) return new CommandResult(CommandStatus.Failure, string.Format("Failed to move item")); if (Context.CurrentItem == null) Context.CurrentItem = movedItem; return new CommandResult(CommandStatus.Success, string.Format("Moved {0} {1}", count, count == 1 ? "item" : "items")); }