Esempio n. 1
0
        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));
        }
Esempio n. 2
0
        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;
        }
Esempio n. 3
0
 public UnrealParameters(
     IServiceProvider serviceProvider,
     ILogger <ITaskParameters> logger,
     ExportCatalog exports,
     ITaskOptions options)
     : base(serviceProvider, logger, exports, options)
 {
 }
Esempio n. 4
0
        public TaskParameters(
            IServiceProvider serviceProvider,
            ILogger <ITaskParameters> logger,
            ExportCatalog exports,
            ITaskOptions options)
        {
            ServiceProvider = serviceProvider;

            Log = logger;

            Exports = exports;
            Options = options;
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
        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;
 }
Esempio n. 10
0
        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;
 }
Esempio n. 12
0
 public SyncTask(Action <TService> task, ITaskOptions options) : base(options)
 {
     Task = task;
 }
Esempio n. 13
0
 public SyncReferencedTask(Action <TService, ITask> task, ITaskOptions options) : base(options)
 {
     Task = task;
 }
Esempio n. 14
0
 public AsyncTask(Func <TService, Task> task, ITaskOptions options) : base(options)
 {
     Task = task;
 }
Esempio n. 15
0
 protected TaskDetails(ITaskOptions options)
 {
     Options = options ?? throw new ArgumentNullException(nameof(options));
 }