public async Task <bool> Run(ITask task, ExportCatalog exports, ITaskOptions options) { if (options != null) { ServiceCollection.AddSingleton(options); ServiceCollection.AddSingleton(typeof(ITaskOptions), options); } else { ServiceCollection.AddSingleton <ITaskOptions, EmptyTaskOptions>(); } if (task.ParameterType != null) { ServiceCollection.AddSingleton(task.ParameterType); ServiceCollection.AddSingleton(typeof(ITaskParameters), task.ParameterType); } ServiceCollection.AddConfigurations(task.GetType().Assembly); ServiceProvider = ServiceCollection.BuildServiceProvider(); var taskParameterType = task.ParameterType ?? typeof(TaskParameters); var parameters = (ITaskParameters)ServiceProvider.GetService(taskParameterType); parameters.PostSetup(ServiceProvider); return(await task.Run(parameters)); }
public TaskBootstrap(TaskCatalog taskCatalog, ExportCatalog exports, string taskName, string taskOptionsFile) { if (!string.IsNullOrEmpty(taskName) && !taskCatalog.HasNamedTask(taskName)) { throw new Exception($"No task found with name {taskName}. Are you sure the task has an [Export] attribute?"); } //if(!File.Exists(taskOptionsFile)) // throw new Exception($"Task options were not defined or the file was not found."); Exports = exports; Task = taskCatalog[taskName]; if (Task == null) { throw new NullReferenceException($"Default task not found. Do the referenced dll's have an [Export] attribute?"); } ITaskOptions taskOptions = null; if (!string.IsNullOrEmpty(taskOptionsFile)) { var optionsStr = File.ReadAllText(taskOptionsFile); taskOptions = JsonConvert.DeserializeObject(optionsStr, Task.OptionsType) as ITaskOptions; if (taskOptions == null) { throw new JsonReaderException($"TaskOptions not parsed."); } } Options = taskOptions; }
public UnrealParameters( IServiceProvider serviceProvider, ILogger <ITaskParameters> logger, ExportCatalog exports, ITaskOptions options) : base(serviceProvider, logger, exports, options) { }
public TaskParameters( IServiceProvider serviceProvider, ILogger <ITaskParameters> logger, ExportCatalog exports, ITaskOptions options) { ServiceProvider = serviceProvider; Log = logger; Exports = exports; Options = options; }
public ITask AddBackgroundTask <TService, TParameter>(TParameter parameter, Action <TService, TParameter> action, Action <ITaskOptionsBuilder> optionsFactory = null) { ITaskOptions options = BuildTaskOptions(optionsFactory); ITaskDetails newTask = new SyncParameterTask <TService, TParameter>(action, parameter, options); if (newTask.Options.Schedule == null) { _taskPool.EnqueueTask(newTask); } else { _taskScheduler.ScheduleTask(newTask); } return(newTask); }
public ITask <TResult> AddBackgroundTask <TService, TResult>(Func <TService, ITask, TResult> action, Action <ITaskOptionsBuilder> optionsFactory = null) { ITaskOptions options = BuildTaskOptions(optionsFactory); ITaskDetails <TResult> newTask = new SyncReferencedTask <TService, TResult>(action, options); if (newTask.Options.Schedule == null) { _taskPool.EnqueueTask(newTask); } else { _taskScheduler.ScheduleTask(newTask); } return(newTask); }
public ITask AddBackgroundTask <TService>(Func <TService, Task> action, Action <ITaskOptionsBuilder> optionsFactory = null) { ITaskOptions options = BuildTaskOptions(optionsFactory); ITaskDetails newTask = new AsyncTask <TService>(action, options); if (newTask.Options.Schedule == null) { _taskPool.EnqueueTask(newTask); } else { _taskScheduler.ScheduleTask(newTask); } return(newTask); }
public AsyncReferencedTask(Func <TService, ITask, Task> task, ITaskOptions options) : base(options) { ReferenceTask = task; }
public AsyncReferencedParameterTask(Func <TService, TValue, ITask, Task> task, TValue parameter, ITaskOptions options) : base(options) { Task = task; Parameter = parameter; }
protected AsyncTaskBase(ITaskOptions options) : base(options) { ServiceType = typeof(TService); IsCancelable = ServiceType.ImplementsInterface <ICancellableTask>(); }
public SyncParameterTask(Action <TService, TValue> task, TValue parameter, ITaskOptions options) : base(options) { Task = task; Parameter = parameter; }
public SyncTask(Action <TService> task, ITaskOptions options) : base(options) { Task = task; }
public SyncReferencedTask(Action <TService, ITask> task, ITaskOptions options) : base(options) { Task = task; }
public AsyncTask(Func <TService, Task> task, ITaskOptions options) : base(options) { Task = task; }
protected TaskDetails(ITaskOptions options) { Options = options ?? throw new ArgumentNullException(nameof(options)); }