public TaskConfigurationModel CreateModel(TaskElement element) { var item = new TaskConfigurationModel { TaskId = element.Id, TaskName = element.Name, DisplayName = element.DisplayName, ClientId = element.ClientId ?? 1, }; if (!string.IsNullOrEmpty(element.LogName)) { item.LogName = element.LogName; } if (element.HasMetaData) { foreach (var metaItem in element.MetaData) { item.AddMetaData(metaItem.Key, metaItem.Value); } } if (element.IsContainer) { foreach (var taskElement in element.SubTasks) { var child = CreateModel(taskElement); item.AddSubTask(child); } } return(item); }
public static List <TaskConfigurationModel> refreshTasks(TaskConfigurationModel taskToUpdate) { var response = new RequestAPI() .addClient(new RestClient(urlRequest)) .addRequest(new RestRequest("taskConfiguration/updateAllowDocsAndDisplayClient", Method.PUT, DataFormat.Json)) .addHeader(new KeyValuePair <string, object>("Accept", "application/json")) .addBodyData(taskToUpdate) .buildRequest(); TaskConfigurationModel userRefreshed = RequestAPI.deserilizeProject <TaskConfigurationModel>(response); return(getAll()); }
public void ExecuteTask(ActiveTaskContext context, TaskConfigurationModel model, CancellationToken token) { var task = new Task(() => { var info = adminDataAccess.LoadClientInfo(context.ClientId); if (info == null) { var message = string.Format("Unable to load configuration for Client \"{0}\". Tasks will not be executed.", context.ClientId); throw new InvalidOperationException(message); } try { var instance = LoadTaskInstance(info, model); logger.TraceFormat("Executing task \"{0}\" for Client \"{1}\".", model.TaskName, model.ClientId); publisher.PublishStatusActive(context.ClientId, context.TaskId, DateTime.Now); instance.Execute(context.Token); } catch (OperationCanceledException) { if (context.ServiceToken.IsCancellationRequested) { context.ServiceToken.ThrowIfCancellationRequested(); } } }, token, TaskCreationOptions.LongRunning); task.ContinueWith(x => ContinueOnComplete(context), TaskContinuationOptions.OnlyOnRanToCompletion); task.ContinueWith(x => ContinueOnCancellation(context), TaskContinuationOptions.OnlyOnCanceled); task.ContinueWith(x => ContinueOnFault(x, context), TaskContinuationOptions.OnlyOnFaulted); contextProvider.TryAdd(context.TaskId, context); context.SetActiveTask(task, token); task.Start(); }
private IMiramarTask LoadTaskInstance(IMiramarClientInfo info, TaskConfigurationModel model) { var factory = ObjectFactory.GetAllInstances <IMiramarTaskFactory>() .FirstOrDefault(x => x.IsSatisfiedBy(model.TaskName)); if (factory == null) { var message = string.Format("No corresponding Task Factory could be found for task \"{0}\". Task will not be executed.", model.TaskName); throw new InvalidOperationException(message); } IMiramarTask instance; if (allowMetaData && model.HasMetaData) { instance = LoadTaskInstanceWithMetaData(factory, info, model); if (instance != null) { return(instance); } } instance = factory.GetTask(info, model.TaskName); if (instance == null) { var message = string.Format("Unable to create instance for task \"{0}\" for Client \"{1}\". Task will not be executed.", model.TaskName, info.ClientId); throw new InvalidOperationException(message); } return(instance); }
private IMiramarTask LoadTaskInstanceWithMetaData(IMiramarTaskFactory factory, IMiramarClientInfo info, TaskConfigurationModel model) { var metaDataFactory = factory as IMiramarMetaDataTaskFactory; if (metaDataFactory == null) { logger.WarnFormat( "The corresponding Task Factory for task \"{0}\" does not support instantiation with meta data. Task will be created without meta data.", model.TaskName); return(null); } if (!metaDataFactory.AllowsMetaDataConfiguration(model.TaskName)) { logger.WarnFormat( "Task \"{0}\" has been configured with meta data but is not supported. Task will be created without meta data.", model.TaskName); return(null); } var metaDataInstance = metaDataFactory.GetTask(info, model.TaskName, model.MetaData); if (metaDataInstance != null) { return(metaDataInstance); } var message = string.Format( "Unable to create instance for task \"{0}\" for Client \"{1}\" with meta data. Task will not be executed.", model.TaskName, info.ClientId); throw new InvalidOperationException(message); }