private static void UndoSequentially(Dictionary <UndoableTaskBase <T>, T> taskDictionary) { foreach (KeyValuePair <UndoableTaskBase <T>, T> current in taskDictionary) { IUndoableTask key = current.Key; key.Undo(); } }
public TaskResult Undo(object ownerKey = null) { if (ownerKey == null) { return(this.Undo()); } TaskService.TaskCollection <IUndoableTask> taskCollection1; if (!this.undoableDictionary.TryGetValue(ownerKey, out taskCollection1)) { throw new InvalidOperationException("No undoable tasks for the specified owner key."); } IUndoableTask undoableTask = taskCollection1.Pop(); TaskService.TaskCollection <IInternalTask> taskCollection2; if (!this.repeatableDictionary.TryGetValue(ownerKey, out taskCollection2)) { throw new InvalidOperationException("No repeatable tasks for the specified owner key."); } taskCollection2.RemoveLast(); CancellableTaskServiceEventArgs e = new CancellableTaskServiceEventArgs((ITask)undoableTask) { OwnerKey = ownerKey }; this.OnUndoing(e); if (e.Cancel) { taskCollection1.AddLast(undoableTask); return(TaskResult.Cancelled); } TaskService.TaskCollection <IUndoableTask> taskCollection3; if (!this.redoableDictionary.TryGetValue(ownerKey, out taskCollection3)) { taskCollection3 = new TaskService.TaskCollection <IUndoableTask>(); this.redoableDictionary[ownerKey] = taskCollection3; } taskCollection3.AddLast(undoableTask); TaskResult taskResult = undoableTask.Undo(); this.TrimIfRequired(ownerKey); this.OnUndone(new TaskServiceEventArgs((ITask)undoableTask)); return(taskResult); }
private TaskResult Undo() { if (this.globallyRepeatableTasks.Count < 1) { throw new InvalidOperationException("No task to undo."); } IUndoableTask undoableTask = this.globallyUndoableTasks.Pop(); IInternalTask internalTask = this.globallyRepeatableTasks.Pop(); CancellableTaskServiceEventArgs e = new CancellableTaskServiceEventArgs((ITask)undoableTask); this.OnUndoing(e); if (e.Cancel) { this.globallyUndoableTasks.AddLast(undoableTask); this.globallyRepeatableTasks.AddLast(internalTask); return(TaskResult.Cancelled); } this.globallyRedoableTasks.AddLast(undoableTask); TaskResult taskResult = undoableTask.Undo(); this.OnUndone(new TaskServiceEventArgs((ITask)undoableTask)); return(taskResult); }