public static HostConfigurator WithStartParameter(this HostConfigurator configurator, string name,
                                                          Action <string> action)
        {
            configurator.AddCommandLineDefinition(Prefix + name, action);
            configurator.AddCommandLineDefinition(name, s => Add(configurator, Prefix + name, s));

            return(configurator);
        }
        public static HostConfigurator WithStartParameter(this HostConfigurator configurator, string installName, string runtimeName,
                                                          Func <string, string> installAction, Action <string> runtimeAction)
        {
            configurator.AddCommandLineDefinition(runtimeName, runtimeAction);
            configurator.AddCommandLineDefinition(installName, s => Add(configurator, runtimeName, installAction(s)));

            return(configurator);
        }
        public static HostConfigurator WithCustomStartParameter(this HostConfigurator configurator, string argName, string paramName,
                                                                Action <string> action)
        {
            configurator.AddCommandLineDefinition(paramName, action);
            configurator.AddCommandLineDefinition(argName, s => Add(configurator, paramName, s));

            return(configurator);
        }
        public static HostConfigurator WithConstantStartParameter(this HostConfigurator configurator, string name, string constantValue,
                                                                  Action <string> runtimeAction)
        {
            Add(configurator, name, constantValue);
            configurator.AddCommandLineDefinition(name, runtimeAction);

            return(configurator);
        }
        public static HostConfigurator WithStartParameter(this HostConfigurator configurator, string name, string value,
                                                          Action <string> action)
        {
            Add(configurator, name, value);
            configurator.AddCommandLineDefinition(name, action);

            return(configurator);
        }
예제 #6
0
        public static (SourceSettings, AwsDestinationSettings) Parse(HostConfigurator x)
        {
            string sourceDirectoryPath = string.Empty;
            int    sourceBufferSecs    = 2;
            string awsBucketName       = string.Empty;
            string awsBucketRegion     = string.Empty;
            string awsAccessKeyId      = string.Empty;
            string awsSecretkey        = string.Empty;

            x.AddCommandLineDefinition(nameof(sourceDirectoryPath), v => sourceDirectoryPath = v);
            x.AddCommandLineDefinition(nameof(sourceBufferSecs), v => sourceBufferSecs       = int.Parse(v));
            x.AddCommandLineDefinition(nameof(awsBucketName), v => awsBucketName             = v);
            x.AddCommandLineDefinition(nameof(awsBucketRegion), v => awsBucketRegion         = v);
            x.AddCommandLineDefinition(nameof(awsAccessKeyId), v => awsAccessKeyId           = v);
            x.AddCommandLineDefinition(nameof(awsSecretkey), v => awsSecretkey = v);
            x.ApplyCommandLine();

            var sourceSettings = new SourceSettings(sourceDirectoryPath, sourceBufferSecs);

            var destinationSettings = new AwsDestinationSettings(
                awsBucketName,
                awsBucketRegion,
                awsAccessKeyId,
                awsSecretkey);

            return(sourceSettings, destinationSettings);
        }
        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)); });
        }
        public CommandLineParameterBuilder AddStringParameter(string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

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

            return(this);
        }
        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;
            });
        }
예제 #10
0
        public static T GetCommandlineOptions <T>(this HostConfigurator configurator) where T : class, new()
        {
            var convertor = new ValueConvertor();
            var options   = new T();

            foreach (var pInfo in options.GetType().GetProperties())
            {
                var type         = Nullable.GetUnderlyingType(pInfo.PropertyType) ?? pInfo.PropertyType;
                var optName      = pInfo.GetCustomAttributes(typeof(OptionAttribute), false).Cast <OptionAttribute>().FirstOrDefault()?.OptionName;
                var currentValue = pInfo.GetValue(options);

                configurator.AddCommandLineDefinition(optName ?? pInfo.Name, val => pInfo.SetValue(options, convertor.ConvertValue(type, val, currentValue)));
            }

            return(options);
        }
예제 #11
0
 public void ApplyCommandLine(HostConfigurator configurator)
 {
     configurator.AddCommandLineDefinition("name", v => Name = v);
     configurator.ApplyCommandLine();
 }
예제 #12
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);
            }
        }
예제 #13
0
 public static void Initialize(HostConfigurator hostConfigurator)
 {
     hostConfigurator.AddCommandLineDefinition("port", v => Port = int.Parse(v));
 }