public void SourceFilesBindsCorrectly() { var args = new[] { "/SourceFiles", "\"abc,def\"" }; var argsConverted = bindingDefinition.CreateAndBind(args); argsConverted.SourceFiles.Length.Should().Be(2); }
public void HappyPath() { var args = new[] { "/n", "my name", "/i", "5" }; var test = modelWithRequiredFieldDefinition.CreateAndBind(args); Assert.AreEqual(5, test.Id); Assert.AreEqual("my name", test.Name); }
public void SimpleModelBindingTest() { var args = new[] { "MyAssembly.dll", "/id", "223", "/fo", "/n", "My Name", "/s", "Low,", "Medium" }; var result = simpleTestModelDefinitionUnderTest.CreateAndBind(args); result.FileName.Should().Be.EqualTo("MyAssembly.dll"); result.Id.Should().Be.EqualTo(223); result.Name.Should().Be.EqualTo("My Name"); result.Force.Should().Be.True(); result.Speed.Should().Be.EqualTo(FanSpeed.Low | FanSpeed.Medium); }
public void SimpleModelBindingTest() { var args = new[] { "MyAssembly.dll", "/id", "223", "/fo", "/n", "My Name", "/s", "Low,", "Medium" }; var result = simpleTestModelDefinitionUnderTest.CreateAndBind(args); Assert.AreEqual("MyAssembly.dll", result.FileName); Assert.AreEqual(223, result.Id); Assert.AreEqual("My Name", result.Name); Assert.IsTrue(result.Force); Assert.AreEqual(FanSpeed.Low | FanSpeed.Medium, result.Speed); }
private ControllerResult ProcessStandardMode() { IModelBindingDefinition <ControllerSelectionArgumentModel> definition = Args.Configuration.Configure <ControllerSelectionArgumentModel>(); ControllerSelectionArgumentModel model; try { model = definition.CreateAndBind(ApplicationContext.Args); //model = definition.CreateAndBind(_args); if (ApplicationContext.Args.First().ToLower().Contains(model.ControllerName)) { ApplicationContext.Args = ApplicationContext.Args.Skip(1).ToArray(); } } catch { model = new ControllerSelectionArgumentModel(); model.ControllerName = "Render"; } //IRtcController controller; ControllerResult result; switch (model.ControllerName.ToLowerInvariant()) { case "help": HelpController controllerHelp = new HelpController(); controllerHelp.ArgumentModel = Args.Configuration.Configure <HelpArgumentModel>().CreateAndBind(ApplicationContext.Args); result = controllerHelp.Execute(); break; case "install": InstallController controllerInstall = new InstallController(); //IModelBindingDefinition<InstallArgumentModel> controllerDefinition = // Args.Configuration.Configure<InstallArgumentModel>(); controllerInstall.ArgumentModel = Args.Configuration.Configure <InstallArgumentModel>().CreateAndBind(ApplicationContext.Args); result = controllerInstall.Execute(); break; default: RenderController controllerRender = new RenderController(); controllerRender.Context = ApplicationContext; IModelBindingDefinition <RenderArgumentModel> definitionRender = Args.Configuration.Configure <RenderArgumentModel>(); //IModelBindingDefinition<RenderArgumentModel> controllerDefinition = // Args.Configuration.Configure<RenderArgumentModel>(); string[] controllerArgs = (string[])ApplicationContext.Args.Clone(); controllerRender.ArgumentModel = definitionRender.CreateAndBind(controllerArgs); _logger.Info("Start Rendreding with arguments:"); _logger.Info("Template Content : " + controllerRender.ArgumentModel.TemplateContent); _logger.Info("Model Content : " + controllerRender.ArgumentModel.ModelContent); _logger.Info("Result path : " + controllerRender.ArgumentModel.ResultFile); result = controllerRender.Execute(); break; } return(result); }
public void FlagOnlyTest() { var args = new[] { "/f" }; var result = simpleSwitchOnlyModelDefinitionUnderTest.CreateAndBind(args); result.Force.Should().Be.True(); }
public void FlagOnlyTest() { var args = new[] { "/f" }; var result = simpleSwitchOnlyModelDefinitionUnderTest.CreateAndBind(args); Assert.IsTrue(result.Force); }
public static void Main(string[] args) { AppLaunchingCommandLine commandLine; IModelBindingDefinition <AppLaunchingCommandLine> modelBindingDefinition = null; try { modelBindingDefinition = Configuration.Configure <AppLaunchingCommandLine>(); commandLine = modelBindingDefinition.CreateAndBind(args); /* * if (commandLine.ProductId == Guid.Empty) * { * Console.WriteLine(""); * Console.WriteLine("***Warning*** - no productId supplied"); * Console.WriteLine(""); * } */ } catch (Exception /*exception*/) { if (modelBindingDefinition != null) { var help = new HelpProvider(); var formatter = new ConsoleHelpFormatter(); var sw = new StringWriter(); var text = help.GenerateModelHelp(modelBindingDefinition); formatter.WriteHelp(text, sw); Console.Write(sw.ToString()); } else { Console.Write("Sorry - no help available!"); } return; } try { Console.WriteLine("AutomationHost starting"); using (var program = new Program(commandLine)) { Console.WriteLine("To show help, enter 'help'"); program.Run(); } } catch (QuitNowPleaseException) { Console.WriteLine("Goodbye"); } catch (Exception exception) { Console.WriteLine(string.Format("Exception seen {0} {1}", exception.GetType().FullName, exception.Message)); } }
public void TestWithOrdinalParameters() { var args = new[] { "5", "Test1.txt", "test5.txt", "backup.sql" }; var test = ordinalModelUnderTest.CreateAndBind(args); Assert.AreEqual(5, test.Id); Assert.IsTrue(new[] { "Test1.txt", "test5.txt", "backup.sql" }.SequenceEqual(test.FileNames)); }
private void DefineStartMode() { IModelBindingDefinition <ServerModeArgumentModel> definition = Args.Configuration.Configure <ServerModeArgumentModel>(); ServerModeArgumentModel model = null; try { model = definition.CreateAndBind(_args); ApplicationContext = new ApplicationContext(_args); ApplicationContext.StartMode = model; } catch { ApplicationContext = new ApplicationContext(_args); ApplicationContext.StartMode = new ServerModeArgumentModel() { ServerMode = ServerMode.StandAlone, StartOptions = string.Empty }; } _logger.Info("Start Mode : {0}", ApplicationContext.StartMode.ServerMode); if (ApplicationContext.StartMode.StartOptions != null && ApplicationContext.StartMode.StartOptions.Contains("wait")) { //Timer t = new Timer(5000); ////t.Elapsed += new ElapsedEventHandler(t_Elapsed); //bool waitForTimer = true; //t.Elapsed += (s,e) => {waitForTimer = false; }; //while (waitForTimer) //{ //} _logger.Info("Please attach a debugger to continue..."); while (!Debugger.IsAttached) { } _logger.Info("Debugger attached, let's continue"); } if (_args[0] == model.ServerMode.ToString()) { int start = 1; if (model != null && !string.IsNullOrEmpty(model.StartOptions) && _args.Length >= 3) { start = 3; } List <string> newargs = new List <string>(); for (int i = start; i < _args.Length; i++) { newargs.Add(_args[i]); } _args = newargs.ToArray(); ApplicationContext.Args = _args; } }
public void TestWithSwitchedParameters() { var args = new[] { "/i", "123", "/n", "My Name", "/d", "1/1/2000", "1/1/2001", "/q", "5", "9", "100", "/t", "12.01", "10.55", "43", "107.6", "/s", "true", "true", "false", "false", "false", "/r", "1.2", "2.3" }; var test = switchOnlyModelUnderTest.CreateAndBind(args); Assert.AreEqual(123, test.Id); Assert.AreEqual("My Name", test.Name); Assert.IsTrue(new[] { new DateTime(2000, 1, 1), new DateTime(2001, 1, 1) }.SequenceEqual(test.Date)); Assert.IsTrue(new[] { 5, 9, 100 }.SequenceEqual(test.Quantities)); Assert.IsTrue(new[] { 12.01M, 10.55M, 43M, 107.6M }.SequenceEqual(test.Totals)); Assert.IsTrue(new[] { true, true, false, false, false }.SequenceEqual(test.Switches)); Assert.IsTrue(new[] { 1.2f, 2.3f }.SequenceEqual(test.Radians)); }
public static void Main(string[] args) { IModelBindingDefinition <CommandArgs> config = null; String errorMessage = null; var showHelp = args.Length == 0; try { config = Configuration.Configure <CommandArgs>(); Command = config.CreateAndBind(args); } catch (InvalidOperationException ex) { showHelp = true; errorMessage = "Error: " + ex.Message; } if (showHelp) { var helpProvider = new HelpProvider(); var help = helpProvider.GenerateModelHelp(config); Console.WriteLine(help.HelpText); Console.WriteLine(errorMessage); return; } else { Console.WriteLine(@" <!-- This tool isn't aware of inherited methods, and the binding generator will complain that the xpath isn't found. -->"); Console.WriteLine(@" <!-- These nodes will be ignored by the generator. -->"); } var files = Directory.EnumerateFiles(Command.JavadocPath, "*.html", SearchOption.AllDirectories); // TODO: Optionally parse allclasses-noframe.html instead foreach (var file in files) { ParseFile(file); // TODO: write the attr nodes direct to metadata.xml. } }
/// <summary> /// Mains the specified arguments. /// </summary> /// <param name="args">The arguments.</param> private static void Main(string[] args) { IModelBindingDefinition <CommandArgs> bindingDefinition = Configuration.Configure <CommandArgs>(); // Show help if required if (args.Length == 1 && args[0].Contains("?")) { ModelHelp modelHelp = new HelpProvider().GenerateModelHelp(bindingDefinition); Console.Write(new ConsoleHelpFormatter().GetHelp(modelHelp)); return; } // Bind cmd line args CommandArgs command = bindingDefinition.CreateAndBind(args); // Get a DeviceManager instance using (var deviceManager = new TC08DeviceManager()) { // List devices if requested if (command.Devices) { foreach (var dev in deviceManager.Devices) { Console.WriteLine(dev.Serial); } return; } // Get the specified device or the first found TC08Device device = string.IsNullOrWhiteSpace(command.Serial) ? deviceManager.Devices.FirstOrDefault() : deviceManager.Devices.FirstOrDefault(d => d.Serial.ToLower() == command.Serial.ToLower()); // Let them know if we couldn't find a device if (device == null) { Console.WriteLine("Device not found"); return; } // Set mains rejection to 60Hz if req if (command.RejFreq > 55) { device.FrequencyRejection = TC08DeviceImports.FreqRej.Sixty; } StringBuilder csvHeader = new StringBuilder(); csvHeader.Append("Time, "); if (command.Type.Length == 1) { SetChannel(device, command.Channel, command.Type[0]); csvHeader.Append("Ch"); csvHeader.Append(command.Channel); csvHeader.Append(", "); } else if (command.Type.Length == 8) { for (int i = 0; i < 8; i++) { char type = command.Type[i]; if (type == DisabledChannel) { continue; } SetChannel(device, i + 1, type); csvHeader.Append("Ch"); csvHeader.Append(i + 1); csvHeader.Append(", "); } } else { Console.WriteLine( "Type should be 1 or 8 characters long. Diasabled channels should be included with a '-'. " + "For example '---j--k-' would set channels 4 and 7 to J and K types respectivly."); return; } // Configure device ready for capture device.Configure(); // If we're in logging mode, write the CSV header if (command.Log) { Console.WriteLine(csvHeader.ToString().Trim(' ', ',')); } var tempUnit = GetUnits(command); do { var stopWatch = Stopwatch.StartNew(); float[] data = device.GetValues(tempUnit); StringBuilder csvLine = new StringBuilder(); if (command.Log) { csvLine.Append(DateTime.Now + ", "); } var values = string.Join(", ", data .Skip(1) // Skip the cold junction value .Where(w => !float.IsNaN(w)) // Ignore the NaNs as these channels are disabled .Select(s => s.ToString("F2"))); // Convert them to string with 2 decimal places csvLine.Append(values); Console.WriteLine(csvLine); // If we're logging, ensure we wait 1 second before continuing... if (command.Log) { Thread.Sleep((int)Math.Max(1, (1000 - stopWatch.ElapsedMilliseconds))); } // Only loop if we're in log mode } while (command.Log); } }