aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/Program.cs
diff options
context:
space:
mode:
authorRoy Ben Shabat <Roy.mail.net@gmail.com>2020-11-17 15:11:40 +0200
committerRoy Ben Shabat <Roy.mail.net@gmail.com>2020-11-17 15:11:40 +0200
commit69dbba322f6ef275134b7b214510e47b9fcdd0b0 (patch)
treefd7a96fcf96ce86b7fa80f38161cb23ea140973c /Software/Visual_Studio/DataStore/Tango.DataStore.CLI/Program.cs
parent6f0f2a7908884deab8aca33ec967d03c5e564060 (diff)
downloadTango-69dbba322f6ef275134b7b214510e47b9fcdd0b0.tar.gz
Tango-69dbba322f6ef275134b7b214510e47b9fcdd0b0.zip
IMplemented NSwag for DataStore WebAPI controller.
Implemented data store tool dsUtil.
Diffstat (limited to 'Software/Visual_Studio/DataStore/Tango.DataStore.CLI/Program.cs')
-rw-r--r--Software/Visual_Studio/DataStore/Tango.DataStore.CLI/Program.cs91
1 files changed, 73 insertions, 18 deletions
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<GetOptions, PutOptions>(args)
.WithParsed<GetOptions>((options) =>
{
- Console.WriteLine($"{options.Email}, {options.Password}");
+ console.Get(options);
})
- .WithParsed<PutOptions>((options) =>
+ .WithParsed<PutOptions>((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<T>(ParserResult<T> result, IEnumerable<Error> 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;
}
}
}