private static void AfterStartingService <T>(ServiceConfigurator <T> configurator,
                                                     IEnumerable <FileSystemWatcherConfigurator.DirectoryConfiguration> configs, LogWriter log,
                                                     Action <TopshelfFileSystemEventArgs> fileSystemChanged) where T : class
        {
            configurator.AfterStartingService(() =>
            {
                foreach (FileSystemWatcherConfigurator.DirectoryConfiguration config in configs)
                {
                    if (config.GetInitialStateEvent)
                    {
                        log.Info("[Topshelf.FileSystemWatcher] Checking for InitialState Events");

                        string[] paths;
                        if (!string.IsNullOrWhiteSpace(config.FileFilter))
                        {
                            paths = Directory.GetFiles(config.Path, config.FileFilter);
                        }
                        else
                        {
                            paths = Directory.GetFiles(config.Path);
                        }

                        if (paths.Any())
                        {
                            foreach (string path in paths)
                            {
                                fileSystemChanged(FileSystemEventFactory.CreateCurrentStateFileSystemEvent(Path.GetDirectoryName(path), Path.GetFileName(path)));
                            }
                        }
                    }
                }
            });
        }
Ejemplo n.º 2
0
        public static ServiceConfigurator <T> WithNancyEndpoint <T>(this ServiceConfigurator <T> configurator, HostConfigurator hostconfigurator, Action <NancyServiceConfiguration> nancyConfigurator) where T : class
        {
            var nancyServiceConfiguration = new NancyServiceConfiguration();

            nancyConfigurator(nancyServiceConfiguration);

            var nancyService = new NancyService();

            nancyService.Configure(nancyServiceConfiguration);

            configurator.AfterStartingService(_ => nancyService.Start());

            configurator.BeforeStoppingService(_ => nancyService.Stop());

            hostconfigurator.BeforeInstall(_ => nancyService.BeforeInstall());

            hostconfigurator.BeforeUninstall(nancyService.BeforeUninstall);

            return(configurator);
        }
Ejemplo n.º 3
0
        public static void Configuration(ServiceConfigurator <ValidationService> config)
        {
            IKernel kernel = null;

            IDisposable webapiApp = null;

            config.ConstructUsing(() =>
            {
                return(new ValidationService());
            });

            config.BeforeStartingService(h =>
            {
                h.RequestAdditionalTime(ServerSettings.AdditionalStartupTime);

                kernel = ConfigModule.GetKernel();

                log.Info("{0} Service Started", ServiceName);
            });

            config.WhenStarted(s =>
            {
                //configuration for hangfire server.
                //tells it to use in memory storage instead of having to have a SQL backend
                Hangfire.GlobalConfiguration.Configuration.UseMemoryStorage();

                // tells hangfire which IoC to use when newing up jobs.
                Hangfire.GlobalConfiguration.Configuration.UseNinjectActivator(kernel);

                RunValidationServer(kernel);

                webapiApp = WebApp.Start(ServerSettings.WebAPIUrl, builder =>
                {
                    kernel.Get <ValidationService>().Configuration(builder);
                });
            });

            config.AfterStartingService(() =>
            {
#if DEBUG
#endif
            });

            config.WhenStopped(s =>
            {
                if (kernel != null)
                {
                    var busCleanup = kernel.Get <IBusCleanup>();
                    busCleanup.StopAllBuses();

                    log.Info("{0} Service Stopped - bus cleanup and kernel disposed", ServiceName);
                }

                //In theory, IBusCleanup should allow notifications to be sent before an app closes down.
                //However, in this case more time was required.
                //TODO - verify not needed System.Threading.Thread.Sleep(500);

                log.Info("{0} Service Stopped", ServiceName);

                webapiApp.Dispose();

                kernel.Dispose();
            });
        }