/// <summary> /// Adds the available task. /// </summary> /// <param name="task">The task.</param> protected void AddAvailableTask(TaskDescription task) { if (String.IsNullOrEmpty(task.Name) && task.TaskType != null) { task.Name = task.TaskType.Name; } if (_availableTasks.ContainsKey(task.Name)) { throw new InvalidOperationException( string.Format("A task with the name {0} already exists in this collection.", task.Name)); } _availableTasks[task.Name] = task; }
/// <summary> /// Creates the task. /// </summary> /// <param name="taskDescription">The task description.</param> /// <returns></returns> public ITask CreateTask(TaskDescription taskDescription) { if (taskDescription != null) { try { return(ServiceLocator.GetService <IObjectBuilder>().Create <ITask>(taskDescription.TaskType)); } catch (Exception ex) { OnError(ex); } } return(null); }
public static object ExecuteTask(this ITaskExecutionService service, string taskName, object contextObject, params object[] contextArgs) { if (service.HasTask(taskName)) { TaskDescription description = service.GetTaskDescription(taskName); if (description != null) { ITask task = service.CreateTask(description); return(service.ExecuteTask(task, contextObject, contextArgs)); } } throw new InvalidOperationException( string.Format("A task with the TaskName of '{0}' could not be found.", taskName)); }
public static object ExecuteTask(this ITaskExecutionService service, ITask task, object contextObject, params object[] contextArgs) { TaskDescription description = service.GetTaskDescription(task); ITaskContext context; if (description == null) { context = service.CreateTaskContext(contextObject, contextArgs); } else { context = description.CreateTaskContext(contextObject, contextArgs); } return(service.ExecuteTask(task, context)); }
/// <summary> /// Gets the description. /// </summary> /// <param name="task">The task.</param> /// <returns></returns> public TaskDescription GetDescription(ITask task) { if (task == null) { return(null); } Type taskType = task.GetType(); foreach (TaskDescription description in _availableTasks.Values) { if (description.TaskType == taskType) { return(description); } } return(TaskDescription.GetDescription(task)); }
/// <summary> /// Creates the task. /// </summary> /// <param name="taskDescription">The task description.</param> /// <returns></returns> public ITask CreateTask(TaskDescription taskDescription) { return(_factory.CreateTask(taskDescription)); }