예제 #1
0
        public void Configure(HostConfigurator configurator)
        {
            configurator.SetServiceName(ServiceName);
            configurator.SetDisplayName(DisplayName);
            configurator.SetDescription(Description);

            configurator.AfterInstall(() =>
            {
                VerifyEventLogSourceExists(ServiceName);

                // this will force the performance counters to register during service installation
                // making them created - of course using the InstallUtil stuff completely skips
                // this part of the install :(
                new WindowsPerformanceCounterInstaller().Install();
            });

            configurator.Service(settings =>
            {
                _bootstrapper = BootstrapperFactory(settings);

                return(_bootstrapper.GetService());
            },
                                 s => s.AfterStoppingService(() =>
            {
                if (_bootstrapper != default(T))
                {
                    _bootstrapper.Dispose();
                }
            }));
        }
예제 #2
0
파일: Program.cs 프로젝트: zhonli/Yams
        public static void AddCommandLineArgumentsToStartupParameters(this HostConfigurator hostConfigurator)
        {
            hostConfigurator.AfterInstall(settings =>
            {
                using (RegistryKey system = Registry.LocalMachine.OpenSubKey("System"))
                    using (RegistryKey currentControlSet = system.OpenSubKey("CurrentControlSet"))
                        using (RegistryKey services = currentControlSet.OpenSubKey("Services"))
                            using (RegistryKey service = services.OpenSubKey(settings.ServiceName, true))
                            {
                                var arguments = Environment.GetCommandLineArgs();
                                var imagePath = service.GetValue("ImagePath");

                                var newImagePath = arguments
                                                   .Skip(1)
                                                   .Where(a => !IsTopShelfArgument(a))
                                                   .Aggregate(imagePath, (o1, o2) => $"{o1} {o2}");

                                service.SetValue("ImagePath", newImagePath, RegistryValueKind.String);
                            }
            });
        }
예제 #3
0
        private void Configure(HostConfigurator hostOptions)
        {
            hostOptions.SetDescription("PickleJar.ServiceHost.Description");
            hostOptions.SetDisplayName("PickleJar.ServiceHost.DisplayName");
            hostOptions.SetServiceName("PickleJar.ServiceHost.ServiceName");

            hostOptions.Service <AppRootService>(ConfigureService);

            hostOptions.EnablePauseAndContinue();
            hostOptions.EnableShutdown();

            hostOptions.DependsOnEventLog();
            hostOptions.RunAsNetworkService();
            hostOptions.StartAutomaticallyDelayed();

            hostOptions.UseSerilog();

            hostOptions.OnException(SetupLogging.LogException);
            hostOptions.AfterInstall(SetupLogging.AfterInstall);
            hostOptions.BeforeUninstall(SetupLogging.BeforeUninstall);
        }