From 8ff2c47cb2a5ea374da92b9c6e3e47ea87583e28 Mon Sep 17 00:00:00 2001 From: Stoyan Zlatev Date: Mon, 26 Feb 2024 10:23:37 +0100 Subject: [PATCH] SignalR integration in VB6 --- Common/Common.sln | 70 ++ Common/CommonConsole/CommonConsole.csproj | 7 +- Common/CommonConsole/FactoryUnseal.cs | 306 ----- Common/CommonConsole/Program.cs | 136 +-- Common/CommonConsole/ProgramLogFileHelper.cs | 1030 ----------------- Common/CommonConsole/ReflectionExtensions.cs | 43 - Common/CommonConsole/ServiceProvider.cs | 158 --- .../ViewModels/ReferenceMeterVM.cs | 2 +- Common/SignalR/DataDictionary.cs | 292 +++++ Common/SignalR/DataHub.cs | 124 ++ Common/SignalR/Properties/AssemblyInfo.cs | 15 + Common/SignalR/SignalR.csproj | 62 + Common/SignalR/app.config | 11 + Common/SignalR/packages.config | 4 + .../LaaProductionWeb/2024_01_03.debug | 0 .../LaaProductionWeb/2024_01_17.debug | 0 .../LaaProductionWeb/2024_02_06.debug | 4 - .../LaaProductionWeb/Hubs/DataHub.cs | 55 + .../LaaProductionWeb/LaaProductionWeb.csproj | 6 +- .../Views/Shared/_Layout.cshtml | 4 +- 20 files changed, 669 insertions(+), 1660 deletions(-) delete mode 100644 Common/CommonConsole/FactoryUnseal.cs delete mode 100644 Common/CommonConsole/ProgramLogFileHelper.cs delete mode 100644 Common/CommonConsole/ReflectionExtensions.cs delete mode 100644 Common/CommonConsole/ServiceProvider.cs create mode 100644 Common/SignalR/DataDictionary.cs create mode 100644 Common/SignalR/DataHub.cs create mode 100644 Common/SignalR/Properties/AssemblyInfo.cs create mode 100644 Common/SignalR/SignalR.csproj create mode 100644 Common/SignalR/app.config create mode 100644 Common/SignalR/packages.config delete mode 100644 LaaProductionWeb/LaaProductionWeb/2024_01_03.debug delete mode 100644 LaaProductionWeb/LaaProductionWeb/2024_01_17.debug delete mode 100644 LaaProductionWeb/LaaProductionWeb/2024_02_06.debug create mode 100644 LaaProductionWeb/LaaProductionWeb/Hubs/DataHub.cs diff --git a/Common/Common.sln b/Common/Common.sln index 39ff7016..2d7bd0c4 100644 --- a/Common/Common.sln +++ b/Common/Common.sln @@ -193,6 +193,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Plugins.Abstraction", "Plug EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Plugins.OMNI", "Plugins.OMNI\Plugins.OMNI.csproj", "{A04A3FE3-1443-45B2-9917-E90168567101}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Exchange", "Exchange", "{10E6BF23-549D-4303-8DD1-2EBB3028307F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SignalR", "SignalR\SignalR.csproj", "{ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}" +EndProject Global GlobalSection(SharedMSBuildProjectFiles) = preSolution Utils\DateTimeServerShared\DateTimeServerShared.projitems*{4806d89a-fbfb-41bc-aaa7-2242444bf55a}*SharedItemsImports = 4 @@ -4515,6 +4519,70 @@ Global {A04A3FE3-1443-45B2-9917-E90168567101}.XP32bit|x64.Build.0 = Release|Any CPU {A04A3FE3-1443-45B2-9917-E90168567101}.XP32bit|x86.ActiveCfg = Release|Any CPU {A04A3FE3-1443-45B2-9917-E90168567101}.XP32bit|x86.Build.0 = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}._MANUAL_CONTROL|Any CPU.ActiveCfg = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}._MANUAL_CONTROL|Any CPU.Build.0 = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}._MANUAL_CONTROL|Mixed Platforms.ActiveCfg = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}._MANUAL_CONTROL|Mixed Platforms.Build.0 = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}._MANUAL_CONTROL|x64.ActiveCfg = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}._MANUAL_CONTROL|x64.Build.0 = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}._MANUAL_CONTROL|x86.ActiveCfg = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}._MANUAL_CONTROL|x86.Build.0 = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.COM|Any CPU.ActiveCfg = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.COM|Any CPU.Build.0 = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.COM|Mixed Platforms.ActiveCfg = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.COM|Mixed Platforms.Build.0 = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.COM|x64.ActiveCfg = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.COM|x64.Build.0 = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.COM|x86.ActiveCfg = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.COM|x86.Build.0 = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.Debug|x64.ActiveCfg = Debug|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.Debug|x64.Build.0 = Debug|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.Debug|x86.ActiveCfg = Debug|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.Debug|x86.Build.0 = Debug|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.GenesisDisplayTool_V01|Any CPU.ActiveCfg = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.GenesisDisplayTool_V01|Any CPU.Build.0 = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.GenesisDisplayTool_V01|Mixed Platforms.ActiveCfg = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.GenesisDisplayTool_V01|Mixed Platforms.Build.0 = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.GenesisDisplayTool_V01|x64.ActiveCfg = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.GenesisDisplayTool_V01|x64.Build.0 = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.GenesisDisplayTool_V01|x86.ActiveCfg = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.GenesisDisplayTool_V01|x86.Build.0 = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.PerformTest|Any CPU.ActiveCfg = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.PerformTest|Any CPU.Build.0 = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.PerformTest|Mixed Platforms.ActiveCfg = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.PerformTest|Mixed Platforms.Build.0 = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.PerformTest|x64.ActiveCfg = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.PerformTest|x64.Build.0 = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.PerformTest|x86.ActiveCfg = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.PerformTest|x86.Build.0 = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.Release|Any CPU.Build.0 = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.Release|x64.ActiveCfg = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.Release|x64.Build.0 = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.Release|x86.ActiveCfg = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.Release|x86.Build.0 = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.ReleaseTest|Any CPU.ActiveCfg = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.ReleaseTest|Any CPU.Build.0 = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.ReleaseTest|Mixed Platforms.ActiveCfg = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.ReleaseTest|Mixed Platforms.Build.0 = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.ReleaseTest|x64.ActiveCfg = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.ReleaseTest|x64.Build.0 = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.ReleaseTest|x86.ActiveCfg = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.ReleaseTest|x86.Build.0 = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.XP32bit|Any CPU.ActiveCfg = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.XP32bit|Any CPU.Build.0 = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.XP32bit|Mixed Platforms.ActiveCfg = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.XP32bit|Mixed Platforms.Build.0 = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.XP32bit|x64.ActiveCfg = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.XP32bit|x64.Build.0 = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.XP32bit|x86.ActiveCfg = Release|Any CPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC}.XP32bit|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -4602,6 +4670,8 @@ Global {8BDA6853-0E0E-427F-AB49-546600A28944} = {68323534-4337-4E3A-89BC-11D8BB55343A} {D96612D9-5B00-42CB-9779-FE5C251BB78F} = {8BDA6853-0E0E-427F-AB49-546600A28944} {A04A3FE3-1443-45B2-9917-E90168567101} = {8BDA6853-0E0E-427F-AB49-546600A28944} + {10E6BF23-549D-4303-8DD1-2EBB3028307F} = {68323534-4337-4E3A-89BC-11D8BB55343A} + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC} = {10E6BF23-549D-4303-8DD1-2EBB3028307F} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {4BCB7B69-696C-436A-86F7-C91EA5588164} diff --git a/Common/CommonConsole/CommonConsole.csproj b/Common/CommonConsole/CommonConsole.csproj index ed8c2070..4fba2daa 100644 --- a/Common/CommonConsole/CommonConsole.csproj +++ b/Common/CommonConsole/CommonConsole.csproj @@ -50,11 +50,8 @@ - - - @@ -69,6 +66,10 @@ {b8523894-2c40-4ff0-a399-b7a91fae45ea} SqlExtensions + + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC} + SignalR + diff --git a/Common/CommonConsole/FactoryUnseal.cs b/Common/CommonConsole/FactoryUnseal.cs deleted file mode 100644 index 27f55287..00000000 --- a/Common/CommonConsole/FactoryUnseal.cs +++ /dev/null @@ -1,306 +0,0 @@ -namespace CommonConsole -{ - using OmniPlus; - - using System; - using System.Linq; - using System.Text; - - public static class OmniExtensions - { - public static void FactoryUnseal(OmniUniProConnection connection) - { - var _sealed = connection.Send(0xFD, 0x63)[1] == 1; - Console.WriteLine($"--- Sealed: {connection.Send(0xFD, 0x63)[1] == 1}"); - Console.WriteLine($"--- Version & Type: {Encoding.ASCII.GetString(connection.Send(0x05))}"); - Console.WriteLine("----------------------------------------------------------------------"); - Console.WriteLine("--- 0. Test parameters:"); - Console.WriteLine("--- SSSS: 1"); - Console.WriteLine("--- IIII: 2"); - Console.WriteLine("--- CCCC: 3"); - Console.WriteLine("--- CCCC: 4"); - Console.WriteLine("--- Command: FD 64 00 SS SS II II CC CC VV VV (Hash is BE)"); - Console.WriteLine("--- : FD 64 00 each part is LE except the last one"); - Console.WriteLine("--- 1.0 According docs: FD 64 00 01 00 02 00 03 00 00 04 (Hash is BE)"); - Console.WriteLine("--- 1.1 According docs: FD 64 00 04 00 00 03 00 02 00 01 (Hash is LE)"); - Console.WriteLine("--- 2.0 When all LE: FD 64 00 01 00 02 00 03 00 04 00 (Hash is BE)"); - Console.WriteLine("--- 2.1 When all LE: FD 64 00 00 04 00 03 00 02 00 01 (Hash is LE)"); - Console.WriteLine("--- 3.0 When all BE: FD 64 00 00 01 00 02 00 03 00 04 (Hash is BE)"); - Console.WriteLine("--- 3.1 When all BE: FD 64 00 04 00 03 00 02 00 01 00 (Hash is LE)"); - Console.WriteLine("----------------------------------------------------------------------"); - - if (_sealed) - { - //____________________0_____1_____2_____3_____4_____5_____6_____7_____8_____9____10__ - //_____________________________________SS____SS____II____II____CC____CC____VV____VV__ - byte[] request = new byte[] { 0xFD, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - - Console.WriteLine("--- 1.0 According docs: hash is sent BE"); - Console.WriteLine("----------------------------------------------------------------------"); - - byte[] hash = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - // Test case 1 - according documentation - hash BE - connection.Calculate_IIII_LE().CopyTo(hash, 2); - connection.Calculate_CCCC_LE().CopyTo(hash, 4); - connection.Calculate_VVVV_LE().CopyTo(hash, 6); - connection.Calculate_SSSS_LE().CopyTo(hash, 0); // .Reverse().ToArray() - - Array.Copy(hash, 0, request, 3, 8); - connection.Send(request); - } - - //Console.WriteLine("----------------------------------------------------------------------"); - //Console.WriteLine("--- 1.1 According docs: hash is sent LE"); - //Console.WriteLine("----------------------------------------------------------------------"); - //hash = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - //// Test case 1 - according documentation - hash LE - //connection.Calculate_IIII_LE().CopyTo(hash, 2); - //connection.Calculate_CCCC_LE().CopyTo(hash, 4); - //connection.Calculate_VVVV_LE().CopyTo(hash, 6); - //connection.Calculate_SSSS_LE().Reverse().ToArray().CopyTo(hash, 0); - - //Array.Copy(hash.Reverse().ToArray(), 0, request, 3, 8); - //connection.Send(request); - //Console.WriteLine("----------------------------------------------------------------------"); - //Console.WriteLine("--- 2.0 When all LE: hash is sent BE"); - //Console.WriteLine("----------------------------------------------------------------------"); - - //hash = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - //// Test case 2 all Little endian - hash BE - //connection.Calculate_IIII_LE().CopyTo(hash, 2); - //connection.Calculate_CCCC_LE().CopyTo(hash, 4); - //connection.Calculate_VVVV_LE().CopyTo(hash, 6); - //connection.Calculate_SSSS_LE().CopyTo(hash, 0); - - //Array.Copy(hash, 0, request, 3, 8); - //connection.Send(request); - //Console.WriteLine("----------------------------------------------------------------------"); - //Console.WriteLine("--- 2.1 When all LE: hash is sent LE"); - //Console.WriteLine("----------------------------------------------------------------------"); - - //hash = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - //// Test case 2 all Little endian - hash LE - //connection.Calculate_IIII_LE().CopyTo(hash, 2); - //connection.Calculate_CCCC_LE().CopyTo(hash, 4); - //connection.Calculate_VVVV_LE().CopyTo(hash, 6); - //connection.Calculate_SSSS_LE().CopyTo(hash, 0); - - //Array.Copy(hash.Reverse().ToArray(), 0, request, 3, 8); - //connection.Send(request); - //Console.WriteLine("----------------------------------------------------------------------"); - //Console.WriteLine("--- 3.0 When all BE: hash is sent BE"); - //Console.WriteLine("----------------------------------------------------------------------"); - - //hash = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - //// Test case 3 all Big endian - hash BE - //connection.Calculate_IIII_LE().Reverse().ToArray().CopyTo(hash, 2); - //connection.Calculate_CCCC_LE().Reverse().ToArray().CopyTo(hash, 4); - //connection.Calculate_VVVV_LE().Reverse().ToArray().CopyTo(hash, 6); - //connection.Calculate_SSSS_LE().Reverse().ToArray().CopyTo(hash, 0); - - //Array.Copy(hash, 0, request, 3, 8); - //connection.Send(request); - //Console.WriteLine("----------------------------------------------------------------------"); - //Console.WriteLine("--- 3.1 When all BE: hash is sent LE"); - //Console.WriteLine("----------------------------------------------------------------------"); - - //hash = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - //// Test case 3 all Big endian - hash BE - //connection.Calculate_IIII_LE().Reverse().ToArray().CopyTo(hash, 2); - //connection.Calculate_CCCC_LE().Reverse().ToArray().CopyTo(hash, 4); - //connection.Calculate_VVVV_LE().Reverse().ToArray().CopyTo(hash, 6); - //connection.Calculate_SSSS_LE().Reverse().ToArray().CopyTo(hash, 0); - - //Array.Copy(hash.Reverse().ToArray(), 0, request, 3, 8); - //connection.Send(request); - - Console.WriteLine("----------------------------------------------------------------------"); - Console.WriteLine($"--- Sealed: {connection.Send(0xFD, 0x63)[1] == 1}"); - } - - static byte[] Calculate_SSSS_LE(this OmniUniProConnection connection) - { - // response with status byte at the start - byte[] response = connection.Send(0xFD, 0x3D); - - ushort result = 0; - - if (response[0] == 0x01) - { - // returns uint32 from 4 little endian bytes - uint seconds = BitConverter.ToUInt32(response, 1); - Console.WriteLine($"--- Seconds active: {seconds}"); - - result = (ushort)((seconds >> 8) & 0xFFFF); - Console.WriteLine($"--- (x >> 8) & 0xFFFF: {result}"); - } - - var ssss_LE = BitConverter.GetBytes(result); - - // returns 2 little endian bytes array from the ushort result - Console.WriteLine($"--- SSSS (LE): {BitConverter.ToString(ssss_LE).Replace("-", " ")}"); - - return ssss_LE; - } - - static byte[] Calculate_IIII_LE(this OmniUniProConnection connection) - { - // response with status byte at the start - byte[] response = connection.Send(0x01); - int responseLength = Math.Max(response.Length - 1, 0); - string factoryID = Encoding - .ASCII - .GetString(response, 1, responseLength) - .Trim('\0') - .Trim(); - ushort crcU16 = 0; - - Console.WriteLine($"--- Factory ID: {factoryID}"); - - if (response[0] == 0x01) - { - byte[] plainData; - - if (string.IsNullOrWhiteSpace(factoryID)) - { - plainData = Encoding.ASCII.GetBytes("Factory"); - } - else - { - plainData = Encoding.ASCII.GetBytes(factoryID); - } - - Console.WriteLine($"--- Bytes to encode: {BitConverter.ToString(plainData).Replace("-", " ")}"); - - foreach (byte byteU8 in plainData) - { - ushort tempU16 = crcU16; - - crcU16 = (ushort)(tempU16 >> 8); - crcU16 += (ushort)(tempU16 << 8); - - crcU16 ^= byteU8; - - tempU16 = (ushort)((crcU16 >> 4) & 0x000F); - crcU16 ^= tempU16; - - tempU16 = (ushort)((crcU16 & 0x000F) << 12); - crcU16 ^= tempU16; - - tempU16 = (ushort)((crcU16 & 0x00FF) << 5); - crcU16 ^= tempU16; - } - } - - byte[] crc_Bytes_LE = BitConverter.GetBytes(crcU16); - - Console.WriteLine($"--- CRC uint16: {crcU16}"); - Console.WriteLine($"--- IIII (LE): {BitConverter.ToString(crc_Bytes_LE).Replace("-", " ")}"); - - // returns 2 little endian bytes array from the ushort crcU16 - return crc_Bytes_LE; - } - - static byte[] Calculate_CCCC_LE(this OmniUniProConnection connection) - { - // response with status byte at the start - byte[] response = connection.Send(0x07); - int responseLength = Math.Max(response.Length - 1, 0); - string customerText = Encoding - .ASCII - .GetString(response, 1, responseLength) - .Trim('\0'); - Console.WriteLine($"--- Customer text: {customerText}"); - byte[] cccc = new byte[2]; - - if (response[0] == 0x01) - { - byte[] plainData = new byte[4]; - - if (string.IsNullOrWhiteSpace(customerText)) - { - plainData = Encoding.ASCII.GetBytes("Factory"); - } - else if (customerText.Length < 4) - { - Encoding.ASCII.GetBytes(customerText).CopyTo(plainData, 0); - } - else - { - plainData = Encoding.ASCII.GetBytes(customerText); - } - - Console.WriteLine($"--- Text to encode: {Encoding.ASCII.GetString(plainData)}"); - Console.Write("--- |"); - - byte[] bits = new byte[16]; - string hex = string.Empty; - - // for each byte from the first 4 bytes - for (int i = 0; i < 4; i++) - { - byte current = plainData[i]; - byte count1 = 0; - - Console.Write($"{current}:"); - - // count bits set to 1 - for (int b = 0; b < 8; b++) - { - int bit = current >> b & 1; - count1 += (byte)bit; - - Console.Write(bit); - } - - hex += count1; - - Console.Write($":{count1}|"); - } - - Console.WriteLine(); - - cccc[0] = Convert.ToByte(hex.Substring(0, 2), 16); - cccc[1] = Convert.ToByte(hex.Substring(2, 2), 16); - } - - Console.WriteLine($"--- CCCC (LE): {BitConverter.ToString(cccc).Replace("-", " ")}"); - - return cccc; - } - - static byte[] Calculate_VVVV_LE(this OmniUniProConnection connection) - { - byte[] response = connection.Send(0x13); - int responseLength = Math.Max(response.Length - 1, 0); - string readingPreset = Encoding - .ASCII - .GetString(response, 1, responseLength) - .Trim('\0'); - Console.WriteLine($"--- Customer text: {readingPreset}"); - Console.WriteLine($"--- Reading preset: {Encoding.ASCII.GetString(response)}"); - - ushort result = 0; - - if (response[0] == 0x01) - { - byte[] bytes = new byte[4]; - Array.Copy(response, 3, bytes, 0, 4); - bytes = bytes.Reverse().ToArray(); - - // copies response bytes 3..6 - uint number = BitConverter.ToUInt32(bytes, 0); - Console.WriteLine($"--- UInt32: {number}"); - - result = (ushort)(number % 11); - Console.WriteLine($"--- UInt32 % 11: {result}"); - } - - byte[] vvvv_LE = BitConverter.GetBytes(result); - Console.WriteLine($"--- VVVV (LE): {BitConverter.ToString(vvvv_LE).Replace("-", " ")}"); - - // returns 2 little endian bytes array from the ushort result - return vvvv_LE; - } - } -} diff --git a/Common/CommonConsole/Program.cs b/Common/CommonConsole/Program.cs index ab3a3445..52f534f3 100644 --- a/Common/CommonConsole/Program.cs +++ b/Common/CommonConsole/Program.cs @@ -1,127 +1,39 @@ namespace CommonConsole { - using Newtonsoft.Json; - using System; - using System.Collections.Generic; - using System.Net.Http; - using System.Text; - using System.Threading.Tasks; + using SignalR; - public partial class Program + using System; + + public class Program { - private static readonly HttpClient httpClient = new HttpClient(); + const string URL = "http://sla12iis01.emea.sensus.net/LaaProductionWeb"; + // const string URL = "http://localhost:52822/LaaProductionWeb/"; public static void Main() { - //Task.Factory - // .StartNew(async () => - // { - // using (var httpRequestMessage = new HttpRequestMessage()) - // { - // httpRequestMessage.Content = new StringContent("{}", Encoding.UTF8, "application/json"); - // httpRequestMessage.Method = HttpMethod.Post; - // httpRequestMessage.RequestUri = new Uri("http://localhost:52822/LaaProductionWeb/api/Login/AD"); - - // //using (var httpResponseMessage = await httpClient.SendAsync(httpRequestMessage)) - // //{ - // // Console.WriteLine(httpResponseMessage); - - // // using (var httpContent = httpResponseMessage.Content) - // // { - // // var content = await httpContent.ReadAsStringAsync(); - // // var obj = JsonConvert.DeserializeObject(content); - - // // Console.WriteLine(JsonConvert.SerializeObject(obj, Formatting.Indented)); - // // } - // //} - // } - // }); - - Console.ReadKey(); - } - } -} - -/** - - public void SaveMeterState() - { - if (this.MeterNr == NA) + var client = new DataHub(); + client.Connect(URL); + client.DataReceived += data => { - return; - } + for (int i = 0; i < data.Count; i++) + { + var proeprty = data.GetProperty(i); + var value = data.GetString(proeprty); + Console.WriteLine($"{proeprty} = {value}"); + } - if (OmniContext.Current.Exists(this.MeterNr)) - { - return; - } - - var commands = new List - { - new byte[] { 0x01 }, - new byte[] { 0x03 }, - new byte[] { 0x05 }, - new byte[] { 0x07 }, - new byte[] { 0x09 }, - new byte[] { 0x0B }, - new byte[] { 0x0D }, - new byte[] { 0x0F }, - new byte[] { 0x11 }, - new byte[] { 0x13 }, - new byte[] { 0x15 }, - new byte[] { 0x17 }, - new byte[] { 0x1F }, - new byte[] { 0x21 }, - new byte[] { 0x25 }, - new byte[] { 0x27 }, - new byte[] { 0x29 }, - new byte[] { 0x2B }, - new byte[] { 0xFD, 0x02 }, - new byte[] { 0xFD, 0x05 }, - new byte[] { 0xFD, 0x06 }, - new byte[] { 0xFD, 0x08 }, - new byte[] { 0xFD, 0x0A }, - new byte[] { 0xFD, 0x0E }, - new byte[] { 0xFD, 0x10 }, - new byte[] { 0xFD, 0x12 }, - new byte[] { 0xFD, 0x14 }, - new byte[] { 0xFD, 0x22 }, - new byte[] { 0xFD, 0x24 }, - new byte[] { 0xFD, 0x26 }, - new byte[] { 0xFD, 0x28 }, - new byte[] { 0xFD, 0x39 }, - new byte[] { 0xFD, 0x3D }, - new byte[] { 0xFD, 0x55 }, - new byte[] { 0xFD, 0x63 }, - new byte[] { 0xFD, 0x7B }, - new byte[] { 0xFD, 0x7E, 0x00 }, - new byte[] { 0xFD, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, - new byte[] { 0xFD, 0x8B }, - new byte[] { 0xFD, 0xA9 }, - new byte[] { 0xFD, 0xAA }, - new byte[] { 0xFD, 0xAC }, - new byte[] { 0xFD, 0xB7 }, - new byte[] { 0xFD, 0xBC }, - new byte[] { 0xFD, 0xC2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, - new byte[] { 0xFD, 0xC3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, - new byte[] { 0xFD, 0xC4, 0x00 }, - new byte[] { 0xFD, 0xC6 }, - new byte[] { 0xFD, 0xC7 } + Console.WriteLine(); }; - var meterState = new StringBuilder(); + var counter = 0; - foreach (var cmd in commands) + while (true) { - var response = this.connection.Send(cmd); - var entry = $"{BitConverter.ToString(cmd)}:{BitConverter.ToString(response)};"; - - meterState.Append(entry); + var dictionary = new DataDictionary(); + dictionary.AddInt(nameof(counter), counter++); + dictionary.AddString("message", Console.ReadLine()); + client.Send(dictionary); } - - OmniContext.Current.Add(this.MeterNr, meterState.ToString()); - - this.WriteToLog(); } - -*/ + } +} \ No newline at end of file diff --git a/Common/CommonConsole/ProgramLogFileHelper.cs b/Common/CommonConsole/ProgramLogFileHelper.cs deleted file mode 100644 index 73804b9b..00000000 --- a/Common/CommonConsole/ProgramLogFileHelper.cs +++ /dev/null @@ -1,1030 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Data; -using System.Globalization; -using System.Linq; -using System.Text; -using Xylem.Common.Logic.ServiceCore; - -namespace CommonConsole -{ - public class ProgramLogFileHelper - { - - public class resultRep - { - public double GreenLEDTime = 0.0; - public string Date { get; internal set; } - public DateTime DataDate { get; internal set; } - public string CustomerName { get; internal set; } - public string PcbId { get; internal set; } - public string Core { get; internal set; } - public string FW { get; internal set; } - public string POWERMON_BatteryVoltage { get; internal set; } - public string POWERMON_BatteryQuantity { get; internal set; } - public string GENESISFLOW_ScaledBilling { get; internal set; } - public string GENESISFLOW_SampleRate { get; internal set; } - public string IRDA_AdapterID { get; internal set; } - public string IRDA_PulseReportRate { get; internal set; } - public string METROLOGYASST_PulseResolution { get; internal set; } - public string METROLOGYASST_PulseEvenDistribution { get; internal set; } - public string POWERMON_TotalUsedCharge { get; internal set; } - public string POWERMON_TotalUsedSeconds { get; internal set; } - public string GENESISFLOW_LedMode { get; internal set; } - public string METROLOGYASST_PulseWeight { get; internal set; } - public string METROLOGYASST_PulseMode { get; internal set; } - public string METROLOGYASST_PulseLength { get; internal set; } - public String Source { get; internal set; } - public Boolean PwFileUpdate { get; internal set; } = false; - - - public void Calc() - { - - string[] formats = { "dd/MM/yyyy", "dd/M/yyyy", "d/M/yyyy", "d/MM/yyyy", - "dd/MM/yy", "dd/M/yy", "d/M/yy", "d/MM/yy"}; - - if (string.IsNullOrEmpty(Date) && DataDate == new DateTime()) - { - return; - } - if (DataDate == new DateTime()) - { - - - if (Date.Contains(":")) - { - if (DateTime.TryParseExact(Date.Trim().Substring(0, "yyyy-MM-dd".Length), "yyyy-MM-dd", null, DateTimeStyles.None, out var tmp)) - { - DataDate = tmp; - } - else - { - - } - - //2019-10-30 15:46:18.767 - } - else if (Date.Contains("/")) - { - if (DateTime.TryParseExact(Date.Trim(), "mm/dd/yyyy", new CultureInfo("us-US"), DateTimeStyles.None, out var tmp)) - { - DataDate = tmp; - } - else - - { - - var strDate = Date.Trim().Split('/'); - if (strDate[0].Length == 1) - { - strDate[0] = "0" + strDate[0]; - } - if (strDate[1].Length == 1) - { - strDate[1] = "0" + strDate[1]; - } - if (DateTime.TryParseExact(strDate[1] + "." + strDate[0] + "." + strDate[2], "dd.MM.yyyy", null, DateTimeStyles.None, out var tmphelp)) - { - DataDate = tmphelp; - } - else - { - - } - } - } - else if (Date.Contains("-")) - { - if (DateTime.TryParseExact(Date.Trim(), "dd.MM.yyyy", null, DateTimeStyles.None, out var tmp)) - { - DataDate = tmp; - } - else - { - - } - } - else - { - if (DateTime.TryParseExact(Date.Trim(), "dd.MM.yyyy", null, DateTimeStyles.None, out var tmp)) - { - DataDate = tmp; - } - else - { - - var strDate = Date.Replace(" ", "").Split('.'); - if (strDate[0].Length == 1) - { - strDate[0] = "0" + strDate[0]; - } - if (strDate[1].Length == 1) - { - strDate[1] = "0" + strDate[1]; - } - if (DateTime.TryParseExact(strDate[1] + "." + strDate[0] + "." + strDate[2], "dd.MM.yyyy", null, DateTimeStyles.None, out var tmphelp)) - { - DataDate = tmphelp; - } - - } - } - } - - if (!string.IsNullOrEmpty(POWERMON_BatteryQuantity)) - { - if (POWERMON_BatteryQuantity.Contains("1")) - { - BatteryQuantity = 1; - } - else - { - BatteryQuantity = 2; - } - - } - DrainedBatteryLoad_uAs = 0; - ExceededLifeTime_s = 0; - if (!string.IsNullOrEmpty(POWERMON_TotalUsedCharge) && POWERMON_TotalUsedCharge != "NULL") - { - if (POWERMON_TotalUsedCharge.Contains(" - ")) - { - var trim = POWERMON_TotalUsedCharge.LastIndexOf(" - ") + 3; - POWERMON_TotalUsedCharge = POWERMON_TotalUsedCharge.Substring(trim, POWERMON_TotalUsedCharge.Length - trim); - UInt64.TryParse(POWERMON_TotalUsedCharge, out DrainedBatteryLoad_uAs); - } - else - { - if (POWERMON_TotalUsedCharge.Length > "E2-AF-58-A3-00-00-00-00".Length) - { - POWERMON_TotalUsedCharge = POWERMON_TotalUsedCharge.Substring(0, "E2-AF-58-A3-00-00-00-00".Length); - } - String[] arr = POWERMON_TotalUsedCharge.Split('-'); - - Byte[] raw = new Byte[arr.Length]; - for (Int32 i = arr.Length - 1; i >= 0; i--) - { - raw[i] = Convert.ToByte(arr[i], 16); - } - if (POWERMON_TotalUsedCharge.Length == "C5-1F-04-BD".Length) - { - Calculated = false; - return; - } - DrainedBatteryLoad_uAs = BitConverter.ToUInt64(raw, 0); - } - - } - if (!string.IsNullOrEmpty(POWERMON_TotalUsedSeconds) && POWERMON_TotalUsedSeconds != "NULL") - { - if (POWERMON_TotalUsedSeconds.Contains(" - ")) - { - var trim = POWERMON_TotalUsedSeconds.LastIndexOf(" - ") + 3; - POWERMON_TotalUsedSeconds = POWERMON_TotalUsedSeconds.Substring(trim, POWERMON_TotalUsedSeconds.Length - trim); - UInt32.TryParse(POWERMON_TotalUsedSeconds, out ExceededLifeTime_s); - } - else - { - String[] arr = POWERMON_TotalUsedSeconds.Split('-'); - - Byte[] raw = new Byte[arr.Length]; - for (Int32 i = arr.Length - 1; i >= 0; i--) - { - raw[i] = Convert.ToByte(arr[i], 16); - } - ExceededLifeTime_s = BitConverter.ToUInt32(raw, 0); - } - - - } - - - - if (DrainedBatteryLoad_uAs == 0 || ExceededLifeTime_s == 0) - { - return; - } - - - - - - InitialBatteryLoad_mAh = 19000; - - - - - - // Calculate the initial overall battery load of all batteries in uAs as the drained load uses this unit. - var initialBatteryLoad_uAs = 1000 * 3600 * InitialBatteryLoad_mAh * (UInt64)BatteryQuantity; - - // Relation of drained to initial load, set the battery to fully unloaded for failed check to force a recalculation - var drainedBatteryLoad_rel = 1.0; - if (initialBatteryLoad_uAs != 0) - { - drainedBatteryLoad_rel = (Double)DrainedBatteryLoad_uAs / initialBatteryLoad_uAs; - } - - DrainedBatteryLoadPercent = drainedBatteryLoad_rel * 100; - - // The estimated life time uses the drained load over the actual exceeded life time and assumes, that further on - // an identical load will be consumed over the remaining life cycle. The initial load will be multiplied with the - // drained load relation. Set the estimated time to the exceeded time to force a recalculation on failed input. - var estimatedLifeTime_s = (Double)ExceededLifeTime_s; - if (drainedBatteryLoad_rel != 0.0) - { - estimatedLifeTime_s = ExceededLifeTime_s / drainedBatteryLoad_rel; - } - - var remainingLifetime_s = estimatedLifeTime_s - ExceededLifeTime_s; - // convert the seconds to years - RemainingLifeTimeYears = remainingLifetime_s / 3600 / 24 / 365.25; - - - UNTLimit = 1368000000 + (ExceededLifeTime_s * 77.7); - // + (POWERMON_TotalUsedSeconds * 77.7) This allows 1 % battery capacity usage during manufacture on top of an average consumption of 77.7uA - - - Calculated = true; - - } - public UInt32 ExceededLifeTime_s; - public UInt64 DrainedBatteryLoad_uAs; - public Int32 BatteryQuantity; - public UInt64 InitialBatteryLoad_mAh; - public Double DrainedBatteryLoadPercent; - public Double RemainingLifeTimeYears; - - public Double UNTLimit { get; private set; } - - public bool Calculated = false; - - - } - - private class GreenHistoryItem - { - - public int SR = 2; - public DateTime Time { get; set; } - - public bool Idel { get; set; } = false; - - public bool LedMode { get; set; } = false; - - public string Remark { get; set; } - - public bool HighConsumption { get; set; } - - public double SecondsInHighConsumption { get; set; } - - public void Cal() - { - if (Idel) - { - HighConsumption = false; - return; - } - if (!LedMode) - { - HighConsumption = false; - return; - } - if (SR == 2) - { - HighConsumption = false; - return; - } - HighConsumption = true; - } - - } - - public static void MainHelper(string[] args) - { - - #region stuff - //var listRes = new Dictionary>(); - - //foreach (var repFile in Directory.GetFiles("E:\\bat\\report\\")) - //{ - // var newlines = new List(); - - // var alllinesfromfile = File.ReadAllLines(repFile); - - // var R = new resultRep(); - // R.Source = "CUST"; - // foreach (var lc in alllinesfromfile) - // { - // if (lc.StartsWith("Datum:")) - // { R.Date = lc.Replace("Datum:", ""); } - // if (lc.StartsWith("Date:")) - // { R.Date = lc.Replace("Date:", ""); } - - - // if (lc.StartsWith("Kundenname:")) - // { R.CustomerName = lc.Replace("Kundenname:", ""); } - // if (lc.StartsWith("Customer Name:")) - // { R.CustomerName = lc.Replace("Customer Name:", ""); } - - // if (lc.StartsWith("PCB ID:")) - // { R.PcbId = lc.Replace("PCB ID:", "").Trim(); ; } - - // if (lc.StartsWith("Systemkern-Version:")) - // { R.Core = lc.Replace("Systemkern-Version:", ""); } - - // if (lc.StartsWith("System Core Revision:")) - // { R.Core = lc.Replace("System Core Revision:", ""); } - - - // if (lc.StartsWith("Nummer: 0x18 - V:")) - // { R.FW = lc.Replace("Nummer: 0x18 - V:", "").Replace(" - Name: FLEXNETVERSION", ""); } - - // if (lc.StartsWith("AppId: 0x18 - V:")) - // { R.FW = lc.Replace("AppId: 0x18 - V:", "").Replace(" - AppName: FLEXNETVERSION", ""); } - - - // if (lc.StartsWith("Lese Register: POWERMON_BatteryVoltage")) - // { R.POWERMON_BatteryVoltage = lc.Replace("Lese Register: POWERMON_BatteryVoltage", ""); } - // if (lc.StartsWith("Lese Register: POWERMON_BatteryQuantity")) - // { R.POWERMON_BatteryQuantity = lc.Replace("Lese Register: POWERMON_BatteryQuantity", ""); } - - // if (lc.StartsWith("Lese Register: POWERMON_TotalUsedCharge")) - // { R.POWERMON_TotalUsedCharge = lc.Replace("Lese Register: POWERMON_TotalUsedCharge", ""); } - - // if (lc.StartsWith("Lese Register: POWERMON_TotalUsedSeconds")) - // { R.POWERMON_TotalUsedSeconds = lc.Replace("Lese Register: POWERMON_TotalUsedSeconds", ""); } - // if (lc.StartsWith("Lese Register: GENESISFLOW_LedMode")) - // { R.GENESISFLOW_LedMode = lc.Replace("Lese Register: GENESISFLOW_LedMode", ""); } - // if (lc.StartsWith("Lese Register: METROLOGYASST_PulseWeight")) - // { R.METROLOGYASST_PulseWeight = lc.Replace("Lese Register: METROLOGYASST_PulseWeight", ""); } - // if (lc.StartsWith("Lese Register: METROLOGYASST_PulseMode")) - // { R.METROLOGYASST_PulseMode = lc.Replace("Lese Register: METROLOGYASST_PulseMode", ""); } - // if (lc.StartsWith("Lese Register: METROLOGYASST_PulseLength")) - // { R.METROLOGYASST_PulseLength = lc.Replace("Lese Register: METROLOGYASST_PulseLength", ""); } - - // if (lc.StartsWith("Lese Register: METROLOGYASST_PulseEvenDistribution")) - // { R.METROLOGYASST_PulseEvenDistribution = lc.Replace("Lese Register: METROLOGYASST_PulseEvenDistribution", ""); } - - // if (lc.StartsWith("Lese Register: METROLOGYASST_PulseResolution")) - // { R.METROLOGYASST_PulseResolution = lc.Replace("Lese Register: METROLOGYASST_PulseResolution", ""); } - - // if (lc.StartsWith("Lese Register: IRDA_PulseReportRate")) - // { R.IRDA_PulseReportRate = lc.Replace("Lese Register: IRDA_PulseReportRate", ""); } - - // if (lc.StartsWith("Lese Register: IRDA_AdapterID ")) - // { R.IRDA_AdapterID = lc.Replace("Lese Register: IRDA_AdapterID ", ""); } - - // if (lc.StartsWith("Lese Register: GENESISFLOW_SampleRate ")) - // { R.GENESISFLOW_SampleRate = lc.Replace("Lese Register: GENESISFLOW_SampleRate ", ""); } - - // if (lc.StartsWith("Lese Register: GENESISFLOW_ScaledBilling ")) - // { R.GENESISFLOW_ScaledBilling = lc.Replace("Lese Register: GENESISFLOW_ScaledBilling ", ""); } - - - // if (lc.StartsWith("Read register: POWERMON_BatteryVoltage")) - // { R.POWERMON_BatteryVoltage = lc.Replace("Read register: POWERMON_BatteryVoltage", ""); } - // if (lc.StartsWith("Read register: POWERMON_BatteryQuantity")) - // { R.POWERMON_BatteryQuantity = lc.Replace("Read register: POWERMON_BatteryQuantity", ""); } - - // if (lc.StartsWith("Read register: POWERMON_TotalUsedCharge")) - // { R.POWERMON_TotalUsedCharge = lc.Replace("Read register: POWERMON_TotalUsedCharge", ""); } - - // if (lc.StartsWith("Read register: POWERMON_TotalUsedSeconds")) - // { R.POWERMON_TotalUsedSeconds = lc.Replace("Read register: POWERMON_TotalUsedSeconds", ""); } - // if (lc.StartsWith("Read register: GENESISFLOW_LedMode")) - // { R.GENESISFLOW_LedMode = lc.Replace("Read register: GENESISFLOW_LedMode", ""); } - // if (lc.StartsWith("Read register: METROLOGYASST_PulseWeight")) - // { R.METROLOGYASST_PulseWeight = lc.Replace("Read register: METROLOGYASST_PulseWeight", ""); } - // if (lc.StartsWith("Read register: METROLOGYASST_PulseMode")) - // { R.METROLOGYASST_PulseMode = lc.Replace("Read register: METROLOGYASST_PulseMode", ""); } - // if (lc.StartsWith("Read register: METROLOGYASST_PulseLength")) - // { R.METROLOGYASST_PulseLength = lc.Replace("Read register: METROLOGYASST_PulseLength", ""); } - - // if (lc.StartsWith("Read register: METROLOGYASST_PulseEvenDistribution")) - // { R.METROLOGYASST_PulseEvenDistribution = lc.Replace("Read register: METROLOGYASST_PulseEvenDistribution", ""); } - - // if (lc.StartsWith("Read register: METROLOGYASST_PulseResolution")) - // { R.METROLOGYASST_PulseResolution = lc.Replace("Read register: METROLOGYASST_PulseResolution", ""); } - - // if (lc.StartsWith("Read register: IRDA_PulseReportRate")) - // { R.IRDA_PulseReportRate = lc.Replace("Read register: IRDA_PulseReportRate", ""); } - - // if (lc.StartsWith("Read register: IRDA_AdapterID ")) - // { R.IRDA_AdapterID = lc.Replace("Read register: IRDA_AdapterID ", ""); } - - // if (lc.StartsWith("Read register: GENESISFLOW_SampleRate ")) - // { R.GENESISFLOW_SampleRate = lc.Replace("Read register: GENESISFLOW_SampleRate ", ""); } - - // if (lc.StartsWith("Read register: GENESISFLOW_ScaledBilling ")) - // { R.GENESISFLOW_ScaledBilling = lc.Replace("Read register: GENESISFLOW_ScaledBilling ", ""); } - - // if (lc.StartsWith("Password file restore succeeded")) - // { - // R.PwFileUpdate = true; - // } - // if (lc.StartsWith("Paßwortdatei erfolgreich wiederhergestellt")) - // { - // R.PwFileUpdate = true; - // } - // // - // } - // if (!string.IsNullOrEmpty(R.PcbId)) - // { - // if (listRes.ContainsKey(R.PcbId)) - // { - // listRes[R.PcbId].Add(R); - // } - // else - // { - // listRes.Add(R.PcbId, new List() { R }); - // } - // } - - //} - - - - - //var listEOL = new Dictionary>(); - - //foreach (var item in listRes) - //{ - // Console.WriteLine($"'{item.Key}', "); - - //} - - - //Console.ReadLine(); - - - - //foreach (var line in File.ReadAllLines("E:\\bat\\History.csv")) - //{ - // var csvelm = line.Split(';'); - // var cPcbId = csvelm[1]; - // if (cPcbId.Length > 5) - // { - // var cAddress = csvelm[2]; - // var cValue = csvelm[3]; - // var cDate = csvelm[4]; - - - // } - - - //} - var listEOL = new Dictionary>(); - var pcbCheck = new List() { - 222830007, -222830022 , -222830068 , -222830076 , -222830077 , -222830097 , -222830099 , -222830101 , -222830109 , -222830112 , -222830118 , -222830121 , -222830153 , -222830172 , -222830174 , -222830213 , -222830249 , -222830296 , -230930011 , -230930019 , -230930032 , -230930049 , -230930051 , -230930059 , -230930122 , -230930127 , -230930128 , -230930129 , -230930136 , -230930137 , -230930143 , -230930149 , -230930227 , -230930228 , -230930237 , -230930277 , -230930279 , -230930280 , -230930281 , -230930299 , -230930308 , -230930325 , -230930329 , -230930382 , -230930387 , -230930391 , -230930396 , -230930403 , -230930408 , -230930411 }; - #endregion - - - if (true) - { - foreach (var item in pcbCheck) - { - //Console.WriteLine($"'{item.Key}', "); - //foreach (var re in item.Value) - //{ - // re.Calc(); - //} - var sbq = new StringBuilder(); - - sbq.AppendLine(" declare @PcbID as nvarchar(50) "); - sbq.AppendLine(" declare @Adress as nvarchar(50) "); - - sbq.AppendLine($" set @PcbID = '{item}' "); - - sbq.AppendLine(" SELECT [ID] "); - sbq.AppendLine(" ,[PcbId] "); - sbq.AppendLine(" ,[Address] "); - sbq.AppendLine(" ,[Value] "); - sbq.AppendLine(" ,[date] "); - sbq.AppendLine(" FROM [Auftrag].[dbo].[GenesisMeterRegisterHistory] "); - sbq.AppendLine(" where PcbId = @PcbID "); - sbq.AppendLine(" and (@Adress is null or [Address] = @Adress ) "); - sbq.AppendLine(" order by [date] desc "); - - - using (var dataacces = new SqlDataAccess("Data Source=SLASQL01.emea.sensus.net;;Initial Catalog=Auftrag;Persist Security Info=False;User ID=GenesisPasswordService;Password=PcbID;Connection Timeout=120")) - { - var dt = dataacces.ExecuteQuery(sbq.ToString()); - foreach (DataRow row in dt.Rows) - { - - resultRep currentRespons; - if (!listEOL.ContainsKey(item)) - { - listEOL.Add(item, new List()); - currentRespons = new resultRep() { DataDate = (DateTime)row["date"], PcbId = item.ToString(), Source = "PROD" }; - listEOL[item].Add(currentRespons); - - } - else - { - if (listEOL[item].Any(r => r.DataDate.Date == ((DateTime)row["date"]).Date)) - { - currentRespons = listEOL[item].First(r => r.DataDate.Date == ((DateTime)row["date"]).Date); - } - else - { - currentRespons = new resultRep() { DataDate = (DateTime)row["date"], PcbId = item.ToString(), Source = "PROD" }; - listEOL[item].Add(currentRespons); - } - - } - - - switch (row["Address"].ToString()) - { - case "12-12": - currentRespons.METROLOGYASST_PulseResolution = row["Value"].ToString(); - break; - case "12-11": - currentRespons.METROLOGYASST_PulseEvenDistribution = row["Value"].ToString(); - break; - case "12-02": - currentRespons.METROLOGYASST_PulseWeight = row["Value"].ToString(); - break; - case "12-03": - currentRespons.METROLOGYASST_PulseMode = row["Value"].ToString(); - break; - case "12-04": - currentRespons.METROLOGYASST_PulseLength = row["Value"].ToString(); - break; - case "0F-13": - currentRespons.GENESISFLOW_ScaledBilling = row["Value"].ToString(); - break; - case "0F-00": - currentRespons.GENESISFLOW_SampleRate = row["Value"].ToString(); - break; - case "0F-16": - currentRespons.GENESISFLOW_LedMode = row["Value"].ToString(); - break; - case "01-09": - var strTmp = row["Value"].ToString(); - if (strTmp.Length > "D5-7A-AC-24-00-00-00-00".Length) - { - strTmp.Substring(0, "D5-7A-AC-24-00-00-00-00".Length); - } - if (String.IsNullOrEmpty(currentRespons.POWERMON_TotalUsedCharge)) - { - currentRespons.POWERMON_TotalUsedCharge = strTmp; - } - else - { - if (strTmp.Length == "D5-7A-AC-24-00-00-00-00".Length) - { - currentRespons.POWERMON_TotalUsedCharge = strTmp; - } - else - { - - } - - } - - break; - case "01-0A": - if (row["Value"].ToString() != "00-00-00-00") - { - currentRespons.POWERMON_TotalUsedSeconds = row["Value"].ToString(); - - } - - break; - case "01-00": - if (row["Value"].ToString() != "00-00-00-00") - { - currentRespons.POWERMON_BatteryVoltage = row["Value"].ToString(); - } - break; - case "01-04": - currentRespons.POWERMON_BatteryQuantity = row["Value"].ToString(); - break; - case "14-09": - if (row["Value"].ToString() != "00-00-00-00") - { - currentRespons.IRDA_AdapterID = row["Value"].ToString(); - } - break; - case "14-00": - if (row["Value"].ToString() != "00-00-00-00") - { - currentRespons.IRDA_PulseReportRate = row["Value"].ToString(); - } - break; - default: - break; - } - - } - } - } - } - - - - - - var pcbDate = new Dictionary(); - - - - var sbLEDQery = new StringBuilder(); - - sbLEDQery.AppendLine("select * from GenesisMeterRegisterHistory where PcbId in ( "); - sbLEDQery.AppendLine(" "); - sbLEDQery.AppendLine("'230930011', "); - sbLEDQery.AppendLine("'230930127', "); - sbLEDQery.AppendLine("'230930281', "); - sbLEDQery.AppendLine("'230930129', "); - sbLEDQery.AppendLine("'230930137', "); - sbLEDQery.AppendLine("'230930280', "); - sbLEDQery.AppendLine("'230930411', "); - sbLEDQery.AppendLine("'230930049', "); - sbLEDQery.AppendLine("'230930279', "); - sbLEDQery.AppendLine("'222830068', "); - sbLEDQery.AppendLine("'222830076', "); - sbLEDQery.AppendLine("'222830174', "); - sbLEDQery.AppendLine("'222830121', "); - sbLEDQery.AppendLine("'222830112', "); - sbLEDQery.AppendLine("'230930059', "); - sbLEDQery.AppendLine("'222830022', "); - sbLEDQery.AppendLine("'222830099', "); - sbLEDQery.AppendLine("'230930122', "); - sbLEDQery.AppendLine("'230930051', "); - sbLEDQery.AppendLine("'230930227', "); - sbLEDQery.AppendLine("'230930382', "); - sbLEDQery.AppendLine("'230930391', "); - sbLEDQery.AppendLine("'230930408', "); - sbLEDQery.AppendLine("'230930308', "); - sbLEDQery.AppendLine("'222830109', "); - sbLEDQery.AppendLine("'230930128', "); - sbLEDQery.AppendLine("'222830077', "); - sbLEDQery.AppendLine("'222830101', "); - sbLEDQery.AppendLine("'222830007', "); - sbLEDQery.AppendLine("'222830249', "); - sbLEDQery.AppendLine("'230930019', "); - sbLEDQery.AppendLine("'230930299', "); - sbLEDQery.AppendLine("'230930396', "); - sbLEDQery.AppendLine("'230930387', "); - sbLEDQery.AppendLine("'222830118', "); - sbLEDQery.AppendLine("'230930403', "); - sbLEDQery.AppendLine("'230930228', "); - sbLEDQery.AppendLine("'222830097', "); - sbLEDQery.AppendLine("'230930237', "); - sbLEDQery.AppendLine("'230930032', "); - sbLEDQery.AppendLine("'230930149', "); - sbLEDQery.AppendLine("'222830213', "); - sbLEDQery.AppendLine("'230930143', "); - sbLEDQery.AppendLine("'230930136', "); - sbLEDQery.AppendLine("'230930329', "); - sbLEDQery.AppendLine("'230930277', "); - sbLEDQery.AppendLine("'230930325', "); - sbLEDQery.AppendLine("'222830296', "); - sbLEDQery.AppendLine("'222830153', "); - sbLEDQery.AppendLine("'222830172' "); - sbLEDQery.AppendLine(") "); - sbLEDQery.AppendLine("and Address in ('0F-16', '0F-00', '0F-22') order by PcbId, date"); - - var dic = new Dictionary>(); - var dateTimeold = new DateTime(); - var oldValue = false; - var oldPCbID = ""; - using (var dataacces = new SqlDataAccess("Data Source=SLASQL01.emea.sensus.net;;Initial Catalog=Auftrag;Persist Security Info=False;User ID=GenesisPasswordService;Password=PcbID;Connection Timeout=120")) - { - var dt = dataacces.ExecuteQuery(sbLEDQery.ToString()); - foreach (DataRow row in dt.Rows) - { - - var time = (DateTime)row["date"]; - - var pcb = (string)row["PcbId"]; - var reg = (string)row["Address"]; - var strVal = (string)row["Value"]; - bool State = false; - var re = ""; - - GreenHistoryItem last; - if (!dic.ContainsKey(pcb)) - { - dic.Add(pcb, new List()); - dic[pcb].Add(new GreenHistoryItem()); - } - - - last = dic[pcb].Last(); - var newItem = new GreenHistoryItem() { Time = time, Idel = last.Idel, SR = last.SR, LedMode = last.LedMode, Remark = "int" }; - - switch (reg) - { - case "0F-16": - if (strVal == "00-00-00-00") - { - newItem.LedMode = false; - re = "LED Mode off"; - } - else - { - re = "LED Mode On"; - newItem.LedMode = true; ; - } - break; - case "0F-22": - if (strVal == "00-00-00-00") - { - re = "Trigger active"; - newItem.Idel = false; - } - else - { - re = "Trigger idel"; - newItem.Idel = true; - } - break; - case "0F-21": - re = "Trigger active"; - newItem.Idel = false; - break; - case "0F-00": - if (strVal == "00-00-00-02") - { - newItem.SR = 2; - re = "Sampel rate 2"; - } - else - { - newItem.SR = 10; - re = "Sampel rate < 2"; - } - break; - - default: - break; - } - - newItem.Cal(); - dic[pcb].Add(newItem); - - oldPCbID = pcb; - - - } - } - Console.WriteLine("key;time;highconsumption;idel;ledmodeSR;totalConsomtion;add seconds;"); - var dicS = new Dictionary(); - foreach (var item in dic) - { - var s = 0.0; - int c = -1; - foreach (var gItem in item.Value) - { - - if (c >= 0) - { - if (!item.Value[c].HighConsumption) - { - //war aus - } - else if (item.Value[c].HighConsumption) - { - gItem.SecondsInHighConsumption = (gItem.Time - item.Value[c].Time).TotalSeconds; - s = s + gItem.SecondsInHighConsumption; - } - - } - if (item.Key == "230930325" || item.Key == "222830153" || item.Key == "230930329") - { - - - - - - Console.WriteLine($"{item.Key};{gItem.Time};{gItem.HighConsumption};{gItem.Idel};{gItem.LedMode};{gItem.SR};{gItem.SecondsInHighConsumption}; {s}"); - } - c = c + 1; - } - - dicS.Add(item.Key.ToString(), s); - } - - Console.WriteLine("PcbId;Date;RemainingLifeTimeYears;DrainedBatteryLoadPercent;ExceededLifeTime_s;DrainedBatteryLoad_uAs;UNTLimit;unt Pass;Green LED days"); - foreach (var item in listEOL) - { - if (item.Value != null && item.Value.Any()) - { - item.Value.ForEach(c => c.Calc()); - foreach (var rItem in item.Value.OrderByDescending(o => o.DataDate)) - { - - if (rItem.Calculated) - { - var s = 0.0; - if (dicS.ContainsKey(rItem.PcbId)) - { - s = dicS[rItem.PcbId]; - } - Console.WriteLine($"{rItem.PcbId};{rItem.DataDate};{rItem.RemainingLifeTimeYears};{rItem.DrainedBatteryLoadPercent};{rItem.ExceededLifeTime_s};{rItem.DrainedBatteryLoad_uAs};{rItem.UNTLimit};{rItem.DrainedBatteryLoad_uAs>= rItem.UNTLimit };{s/60/60/24}"); - break; - } - - - } - - - } - - } - foreach (var item in dic) - { - Console.WriteLine($"{item.Key};{item.Value}"); - } - Console.ReadLine(); - - - //foreach (var item in listRes) - //{ - // if (item.Value.Any(a => a.PwFileUpdate)) - // { - // foreach (var v in item.Value) - // { - // v.Calc(); - // Console.WriteLine($"{item.Key}; {v.DataDate}"); - // } - - // } - //} - - ////foreach (var item in listRes) - ////{ - //// if (item.Value.Any(a => !a.PwFileUpdate)) - //// { - //// Console.WriteLine($"{item.Key}; Prob Good"); - //// } - ////} - - //foreach (var item in listEOL.Where(c => c.Value.Any(r => r.Calculated))) - //{ - - //} - - //var sb = new StringBuilder(); - //foreach (var item in listRes) - //{ - - - // var Reps = item.Value.OrderBy(o => o.DataDate); - // var SbDate = new StringBuilder(); - // var SbSource = new StringBuilder(); - // var sbCore = new StringBuilder(); - // var sbCustomerName = new StringBuilder(); - // var sbDrainedBatteryLoadPercent = new StringBuilder(); - // var sbDrainedBatteryLoad_uAs = new StringBuilder(); - // var sbExceededLifeTime_s = new StringBuilder(); - // var sbPOWERMON_BatteryQuantity = new StringBuilder(); - // var sbRemainingLifeTimeYears = new StringBuilder(); - // var sbFW = new StringBuilder(); - // var sbGENESISFLOW_LedMode = new StringBuilder(); - // var sbGENESISFLOW_SampleRate = new StringBuilder(); - // var sbGENESISFLOW_ScaledBilling = new StringBuilder(); - // var sbIRDA_AdapterID = new StringBuilder(); - // var sbIRDA_PulseReportRate = new StringBuilder(); - // var sbMETROLOGYASST_PulseEvenDistribution = new StringBuilder(); - // var sbMETROLOGYASST_PulseLength = new StringBuilder(); - // var sbMETROLOGYASST_PulseMode = new StringBuilder(); - // var sbMETROLOGYASST_PulseResolution = new StringBuilder(); - // var sbMETROLOGYASST_PulseWeight = new StringBuilder(); - - - // foreach (var rep in Reps.Where(c => c.Calculated)) - // { - // SbDate.Append(rep.DataDate).Append(';'); - // SbSource.Append(rep.Source).Append(';'); - // sbCore.Append(rep.Core).Append(';'); - // sbCustomerName.Append(rep.CustomerName).Append(';'); - // sbDrainedBatteryLoadPercent.Append(rep.DrainedBatteryLoadPercent).Append(';'); - // sbDrainedBatteryLoad_uAs.Append(rep.DrainedBatteryLoad_uAs).Append(';'); - // sbExceededLifeTime_s.Append(rep.ExceededLifeTime_s).Append(';'); - // sbPOWERMON_BatteryQuantity.Append(rep.POWERMON_BatteryQuantity).Append(';'); - // sbRemainingLifeTimeYears.Append(rep.RemainingLifeTimeYears).Append(';'); - // sbFW.Append(rep.FW).Append(';'); - // sbGENESISFLOW_LedMode.Append(rep.GENESISFLOW_LedMode).Append(';'); - // sbGENESISFLOW_SampleRate.Append(rep.GENESISFLOW_SampleRate).Append(';'); - // sbGENESISFLOW_ScaledBilling.Append(rep.GENESISFLOW_ScaledBilling).Append(';'); - // sbIRDA_AdapterID.Append(rep.IRDA_AdapterID).Append(';'); - // sbIRDA_PulseReportRate.Append(rep.IRDA_PulseReportRate).Append(';'); - // sbMETROLOGYASST_PulseEvenDistribution.Append(rep.METROLOGYASST_PulseEvenDistribution).Append(';'); - // sbMETROLOGYASST_PulseLength.Append(rep.METROLOGYASST_PulseLength).Append(';'); - // sbMETROLOGYASST_PulseMode.Append(rep.METROLOGYASST_PulseMode).Append(';'); - // sbMETROLOGYASST_PulseResolution.Append(rep.METROLOGYASST_PulseResolution).Append(';'); - // sbMETROLOGYASST_PulseWeight.Append(rep.METROLOGYASST_PulseWeight).Append(';'); - - // } - // if (Reps.Any(c => c.Calculated && c.Source == "PROD") && Reps.Any(c => c.Calculated && c.Source == "CUST")) - // { - - - - // sb.AppendLine($"PCBId;{item.Key};"); - // sb.AppendLine($"Date;{SbDate}"); - // sb.AppendLine($"Source;{SbSource}"); - // sb.AppendLine($"Core;{sbCore}"); - // sb.AppendLine($"CustomerName;{sbCustomerName}"); - // sb.AppendLine($"DrainedBatteryLoadPercent;{sbDrainedBatteryLoadPercent}"); - // sb.AppendLine($"DrainedBatteryLoad_uAs;{sbDrainedBatteryLoad_uAs}"); - // sb.AppendLine($"ExceededLifeTime_s;{sbExceededLifeTime_s}"); - // sb.AppendLine($"POWERMON_BatteryQuantity;{sbPOWERMON_BatteryQuantity}"); - // sb.AppendLine($"RemainingLifeTimeYears;{sbRemainingLifeTimeYears}"); - // sb.AppendLine($"FW;{sbFW}"); - // sb.AppendLine($"GENESISFLOW_LedMode;{sbGENESISFLOW_LedMode}"); - // sb.AppendLine($"GENESISFLOW_SampleRate;{sbGENESISFLOW_SampleRate}"); - // sb.AppendLine($"GENESISFLOW_ScaledBilling;{sbGENESISFLOW_ScaledBilling}"); - // sb.AppendLine($"IRDA_AdapterID;{sbIRDA_AdapterID}"); - // sb.AppendLine($"IRDA_PulseReportRate;{sbIRDA_PulseReportRate}"); - // sb.AppendLine($"METROLOGYASST_PulseEvenDistribution;{sbMETROLOGYASST_PulseEvenDistribution}"); - // sb.AppendLine($"METROLOGYASST_PulseLength;{sbMETROLOGYASST_PulseLength}"); - // sb.AppendLine($"METROLOGYASST_PulseMode;{sbMETROLOGYASST_PulseMode}"); - // sb.AppendLine($"METROLOGYASST_PulseResolution;{sbMETROLOGYASST_PulseResolution}"); - // sb.AppendLine($"METROLOGYASST_PulseWeight;{sbMETROLOGYASST_PulseWeight}"); - // } - - //} - //sb.AppendLine(); - //sb.AppendLine(); - //sb.AppendLine($"PCbID;LastProdDate;LastCUSTDate;TotalDays;LastProd_DrainedBatteryLoadPercent ;LastCUST_DrainedBatteryLoadPercent;LastProd_RemainingLifeTimeYears ;LastCUST_RemainingLifeTimeYears; "); - - //foreach (var item in listRes) - //{ - // if (item.Value.Any(c => c.Calculated && c.Source == "PROD") && item.Value.Any(c => c.Calculated && c.Source == "CUST")) - // { - // var LastProd = item.Value.First(f => f.DataDate == item.Value.Where(c => c.Source == "PROD").Max(m => m.DataDate)); - // var LastCUST = item.Value.First(f => f.DataDate == item.Value.Where(c => c.Source == "CUST").Max(m => m.DataDate)); - - // if (LastProd.DataDate < LastCUST.DataDate) - // { - // var ts = LastCUST.DataDate - LastProd.DataDate; - // sb.AppendLine($"{item.Key};{LastProd.DataDate};{LastCUST.DataDate };{ts.TotalDays};{LastProd.DrainedBatteryLoadPercent} ;{LastCUST.DrainedBatteryLoadPercent};{LastProd.RemainingLifeTimeYears} ;{LastCUST.RemainingLifeTimeYears}; "); - // } - - // } - - - //} - - //File.WriteAllText("output.csv", sb.ToString()); - Console.ReadLine(); - } - } -} diff --git a/Common/CommonConsole/ReflectionExtensions.cs b/Common/CommonConsole/ReflectionExtensions.cs deleted file mode 100644 index 699352fe..00000000 --- a/Common/CommonConsole/ReflectionExtensions.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Reflection; - -namespace CommonConsole -{ - public static class ReflectionExtensions - { - private static readonly ConcurrentDictionary, Action>> metadata - = new ConcurrentDictionary, Action>>(); - - public static void CopyTo(this T source, T destination) where T : class - { - var type = typeof(T); - var properties = metadata.GetOrAdd(type, AddTypeProperties); - - foreach (var kvp in properties) - { - var getter = kvp.Key; - var setter = kvp.Value; - var value = getter(source, null); - - setter(destination, value, null); - } - } - - private static IDictionary, Action> AddTypeProperties(Type type) - { - var properties = new Dictionary, Action>(); - - foreach (var property in type.GetProperties(BindingFlags.Instance | BindingFlags.Public)) - { - if (property.CanWrite) - { - properties[property.GetValue] = property.SetValue; - } - } - - return properties; - } - } -} diff --git a/Common/CommonConsole/ServiceProvider.cs b/Common/CommonConsole/ServiceProvider.cs deleted file mode 100644 index 0890906d..00000000 --- a/Common/CommonConsole/ServiceProvider.cs +++ /dev/null @@ -1,158 +0,0 @@ -namespace CommonConsole -{ - using System; - using System.Collections.Concurrent; - using System.Linq; - using System.Reflection; - - public partial class Program - { - class Outer - { - private readonly Middle middle; - - Outer(Middle middle) - { - Console.WriteLine($"{nameof(Outer)}: I am transient!"); - - this.middle = middle; - } - - internal string Text => $"{nameof(Outer)}.{nameof(Text)} => {this.middle.Text}"; - } - - class Middle - { - private readonly Inner inner; - - Middle(Inner inner) - { - Console.WriteLine($"{nameof(Middle)}: I am transient!"); - - this.inner = inner; - } - - internal string Text => $"{nameof(Middle)}.{nameof(Text)} => {this.inner.Text}"; - } - - class Inner - { - private readonly string text; - - internal Inner(string text) - { - Console.WriteLine($"{nameof(Inner)}: I am singleton!"); - - this.text = text; - } - - internal string Text => $"{nameof(Inner)}.{nameof(Text)} => {this.text}"; - } - - public static void DependencyInjectionTest() - { - ServiceProvider - .ServiceCollection - .AddSingleton(new Inner("It works!")); - - var outer = ServiceProvider.GetService(); - - Console.WriteLine(outer.Text); - } - } - - public interface IServiceCollection - { - IServiceCollection AddSingleton(T instance); - } - - public class ServiceProvider : IServiceProvider, IServiceCollection - { - private static readonly ServiceProvider serviceProvider = new ServiceProvider(); - - private readonly ConcurrentDictionary services; - - private ServiceProvider() - { - this.services = new ConcurrentDictionary(); - } - - public IServiceCollection AddSingleton(T instance) - { - services.AddOrUpdate(typeof(T), instance, (t, i) => instance); - - return this; - } - - public object GetService(Type serviceType) - { - return services.GetOrAdd(serviceType, default(object)); - } - - public static IServiceCollection ServiceCollection - { - get => serviceProvider; - } - - public static T GetService() - { - var serviceType = typeof(T); - var serviceInstance = default(T); - - if (serviceProvider.GetService(serviceType) is T existingInstance) - { - serviceInstance = existingInstance; - } - else if (CreateInstance(serviceType) is T newInstance) - { - serviceInstance = newInstance; - } - - return serviceInstance; - } - - private static object CreateInstance(Type instanceType) - { - var instance = default(object); - var constructors = instanceType - .GetConstructors(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) - .OrderByDescending(x => x.GetParameters().Length); - - foreach (var constructor in constructors) - { - var parameters = constructor.GetParameters(); - var parametersLength = parameters.Length; - var createParameters = new object[parametersLength]; - - for (int i = 0; i < parametersLength; i++) - { - var parameterType = parameters[i].ParameterType; - var parameter = serviceProvider.GetService(parameterType); - - if (parameter is null) - { - parameter = CreateInstance(parameterType); - } - - createParameters[i] = parameter; - } - - try - { - instance = constructor.Invoke(createParameters); - - if (instance != null) - { - break; - } - } - catch (Exception e) - { - Console.WriteLine(e); - } - } - - return instance; - } - } -} diff --git a/Common/OmniPlus/InspectionUI/ViewModels/ReferenceMeterVM.cs b/Common/OmniPlus/InspectionUI/ViewModels/ReferenceMeterVM.cs index 5c11026a..f714284a 100644 --- a/Common/OmniPlus/InspectionUI/ViewModels/ReferenceMeterVM.cs +++ b/Common/OmniPlus/InspectionUI/ViewModels/ReferenceMeterVM.cs @@ -5,7 +5,7 @@ using InspectionUI.Models; using OmniPlus; - using OmniPlus.Inspection; + using System; using System.Threading; using System.Timers; diff --git a/Common/SignalR/DataDictionary.cs b/Common/SignalR/DataDictionary.cs new file mode 100644 index 00000000..a044e862 --- /dev/null +++ b/Common/SignalR/DataDictionary.cs @@ -0,0 +1,292 @@ +namespace SignalR +{ + using System; + using System.Collections.Generic; + using System.Linq; + using System.Runtime.InteropServices; + + [Guid("C563D998-1B4C-46D7-8F44-05DD9D31C38F")] + [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)] + public interface IDataDictionary + { + int Count { get; } + + void AddBool(string property, bool value); + + void AddByte(string property, byte value); + + void AddDictionary(string property, DataDictionary value); + + void AddDouble(string property, double value); + + void AddInt(string property, int value); + + void AddLong(string property, long value); + + void AddString(string property, string value); + + void AddValue(string property, object value); + + bool GetBool(string property); + + byte GetByte(string property); + + DataDictionary GetDictionary(string property); + + double GetDouble(string property); + + float GetFloat(string property); + + int GetInt(string property); + + long GetLong(string property); + + string GetProperty(int index); + + string GetString(string property, string format = "{0}"); + + object GetValue(string property); + } + + [Guid("7C27758C-784B-49C6-BED7-394F1D90AA74")] + [ComSourceInterfaces(typeof(IDataDictionary))] + [ClassInterface(ClassInterfaceType.None)] + [ProgId("SignalR.DataDictionary")] + public class DataDictionary : IDataDictionary + { + private readonly IDictionary data; + + public DataDictionary() + { + this.data = new Dictionary(); + } + + internal DataDictionary(Dictionary data) + { + this.data = data; + } + + public int Count + { + get => this.data.Count; + } + + public void AddBool(string property, bool value) + { + this.ToLower(ref property); + + this.data[property] = value; + } + + public void AddByte(string property, byte value) + { + this.ToLower(ref property); + + this.data[property] = value; + } + + public void AddDictionary(string property, DataDictionary value) + { + this.ToLower(ref property); + + this.data[property] = value; + } + + public void AddDouble(string property, double value) + { + this.ToLower(ref property); + + this.data[property] = value; + } + + public void AddInt(string property, int value) + { + this.ToLower(ref property); + + this.data[property] = value; + } + + public void AddLong(string property, long value) + { + this.ToLower(ref property); + + this.data[property] = value; + } + + public void AddString(string property, string value) + { + this.ToLower(ref property); + + this.data[property] = value; + } + + internal Dictionary Generic() + { + return this.data as Dictionary; + } + + public bool GetBool(string property) + { + this.ToLower(ref property); + + if (this.data.TryGetValue(property, out var value)) + { + return this.Cast(value); + } + + return default(bool); + } + + public byte GetByte(string property) + { + this.ToLower(ref property); + + if (this.data.TryGetValue(property, out var value)) + { + return this.Cast(value); + } + + return default(byte); + } + + public DataDictionary GetDictionary(string property) + { + this.ToLower(ref property); + + if (this.data.TryGetValue(property, out var value) && value is DataDictionary _value) + { + return _value; + } + + return default(DataDictionary); + } + + public double GetDouble(string property) + { + this.ToLower(ref property); + + if (this.data.TryGetValue(property, out var value)) + { + return this.Cast(value); + } + + return default(double); + } + + public float GetFloat(string property) + { + this.ToLower(ref property); + + if (this.data.TryGetValue(property, out var value)) + { + return this.Cast(value); + } + + return default(float); + } + + public int GetInt(string property) + { + this.ToLower(ref property); + + if (this.data.TryGetValue(property, out var value)) + { + return this.Cast(value); + } + + return default(int); + } + + public long GetLong(string property) + { + this.ToLower(ref property); + + if (this.data.TryGetValue(property, out var value)) + { + return this.Cast(value); + } + + return default(long); + } + + public string GetProperty(int index) + { + var properties = this.data.Keys.ToArray(); + var length = properties.Length; + + if (0 <= index && index < length) + { + return properties[index]; + } + + return default(string); + } + + public string GetString(string property, string format = "{0}") + { + this.ToLower(ref property); + + if (this.data.TryGetValue(property, out var value)) + { + try + { + return string.Format(format, value?.ToString()); + } + catch (Exception e) + { + this.AddString(nameof(Exception), e.ToString()); + } + } + + return default(string); + } + + private void ToLower(ref string property) + { + if (string.IsNullOrWhiteSpace(property)) + { + property = string.Empty; + } + + property = property.ToLower(); + } + + private T Cast(object value) + { + try + { + value = Convert.ChangeType(value, typeof(T)); + } + catch (Exception e) + { + this.AddString(nameof(Exception), e.ToString()); + } + + if (value is T _value) + { + return _value; + } + + return default(T); + } + + public void AddValue(string property, object value) + { + this.ToLower(ref property); + + this.data[property] = value; + } + + public object GetValue(string property) + { + this.ToLower(ref property); + + if (this.data.TryGetValue(property, out var value)) + { + return value; + } + + return default(object); + } + } +} diff --git a/Common/SignalR/DataHub.cs b/Common/SignalR/DataHub.cs new file mode 100644 index 00000000..6fb134d5 --- /dev/null +++ b/Common/SignalR/DataHub.cs @@ -0,0 +1,124 @@ +namespace SignalR +{ + using Microsoft.AspNet.SignalR.Client; + + using System; + using System.Collections.Generic; + using System.Runtime.InteropServices; + + public delegate void DataReceivedHandler(DataDictionary data); + + public delegate void StateHandler(string state); + + [Guid("26CA0187-06E4-4A6E-B7EB-A57996365FEF")] + [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)] + public interface IDataHub + { + void DataReceived(DataDictionary data); + + void StateChanged(string state); + } + + [Guid("B126CD14-DF35-4D56-B3B3-97D9FE606D61")] + [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)] + public interface IDataHubClient + { + void Connect(string url); + + void Send(DataDictionary dictionary); + } + + [Guid("BBF1EDDB-84BC-4FA0-85E8-1B16BD331C42")] + [ComSourceInterfaces(typeof(IDataHub))] + [ClassInterface(ClassInterfaceType.None)] + [ProgId("SignalR.DataHub")] + public class DataHub : IDataHubClient + { + private HubConnection connection; + private IDisposable disposable; + private IHubProxy proxy; + + public DataHub() + { + } + + public event DataReceivedHandler DataReceived; + public event StateHandler StateChanged; + + public void Connect(string url) + { + this.connection = new HubConnection(url, queryString: $"key={Environment.MachineName}"); + this.connection.Closed += this.Connection_Closed; + this.connection.ConnectionSlow += this.Connection_ConnectionSlow; + this.connection.Error += this.Connection_Error; + this.connection.Received += this.Connection_Received; + this.connection.Reconnected += this.Connection_Reconnected; + this.connection.Reconnecting += this.Connection_Reconnecting; + this.connection.StateChanged += this.Connection_StateChanged; + + this.proxy = this.connection.CreateHubProxy("DataHub"); + this.disposable = this.proxy.On>(nameof(this.Send), this.Receive); + + try + { + this.connection + .Start() + .Wait(); + } + catch (Exception e) + { + this.NotifyStateChanged(e.ToString()); + } + } + + public void Send(DataDictionary dictionary) + { + this.proxy.Invoke(nameof(this.Send), dictionary.Generic()); + } + + private void Connection_Closed() + { + this.NotifyStateChanged("Connection closed."); + } + + private void Connection_ConnectionSlow() + { + this.NotifyStateChanged("Connection slow."); + } + + private void Connection_Error(Exception exception) + { + this.NotifyStateChanged(exception); + } + + private void Connection_Received(string data) + { + this.NotifyStateChanged(data); + } + + private void Connection_Reconnected() + { + this.NotifyStateChanged("Connection reconnected."); + } + + private void Connection_Reconnecting() + { + this.NotifyStateChanged("Connection reconnecting."); + } + + private void Connection_StateChanged(StateChange state) + { + this.NotifyStateChanged(state); + } + + private void NotifyStateChanged(object state) + { + this.StateChanged?.Invoke($"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] {state}"); + } + + private void Receive(Dictionary data) + { + this.DataReceived?.Invoke(new DataDictionary(data)); + } + } +} diff --git a/Common/SignalR/Properties/AssemblyInfo.cs b/Common/SignalR/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..d1629c2a --- /dev/null +++ b/Common/SignalR/Properties/AssemblyInfo.cs @@ -0,0 +1,15 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("SignalR")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("SignalR")] +[assembly: AssemblyCopyright("Copyright © 2024")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] +[assembly: ComVisible(true)] +[assembly: Guid("abf3ec64-1257-4ca2-ad62-8a27a5f1edcc")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Common/SignalR/SignalR.csproj b/Common/SignalR/SignalR.csproj new file mode 100644 index 00000000..2e39ac21 --- /dev/null +++ b/Common/SignalR/SignalR.csproj @@ -0,0 +1,62 @@ + + + + + Debug + AnyCPU + {ABF3EC64-1257-4CA2-AD62-8A27A5F1EDCC} + Library + Properties + SignalR + SignalR + v4.0 + 512 + true + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + false + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + false + + + + ..\packages\Microsoft.AspNet.SignalR.Client.2.4.3\lib\net40\Microsoft.AspNet.SignalR.Client.dll + + + False + ..\packages\Newtonsoft.Json.6.0.4\lib\net40\Newtonsoft.Json.dll + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Common/SignalR/app.config b/Common/SignalR/app.config new file mode 100644 index 00000000..33fb875c --- /dev/null +++ b/Common/SignalR/app.config @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/Common/SignalR/packages.config b/Common/SignalR/packages.config new file mode 100644 index 00000000..79319de0 --- /dev/null +++ b/Common/SignalR/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/LaaProductionWeb/LaaProductionWeb/2024_01_03.debug b/LaaProductionWeb/LaaProductionWeb/2024_01_03.debug deleted file mode 100644 index e69de29b..00000000 diff --git a/LaaProductionWeb/LaaProductionWeb/2024_01_17.debug b/LaaProductionWeb/LaaProductionWeb/2024_01_17.debug deleted file mode 100644 index e69de29b..00000000 diff --git a/LaaProductionWeb/LaaProductionWeb/2024_02_06.debug b/LaaProductionWeb/LaaProductionWeb/2024_02_06.debug deleted file mode 100644 index 030990ff..00000000 --- a/LaaProductionWeb/LaaProductionWeb/2024_02_06.debug +++ /dev/null @@ -1,4 +0,0 @@ -[SQL ERROR] Violation of PRIMARY KEY constraint 'PK_MitarbeiterTokens'. Cannot insert duplicate key in object 'dbo.MitarbeiterTokens'. The duplicate key value is (13, 19207). -[SQL ERROR] The statement has been terminated. -[SQL ERROR] Violation of PRIMARY KEY constraint 'PK_MitarbeiterTokens'. Cannot insert duplicate key in object 'dbo.MitarbeiterTokens'. The duplicate key value is (13, 19207). -[SQL ERROR] The statement has been terminated. diff --git a/LaaProductionWeb/LaaProductionWeb/Hubs/DataHub.cs b/LaaProductionWeb/LaaProductionWeb/Hubs/DataHub.cs new file mode 100644 index 00000000..4314f4a8 --- /dev/null +++ b/LaaProductionWeb/LaaProductionWeb/Hubs/DataHub.cs @@ -0,0 +1,55 @@ +namespace LaaProductionWeb.Hubs +{ + using Microsoft.AspNet.SignalR; + using Microsoft.AspNet.SignalR.Hubs; + + using System.Collections.Concurrent; + using System.Collections.Generic; + using System.Threading.Tasks; + + [HubName(nameof(DataHub))] + public class DataHub : Hub + { + private static readonly ConcurrentDictionary messageIds + = new ConcurrentDictionary(); + + protected string ConnectionId + { + get => this.Context.ConnectionId; + } + + protected string GroupName + { + get => this.Context + .QueryString + .Get("key"); + } + + public void Send(Dictionary data) + { + var messageId = messageIds.AddOrUpdate(this.ConnectionId, 1, (connectionId, msgId) => msgId + 1); + + data["connectionid"] = this.ConnectionId; + data["groupname"] = this.GroupName; + data["messageid"] = messageId; + + this.Clients + .OthersInGroup(this.GroupName) + .Send(data); + } + + public override async Task OnConnected() + { + _ = messageIds.GetOrAdd(this.ConnectionId, 0); + + await this.Groups.Add(this.ConnectionId, this.GroupName); + } + + public override async Task OnDisconnected(bool stopCalled) + { + _ = messageIds.TryRemove(this.ConnectionId, out var _); + + await this.Groups.Remove(this.ConnectionId, this.GroupName); + } + } +} \ No newline at end of file diff --git a/LaaProductionWeb/LaaProductionWeb/LaaProductionWeb.csproj b/LaaProductionWeb/LaaProductionWeb/LaaProductionWeb.csproj index 365aa125..a42b892b 100644 --- a/LaaProductionWeb/LaaProductionWeb/LaaProductionWeb.csproj +++ b/LaaProductionWeb/LaaProductionWeb/LaaProductionWeb.csproj @@ -45,6 +45,9 @@ 4 + + ..\..\Common\OmniPlus\ExchangeHub\bin\Debug\ExchangeHub.dll + ..\packages\LaaProductionDI.1.0.4\lib\netstandard2.0\LaaProductionDI.dll @@ -221,6 +224,8 @@ Global.asax + + @@ -316,7 +321,6 @@ - 10.0 diff --git a/LaaProductionWeb/LaaProductionWeb/Views/Shared/_Layout.cshtml b/LaaProductionWeb/LaaProductionWeb/Views/Shared/_Layout.cshtml index 977056bb..424d1800 100644 --- a/LaaProductionWeb/LaaProductionWeb/Views/Shared/_Layout.cshtml +++ b/LaaProductionWeb/LaaProductionWeb/Views/Shared/_Layout.cshtml @@ -60,7 +60,7 @@ @if (this.User.IsInRole(EmployeesRoles.WEB_Approvals)) { } @if (this.User.IsInRole(EmployeesRoles.WEB_Equipments)) @@ -72,7 +72,7 @@ @if (this.User.IsInRole(EmployeesRoles.WEB_Passwords)) { } @if (this.User.IsInRole(EmployeesRoles.WEB_Wildcard))