From 69dbba322f6ef275134b7b214510e47b9fcdd0b0 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Tue, 17 Nov 2020 15:11:40 +0200 Subject: IMplemented NSwag for DataStore WebAPI controller. Implemented data store tool dsUtil. --- .../DataStore/Tango.DataStore.CLI/Program.cs | 91 +++++++++++++++++----- 1 file changed, 73 insertions(+), 18 deletions(-) (limited to 'Software/Visual_Studio/DataStore/Tango.DataStore.CLI/Program.cs') diff --git a/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/Program.cs b/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/Program.cs index e27f76c79..db4f54620 100644 --- a/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/Program.cs +++ b/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/Program.cs @@ -1,10 +1,15 @@ using CommandLine; +using ConsoleTables; using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; +using System.Net.Http; using System.Text; using System.Threading.Tasks; using Tango.BL; +using Tango.DataStore.Web; +using Tango.Web; namespace Tango.DataStore.CLI { @@ -12,38 +17,88 @@ namespace Tango.DataStore.CLI { static void Main(string[] args) { + var console = new DataStoreConsole(); + var result = Parser.Default.ParseArguments(args) .WithParsed((options) => { - Console.WriteLine($"{options.Email}, {options.Password}"); + console.Get(options); }) - .WithParsed((options) => + .WithParsed((options) => { - Console.WriteLine($"{options.Email}, {options.Password}"); + console.Put(options); }) - .WithNotParsed((errors) => + .WithNotParsed((errors) => { - + }); - Console.ReadLine(); + if (Debugger.IsAttached) + { + Console.WriteLine(); + Console.WriteLine("Press return to exit..."); + Console.ReadLine(); + } + } + } + + public class DataStoreConsole + { + public void Get(GetOptions options) + { + try + { + if (options.MachineSerialNumber != null) + { + Console.WriteLine($"Retrieving data store values for '{options.MachineSerialNumber}'..."); + } + else + { + Console.WriteLine("Retrieving global data store values..."); + } + + var client = CreateClient(options.Email, options.Password, options.Environment); + + var items = client.Get(options.MachineSerialNumber, options.Collection, options.Key).ToList(); + + ConsoleTable table = new ConsoleTable("COLLECTION", "KEY", "DATA TYPE", "STATE", "GLOBAL", "LOCAL"); + + foreach (var item in items) + { + table.AddRow(item.Collection, item.Key, item.DataType, item.Type, item.GlobalValue.ToStringSafe().ToOneLine(), item.LocalValue.ToStringSafe().ToOneLine()); + } + + Console.WriteLine(); + Console.WriteLine("DATA STORE RESULTS:"); + Console.WriteLine(); + + table.Write(); + } + catch (Exception ex) + { + Console.WriteLine(ex.FlattenMessage()); + } } - private static int DisplayHelp(ParserResult result, IEnumerable errs) + public void Put(PutOptions options) { - var helpText = CommandLine.Text.HelpText.AutoBuild(result, h => + + } + + private DataStoreClient CreateClient(String email, String password, DeploymentSlot slot) + { + String token = String.Empty; + + HttpClient http = new HttpClient(); + DataStoreClient dsClient = new DataStoreClient(slot.ToAddress(), http); + var response = dsClient.Login(new LoginRequest() { - h.AdditionalNewLineAfterOption = false; - h.AddNewLineBetweenHelpSections = true; - h.AddEnumValuesToHelpText = true; - h.AutoVersion = false; - h.Heading = CommandLine.Text.HeadingInfo.Empty; - h.MaximumDisplayWidth = 110; - // h.AddVerbs(typeof(SyncOptions), typeof(QueryOptions), typeof(TokenOptions)); - return h; // only h + Email = "roy@twine-s.com", + Password = "1Creativity", }); - Console.WriteLine(helpText); - return 1; + http.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", response.Token); + + return dsClient; } } } -- cgit v1.3.1