Ejemplo n.º 1
0
        private TaskResult Repeat()
        {
            IInternalTask internalTask = this.globallyRepeatableTasks.Peek();

            if (!internalTask.Repeatable)
            {
                return(TaskResult.NoTask);
            }
            CancellableTaskServiceEventArgs e = new CancellableTaskServiceEventArgs((ITask)internalTask);

            this.OnExecuting(e);
            if (e.Cancel)
            {
                return(TaskResult.Cancelled);
            }
            this.globallyRedoableTasks.Clear();
            this.globallyRepeatableTasks.AddLast(internalTask);
            IUndoableTask undoableTask = internalTask as IUndoableTask;

            if (undoableTask != null)
            {
                this.globallyUndoableTasks.AddLast(undoableTask);
            }
            else
            {
                this.globallyUndoableTasks.Clear();
                this.globallyRedoableTasks.Clear();
            }
            TaskResult taskResult = internalTask.PerformTask(internalTask.Argument, TaskMode.Repeat);

            this.OnExecuted(new TaskServiceEventArgs((ITask)internalTask));
            return(taskResult);
        }
Ejemplo n.º 2
0
        private TaskResult Redo()
        {
            if (this.globallyRedoableTasks.Count < 1)
            {
                throw new InvalidOperationException("No task to redo.");
            }
            IUndoableTask undoableTask        = this.globallyRedoableTasks.Pop();
            CancellableTaskServiceEventArgs e = new CancellableTaskServiceEventArgs((ITask)undoableTask);

            this.OnRedoing(e);
            if (e.Cancel)
            {
                this.globallyRedoableTasks.AddLast(undoableTask);
                return(TaskResult.Cancelled);
            }
            IInternalTask internalTask = (IInternalTask)undoableTask;

            this.globallyRepeatableTasks.AddLast(internalTask);
            this.globallyUndoableTasks.AddLast(undoableTask);
            TaskResult taskResult = internalTask.PerformTask(internalTask.Argument, TaskMode.Redo);

            this.TrimIfRequired((object)null);
            this.OnRedone(new TaskServiceEventArgs((ITask)undoableTask));
            return(taskResult);
        }
Ejemplo n.º 3
0
        public TaskResult PerformTask <T>(TaskBase <T> task, T argument, object ownerKey = null)
        {
            if (!this.Enable || this.IsUndoing)
            {
                return(TaskResult.NoEnable);
            }
            ArgumentValidator.AssertNotNull <TaskBase <T> >(task, "task");
            if (ownerKey == null)
            {
                return(this.PerformTask <T>(task, argument));
            }
            CancellableTaskServiceEventArgs e = new CancellableTaskServiceEventArgs((ITask)task);

            this.OnExecuting(e);
            if (e.Cancel)
            {
                return(TaskResult.Cancelled);
            }
            this.undoableDictionary.Remove(ownerKey);
            this.redoableDictionary.Remove(ownerKey);
            TaskService.TaskCollection <IInternalTask> taskCollection;
            if (!this.repeatableDictionary.TryGetValue(ownerKey, out taskCollection))
            {
                taskCollection = new TaskService.TaskCollection <IInternalTask>();
                this.repeatableDictionary[ownerKey] = taskCollection;
            }
            taskCollection.AddLast((IInternalTask)task);
            TaskResult taskResult = task.PerformTask((object)argument, TaskMode.FirstTime);

            this.TrimIfRequired(ownerKey);
            this.OnExecuted(new TaskServiceEventArgs((ITask)task));
            return(taskResult);
        }
Ejemplo n.º 4
0
 private void OnExecuting(CancellableTaskServiceEventArgs e)
 {
     if (this.executing == null)
     {
         return;
     }
     this.executing((object)this, e);
 }
Ejemplo n.º 5
0
 protected virtual void OnRedoing(CancellableTaskServiceEventArgs e)
 {
     this.IsUndoing = true;
     if (this.redoing == null)
     {
         return;
     }
     this.redoing((object)this, e);
 }
Ejemplo n.º 6
0
        public TaskResult Repeat(object ownerKey = null)
        {
            if (ownerKey == null)
            {
                return(this.Repeat());
            }
            TaskService.TaskCollection <IInternalTask> taskCollection1;
            if (!this.repeatableDictionary.TryGetValue(ownerKey, out taskCollection1))
            {
                throw new InvalidOperationException("No tasks to be redone for the specified owner key.");
            }
            IInternalTask internalTask = taskCollection1.Peek();

            if (!internalTask.Repeatable)
            {
                return(TaskResult.NoTask);
            }
            CancellableTaskServiceEventArgs e = new CancellableTaskServiceEventArgs((ITask)internalTask)
            {
                OwnerKey = ownerKey
            };

            this.OnExecuting(e);
            if (e.Cancel)
            {
                return(TaskResult.Cancelled);
            }
            taskCollection1.AddLast(internalTask);
            TaskService.TaskCollection <IUndoableTask> taskCollection2;
            if (!this.undoableDictionary.TryGetValue(ownerKey, out taskCollection2))
            {
                taskCollection2 = new TaskService.TaskCollection <IUndoableTask>();
                this.undoableDictionary[ownerKey] = taskCollection2;
            }
            IUndoableTask undoableTask = internalTask as IUndoableTask;

            if (undoableTask != null)
            {
                taskCollection2.AddLast(undoableTask);
            }
            else
            {
                this.undoableDictionary[ownerKey] = (TaskService.TaskCollection <IUndoableTask>)null;
                this.redoableDictionary[ownerKey] = (TaskService.TaskCollection <IUndoableTask>)null;
            }
            TaskResult taskResult = internalTask.PerformTask(internalTask.Argument, TaskMode.Repeat);

            this.TrimIfRequired(ownerKey);
            this.OnExecuted(new TaskServiceEventArgs((ITask)internalTask));
            return(taskResult);
        }
Ejemplo n.º 7
0
        private TaskResult PerformTask <T>(UndoableTaskBase <T> task, T argument)
        {
            CancellableTaskServiceEventArgs e = new CancellableTaskServiceEventArgs((ITask)task);

            this.OnExecuting(e);
            if (e.Cancel)
            {
                return(TaskResult.Cancelled);
            }
            this.globallyRedoableTasks.Clear();
            this.globallyRepeatableTasks.AddLast((IInternalTask)task);
            this.globallyUndoableTasks.AddLast((IUndoableTask)task);
            TaskResult taskResult = task.PerformTask((object)argument, TaskMode.FirstTime);

            this.TrimIfRequired((object)null);
            this.OnExecuted(new TaskServiceEventArgs((ITask)task));
            return(taskResult);
        }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 9
0
        public TaskResult Redo(object ownerKey = null)
        {
            if (ownerKey == null)
            {
                return(this.Redo());
            }
            TaskService.TaskCollection <IUndoableTask> taskCollection1;
            if (!this.redoableDictionary.TryGetValue(ownerKey, out taskCollection1))
            {
                throw new InvalidOperationException("No tasks to be redone for the specified owner key.");
            }
            IUndoableTask undoableTask        = taskCollection1.Pop();
            CancellableTaskServiceEventArgs e = new CancellableTaskServiceEventArgs((ITask)undoableTask);

            this.OnRedoing(e);
            if (e.Cancel)
            {
                taskCollection1.AddLast(undoableTask);
                return(TaskResult.Cancelled);
            }
            IInternalTask internalTask = (IInternalTask)undoableTask;

            TaskService.TaskCollection <IInternalTask> taskCollection2;
            if (!this.repeatableDictionary.TryGetValue(ownerKey, out taskCollection2))
            {
                taskCollection2 = new TaskService.TaskCollection <IInternalTask>();
            }
            taskCollection2.AddLast(internalTask);
            TaskService.TaskCollection <IUndoableTask> taskCollection3;
            if (!this.undoableDictionary.TryGetValue(ownerKey, out taskCollection3))
            {
                taskCollection3 = new TaskService.TaskCollection <IUndoableTask>();
            }
            taskCollection3.AddLast(undoableTask);
            TaskResult taskResult = internalTask.PerformTask(internalTask.Argument, TaskMode.Redo);

            this.TrimIfRequired(ownerKey);
            this.OnRedone(new TaskServiceEventArgs((ITask)undoableTask));
            return(taskResult);
        }
Ejemplo n.º 10
0
        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);
        }