From 4ccaf0b3f68b3675a8527df349b3bc4b5b566682 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Mon, 21 Dec 2020 02:19:12 +0200 Subject: StubUtils. --- .../Tango.FSE.Procedures/ProcedureContext.cs | 4 +- .../Tango.StubsUtils.Client.CLI/Program.cs | 4 +- .../Program.cs | 74 +++++++++++++++++-- .../App.config | 6 ++ .../Program.cs | 71 ++++++++++++++++++ .../Properties/AssemblyInfo.cs | 36 ++++++++++ .../Tango.StubsUtils.ProcedureClient.CLI.csproj | 62 ++++++++++++++++ .../procedure_test.pproj | 1 + .../Tango.StubsUtils.Service.UI/App.config | 15 +--- .../Tango.StubsUtils.Service.UI.csproj | 32 +++++++++ .../System.Collections.Immutable.dll | Bin 0 -> 244432 bytes .../System.Composition.AttributedModel.dll | Bin 0 -> 24840 bytes .../System.Composition.Hosting.dll | Bin 0 -> 62184 bytes .../System.Composition.Runtime.dll | Bin 0 -> 29928 bytes .../System.Composition.TypedParts.dll | Bin 0 -> 64760 bytes .../System.Reflection.Metadata.dll | Bin 0 -> 465104 bytes .../System.Text.Encoding.CodePages.dll | Bin 0 -> 766872 bytes .../Reference Assemblies/System.ValueTuple.dll | Bin 0 -> 79176 bytes .../Tango.StubsUtils.Service/StubsService.cs | 75 +++++++++++++++++-- .../StubsServiceProcedureContext.cs | 80 +++++++++++++++++++++ .../StubsServiceProcedureLogger.cs | 34 +++++++++ .../Tango.StubsUtils.Service.csproj | 34 +++++++++ .../StubsUtils/Tango.StubsUtils.Service/app.config | 80 +++++++++++++++++++++ .../Tango.StubsUtils.Service/packages.config | 4 ++ .../Tango.StubsUtils.SessionClient.CLI/Program.cs | 2 +- Software/Visual_Studio/Tango.sln | 35 +++++++-- 26 files changed, 614 insertions(+), 35 deletions(-) create mode 100644 Software/Visual_Studio/StubsUtils/Tango.StubsUtils.ProcedureClient.CLI/App.config create mode 100644 Software/Visual_Studio/StubsUtils/Tango.StubsUtils.ProcedureClient.CLI/Program.cs create mode 100644 Software/Visual_Studio/StubsUtils/Tango.StubsUtils.ProcedureClient.CLI/Properties/AssemblyInfo.cs create mode 100644 Software/Visual_Studio/StubsUtils/Tango.StubsUtils.ProcedureClient.CLI/Tango.StubsUtils.ProcedureClient.CLI.csproj create mode 100644 Software/Visual_Studio/StubsUtils/Tango.StubsUtils.ProcedureClient.CLI/procedure_test.pproj create mode 100644 Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/Reference Assemblies/System.Collections.Immutable.dll create mode 100644 Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/Reference Assemblies/System.Composition.AttributedModel.dll create mode 100644 Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/Reference Assemblies/System.Composition.Hosting.dll create mode 100644 Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/Reference Assemblies/System.Composition.Runtime.dll create mode 100644 Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/Reference Assemblies/System.Composition.TypedParts.dll create mode 100644 Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/Reference Assemblies/System.Reflection.Metadata.dll create mode 100644 Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/Reference Assemblies/System.Text.Encoding.CodePages.dll create mode 100644 Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/Reference Assemblies/System.ValueTuple.dll create mode 100644 Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/StubsServiceProcedureContext.cs create mode 100644 Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/StubsServiceProcedureLogger.cs (limited to 'Software/Visual_Studio') diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Procedures/ProcedureContext.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Procedures/ProcedureContext.cs index f47f1174e..594698c4c 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Procedures/ProcedureContext.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Procedures/ProcedureContext.cs @@ -152,7 +152,7 @@ namespace Tango.FSE.Procedures return Send(messageName, null, args); } - public IMessage Send(IMessage message, int? timeout = null) + public virtual IMessage Send(IMessage message, int? timeout = null) { TimeSpan? timespan = null; @@ -172,7 +172,7 @@ namespace Tango.FSE.Procedures return Send(messageName, timeout) as T; } - public void SendContinuous(IMessage message, Action callback, int? timeout = null) where T : class, IMessage + public virtual void SendContinuous(IMessage message, Action callback, int? timeout = null) where T : class, IMessage { TaskCompletionSource completion = new TaskCompletionSource(); diff --git a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Client.CLI/Program.cs b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Client.CLI/Program.cs index b975093d1..f59f97de3 100644 --- a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Client.CLI/Program.cs +++ b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Client.CLI/Program.cs @@ -26,9 +26,9 @@ namespace Tango.StubsUtils.Client.CLI var writer = new StreamWriter(_client); - var jsonRequest = String.Join(" ", args); + var request = String.Join("^", args); - writer.WriteLine(jsonRequest); + writer.WriteLine(request); writer.Flush(); var reader = new StreamReader(_client); diff --git a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.PerformanceTest.CLI/Program.cs b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.PerformanceTest.CLI/Program.cs index ff172737a..b6fde8383 100644 --- a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.PerformanceTest.CLI/Program.cs +++ b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.PerformanceTest.CLI/Program.cs @@ -10,7 +10,8 @@ namespace Tango.StubsUtils.PerformanceTest.CLI { class Program { - private const int ROUNDS = 100; + private const int ROUNDS_SMALL = 100; + private const int ROUNDS_BIG = 1000; private const int DELAY = 0; static void Main(string[] args) @@ -18,6 +19,8 @@ namespace Tango.StubsUtils.PerformanceTest.CLI PerformanceTestStandard(); Console.WriteLine(); PerformanceTestSession(); + Console.WriteLine(); + PerformanceTestProcedure(); Console.WriteLine(); Console.WriteLine(); @@ -31,7 +34,7 @@ namespace Tango.StubsUtils.PerformanceTest.CLI Stopwatch watch = new Stopwatch(); - for (int i = 0; i < ROUNDS; i++) + for (int i = 0; i < ROUNDS_SMALL; i++) { watch.Restart(); @@ -61,7 +64,7 @@ namespace Tango.StubsUtils.PerformanceTest.CLI durations.Add(watch.ElapsedMilliseconds); Console.SetCursorPosition(0, 0); - Console.Write($"Performance Test (Standard): {i + 1}/{ROUNDS}, Avg: {Math.Round(durations.Average(), 2)} ms "); + Console.Write($"Performance Test (Standard): {i + 1}/{ROUNDS_SMALL}, Avg: {Math.Round(durations.Average(), 2)} ms "); } } @@ -83,7 +86,7 @@ namespace Tango.StubsUtils.PerformanceTest.CLI Stopwatch watch = new Stopwatch(); - for (int i = 0; i < ROUNDS; i++) + for (int i = 0; i < ROUNDS_BIG; i++) { watch.Restart(); @@ -127,10 +130,71 @@ namespace Tango.StubsUtils.PerformanceTest.CLI durations.Add(watch.ElapsedMilliseconds); Console.SetCursorPosition(0, 1); - Console.Write($"Performance Test (Session) : {i + 1}/{ROUNDS}, Avg: {Math.Round(durations.Average(), 2)} ms "); + Console.Write($"Performance Test (Session) : {i + 1}/{ROUNDS_BIG}, Avg: {Math.Round(durations.Average(), 2)} ms "); } } + private static void PerformanceTestProcedure() + { + List durations = new List(); + + Process process = new Process(); + process.StartInfo.FileName = "tangostub_p.exe"; + process.StartInfo.Arguments = $"procedure_test.pproj {ROUNDS_BIG} 10 15"; + process.StartInfo.CreateNoWindow = true; + process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; + process.StartInfo.RedirectStandardOutput = true; + process.StartInfo.RedirectStandardInput = true; + process.StartInfo.UseShellExecute = false; + process.Start(); + process.PriorityClass = ProcessPriorityClass.RealTime; + + Stopwatch watch = new Stopwatch(); + Stopwatch realWatch = new Stopwatch(); + realWatch.Stop(); + + int count = 0; + + do + { + watch.Restart(); + + String line = process.StandardOutput.ReadLine(); + + if (count == 0) + { + realWatch.Start(); + } + + if (line == null) + { + break; + } + + if (line.StartsWith("Status: Error")) + { + OnError(process.StandardOutput.ReadToEnd()); + return; + } + else if (line.StartsWith("Status: Completed")) + { + break; + } + + if (count > 0) + { + durations.Add(watch.ElapsedMilliseconds); + Console.SetCursorPosition(0, 2); + Console.Write($"Performance Test (Procedure) : {count + 1}/{ROUNDS_BIG}, Avg: {Math.Round(durations.Average(), 2)} ms "); + } + + count++; + } while (!process.HasExited); + + Console.SetCursorPosition(0, 2); + Console.Write($"Performance Test (Procedure) : {ROUNDS_BIG}/{ROUNDS_BIG}, Avg: {Math.Round(realWatch.ElapsedMilliseconds / (double)ROUNDS_BIG, 2)} ms "); + } + private static void OnError(String error) { Console.ForegroundColor = ConsoleColor.Red; diff --git a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.ProcedureClient.CLI/App.config b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.ProcedureClient.CLI/App.config new file mode 100644 index 000000000..731f6de6c --- /dev/null +++ b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.ProcedureClient.CLI/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.ProcedureClient.CLI/Program.cs b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.ProcedureClient.CLI/Program.cs new file mode 100644 index 000000000..c5b7a030e --- /dev/null +++ b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.ProcedureClient.CLI/Program.cs @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.IO.Pipes; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.StubsUtils.Shared; + +namespace Tango.StubsUtils.ProcedureClient.CLI +{ + class Program + { + private const string PIPE_NAME = "Tango_Stubs_Server"; + + static void Main(string[] args) + { + try + { + Console.ForegroundColor = ConsoleColor.Gray; + + var _client = new NamedPipeClientStream(PIPE_NAME); + _client.Connect(1000); + + var writer = new StreamWriter(_client); + + String s = Environment.CommandLine; + + List arguments = args.ToList(); + arguments.Insert(0, "procedure"); + var request = String.Join("^", arguments); + + writer.WriteLine(request); + writer.Flush(); + + var reader = new StreamReader(_client); + + while (true) + { + String responseString = reader.ReadLine(); + Console.WriteLine(responseString); + + if (responseString.StartsWith("Status: OK")) + { + responseString = reader.ReadToEnd(); + Console.WriteLine(responseString); + Environment.Exit(0); + } + else if (responseString.StartsWith("Status: Error")) + { + responseString = reader.ReadToEnd(); + Console.WriteLine(responseString); + ExitError(responseString); + } + } + } + catch (Exception ex) + { + ExitError($"Status: Error\nError: Error communicating with the stubs service. {ex.Message}"); + } + } + + private static void ExitError(String error) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine($"{error}"); + Console.ForegroundColor = ConsoleColor.Gray; + Environment.Exit(-1); + } + } +} diff --git a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.ProcedureClient.CLI/Properties/AssemblyInfo.cs b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.ProcedureClient.CLI/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..82bf9f837 --- /dev/null +++ b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.ProcedureClient.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.StubsUtils.ProcedureClient.CLI")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Tango.StubsUtils.ProcedureClient.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("8f0bcfc8-af0f-40d3-882a-902cd221a6de")] + +// 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/StubsUtils/Tango.StubsUtils.ProcedureClient.CLI/Tango.StubsUtils.ProcedureClient.CLI.csproj b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.ProcedureClient.CLI/Tango.StubsUtils.ProcedureClient.CLI.csproj new file mode 100644 index 000000000..606fcfcfe --- /dev/null +++ b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.ProcedureClient.CLI/Tango.StubsUtils.ProcedureClient.CLI.csproj @@ -0,0 +1,62 @@ + + + + + Debug + AnyCPU + {8F0BCFC8-AF0F-40D3-882A-902CD221A6DE} + Exe + Tango.StubsUtils.ProcedureClient.CLI + tangostub_p + v4.6.1 + 512 + true + true + + + AnyCPU + true + full + false + ..\..\Build\StubsUtils\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + ..\..\Build\StubsUtils\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + PreserveNewest + + + + + {dae96f06-72cd-411d-90a3-9456ae79f699} + Tango.StubsUtils.Shared + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.ProcedureClient.CLI/procedure_test.pproj b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.ProcedureClient.CLI/procedure_test.pproj new file mode 100644 index 000000000..2ed7a56d3 --- /dev/null +++ b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.ProcedureClient.CLI/procedure_test.pproj @@ -0,0 +1 @@ +{"$id":"1","Name":"procedure_test","Visibility":"Public","Description":null,"Scripts":{"$id":"2","$values":[{"$id":"3","Code":"using System;\r\nusing System.Collections.Generic;\r\nusing System.Collections.ObjectModel;\r\nusing System.ComponentModel;\r\nusing System.Linq;\r\nusing System.Text;\r\nusing System.Threading;\r\nusing System.Threading.Tasks;\r\nusing System.Drawing;\r\nusing Google.Protobuf;\r\nusing Tango.BL.Entities;\r\nusing Tango.BL.Enumerations;\r\nusing Tango.PMR.Stubs;\r\nusing Tango.PMR.Diagnostics;\r\nusing Tango.FSE.Common.Connection;\r\nusing Tango.FSE.Common.Diagnostics;\r\nusing Tango.FSE.Procedures;\r\n\r\npublic class Program\r\n{\r\n public const String Iterations = \"1\";\r\n public const String Num1 = \"1\";\r\n public const String Num2 = \"2\";\r\n\r\n public void OnExecute(IProcedureContext context)\r\n {\r\n int rounds = int.Parse(Iterations);\r\n\r\n for (int i = 0; i < rounds; i++)\r\n {\r\n CalculateRequest request = new CalculateRequest();\r\n request.A = double.Parse(Num1);\r\n request.B = double.Parse(Num2);\r\n CalculateResponse response = context.Send(request);\r\n context.WriteLine(\"Sum: \" + response.Sum);\r\n }\r\n }\r\n}","Name":"Program.csx","IsEntryPoint":true},{"$id":"4","Code":"using System;\r\nusing System.Collections.Generic;\r\nusing System.Collections.ObjectModel;\r\nusing System.ComponentModel;\r\nusing System.Linq;\r\nusing System.Text;\r\nusing System.Threading;\r\nusing System.Threading.Tasks;\r\nusing System.Drawing;\r\nusing Google.Protobuf;\r\nusing Tango.BL.Entities;\r\nusing Tango.BL.Enumerations;\r\nusing Tango.PMR.Stubs;\r\nusing Tango.PMR.Diagnostics;\r\nusing Tango.FSE.Common.Connection;\r\nusing Tango.FSE.Common.Diagnostics;\r\nusing Tango.FSE.Procedures;\r\n\r\npublic class Service\r\n{\r\n public double Calc(double a, double b)\r\n {\r\n return a + b;\r\n }\r\n}","Name":"Service.csx","IsEntryPoint":false}]},"Inputs":{"$id":"5","$values":[]},"Variables":{"$id":"6","$values":[]},"ReferenceAssemblies":{"$id":"7","$values":[{"$id":"8","File":"C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\mscorlib.dll","HintType":"System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"},{"$id":"9","File":"C:\\WINDOWS\\Microsoft.Net\\assembly\\GAC_MSIL\\System.Core\\v4.0_4.0.0.0__b77a5c561934e089\\System.Core.dll","HintType":"System.Linq.Enumerable, System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"},{"$id":"10","File":"C:\\WINDOWS\\Microsoft.Net\\assembly\\GAC_MSIL\\System.Windows.Forms\\v4.0_4.0.0.0__b77a5c561934e089\\System.Windows.Forms.dll","HintType":"System.Windows.Forms.Form, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"},{"$id":"11","File":"C:\\DATA\\Development\\Tango\\Software\\Visual_Studio\\Build\\FSE\\Debug\\Tango.FSE.Procedures.dll","HintType":"Tango.FSE.Procedures.ProcedureProject, Tango.FSE.Procedures, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"},{"$id":"12","File":"C:\\DATA\\Development\\Tango\\Software\\Visual_Studio\\Build\\FSE\\Debug\\Tango.FSE.Common.dll","HintType":"Tango.FSE.Common.Diagnostics.IDiagnosticsProvider, Tango.FSE.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"},{"$id":"13","File":"C:\\DATA\\Development\\Tango\\Software\\Visual_Studio\\Build\\FSE\\Debug\\Tango.BL.dll","HintType":"Tango.BL.Enumerations.TechMonitors, Tango.BL, Version=2.0.36.1608, Culture=neutral, PublicKeyToken=null"},{"$id":"14","File":"C:\\DATA\\Development\\Tango\\Software\\Visual_Studio\\Build\\FSE\\Debug\\Tango.PMR.dll","HintType":"Tango.PMR.Common.MessageType, Tango.PMR, Version=2.0.40.1608, Culture=neutral, PublicKeyToken=null"},{"$id":"15","File":"C:\\DATA\\Development\\Tango\\Software\\Visual_Studio\\Build\\FSE\\Debug\\Tango.Transport.dll","HintType":"Tango.Transport.ITransporter, Tango.Transport, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"},{"$id":"16","File":"C:\\DATA\\Development\\Tango\\Software\\Visual_Studio\\Build\\FSE\\Debug\\Tango.Integration.dll","HintType":"Tango.Integration.Operation.IMachineOperator, Tango.Integration, Version=2.0.31.1608, Culture=neutral, PublicKeyToken=null"},{"$id":"17","File":"C:\\DATA\\Development\\Tango\\Software\\Visual_Studio\\Build\\FSE\\Debug\\Google.Protobuf.dll","HintType":"Google.Protobuf.IMessage, Google.Protobuf, Version=3.4.1.0, Culture=neutral, PublicKeyToken=a7d26565bac4d604"},{"$id":"18","File":"C:\\WINDOWS\\Microsoft.Net\\assembly\\GAC_MSIL\\System.Drawing\\v4.0_4.0.0.0__b03f5f7f11d50a3a\\System.Drawing.dll","HintType":"System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"},{"$id":"19","File":"C:\\DATA\\Development\\Tango\\Software\\Visual_Studio\\Build\\FSE\\Debug\\Tango.DataStore.dll","HintType":"Tango.DataStore.IDataStoreItem, Tango.DataStore, Version=2.0.4.1608, Culture=neutral, PublicKeyToken=null"}]},"Resources":{"$id":"20","$values":[]},"Dialogs":{"$id":"21","$values":[]},"ID":"44a4b6b3-647d-4ffd-9144-b44f871bffe2","ApartmentState":"STA"} \ No newline at end of file diff --git a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service.UI/App.config b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service.UI/App.config index 9dfd8545b..e49ea898a 100644 --- a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service.UI/App.config +++ b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service.UI/App.config @@ -7,19 +7,6 @@ - - - - - - - - - - - - - - + \ No newline at end of file diff --git a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service.UI/Tango.StubsUtils.Service.UI.csproj b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service.UI/Tango.StubsUtils.Service.UI.csproj index 28d49f4d2..abf378e14 100644 --- a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service.UI/Tango.StubsUtils.Service.UI.csproj +++ b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service.UI/Tango.StubsUtils.Service.UI.csproj @@ -59,8 +59,40 @@ ..\..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll + + False + ..\Tango.StubsUtils.Service\Reference Assemblies\System.Collections.Immutable.dll + + + False + ..\Tango.StubsUtils.Service\Reference Assemblies\System.Composition.AttributedModel.dll + + + False + ..\Tango.StubsUtils.Service\Reference Assemblies\System.Composition.Hosting.dll + + + False + ..\Tango.StubsUtils.Service\Reference Assemblies\System.Composition.Runtime.dll + + + False + ..\Tango.StubsUtils.Service\Reference Assemblies\System.Composition.TypedParts.dll + + + False + ..\Tango.StubsUtils.Service\Reference Assemblies\System.Reflection.Metadata.dll + + + False + ..\Tango.StubsUtils.Service\Reference Assemblies\System.Text.Encoding.CodePages.dll + + + False + ..\Tango.StubsUtils.Service\Reference Assemblies\System.ValueTuple.dll + ..\..\packages\ControlzEx.3.0.2.4\lib\net45\System.Windows.Interactivity.dll diff --git a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/Reference Assemblies/System.Collections.Immutable.dll b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/Reference Assemblies/System.Collections.Immutable.dll new file mode 100644 index 000000000..ce6fc0e8d Binary files /dev/null and b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/Reference Assemblies/System.Collections.Immutable.dll differ diff --git a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/Reference Assemblies/System.Composition.AttributedModel.dll b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/Reference Assemblies/System.Composition.AttributedModel.dll new file mode 100644 index 000000000..4acc216e1 Binary files /dev/null and b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/Reference Assemblies/System.Composition.AttributedModel.dll differ diff --git a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/Reference Assemblies/System.Composition.Hosting.dll b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/Reference Assemblies/System.Composition.Hosting.dll new file mode 100644 index 000000000..a446fe6e0 Binary files /dev/null and b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/Reference Assemblies/System.Composition.Hosting.dll differ diff --git a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/Reference Assemblies/System.Composition.Runtime.dll b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/Reference Assemblies/System.Composition.Runtime.dll new file mode 100644 index 000000000..a05bfe9c8 Binary files /dev/null and b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/Reference Assemblies/System.Composition.Runtime.dll differ diff --git a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/Reference Assemblies/System.Composition.TypedParts.dll b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/Reference Assemblies/System.Composition.TypedParts.dll new file mode 100644 index 000000000..cfae95d0c Binary files /dev/null and b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/Reference Assemblies/System.Composition.TypedParts.dll differ diff --git a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/Reference Assemblies/System.Reflection.Metadata.dll b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/Reference Assemblies/System.Reflection.Metadata.dll new file mode 100644 index 000000000..ee68731c0 Binary files /dev/null and b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/Reference Assemblies/System.Reflection.Metadata.dll differ diff --git a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/Reference Assemblies/System.Text.Encoding.CodePages.dll b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/Reference Assemblies/System.Text.Encoding.CodePages.dll new file mode 100644 index 000000000..0f2f44744 Binary files /dev/null and b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/Reference Assemblies/System.Text.Encoding.CodePages.dll differ diff --git a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/Reference Assemblies/System.ValueTuple.dll b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/Reference Assemblies/System.ValueTuple.dll new file mode 100644 index 000000000..502f8cd47 Binary files /dev/null and b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/Reference Assemblies/System.ValueTuple.dll differ diff --git a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/StubsService.cs b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/StubsService.cs index 13a8b38e5..f1b6f9d9c 100644 --- a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/StubsService.cs +++ b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/StubsService.cs @@ -9,10 +9,13 @@ using System.Linq; using System.Reflection; using System.Runtime.Serialization.Formatters.Binary; using System.Text; +using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; using Tango.Core; +using Tango.Core.DI; using Tango.Core.ExtensionMethods; +using Tango.FSE.Procedures; using Tango.Logging; using Tango.PMR; using Tango.PMR.Common; @@ -196,14 +199,37 @@ namespace Tango.StubsUtils.Service if (EnableLogs) LogManager.Log($"Stub package received: '{request}'..."); var package = new StubPackageRequestDTO(); - package.Arguments = request.Split(' '); + package.Arguments = request.Split('^'); - var response = ProcessStubPackage(package); + if (package.Arguments.Length == 0) + { + throw new InvalidOperationException("Zero arguments provided."); + } + + if (package.Arguments[0] == "procedure") + { + ProcessProcedureProject(package); - //if (EnableLogs) LogManager.Log($"Stub package response:\n'{response.ToJsonString()}'..."); + try + { + var response = new StubPackageResponseDTO() + { + Status = StubPackageResponseStatus.OK, + Message = $"Completed." + }; + + _writer.WriteLine(response.ToString()); + _writer.Flush(); + } + catch { } + } + else + { + var response = ProcessStubPackage(package); - _writer.Write(response.ToString()); - _writer.Flush(); + _writer.Write(response.ToString()); + _writer.Flush(); + } } catch (Exception ex) { @@ -231,6 +257,45 @@ namespace Tango.StubsUtils.Service #endregion + #region Process Procedure + + public void ProcessProcedureProject(StubPackageRequestDTO package) + { + List arguments = package.Arguments.Skip(1).ToList(); + String projectPath = arguments[0]; + arguments = arguments.Skip(1).ToList(); + String json = File.ReadAllText(projectPath); + ProcedureProject project = ProcedureProject.FromJson(json); + var mainScript = project.Scripts.FirstOrDefault(x => x.IsEntryPoint); + + int index = 0; + + foreach (var match in Regex.Matches(mainScript.Code, "public const [S|s]tring.+;").OfType()) + { + if (index < arguments.Count) + { + String defLine = match.Value; + String replace = Regex.Replace(defLine, "(?<=\").*(?=\")", arguments[index]); + mainScript.Code = mainScript.Code.Replace(defLine, replace); + index++; + } + } + + TangoIOC.Default.ThrowOnRequestedTypeNotFound = false; + + StubsServiceProcedureContext context = new StubsServiceProcedureContext(project, Transporter, new StubsServiceProcedureLogger((message) => + { + _writer.WriteLine(message); + })); + + var session = project.Run(context).Result; + var obj = session.WaitForCompletion().Result; + + return; + } + + #endregion + #region Process Package private StubPackageResponseDTO ProcessStubPackage(StubPackageRequestDTO package) diff --git a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/StubsServiceProcedureContext.cs b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/StubsServiceProcedureContext.cs new file mode 100644 index 000000000..02eba672e --- /dev/null +++ b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/StubsServiceProcedureContext.cs @@ -0,0 +1,80 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Reactive.Concurrency; +using System.Reactive.Linq; +using System.Reflection; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Google.Protobuf; +using Tango.Core; +using Tango.Core.ExtensionMethods; +using Tango.FSE.Procedures; +using Tango.PMR; +using Tango.Transport; + +namespace Tango.StubsUtils.Service +{ + public class StubsServiceProcedureContext : ProcedureContext + { + private ITransporter _transporter; + + public StubsServiceProcedureContext(ProcedureProject project, ITransporter transporter, IProcedureLogger logger) : base(project, logger) + { + _transporter = transporter; + } + + public override IMessage Send(IMessage message, int? timeout = null) + { + TimeSpan? timespan = null; + + if (timeout != null) + { + timespan = TimeSpan.FromMilliseconds(timeout.Value); + } + + return _transporter.SendRequest(message, new TransportRequestConfig() + { + Timeout = timespan, + }).Result; + } + + public override void SendContinuous(IMessage message, Action callback, int? timeout = null) + { + TaskCompletionSource completion = new TaskCompletionSource(); + + TimeSpan? timespan = null; + + if (timeout != null) + { + timespan = TimeSpan.FromMilliseconds(timeout.Value); + } + + _transporter.SendContinuousRequest(message, new TransportContinuousRequestConfig() + { + Timeout = timespan, + ContinuousTimeout = timespan + }).ObserveOn(new NewThreadScheduler()).Subscribe((msg) => + { + try + { + callback?.Invoke(msg as T); + } + catch { } + }, (ex) => + { + completion.SetException(ex); + }, () => + { + completion.SetResult(true); + }); + + completion.Task.GetAwaiter().GetResult(); + } + } +} diff --git a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/StubsServiceProcedureLogger.cs b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/StubsServiceProcedureLogger.cs new file mode 100644 index 000000000..7b3f34a04 --- /dev/null +++ b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/StubsServiceProcedureLogger.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.FSE.Procedures; + +namespace Tango.StubsUtils.Service +{ + public class StubsServiceProcedureLogger : IProcedureLogger + { + private Action _writeLineCallback; + + public StubsServiceProcedureLogger(Action writeLineCallback) + { + _writeLineCallback = writeLineCallback; + } + + public void WriteLine(string text) + { + _writeLineCallback(text); + } + + public void Write(string text) + { + throw new NotImplementedException(); + } + + public void Clear() + { + throw new NotImplementedException(); + } + } +} diff --git a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/Tango.StubsUtils.Service.csproj b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/Tango.StubsUtils.Service.csproj index 40ec9d29f..035fa39e0 100644 --- a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/Tango.StubsUtils.Service.csproj +++ b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/Tango.StubsUtils.Service.csproj @@ -42,6 +42,22 @@ + + ..\..\packages\System.Reactive.Core.3.1.1\lib\net46\System.Reactive.Core.dll + + + ..\..\packages\System.Reactive.Interfaces.3.1.1\lib\net45\System.Reactive.Interfaces.dll + + + ..\..\packages\System.Reactive.Linq.3.1.1\lib\net46\System.Reactive.Linq.dll + + + ..\..\packages\System.Reactive.PlatformServices.3.1.1\lib\net46\System.Reactive.PlatformServices.dll + + + False + Reference Assemblies\System.ValueTuple.dll + @@ -53,9 +69,27 @@ + + + + {1754f846-4763-4000-807f-c7bfaa145db2} + Tango.FSE.Procedures + + + {2b29a699-1d65-463a-8250-a2ce81d019c9} + Tango.Scripting.Basic + + + {5812e1c6-abaa-4066-94ac-971c27b4f46a} + Tango.Scripting.Core + + + {da62fa39-668b-47a6-b0f2-d2c1daf777b0} + Tango.Scripting.Editors + {a34ee0f0-649d-41c8-8489-b6f1cc6924ee} Tango.Core diff --git a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/app.config b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/app.config index f63670818..c3e34655f 100644 --- a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/app.config +++ b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/app.config @@ -14,6 +14,86 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/packages.config b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/packages.config index 52834fea3..41d99b940 100644 --- a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/packages.config +++ b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/packages.config @@ -3,4 +3,8 @@ + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.SessionClient.CLI/Program.cs b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.SessionClient.CLI/Program.cs index d384ebba6..60f4c3def 100644 --- a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.SessionClient.CLI/Program.cs +++ b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.SessionClient.CLI/Program.cs @@ -41,7 +41,7 @@ namespace Tango.StubsUtils.SessionClient.CLI var writer = new StreamWriter(_client); - var jsonRequest = String.Join(" ", args); + var jsonRequest = String.Join("^", args); writer.WriteLine(jsonRequest); writer.Flush(); diff --git a/Software/Visual_Studio/Tango.sln b/Software/Visual_Studio/Tango.sln index 0593cb0ec..5ace654c3 100644 --- a/Software/Visual_Studio/Tango.sln +++ b/Software/Visual_Studio/Tango.sln @@ -457,6 +457,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tango.StubsUtils.SessionCli EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Notifications.Wpf", "StubsUtils\Notifications.Wpf\Notifications.Wpf.csproj", "{5C9A4F46-263D-4C23-B361-F09E14BB109E}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tango.StubsUtils.ProcedureClient.CLI", "StubsUtils\Tango.StubsUtils.ProcedureClient.CLI\Tango.StubsUtils.ProcedureClient.CLI.csproj", "{8F0BCFC8-AF0F-40D3-882A-902CD221A6DE}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -4332,6 +4334,26 @@ Global {5C9A4F46-263D-4C23-B361-F09E14BB109E}.Release|x64.Build.0 = Release 4.6.1|Any CPU {5C9A4F46-263D-4C23-B361-F09E14BB109E}.Release|x86.ActiveCfg = Release 4.6.1|Any CPU {5C9A4F46-263D-4C23-B361-F09E14BB109E}.Release|x86.Build.0 = Release 4.6.1|Any CPU + {8F0BCFC8-AF0F-40D3-882A-902CD221A6DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8F0BCFC8-AF0F-40D3-882A-902CD221A6DE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8F0BCFC8-AF0F-40D3-882A-902CD221A6DE}.Debug|ARM.ActiveCfg = Debug|Any CPU + {8F0BCFC8-AF0F-40D3-882A-902CD221A6DE}.Debug|ARM.Build.0 = Debug|Any CPU + {8F0BCFC8-AF0F-40D3-882A-902CD221A6DE}.Debug|ARM64.ActiveCfg = Debug|Any CPU + {8F0BCFC8-AF0F-40D3-882A-902CD221A6DE}.Debug|ARM64.Build.0 = Debug|Any CPU + {8F0BCFC8-AF0F-40D3-882A-902CD221A6DE}.Debug|x64.ActiveCfg = Debug|Any CPU + {8F0BCFC8-AF0F-40D3-882A-902CD221A6DE}.Debug|x64.Build.0 = Debug|Any CPU + {8F0BCFC8-AF0F-40D3-882A-902CD221A6DE}.Debug|x86.ActiveCfg = Debug|Any CPU + {8F0BCFC8-AF0F-40D3-882A-902CD221A6DE}.Debug|x86.Build.0 = Debug|Any CPU + {8F0BCFC8-AF0F-40D3-882A-902CD221A6DE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8F0BCFC8-AF0F-40D3-882A-902CD221A6DE}.Release|Any CPU.Build.0 = Release|Any CPU + {8F0BCFC8-AF0F-40D3-882A-902CD221A6DE}.Release|ARM.ActiveCfg = Release|Any CPU + {8F0BCFC8-AF0F-40D3-882A-902CD221A6DE}.Release|ARM.Build.0 = Release|Any CPU + {8F0BCFC8-AF0F-40D3-882A-902CD221A6DE}.Release|ARM64.ActiveCfg = Release|Any CPU + {8F0BCFC8-AF0F-40D3-882A-902CD221A6DE}.Release|ARM64.Build.0 = Release|Any CPU + {8F0BCFC8-AF0F-40D3-882A-902CD221A6DE}.Release|x64.ActiveCfg = Release|Any CPU + {8F0BCFC8-AF0F-40D3-882A-902CD221A6DE}.Release|x64.Build.0 = Release|Any CPU + {8F0BCFC8-AF0F-40D3-882A-902CD221A6DE}.Release|x86.ActiveCfg = Release|Any CPU + {8F0BCFC8-AF0F-40D3-882A-902CD221A6DE}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -4492,14 +4514,15 @@ Global {F423324C-7D0A-4512-BEBA-DF3A931A09F6} = {4A8BD6EC-41CF-46A9-B2CD-9D0DF6465963} {F1B727F5-ADF5-4A81-A740-7E64E48B29D4} = {4A8BD6EC-41CF-46A9-B2CD-9D0DF6465963} {5C9A4F46-263D-4C23-B361-F09E14BB109E} = {4A8BD6EC-41CF-46A9-B2CD-9D0DF6465963} + {8F0BCFC8-AF0F-40D3-882A-902CD221A6DE} = {4A8BD6EC-41CF-46A9-B2CD-9D0DF6465963} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution - BuildVersion_UseGlobalSettings = False - BuildVersion_AssemblyInfoFilename = Properties\AssemblyInfo.cs - BuildVersion_StartDate = 2000/1/1 - BuildVersion_UpdateFileVersion = False - BuildVersion_UpdateAssemblyVersion = True - BuildVersion_BuildVersioningStyle = None.None.Increment.DeltaBaseYearDayOfYear SolutionGuid = {7986F7F4-A86A-4994-B1B6-0988D7F057B6} + BuildVersion_BuildVersioningStyle = None.None.Increment.DeltaBaseYearDayOfYear + BuildVersion_UpdateAssemblyVersion = True + BuildVersion_UpdateFileVersion = False + BuildVersion_StartDate = 2000/1/1 + BuildVersion_AssemblyInfoFilename = Properties\AssemblyInfo.cs + BuildVersion_UseGlobalSettings = False EndGlobalSection EndGlobal -- cgit v1.3.1