public void SetUp() { sut = new ImportManyFromDirectory<IService>(); }
/// <summary> /// Find services to run and start them /// </summary> /// <param name="token">Cancellation token</param> private void LookUpServicesAndStart(CancellationToken token) { try { Thread.CurrentThread.TrySetName("Worker"); log.Info("Starting Worker thread"); while (!token.IsCancellationRequested) { log.Info("Looking into directory for live services"); var services = new ImportManyFromDirectory<IPollingService>().Get(AppSettingsReader.Get<string>(AppSettingsKeys.LIVE_SERVICES_DIRECTORY)); // only run if new service is found var newServices = services.Where(s => !currentlyRunningServices.Contains(s.Name)); if (services.Count() > 0 && newServices.Count() > 0) { foreach (var service in newServices) { IPollingService pollingService = service; log.Info(string.Format("Starting service - {0}", pollingService)); Task.Factory.StartNew(() => ServiceExecutor.Execute(pollingService, token), token); currentlyRunningServices.Add(pollingService.Name); } } else { log.Info("There is no new service to run"); } Thread.Sleep(new TimeSpan(0, 0, 0, AppSettingsReader.Get<int>(AppSettingsKeys.LOOK_UP_SERVICE_POLL_INTERVAL))); } log.Info("Cancellation request found in worker thread"); token.ThrowIfCancellationRequested(); } catch (Exception ex) { log.Info("Exception in Worker thread"); log.Error(ex); } }