public bool Start(HostControl hostControl) { _log.InfoFormat($"Starting {GetType().GetDisplayName()}"); var started = new List<ServiceControl>(); try { var scanner = new ServiceAssemblyScanner(); List<AssemblyRegistration> registrations = scanner.GetAssemblyRegistrations().ToList(); _log.Info($"Found {registrations.Count} assembly registrations"); foreach (var registration in registrations) { _log.Info($"Assembly: {registration.Assembly.GetName().Name}"); foreach (var type in registration.Types) _log.Info($" Type: {type.GetTypeName()}"); } var busFactoryType = scanner.GetHostBusFactoryType(); if (busFactoryType == null) throw new ConfigurationException("A valid transport assembly was not found."); _bootstrapperScope = CreateBootstrapperScope(registrations, busFactoryType); var bootstrappers = _bootstrapperScope.Resolve<IEnumerable<IServiceBootstrapper>>(); List<ServiceControl> services = bootstrappers.Select(x => x.CreateService()).ToList(); Parallel.ForEach(services, serviceControl => { hostControl.RequestAdditionalTime(TimeSpan.FromMinutes(1)); StartService(hostControl, serviceControl); lock (started) { started.Add(serviceControl); } }); _services.AddRange(started); return true; } catch (Exception ex) { _log.Error("Service failed to start", ex); Parallel.ForEach(started, service => { hostControl.RequestAdditionalTime(TimeSpan.FromMinutes(1)); StopService(hostControl, service); }); throw; } }
public bool Start(HostControl hostControl) { _log.InfoFormat($"Starting {GetType().GetDisplayName()}"); var started = new List <ServiceControl>(); try { var scanner = new ServiceAssemblyScanner(); List <AssemblyRegistration> registrations = scanner.GetAssemblyRegistrations().ToList(); _log.Info($"Found {registrations.Count} assembly registrations"); foreach (var registration in registrations) { _log.Info($"Assembly: {registration.Assembly.GetName().Name}"); foreach (var type in registration.Types) { _log.Info($" Type: {type.GetTypeName()}"); } } var busFactoryType = scanner.GetHostBusFactoryType(); if (busFactoryType == null) { throw new ConfigurationException("A valid transport assembly was not found."); } _bootstrapperScope = CreateBootstrapperScope(registrations, busFactoryType); var bootstrappers = _bootstrapperScope.Resolve <IEnumerable <IServiceBootstrapper> >(); List <ServiceControl> services = bootstrappers.Select(x => x.CreateService()).ToList(); Parallel.ForEach(services, serviceControl => { hostControl.RequestAdditionalTime(TimeSpan.FromMinutes(1)); StartService(hostControl, serviceControl); lock (started) { started.Add(serviceControl); } }); _services.AddRange(started); return(true); } catch (Exception ex) { _log.Error("Service failed to start", ex); Parallel.ForEach(started, service => { hostControl.RequestAdditionalTime(TimeSpan.FromMinutes(1)); StopService(hostControl, service); }); throw; } }