public CommandLineParameterBuilder AddBooleanParameter(string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            _configurator.AddCommandLineSwitch(name, value =>
            {
                _parameters[name] = value;
            });

            return(this);
        }
        private void Configure(HostConfigurator config)
        {
            config.Service <ISelfUpdatableService>(service =>
            {
                service.ConstructUsing(settings => selfUpdatableService);

                service.WhenStarted((s, hostControl) =>
                {
                    s.Start();
                    return(true);
                });

                service.AfterStartingService(() => { updater?.Start(); });

                service.WhenStopped(s => { s.Stop(); });
            });

            config.SetServiceName(serviceName);
            config.SetDisplayName(serviceDisplayName);
            config.StartAutomatically();
            config.EnableShutdown();

            if (promtCredsWhileInstall)
            {
                config.RunAsFirstPrompt();
            }
            else
            {
                config.RunAsLocalSystem();
            }

            config.AddCommandLineSwitch("squirrel", _ => { });
            config.AddCommandLineDefinition("firstrun", _ => Environment.Exit(0));
            config.AddCommandLineDefinition("obsolete", _ => Environment.Exit(0));
            config.AddCommandLineDefinition("updated", version => { config.UseHostBuilder((env, settings) => new UpdateHostBuilder(env, settings, version, withOverlapping)); });
            config.AddCommandLineDefinition("install", version => { config.UseHostBuilder((env, settings) => new InstallAndStartHostBuilder(env, settings, version)); });
            config.AddCommandLineDefinition("uninstall", _ => { config.UseHostBuilder((env, settings) => new StopAndUninstallHostBuilder(env, settings)); });
        }
        private void SetServiceCommandLine(HostConfigurator hc)
        {
            //
            // INFO: 서비스 Argument는 대/소문자를 구분한다.
            //

            // -path:"c:\temp"
            hc.AddCommandLineDefinition("path", ci =>
            {
                _commandLine.Path = ci.Trim();
            });

            // -frequency:2
            hc.AddCommandLineDefinition("frequency", ci =>
            {
                _commandLine.Frequency = int.Parse(ci);
            });

            // --active
            hc.AddCommandLineSwitch("active", ci =>
            {
                _commandLine.Active = ci;
            });
        }
Beispiel #4
0
        /// <summary>
        /// Configures the specified configuration.
        /// </summary>
        /// <param name="config">The configuration.</param>
        private void Configure(HostConfigurator config)
        {
            try
            {
                config.Service <ISelfUpdatableService>(service =>
                {
                    service.ConstructUsing(settings => selfUpdatableService);
                    service.WhenStarted((s, hostControl) =>
                    {
                        s.Start();
                        return(true);
                    });
                    service.AfterStartingService(() => { updater?.Start(); });
                    service.WhenStopped(s => { s.Stop(); });
                });
                config.StartAutomatically();
                config.EnableShutdown();
                config.UseAssemblyInfoForServiceInfo(HostAssembly);
                if (promptForCredentialsWhileInstalling)
                {
                    config.RunAsFirstPrompt();
                }
                else
                {
                    if (TypeRunAs == RunAS.LocalSystem)
                    {
                        config.RunAsLocalSystem();
                    }
                    else if (TypeRunAs == RunAS.LocalService)
                    {
                        config.RunAsLocalService();
                    }
                    else if (TypeRunAs == RunAS.NetworkService)
                    {
                        config.RunAsNetworkService();
                    }
                    else if (TypeRunAs == RunAS.SpecificUser)
                    {
                        if (string.IsNullOrEmpty(serviceLogin))
                        {
                            throw new Exception("Service Login not specified");
                        }

                        if (string.IsNullOrEmpty(servicePassword))
                        {
                            throw new Exception("Service Password not specified");
                        }

                        config.RunAs(serviceLogin, servicePassword);
                    }
                }

                config.AddCommandLineSwitch("squirrel", _ => { });
                config.AddCommandLineDefinition("firstrun", _ => Environment.Exit(0));
                config.AddCommandLineDefinition("obsolete", _ => Environment.Exit(0));
                config.AddCommandLineDefinition("updated", version => { config.UseHostBuilder((env, settings) => new UpdateHostBuilder(env, settings, version, withOverlapping)); });
                config.AddCommandLineDefinition("install", version => { config.UseHostBuilder((env, settings) => new InstallAndStartHostBuilder(env, settings, version)); });
                config.AddCommandLineDefinition("uninstall", _ => { config.UseHostBuilder((env, settings) => new StopAndUninstallHostBuilder(env, settings)); });
            } catch (Exception ex)
            {
                Log.Error("Exception : ", ex);
            }
        }