/// <summary> /// The run workers host service. /// </summary> /// <param name="optionsBootstrap"> /// The options bootstrap. /// </param> /// <param name="actionFactoryBootstrap"> /// The action factory bootstrap. /// </param> public void RunWorkersHostService(Func <string[], WinServiceOptions> optionsBootstrap, Func <string[], IWorkerActionFactory> actionFactoryBootstrap) { this.RunWorkersHostService( optionsBootstrap, delegate(string[] strings) { IWorkerActionFactory actionFactory = actionFactoryBootstrap(strings); const string SectionName = "workersHost"; WorkerConfigurationSection configurationSection = ConfigurationManager.GetSection(SectionName) as WorkerConfigurationSection; if (configurationSection == null) { throw new InvalidOperationException($"Unable to find {SectionName} configuration section"); } return(new ActionWorkersProvider( configurationSection, actionFactory)); }); }
/// <summary> /// Initializes a new instance of the <see cref="ActionWorkersProvider" /> class. /// </summary> /// <param name="workerConfigurationSection">The worker configuration section.</param> /// <param name="workerActionFactory">The worker Action Factory.</param> /// <exception cref="System.ArgumentNullException"> /// Thrown if any argument is null. /// </exception> public ActionWorkersProvider(WorkerConfigurationSection workerConfigurationSection, IWorkerActionFactory workerActionFactory) { if (workerConfigurationSection == null) { throw new ArgumentNullException(nameof(workerConfigurationSection)); } if (workerActionFactory == null) { throw new ArgumentNullException(nameof(workerActionFactory)); } this.workerActionFactory = workerActionFactory; IList <IWorkerActionConfiguration> workersList = new List <IWorkerActionConfiguration>(); foreach (WorkerConfig workerConfiguration in workerConfigurationSection.WorkerActions) { workersList.Add(new WorkerActionConfiguration(workerConfiguration)); } this.workers = workersList; }