From 0ee81ef847af3702b3b37f94cc62e835f9294e55 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Mon, 16 Nov 2020 14:35:19 +0200 Subject: Working on DataStore WebAPI & CLI. --- .../DataStore/Tango.DataStore.CLI/App.config | 28 +++++++ .../DataStore/Tango.DataStore.CLI/Options.cs | 51 +++++++++++++ .../DataStore/Tango.DataStore.CLI/Program.cs | 49 ++++++++++++ .../Tango.DataStore.CLI/Properties/AssemblyInfo.cs | 36 +++++++++ .../Tango.DataStore.CLI/Tango.DataStore.CLI.csproj | 86 ++++++++++++++++++++++ .../DataStore/Tango.DataStore.CLI/packages.config | 5 ++ .../Tango.DataStore.EF/EFDataStoreCollection.cs | 15 +++- .../Tango.DataStore/DataStoreProtoObject.cs | 2 + 8 files changed, 269 insertions(+), 3 deletions(-) create mode 100644 Software/Visual_Studio/DataStore/Tango.DataStore.CLI/App.config create mode 100644 Software/Visual_Studio/DataStore/Tango.DataStore.CLI/Options.cs create mode 100644 Software/Visual_Studio/DataStore/Tango.DataStore.CLI/Program.cs create mode 100644 Software/Visual_Studio/DataStore/Tango.DataStore.CLI/Properties/AssemblyInfo.cs create mode 100644 Software/Visual_Studio/DataStore/Tango.DataStore.CLI/Tango.DataStore.CLI.csproj create mode 100644 Software/Visual_Studio/DataStore/Tango.DataStore.CLI/packages.config (limited to 'Software/Visual_Studio/DataStore') diff --git a/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/App.config b/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/App.config new file mode 100644 index 000000000..a46da65da --- /dev/null +++ b/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/App.config @@ -0,0 +1,28 @@ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/Options.cs b/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/Options.cs new file mode 100644 index 000000000..80b3caf7e --- /dev/null +++ b/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/Options.cs @@ -0,0 +1,51 @@ +using CommandLine; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Web; + +namespace Tango.DataStore.CLI +{ + public class OptionsBase + { + [Option(longName: "email", HelpText = "Email address", Required = true)] + public String Email { get; set; } + + [Option(longName: "password", HelpText = "Password")] + public String Password { get; set; } + + [Option(longName: "env", HelpText = "Environment")] + public DeploymentSlot Environment { get; set; } + } + + [Verb("get", HelpText = "Get a data store item.")] + public class GetOptions : OptionsBase + { + [Option(longName: "sn", HelpText = "Machine serial number")] + public String MachineSerialNumber { get; set; } + + [Option(longName: "collection", HelpText = "Collection name")] + public String Collection { get; set; } + + [Option(longName: "key", HelpText = "Item key")] + public String Key { get; set; } + } + + [Verb("put", HelpText = "Get a data store item.")] + public class PutOptions : OptionsBase + { + [Option(longName: "sn", HelpText = "Machine serial number")] + public String MachineSerialNumber { get; set; } + + [Option(longName: "collection", HelpText = "Collection name")] + public String Collection { get; set; } + + [Option(longName: "key", HelpText = "Item key")] + public String Key { get; set; } + + [Option(longName: "value", HelpText = "Item value")] + public String Value { get; set; } + } +} diff --git a/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/Program.cs b/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/Program.cs new file mode 100644 index 000000000..e27f76c79 --- /dev/null +++ b/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/Program.cs @@ -0,0 +1,49 @@ +using CommandLine; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.BL; + +namespace Tango.DataStore.CLI +{ + class Program + { + static void Main(string[] args) + { + var result = Parser.Default.ParseArguments(args) + .WithParsed((options) => + { + Console.WriteLine($"{options.Email}, {options.Password}"); + }) + .WithParsed((options) => + { + Console.WriteLine($"{options.Email}, {options.Password}"); + }) + .WithNotParsed((errors) => + { + + }); + + Console.ReadLine(); + } + + private static int DisplayHelp(ParserResult result, IEnumerable errs) + { + var helpText = CommandLine.Text.HelpText.AutoBuild(result, h => + { + 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 + }); + Console.WriteLine(helpText); + return 1; + } + } +} diff --git a/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/Properties/AssemblyInfo.cs b/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..366b8e28e --- /dev/null +++ b/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Tango.DataStore.CLI")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Tango.DataStore.CLI")] +[assembly: AssemblyCopyright("Copyright © 2020")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("6189b8c3-7af9-43dd-8a61-a8a05f526f62")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/Tango.DataStore.CLI.csproj b/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/Tango.DataStore.CLI.csproj new file mode 100644 index 000000000..05e4022c4 --- /dev/null +++ b/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/Tango.DataStore.CLI.csproj @@ -0,0 +1,86 @@ + + + + + Debug + AnyCPU + {6189B8C3-7AF9-43DD-8A61-A8A05F526F62} + Exe + Tango.DataStore.CLI + Tango.DataStore.CLI + v4.6.1 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\..\packages\CommandLineParser.2.8.0\lib\net461\CommandLine.dll + + + ..\..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.dll + + + ..\..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.SqlServer.dll + + + + + + + + + + + + + + + + + + + + + + + {F441FEEE-322A-4943-B566-110E12FD3B72} + Tango.BL + + + {5001990f-977b-48ff-b217-0236a5022ad8} + Tango.Web + + + {88d9906b-8fc4-4fe0-b7eb-127a0a8fcee4} + Tango.DataStore.EF + + + {e0364dfa-0721-4637-9d32-9d22aac109d6} + Tango.DataStore + + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/packages.config b/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/packages.config new file mode 100644 index 000000000..71553e4ac --- /dev/null +++ b/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/DataStore/Tango.DataStore.EF/EFDataStoreCollection.cs b/Software/Visual_Studio/DataStore/Tango.DataStore.EF/EFDataStoreCollection.cs index 0baf5bb19..c42935368 100644 --- a/Software/Visual_Studio/DataStore/Tango.DataStore.EF/EFDataStoreCollection.cs +++ b/Software/Visual_Studio/DataStore/Tango.DataStore.EF/EFDataStoreCollection.cs @@ -113,11 +113,20 @@ namespace Tango.DataStore.EF { using (var db = ObservablesContext.CreateDefault()) { - var items = db.DataStoreItems.Where(x => x.CollectionName == Name).ToList().Select(x => x.ToDataStoreItem()).ToList(); - var globalItems = db.GlobalDataStoreItems.Where(x => x.CollectionName == Name).ToList().Select(x => x.ToDataStoreItem()).ToList(); + var localItems = db.DataStoreItems.Where(x => x.CollectionName == Name).ToList(); + var globalItems = db.GlobalDataStoreItems.Where(x => x.CollectionName == Name).ToList(); + foreach (var globalItem in globalItems.ToList()) + { + var localItem = localItems.FirstOrDefault(x => x.CollectionName == globalItem.CollectionName && x.Key == globalItem.Key); + + if (localItem != null) + { + globalItems.Remove(globalItem); + } + } - return globalItems.Concat(items).ToList(); + return localItems.Select(x => x.ToDataStoreItem()).Concat(localItems.Select(x => x.ToDataStoreItem())).ToList(); } } diff --git a/Software/Visual_Studio/DataStore/Tango.DataStore/DataStoreProtoObject.cs b/Software/Visual_Studio/DataStore/Tango.DataStore/DataStoreProtoObject.cs index 5aa7c5342..1a9dd324d 100644 --- a/Software/Visual_Studio/DataStore/Tango.DataStore/DataStoreProtoObject.cs +++ b/Software/Visual_Studio/DataStore/Tango.DataStore/DataStoreProtoObject.cs @@ -1,5 +1,6 @@ using Google.Protobuf; using Newtonsoft.Json; +using Newtonsoft.Json.Converters; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; @@ -17,6 +18,7 @@ namespace Tango.DataStore { public class DataStoreProtoObject { + [JsonConverter(typeof(StringEnumConverter))] public MessageType MessageType { get; set; } public Type Type { get; set; } public byte[] Data { get; set; } -- cgit v1.3.1