public void Start(CommandLineParameters parameters) { logger.Info("Starting BottomShelf host."); var servicesDirectory = Path.GetFullPath(parameters.ServicesDirectory); watcher = new FileSystemWatcher(servicesDirectory, parameters.FileSystemPoll); hostedServices = new AssemblyScanner().Scan(servicesDirectory); hostedServices.ForEach(hs => StartHostedService(hs, watcher)); watcher.Start(); logger.Info("Started monitoring changes in '{0}'.", servicesDirectory); }
public void Start(FileSystemWatcher watcher, Action removeHostedService) { var appDomainSetup = new AppDomainSetup { ConfigurationFile = string.Format("{0}.config", assemblyFile), ShadowCopyFiles = "true", ApplicationBase = Path.GetDirectoryName(assemblyFile)}; appDomain = AppDomain.CreateDomain(string.Format("BottomShelf.Host - {0}", HostedServiceTypeName), new Evidence(), appDomainSetup); try { hostedServiceInstance = (HostedServiceBase)appDomain.CreateInstanceAndUnwrap(assemblyName.FullName, HostedServiceTypeName); hostedServiceInstance.Start(); } catch(Exception exception) { logger.Error(exception); removeHostedService(); } }
private void StartHostedService(HostedService hostedService, FileSystemWatcher watcher) { logger.Info("Starting service '{0}'.", hostedService.HostedServiceTypeName); hostedService.Start(watcher, () => hostedServices.Remove(hostedService)); logger.Info("Started service '{0}'.", hostedService.HostedServiceTypeName); }