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));
        }