public void GetThrowsOnMissingKey() { var settings = CommandLineSettings.Parse(new string[0]); TestDelegate call = () => settings.Get <string>("stuff"); Assert.That(call, Throws.InstanceOf <InvalidOperationException>()); }
public void CommandLineGoodKeyValueTest() { CommandLineSettings.Run(new string[] { "-k", "\"e29y7Y09bQpdcc/0KfO4WYUOJIMvs6I8cNM8EZpAdHQ=\"" }, (settings) => { Config.LoadConfig(settings); return(0); }); }
public void CommandLineGoodKeyNameTest() { CommandLineSettings.Run(new string[] { "-K", "\"sendlisten\"" }, (settings) => { Config.LoadConfig(settings); return(0); }); }
public void CommandLineBadArgumentTest() { var ex = Assert.Throws <CommandParsingException>(() => { CommandLineSettings.Run(new string[] { "-bad" }, (settings) => { return(0); }); }); Assert.Contains("-bad", ex.Message); }
static void Main(string[] args) { try { CommandLineSettings.Run(args, (c) => Run(c, args)); } catch (CommandParsingException exception) { Console.WriteLine(exception.Message); } }
public void ConfigFileMaxTest() { var configFileName = CreateMaxConfig(); CommandLineSettings settings = new CommandLineSettings(); settings.ConfigFile = configFileName; Config config = Config.LoadConfig(settings); CheckMaxConfig(config); File.Delete(configFileName); }
public void CommandLineBadConnectionStringTest() { var ex = Assert.Throws <ArgumentOutOfRangeException>(() => { CommandLineSettings.Run(new string[] { "-x", "Endpoint=total^^^garbage" }, (settings) => { Config.LoadConfig(settings); return(0); }); }); Assert.Contains("-x", ex.Message); }
public void CommandLineMaxTest() { bool callbackInvoked = false; CommandLineSettings.Run(CreateMaxCommandLine().Split(' '), (settings) => { Config config = Config.LoadConfig(settings); CheckMaxCommandLine(config); callbackInvoked = true; return(0); }); Assert.True(callbackInvoked); }
public void CommandLineBadKeyValueTest() { { var ex = Assert.Throws <ArgumentOutOfRangeException>(() => { CommandLineSettings.Run(new string[] { "-k", "\"^^^^\"" }, (settings) => { Config.LoadConfig(settings); return(0); }); }); Assert.Contains("-k", ex.Message); } }
public void Init() { modpackSettings = new ModpackSettings() { DatabaseDistroVersion = DatabaseVersions.Beta, SaveLastSelection = true }; commandLineSettings = new CommandLineSettings(null) { }; databaseManager = new DatabaseManager(modpackSettings, commandLineSettings) { ManagerInfoZipfile = ((App)RelhaxModpack.App.Current).ManagerInfoZipfile }; }
public CommandLineProcessorProvider( ICommandRepositoryService commandRepository, ICommandPathCalculator commandPathCalculator, Func <ICommandContext> contextFactory, ICommandHistoryService historyService) { this.commandRepository = commandRepository; this.commandPathCalculator = commandPathCalculator; this.contextFactory = contextFactory; HistoryService = historyService; stateStack = new Stack <CommandLineProcessorState>(); state = new CommandLineProcessorState { Status = CommandLineStatus.WaitingForCommandRegistration, Context = this.contextFactory() }; Settings = new CommandLineSettings(); }
public void CommandLineBadRemoteForwardTest() { var ex = Assert.Throws <ArgumentOutOfRangeException>(() => { CommandLineSettings.Run(new string[] { "-R", "foobar:70000" }, (settings) => { Config.LoadConfig(settings); return(0); }); }); Assert.Contains("-R", ex.Message); Assert.Contains("HostPort", ex.Message); var ex1 = Assert.Throws <ArgumentOutOfRangeException>(() => { // public IP address that isn't "here" and thus can't be bound CommandLineSettings.Run(new string[] { "-R", "foo^^^bar:80" }, (settings) => { Config.LoadConfig(settings); return(0); }); }); Assert.Contains("-R", ex1.Message); Assert.Contains("RelayName", ex1.Message); var ex2 = Assert.Throws <ArgumentOutOfRangeException>(() => { // public IP address that isn't "here" and thus can't be bound CommandLineSettings.Run(new string[] { "-R", "foobar:foo^^^bar:80" }, (settings) => { Config.LoadConfig(settings); return(0); }); }); Assert.Contains("-R", ex2.Message); Assert.Contains("Host", ex2.Message); }
/// <summary> /// Sets application settings with the help of a configuration file supplied. /// </summary> /// <param name="settings"></param> /// <returns></returns> static Configuration SetApplicationConfiguration(CommandLineSettings settings) { if (settings.ConfigSupplied && string.IsNullOrEmpty(settings.ConfigFilePath)) { throw new ConfigurationErrorsException("Please supply a configuration file"); } try { var configMap = new ExeConfigurationFileMap { ExeConfigFilename = string.IsNullOrEmpty(settings.ConfigFilePath) ? AppConstants.DefaultConfigFile : settings.ConfigFilePath }; return(ConfigurationManager.OpenMappedExeConfiguration(configMap, ConfigurationUserLevel.None)); } catch { throw new ConfigurationErrorsException("Invalid or no configuration file"); } }
public void ConfigSaveLoadFileTest() { var configFileName = CreateMaxConfig(); try { CommandLineSettings settings = new CommandLineSettings(); settings.ConfigFile = configFileName; Config config = Config.LoadConfig(settings); config.SaveConfigFile(configFileName, false); config = Config.LoadConfigFile(configFileName); CheckMaxConfig(config); } finally { File.Delete(configFileName); } }
static void Main(string[] args) { // before we localize, make sure we have all the error // messages in en-us CultureInfo.CurrentUICulture = CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.GetCultureInfoByIetfLanguageTag("en-us"); try { CommandLineSettings.Run(args, (c) => Run(c, args)); } catch (CommandParsingException exception) { Console.WriteLine(exception.Message); } catch (ConfigException exception) { Console.WriteLine($"{exception.FileName}: {exception.Message}"); } }
public void CommandLineBadBindAddressTest() { var ex = Assert.Throws <ArgumentOutOfRangeException>(() => { CommandLineSettings.Run(new string[] { "-b", "abc^^$foo" }, (settings) => { Config.LoadConfig(settings); return(0); }); }); Assert.Contains("-b", ex.Message); var ex1 = Assert.Throws <ArgumentOutOfRangeException>(() => { // public IP address that isn't "here" and thus can't be bound CommandLineSettings.Run(new string[] { "-b", "1.1.1.1" }, (settings) => { Config.LoadConfig(settings); return(0); }); }); Assert.Contains("-b", ex1.Message); var ex2 = Assert.Throws <ArgumentOutOfRangeException>(() => { // public IP address that isn't "here" and thus can't be bound CommandLineSettings.Run(new string[] { "-b", "bing.com" }, (settings) => { Config.LoadConfig(settings); return(0); }); }); Assert.Contains("-b", ex2.Message); }
/// <summary> /// Reads and processes the command line arguments passed to this application. /// </summary> /// <param name="arguments"></param> /// <returns></returns> static CommandLineSettings ProcessCommandLineArguments(string[] arguments) { var settings = new CommandLineSettings(); IFolderUtility _folderUtility = new FolderUtility(); //Where only single arguments will be catered to for (var index = 0; index < arguments.Length; index++) { var currentArgument = arguments[index]; if (_folderUtility.IsHelpCommand(currentArgument)) { CommandLineHelper.PrintHelp(); settings.VanityCommandRequested = true; return(settings); } if (_folderUtility.IsVersionCommand(currentArgument)) { CommandLineHelper.PrintVersion(); settings.VanityCommandRequested = true; return(settings); } } //Where multiple arguments are allowed for (var index = 0; index < arguments.Length; index++) { var currentArgument = arguments[index]; if (_folderUtility.IsConfigCommand(currentArgument)) { settings.ConfigFilePath = _folderUtility.DoesArrayContentExists(arguments, index + 1) ? arguments[index + 1] : null; settings.ConfigSupplied = true; } } return(settings); }
public void CommandLineGoodBindAddressTest() { CommandLineSettings.Run(new string[] { "-b", "localhost" }, (settings) => { Config.LoadConfig(settings); return(0); }); CommandLineSettings.Run(new string[] { "-b", "\"127.0.1.0\"" }, (settings) => { Config.LoadConfig(settings); return(0); }); CommandLineSettings.Run(new string[] { "-b", "\"[::1]\"" }, (settings) => { Config.LoadConfig(settings); return(0); }); }
public SelfHostSettings(CommandLineSettings commandLineSettings) :base(prefix:"") { this.commandLineSettings = commandLineSettings; this.virtualPathUtility = new SelfHostVirtualPathUtility(BaseDirectory, VirtualPathRoot); }
public async void Run(string[] args) { try { var settings = new CommandLineSettings(args); if (CurrentPlatform == OSPlatform.Windows) { Console.SetWindowSize(120, 40); } Console.BackgroundColor = ConsoleColor.Black; Console.Clear(); WriteCenteredText( $"{Constants.APP_NAME} {Assembly.GetExecutingAssembly().GetName().Version} (.NET Core 3.0 Edition)", ConsoleColor.DarkRed); WriteCenteredText("(C) 2012-2019 Jarred Capellman", ConsoleColor.DarkRed); WriteCenteredText("Source code is available on https://github.com/jcapellman/jcBENCH", ConsoleColor.DarkRed); Console.BackgroundColor = ConsoleColor.Black; var deviceInformation = DeviceInformation.GetInformation(CurrentPlatform); if (deviceInformation == null) { Console.WriteLine($"Could not load Platform Library for {CurrentPlatform}"); return; } Console.WriteLine( $"{Environment.NewLine}Operating System: {deviceInformation.OperatingSystem}{Environment.NewLine}"); var(manufacturer, model, numberCores, frequency, architecture) = deviceInformation.GetCpuInformation(); Console.WriteLine("---------------"); Console.WriteLine("CPU Information"); Console.WriteLine("---------------"); Console.WriteLine($"Manufacturer: {manufacturer}"); Console.WriteLine($"Model: {model}"); Console.WriteLine($"Count: {numberCores}x{frequency}"); Console.WriteLine($"Architecture: {architecture}"); Console.WriteLine($"---------------{Environment.NewLine}"); var benchmark = new HashingBenchmark(); var benchmarkResult = benchmark.Run(settings); Console.WriteLine($"Hashing Benchmark Score: {benchmarkResult}{Environment.NewLine}"); Console.Write("Do you want to submit your result (y/n)?"); var key = Console.ReadKey(); if (key.Key != ConsoleKey.Y) { return; } var submissionResult = await new SubmissionHandler().SubmitResultsAsync( new lib.Objects.ResultSubmissionItem { BenchmarkID = "Hashing", BenchmarkResult = benchmarkResult, CPUArchitecture = architecture, CPUFrequency = $"{numberCores}x{frequency}", CPUManufacturer = manufacturer, CPUName = model, OperatingSystem = deviceInformation.OperatingSystem, PlatformID = OSPlatform.Windows.ToString() }); Console.WriteLine(submissionResult ? "Submission was successful" : "Submission failed"); } catch (Exception ex) { Console.WriteLine($"Error running {Constants.APP_NAME}: {Environment.NewLine}{ex}"); } }
public int Run(CommandLineSettings settings, bool multiThreaded = false) { return(multiThreaded ? RunMultiThreaded() : RunSingleThreaded()); }
public void CaseInsensitive() { var settings = CommandLineSettings.Parse(new[] { "/STUFF=five" }); Assert.That(settings.Get <string>("stuff"), Is.EqualTo("five"), "stuff"); }
public void KeyEqualsValueDoubleHyphen() { var settings = CommandLineSettings.Parse(new[] { "--somekey=true" }); Assert.That(settings.Get <bool>("somekey"), Is.True, "somekey"); }
public void MultipleValuesForKey() { var settings = CommandLineSettings.Parse(new[] { "--thing=a", "--thing=b" }); Assert.That(settings.GetValues <string>("thing"), Is.EqualTo(new[] { "a", "b" })); }
public void KeyEqualsValueSingleHyphen() { var settings = CommandLineSettings.Parse(new[] { "-x=5" }); Assert.That(settings.Get <int>("x"), Is.EqualTo(5), "x"); }
public void ImplicitTrue() { var settings = CommandLineSettings.Parse(new[] { "--stuff" }); Assert.That(settings.Get <bool>("stuff"), Is.EqualTo(true), "x"); }
internal CommandLineSettings GetCommandLineSettings() { var commandLineSettings = new CommandLineSettings() { Settings = new Settings() }; _options = new OptionSet() { { "a=|awsaccesskey=", "Access key of AWS IAM user that can list and terminate instances", x =>commandLineSettings.Settings.AwsAccessKey = x }, { "d=|delay=", "Delay (milliseconds) before chaos is unleashed again (if repeat option set)", (int x) => commandLineSettings.Settings.Delay = x }, { "D|acceptdisclaimer", "Chaos Monkey is designed to break stuff, setting this option means that you acknowledge this", x => commandLineSettings.AcceptDisclaimer = x != null }, { "e=|endpoint=", "AWS endpoint name (US-East, US-West, EU, Asia-Pacific-Singapore, Asia-Pacific-Japan)", x => commandLineSettings.Settings.Ec2Endpoint = x }, { "h|?|help", "Show help (this screen)", x =>commandLineSettings.ShowHelp = x != null }, { "i=|loadsettings=", "Load settings xml file", x => commandLineSettings.LoadSettingsFile = x }, { "l=|log=", "Save log to file", x => commandLineSettings.Settings.LogFileName = x }, { "o=|savesettings=", "Save settings to xml file", x => commandLineSettings.SaveSettingsFile = x }, { "r=|repeat=", "Number of times chaos is unleashed (default 1)", (int x) => commandLineSettings.Settings.Repeat = x }, { "s=|awssecretkey=", "Access key of AWS IAM user that can list and terminate instances", x => commandLineSettings.Settings.AwsSecretKey = x }, { "S=|serviceurl=", "URL of EC2 service endpoint (use e|endpoint to use defaults)", x => commandLineSettings.Settings.ServiceUrl = x }, { "t=|tagkey=", "Key of Tag that will be search for in instances e.g. if EC2 tag is chaos=1, ChaosMonkey TagKey=chaos", x => commandLineSettings.Settings.Tagkey = x }, { "v=|tagvalue=", "Value of Tag that will be search for in instances e.g. if EC2 tag is chaos=1, ChaosMonkey TagValue=1", x => commandLineSettings.Settings.TagValue = x }, { "m=|mode=", "Application mode which decides whether to run in AWS only mode or load plugins.eg. m=Pluggable for loading other plugins", (ApplicationMode x)=>commandLineSettings.ApplicationMode=x } }; _options.Parse(_args); return commandLineSettings; }
public void KeyEqualsValueSlash() { var settings = CommandLineSettings.Parse(new[] { "/x=five" }); Assert.That(settings.Get <string>("x"), Is.EqualTo("five"), "x"); }
static int Run(CommandLineSettings settings, string[] args) { try { #if NET462 if (settings.ServiceInstall.HasValue && settings.ServiceInstall.Value) { ServiceLauncher.InstallService(); return(0); } else if (settings.ServiceUninstall.HasValue && settings.ServiceUninstall.Value) { ServiceLauncher.UninstallService(); return(0); } else if (settings.ServiceRun.HasValue && settings.ServiceRun.Value) { ServiceLauncher.Run(args); return(0); } #endif if (!string.IsNullOrEmpty(settings.ConfigFile) && !File.Exists(settings.ConfigFile)) { Console.WriteLine($"The config file was not found: {settings.ConfigFile}"); return(3); } Config config = Config.LoadConfig(settings); if (config.LocalForward.Count == 0 && config.RemoteForward.Count == 0) { Console.WriteLine("You must specify at least one -L or -R forwarder."); return(2); } var globalCxn = config.AzureRelayConnectionString; if (globalCxn == null && (config.LocalForward.Any((f) => f.ConnectionString == null) || config.RemoteForward.Any((f) => f.ConnectionString == null))) { Console.WriteLine("Connection string(s) undefined; -x/AzureRelayConnectionString. azbridge -h for help."); return(3); } var loggerFactory = new LoggerFactory(); LogLevel logLevel = LogLevel.Error; if (!settings.Quiet.HasValue || !settings.Quiet.Value) { if (config.LogLevel != null) { switch (config.LogLevel.ToUpper()) { case "QUIET": logLevel = LogLevel.None; break; case "FATAL": logLevel = LogLevel.Critical; break; case "ERROR": logLevel = LogLevel.Error; break; case "INFO": logLevel = LogLevel.Information; break; case "VERBOSE": logLevel = LogLevel.Trace; break; case "DEBUG": case "DEBUG1": case "DEBUG2": case "DEBUG3": logLevel = LogLevel.Debug; break; } } } else { logLevel = LogLevel.None; } if (!string.IsNullOrEmpty(config.LogFileName)) { loggerFactory.AddFile(config.LogFileName, logLevel); } else { loggerFactory.AddConsole(logLevel); } logger = loggerFactory.CreateLogger("azbridge"); DiagnosticListener.AllListeners.Subscribe(new SubscriberObserver(logger)); Host host = new Host(config); host.Start(); EventWaitHandle _closing = new EventWaitHandle(false, EventResetMode.AutoReset); Console.CancelKeyPress += (sender, eventArgs) => { host.Stop(); loggerFactory.Dispose(); _closing.Set(); }; _closing.WaitOne(); } catch (FileNotFoundException e) { Console.WriteLine("Configuration file not found:" + e.Message); } catch (Exception e) { Console.WriteLine(e.Message); } return(0); }
public void ValueOrDefaultGetsValue() { var settings = CommandLineSettings.Parse(new[] { "--stuff" }); Assert.That(settings.GetValueOrDefault <bool>("stuff", false), Is.EqualTo(true), "x"); }
static int Run(CommandLineSettings settings, string[] args) { try { #if NET462 if (settings.ServiceInstall.HasValue && settings.ServiceInstall.Value) { ServiceLauncher.InstallService(); return(0); } else if (settings.ServiceUninstall.HasValue && settings.ServiceUninstall.Value) { ServiceLauncher.UninstallService(); return(0); } else if (settings.ServiceRun.HasValue && settings.ServiceRun.Value) { ServiceLauncher.Run(args); return(0); } #endif Config config = Config.LoadConfig(settings); if (config.LocalForward.Count == 0 && config.RemoteForward.Count == 0) { CommandLineSettings.Help(); Console.WriteLine("You must specify at least one -L or -R forwarder."); return(2); } var loggerFactory = new LoggerFactory(); if (!settings.Quiet.HasValue || !settings.Quiet.Value) { LogLevel logLevel = LogLevel.Error; if (config.LogLevel != null) { switch (config.LogLevel.ToUpper()) { case "QUIET": logLevel = LogLevel.None; break; case "FATAL": logLevel = LogLevel.Critical; break; case "ERROR": logLevel = LogLevel.Error; break; case "INFO": logLevel = LogLevel.Information; break; case "VERBOSE": logLevel = LogLevel.Trace; break; case "DEBUG": case "DEBUG1": case "DEBUG2": case "DEBUG3": logLevel = LogLevel.Debug; break; } } loggerFactory.AddConsole(logLevel); } logger = loggerFactory.CreateLogger("azbridge"); DiagnosticListener.AllListeners.Subscribe(new SubscriberObserver(logger)); SemaphoreSlim semaphore = new SemaphoreSlim(1); semaphore.Wait(); Host host = new Host(config); host.Start(); Console.CancelKeyPress += (e, a) => semaphore.Release(); semaphore.Wait(); host.Stop(); } catch (FileNotFoundException e) { Console.WriteLine("Configuration file not found:" + e.Message); } catch (Exception e) { Console.WriteLine(e.Message); } return(0); }
public void ValueOrDefaultGetsDefault() { var settings = CommandLineSettings.Parse(new string[0]); Assert.That(settings.GetValueOrDefault("stuff", 157), Is.EqualTo(157), "stuff"); }