public IDictionary <string, object> GeteParameterValues() { _parameters.Clear(); if (MonoHelper.RunninOnLinux) { _configurator.ApplyCommandLine(TopshelfHelper.NormalizeCommandLine()); } else { _configurator.ApplyCommandLine(); } return(new ReadOnlyDictionary <string, object>(_parameters)); }
/// <summary> /// Configures the test host, which simply starts and stops the service. Meant to be used /// to verify the service can be created, started, stopped, and disposed without issues. /// </summary> public static HostConfigurator UseTestHost(this HostConfigurator configurator) { configurator.UseHostBuilder((environment, settings) => new TestBuilder(environment, settings)); configurator.ApplyCommandLine(""); return(configurator); }
/// <summary> /// Конфигурация сервиса средствами Topshelf. /// </summary> private static void ConfigureService ( HostConfigurator configurator ) { configurator.ApplyCommandLine(); var service = configurator.Service <WebHello>(); service.SetDescription("ASP.NET Hello service"); service.SetDisplayName("Web Hello Service"); service.SetServiceName("WebHelloService"); service.StartAutomaticallyDelayed(); service.RunAsLocalSystem(); service.EnableShutdown(); // Необязательная настройка восстановления после сбоев service.EnableServiceRecovery(recovery => { recovery.RestartService(1); }); // Реакция на исключение service.OnException(exception => { var log = HostLogger.Get <WebHello>(); log.ErrorFormat($"Exception {exception}"); }); }
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); }
public static IDisposable UseApplicationHostBuilder(this HostConfigurator hostConfigurator, string[] commandLineArguments) { hostConfigurator.UseHostBuilder((environment, settings) => new ApplicationHostBuilder(environment, settings)); var commandLine = string.Join(" ", commandLineArguments); return(new DisposableAction(() => hostConfigurator.ApplyCommandLine(commandLine))); }
public static void UseLinuxIfAvailable(this HostConfigurator configurator) { if (MonoHelper.RunninOnLinux) { // Needed to overcome mono-service style arguments. configurator.ApplyCommandLine(MonoHelper.GetUnparsedCommandLine()); configurator.UseEnvironmentBuilder((cfg) => new LinuxHostEnvironmentBuilder(cfg)); } }
/// <summary> /// Apply valid TopShelf command line parameters to the TopShelf configurator /// </summary> /// <param name="configurator">TopShelf HostConfigurator</param> /// <param name="arguments">List of command line arguments</param> public static void ApplyValidCommandLine(this HostConfigurator configurator, List <string> arguments) { var validCommandlineParameters = new List <string>(); validCommandlineParameters.AddRange(arguments.Where(t => TopShelfCommandLineArguments.Verbs.Contains(t))); validCommandlineParameters.AddRange(arguments.Where(t => TopShelfCommandLineArguments.Options.FirstOrDefault(t.StartsWith) != null)); validCommandlineParameters.AddRange(arguments.Where(t => TopShelfCommandLineArguments.Switches.FirstOrDefault(t.StartsWith) != null)); configurator.ApplyCommandLine(string.Join(" ", validCommandlineParameters)); }
public static void ApplyCommandLineWithDebuggerSupport(this HostConfigurator hc) { var svcpath = Assembly.GetExecutingAssembly().Location; var cmdline = Environment.CommandLine; var ind = cmdline.IndexOf(svcpath, StringComparison.InvariantCultureIgnoreCase); if (ind < 0) { hc.ApplyCommandLine(); } else { ind = ind + svcpath.Length; if (cmdline.Length > ind && cmdline[ind] == '"') { ind = ind + 1; } hc.ApplyCommandLine(cmdline.Substring(ind)); } }
private static void ValidateCommandLine(HostConfigurator configurator, IReadOnlyList <string> args) { if (!args.Any()) { return; } if (TopShelfMangeVerbs.Contains(args[0], StringComparer.OrdinalIgnoreCase)) { return; } if (string.Equals("run", args[0], StringComparison.OrdinalIgnoreCase)) { configurator.ApplyCommandLine(""); return; } if (string.Equals("start", args[0], StringComparison.OrdinalIgnoreCase)) { if (args.Count == 1) { return; } if (string.Equals(args[1], "-instance", StringComparison.OrdinalIgnoreCase) || args[1].StartsWith("-instance:", StringComparison.OrdinalIgnoreCase)) { return; } configurator.ApplyCommandLine("start"); } configurator.ApplyCommandLine(""); }
public void ApplyCommandLine(HostConfigurator configurator) { configurator.AddCommandLineDefinition("name", v => Name = v); configurator.ApplyCommandLine(); }