Example #1
0
        /// <summary>
        /// Executes the task synchronously.
        /// This does not make use of a controller and therefore the <see cref="AppTask.ID"/>
        /// property will not get set.
        /// </summary>
        /// <param name="task">The task to run.</param>
        /// <param name="taskFolderPath">
        /// The folder path to use when running this task.
        /// If not specified, the <see cref="Environment.CurrentDirectory"/> will be used.
        /// </param>
        public static void ExecuteTaskInline(AppTask task, string taskFolderPath = null)
        {
            if (String.IsNullOrEmpty(taskFolderPath))
            {
                taskFolderPath = Environment.CurrentDirectory;
            }

            task.Setup(taskFolderPath);
            if (!task.IsComplete)    // i.e. has not completed with an error during setup.
            {
                task.RunSynchronously();
            }
        }
Example #2
0
        internal ContinuationAppTask(AppTask antecedentTask, Action <AppTask> body)
        {
            if (antecedentTask == null)
            {
                throw new ArgumentNullException("antecendantTask");
            }
            if (body == null)
            {
                throw new ArgumentNullException("body");
            }

            _antecedentTask = antecedentTask;
            _body           = body;
        }
Example #3
0
        private void SetupTask(AppTask task)
        {
            if (task.Status > AppTaskStatus.Waiting)
            {
                throw new InvalidOperationException("The task is already setup.");
            }


            // Setup the task
            string taskFolderPath = task.TaskFolderPath;

            if (String.IsNullOrEmpty(taskFolderPath))
            {
                taskFolderPath = Path.Combine(BaseFolderPath, String.Format(TaskFolderNameFormatString, task.ID));
            }

            task.Setup(taskFolderPath);
        }
Example #4
0
        void task_StatusChanged(AppTask task, AppTaskStatusChangedEventArgs e)
        {
            switch (e.CurrentStatus)
            {
            case AppTaskStatus.Preparing:
            case AppTaskStatus.Setup:
                break;     // Nothing to do

            case AppTaskStatus.Waiting:
                _waitingTasks.Enqueue(task);
                break;

            case AppTaskStatus.Starting:
                _executingTasks.Add(task);
                break;

            case AppTaskStatus.Running:
                Debug.Assert(_executingTasks.Contains(task));
                OnTaskStarted(task);
                break;

            case AppTaskStatus.Complete:
            case AppTaskStatus.Cancelled:
            case AppTaskStatus.Error:
                if (e.PreviousStatus == AppTaskStatus.Starting || e.PreviousStatus == AppTaskStatus.Running)
                {
                    _executingTasks.Remove(task);
                }
                OnTaskCompleted(task);
                AddContinuations(task);
                break;

            default:
                throw new NotImplementedException("The CurrentStatus is not handled: " + e.CurrentStatus);
            }
        }
Example #5
0
 void task_TaskSetup(AppTask task, EventArgs e)
 {
     task.SetWaiting();
 }