private void Run(string [] args) { var showHelp = false; var sampleSettings = new SampleSettings (); var promptForPassword = false; var isJson = false; var isXml = false; options = new OptionSet { {"<>", "The url of the API.", v => sampleSettings.Api = v}, {"u|username="******"The username used to log into RaMP.", v => sampleSettings.Username = v}, {"e", "The username used to log into RaMP.", v => promptForPassword = v!=null}, {"p|password="******"The password for the user.", v => sampleSettings.Password = v}, {"j|json", "(Optional) Show output as JSON. (Default)", v => isJson = v!=null}, {"x|xml", "(Optional) Show output as XML. (Default)", v => isXml = v!= null}, {"h|?|help", "Show available options", v => showHelp = true} }; try { options.Parse (args); } catch (OptionException exception) { log.Debug ("Encountered an error parsing arguments!", exception); Console.WriteLine ("Error parsing arguments!"); showHelp = true; } if (!isJson && !isXml) { showHelp = true; } if (showHelp) { ShowHelp (options); return; } if (promptForPassword) { var pass = ""; Console.Write ("Enter your password: "******"*"); } else { if (key.Key == ConsoleKey.Backspace && pass.Length > 0) { pass = pass.Substring (0, (pass.Length - 1)); Console.Write ("\b \b"); } } } // Stops Receiving Keys Once Enter is Pressed while (key.Key != ConsoleKey.Enter); sampleSettings.Password = pass; } if (isJson) { Run (jsonApiRunner, sampleSettings); } if (isXml) { Run (xmlApiRunner, sampleSettings); } Console.WriteLine ("Complete. Press enter to exit."); Console.ReadLine (); }
private void Run(IApiRunner<XDocument> runner, SampleSettings settings) { //1. You will need to login to the site to retrieve the token to use for authentication on the other requests runner.Login (settings); //2. Retrieve the list of racks (racks.xml) var collection = runner.RetrieveRackCollection (settings); WriteResults ("racks.xml", collection); //I am just using the id from the first rack if (collection == null) { return; } var token = collection.XPathSelectElement ("/assets/asset[position()=1]/id"); if (token == null) { return; } var id = token.Value; //3. Retrieve the list of racks (rackContents.xml) var rackContentsResponse = runner.RetrieveRackContents (settings, id); WriteResults ("rackContents.xml", rackContentsResponse); //4. Retrieves the rack item (NLSRack.xml) var rackResponse = runner.RetrieveAsset (settings, id); WriteResults ("rack.xml", rackResponse); }