Exemple #1
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);
        }
Exemple #2
0
        private void TrimIfRequired(object ownerKey = null)
        {
            long num1 = this.taskCountMax;

            TaskService.TaskCollection <IUndoableTask> globallyUndoableTasks;
            TaskService.TaskCollection <IInternalTask> globallyRepeatableTasks;
            TaskService.TaskCollection <IUndoableTask> globallyRedoableTasks;
            if (ownerKey != null)
            {
                int num2;
                if (this.taskCountMaximums.TryGetValue(ownerKey, out num2))
                {
                    num1 = (long)num2;
                }
                if (num1 == long.MaxValue)
                {
                    return;
                }
                this.undoableDictionary.TryGetValue(ownerKey, out globallyUndoableTasks);
                this.repeatableDictionary.TryGetValue(ownerKey, out globallyRepeatableTasks);
                this.redoableDictionary.TryGetValue(ownerKey, out globallyRedoableTasks);
            }
            else
            {
                if (this.taskCountMax == long.MaxValue)
                {
                    return;
                }
                globallyUndoableTasks   = this.globallyUndoableTasks;
                globallyRepeatableTasks = this.globallyRepeatableTasks;
                globallyRedoableTasks   = this.globallyRedoableTasks;
            }
            int  num3 = globallyUndoableTasks != null ? globallyUndoableTasks.Count : 0;
            int  num4 = globallyRepeatableTasks != null ? globallyRepeatableTasks.Count : 0;
            int  num5 = globallyRedoableTasks != null ? globallyRedoableTasks.Count : 0;
            long num6 = (long)num3 - num1;
            long num7 = (long)num4 - num1;
            long num8 = (long)num5 - num1;

            for (long index = 0; index < num6; ++index)
            {
                globallyUndoableTasks.RemoveFirst();
            }
            for (long index = 0; index < num7; ++index)
            {
                globallyRepeatableTasks.RemoveFirst();
            }
            for (long index = 0; index < num8; ++index)
            {
                globallyRedoableTasks.RemoveFirst();
            }
        }
Exemple #3
0
 public bool CanRepeat(object ownerKey = null)
 {
     TaskService.TaskCollection <IInternalTask> globallyRepeatableTasks;
     if (ownerKey == null)
     {
         globallyRepeatableTasks = this.globallyRepeatableTasks;
     }
     else if (!this.repeatableDictionary.TryGetValue(ownerKey, out globallyRepeatableTasks))
     {
         return(false);
     }
     return(globallyRepeatableTasks.Count > 0 && globallyRepeatableTasks.Peek().Repeatable);
 }
Exemple #4
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);
        }
Exemple #5
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);
        }
Exemple #6
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);
        }