예제 #1
0
        public static void RunSimple()
        {
            StateBase initialState = new StateA()
            {
                A = 1
            };
            IReadOnlyCollection <ITaskBase <StateBase, StateBase> > tasks = new ITaskBase <StateBase, StateBase>[]
            {
                new DeterministicTask(),
                new DryTask(),
                new GenericInputTask()
            };

            Logger.Message($"InitialState: {initialState}");
            var terminationState = SimpleExecutor.Run(initialState, tasks);

            Logger.Message($"FinalState: {terminationState}");

            initialState = new StateA()
            {
                A = 2
            };

            Logger.Message($"InitialState: {initialState}");
            terminationState = SimpleExecutor.Run(initialState, tasks);
            Logger.Message($"FinalState: {terminationState}");
        }
예제 #2
0
 private void ShowInformation(ITaskBase task)
 {
     CrossThreadSetText(this.lblTaskState, String.Format("Task State: {0}", task.State.GetStateDescription()));
     CrossThreadSetText(this.txtBasicInfo, task.Information);
     CrossThreadSetText(this.lblElapsed, (task.Elapsed != null) ? String.Format("Time Elapsed: {0}", task.Elapsed) : "N/A");
     CrossThreadSetEnabled(this.btnCancel, task.IsCancellable && task.State != TaskState.Completed && task.State != TaskState.CompletedWithErrors);
     CrossThreadSetEnabled(this.btnErrorTrace, task.Error != null);
     CrossThreadSetEnabled(this.btnViewResults, false);
 }
예제 #3
0
        private void AddTask <T>(ITask <T> task, TaskCallback <T> callback) where T : class
        {
            String[] items = new String[]
            {
                (++this._taskID).ToString(),
                task.Name,
                task.State.GetStateDescription(),
                task.Information
            };
            ListViewItem item = new ListViewItem(items);

            item.Tag = task;
            CrossThreadAddItem(this.lvwTasks, item);

            //Ensure that the Task Information gets updated automatically when the Task State changes
            TaskStateChanged d = delegate()
            {
                CrossThreadAlterSubItem(item, 2, task.State.GetStateDescription());
                CrossThreadAlterSubItem(item, 3, task.Information);
                CrossThreadRefresh(this.lvwTasks);
            };

            task.StateChanged += d;

            //Clear old Tasks if necessary and enabled
            if (this.chkRemoveOldTasks.Checked)
            {
                if (this.lvwTasks.Items.Count > 10)
                {
                    int i = this.lvwTasks.Items.Count - 1;
                    do
                    {
                        ListViewItem oldItem = this.lvwTasks.Items[i];
                        if (oldItem.Tag is ITaskBase)
                        {
                            ITaskBase t = (ITaskBase)oldItem.Tag;
                            if (t.State == TaskState.Completed || t.State == TaskState.CompletedWithErrors)
                            {
                                this.lvwTasks.Items.RemoveAt(i);
                                i--;
                            }
                        }

                        i--;
                    } while (this.lvwTasks.Items.Count > 10 && i >= 0);
                }
            }

            //Start the Task
            task.RunTask(callback);
        }
예제 #4
0
        public TaskScheduler()
        {
            IUow uow = ObjectFactory.GetInstance <IUow>();

            tasks = new List <ITaskBase>();

            string s = WebUtils.AppSettings("TaskScheduler_Tasks", string.Empty);

            if (string.IsNullOrEmpty(s) == false)
            {
                string[] items = s.Split(',', ';', '|');
                foreach (string item in items)
                {
                    ITaskBase q = ObjectFactory.GetInstance <ITaskBase>(item.Trim());
                    tasks.Add(q);
                }
            }
        }