/// <summary> /// Initializes a new instance of the <see cref="TaskSchedulerPollingJob"/> class. /// </summary> /// <param name="configProvider">The configuration provider to retrieve configuration.</param> /// <param name="repository">The repository to use.</param> /// <param name="dateTimeProvider">The date time provider to use.</param> /// <param name="facade">The task processor facade to use to submit tasks.</param> public TaskSchedulerPollingJob(ITaskProcessorConfigurationProvider configProvider, ITaskProcessorRepository repository, IDateTimeProvider dateTimeProvider, ITaskProcessorFacade facade) { if (configProvider == null) { throw new ArgumentNullException(nameof(configProvider)); } if (repository == null) { throw new ArgumentNullException(nameof(repository)); } if (dateTimeProvider == null) { throw new ArgumentNullException(nameof(dateTimeProvider)); } if (facade == null) { throw new ArgumentNullException(nameof(facade)); } this.configuration = configProvider.GetTaskSchedulerConfiguration(); this.repository = repository; this.dateTimeProvider = dateTimeProvider; this.facade = facade; this.repository.ScheduledTasks.Added += this.OnScheduledTaskAdded; this.repository.ScheduledTasks.Updated += this.OnScheduledTaskUpdated; this.repository.ScheduledTasks.Deleted += this.OnScheduledTaskDeleted; }
/// <summary> /// Clears the task job settings for task type. /// </summary> /// <typeparam name="TTask">The type of the task.</typeparam> /// <param name="facade">The <see cref="ITaskProcessorFacade"/> instance to extend.</param> /// <exception cref="ArgumentNullException">Parameter <paramref name="facade"/> is null.</exception> public static void ClearTaskJobSettings <TTask>(this ITaskProcessorFacade facade) where TTask : ITask { if (facade == null) { throw new ArgumentNullException(nameof(facade)); } facade.ClearTaskJobSettings(typeof(TTask)); }
/// <summary> /// Gets task job settings for task type. /// </summary> /// <typeparam name="TTask">The type of the task.</typeparam> /// <param name="facade">The <see cref="ITaskProcessorFacade"/> instance to extend.</param> /// <returns>Task job settings for the specified task type, or null if not found.</returns> /// <exception cref="ArgumentNullException">Parameter <paramref name="facade"/> is null.</exception> public static ITaskJobSettings GetTaskJobSettings <TTask>(this ITaskProcessorFacade facade) where TTask : ITask { if (facade == null) { throw new ArgumentNullException(nameof(facade)); } return(facade.GetTaskJobSettings(typeof(TTask))); }
public MainViewModel( ITaskProcessorRepository repository, ITaskProcessorMessageBus messageBus, ITaskProcessorFacade taskProcessorFacade, ITimer performanceMonitoringTimer) { if (repository == null) { throw new ArgumentNullException("repository"); } if (messageBus == null) { throw new ArgumentNullException("messageBus"); } if (taskProcessorFacade == null) { throw new ArgumentNullException("taskProcessorFacade"); } if (performanceMonitoringTimer == null) { throw new ArgumentNullException("performanceMonitoringTimer"); } this.repository = repository; this.messageBus = messageBus; this.taskProcessorFacade = taskProcessorFacade; this.performanceMonitoringTimer = performanceMonitoringTimer; this.messageBus.TaskProcessors.Receiver.MasterModeChanged += this.OnMasterModeChanged; this.messageBus.TaskProcessors.Receiver.StateChanged += this.OnTaskProcessorStateChanged; this.messageBus.TaskProcessors.Receiver.PerformanceReportReceived += this.OnPerformanceReport; this.messageBus.Tasks.Receiver.TaskSubmitted += this.OnTaskSubmitted; this.messageBus.Tasks.Receiver.TaskAssigned += this.OnTaskAssignedToProcessor; this.messageBus.Tasks.Receiver.TaskStarted += this.OnTaskStarted; this.messageBus.Tasks.Receiver.TaskProgress += this.OnTaskProgress; this.messageBus.Tasks.Receiver.TaskCancelRequested += this.OnTaskCancelRequested; this.messageBus.Tasks.Receiver.TaskCancelCompleted += this.OnTaskCancelCompleted; this.messageBus.Tasks.Receiver.TaskFailed += this.OnTaskFailed; this.messageBus.Tasks.Receiver.TaskCompleted += this.OnTaskCompleted; this.performanceMonitoringTimer.Interval = TimeSpan.FromSeconds(5); this.performanceMonitoringTimer.Tick += this.OnPerformanceMonitoringTimerTick; this.InitializeTasks(); this.messageBus.TaskProcessors.Receiver.SubscribeForChannels( MessageBusChannel.TaskProcessorState, MessageBusChannel.MasterModeChanged, MessageBusChannel.PerformanceReport); this.messageBus.Tasks.Receiver.SubscribeForChannels( MessageBusChannel.TaskSubmitted, MessageBusChannel.TaskAssigned, MessageBusChannel.TaskStarted, MessageBusChannel.TaskProgress, MessageBusChannel.TaskCancelRequest, MessageBusChannel.TaskCancelCompleted, MessageBusChannel.TaskFailed, MessageBusChannel.TaskCompleted); }
internal static void Main(string[] args) { ITaskProcessorFacade facade = RadoslavServiceLocator.DefaultInstance.ResolveSingle <ITaskProcessorFacade>(); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("Choose an option from the menu: "); Program.PrintOption("T", "Submit task."); Program.PrintOption("PQ", "Submit polling queue task."); Program.PrintOption("PL", "Submit task with low priority."); Program.PrintOption("PH", "Submit task with high priority."); Program.PrintOption("SS", "Submit task with a string summary."); Program.PrintOption("DS", "Submit task with a dictionary summary."); Program.PrintOption("CS", "Submit task with a custom summary."); Program.PrintOption("GDTJS", "Get dictionary task job settings."); Program.PrintOption("SDTJS", "Set dictionary task job settings."); Program.PrintOption("GCTJS", "Get custom task job settings."); Program.PrintOption("SCTJS", "Set custom task job settings."); Program.PrintOption("EXIT", "Exit application."); while (true) { string option = Console.ReadLine(); ITask task; switch (option.ToUpperInvariant()) { case "PQ": task = Program.CreateTask(true); break; case "EXIT": return; default: task = Program.CreateTask(false); break; } Guid?taskId = null; switch (option.ToUpperInvariant()) { // Submit task. case "T": taskId = facade.SubmitTask(task); break; // Submit polling queue task. case "PQ": taskId = facade.SubmitTask(task); break; // Submit task with low priority. case "PL": taskId = facade.SubmitTask(task, TaskPriority.Low); break; // Submit task with high priority. case "PH": taskId = facade.SubmitTask(task, TaskPriority.High); break; // Submit task with a text summary. case "SS": taskId = facade.SubmitTask(task, new StringTaskSummary("Sample text task summary.")); break; // Submit task with a dictionary summary. case "DS": taskId = facade.SubmitTask(task, new DictionaryTaskSummary() { { "Key 1", "Value 1" }, { "Key 2", "Value 2" } }); break; // Submit task with a custom summary. case "CS": taskId = facade.SubmitTask(task, new SampleTaskSummary() { Description = "Custom task summary", TaskId = 11, TenantId = 1 }); break; case "GDTJS": { DictionaryTaskJobSettings settings = facade.GetTaskJobSettings <SampleTask, DictionaryTaskJobSettings>(); if (settings == null) { Console.WriteLine("'{0}' job settings not found.", typeof(SampleTaskJobSettings).Name); } else { Console.WriteLine("{0}: {1}.", settings.GetType().Name, string.Join(", ", settings.Select(p => "{0} = {1}".FormatInvariant(p.Key, p.Value)))); } } break; case "SDTJS": { DictionaryTaskJobSettings settings = new DictionaryTaskJobSettings() { { "Username", Path.GetFileNameWithoutExtension(Path.GetTempFileName()) }, { "Password", Path.GetFileNameWithoutExtension(Path.GetTempFileName()) } }; facade.SetTaskJobSettings <SampleTask>(settings); Console.WriteLine("{0} set: {1}.", settings.GetType().Name, string.Join(", ", settings.Select(p => "{0} = {1}".FormatInvariant(p.Key, p.Value)))); } break; case "GCTJS": { SampleTaskJobSettings settings = facade.GetTaskJobSettings <SampleTask, SampleTaskJobSettings>(); if (settings == null) { Console.WriteLine("'{0}' job settings not found.", typeof(SampleTaskJobSettings).Name); } else { Console.WriteLine("{0}: username '{1}' and password '{2}'.", settings.GetType().Name, settings.Username, settings.Password); } } break; case "SCTJS": { SampleTaskJobSettings settings = new SampleTaskJobSettings() { Username = Path.GetFileNameWithoutExtension(Path.GetTempFileName()), Password = Path.GetFileNameWithoutExtension(Path.GetTempFileName()) }; facade.SetTaskJobSettings <SampleTask>(settings); Console.WriteLine("{0} set with username '{1}' and password '{2}'.", settings.GetType().Name, settings.Username, settings.Password); } break; default: throw new NotSupportedException <string>(option); } if (taskId.HasValue) { Console.WriteLine("Task submitted with ID '{0}'.", taskId); } } }