diff --git a/Common/.vs/config/applicationhost.config b/Common/.vs/config/applicationhost.config index 883679a3..a894c3cf 100644 --- a/Common/.vs/config/applicationhost.config +++ b/Common/.vs/config/applicationhost.config @@ -155,7 +155,7 @@ - + diff --git a/Common/CommonConsole/Program.cs b/Common/CommonConsole/Program.cs index d8c5ef67..878f5805 100644 --- a/Common/CommonConsole/Program.cs +++ b/Common/CommonConsole/Program.cs @@ -17,7 +17,7 @@ // 01020304050607081112131415161718 // E6C88800DEB868C0D6A84880CE982840 var encryptionKey = new Byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18 }; - var task = new JusteRegisterTask + var task = new JusteRegisterProgrammingTask { Cmd = JustSirtMessage.W_PAM, P1 = new P811 diff --git a/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/JusteRegisterParameterSet.cs b/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/JusteRegisterParameterSet.cs new file mode 100644 index 00000000..73734f87 --- /dev/null +++ b/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/JusteRegisterParameterSet.cs @@ -0,0 +1,37 @@ +namespace Common.Hardware.WaterMeter.eRegister +{ + using System; + + public class JusteRegisterParameterSet + { + public Int32 SharedId { get; set; } + + public Int32 Runno { get; set; } + + public Int32 Psno { get; set; } + + public Int32 Slotno { get; set; } + + public Int32 Serialno { get; set; } + + public String RadioKey { get; set; } + + public UInt32 RadioAddress { get; set; } + + public UInt32 FinalAddress { get; set; } + + public Int64 Vpp { get; set; } + + public Int64 VpLp { get; set; } + + public Double OffsetFactor { get; set; } + + public Byte OffsetTime { get; set; } + + public Byte FactoryCalibration { get; set; } + + public Byte DecimalPoint { get; set; } + + public Byte MeterSize { get; set; } + } +} diff --git a/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/JusteRegisterProgrammingBatch.cs b/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/JusteRegisterProgrammingBatch.cs index 62884f9f..e8b77ac8 100644 --- a/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/JusteRegisterProgrammingBatch.cs +++ b/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/JusteRegisterProgrammingBatch.cs @@ -7,6 +7,8 @@ public class JusteRegisterProgrammingBatch { + private readonly Dictionary<> + private JustSirtBroadcaster broadcaster; public Boolean StartOnCOMPort(String portName) @@ -14,24 +16,20 @@ this.Stop(); this.broadcaster = new JustSirtBroadcaster(portName); - this.broadcaster.Logging += this.Broadcaster_Logging; return this.broadcaster.TryActivate(); } - private void Broadcaster_Logging(String value) { }// => Console.WriteLine(value); - public void Stop() { if (this.broadcaster != null) { this.broadcaster.TryDeactivate(); - this.broadcaster.Logging -= this.Broadcaster_Logging; this.broadcaster = null; } } - public void Run(JusteRegisterTask task) + public void Run(JusteRegisterProgrammingTask task) { var status = this.broadcaster.TryRun(task); @@ -42,5 +40,10 @@ status = this.broadcaster.TryRun(task); } } + + public void Add(JusteRegisterParameterSet parameterSet) + { + + } } } diff --git a/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/JusteRegisterTask.cs b/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/JusteRegisterProgrammingTask.cs similarity index 98% rename from Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/JusteRegisterTask.cs rename to Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/JusteRegisterProgrammingTask.cs index 84ead955..54dadf95 100644 --- a/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/JusteRegisterTask.cs +++ b/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/JusteRegisterProgrammingTask.cs @@ -5,7 +5,7 @@ using Newtonsoft.Json; using System; - public class JusteRegisterTask : JustSirtTask + public class JusteRegisterProgrammingTask : JustSirtTask { public Byte[] EncryptionKey { get; set; } diff --git a/Common/Logic/Common.Logic.Extensions.SQL/SQLReader.cs b/Common/Logic/Common.Logic.Extensions.SQL/SQLReader.cs index fca11316..1a19eaf5 100644 --- a/Common/Logic/Common.Logic.Extensions.SQL/SQLReader.cs +++ b/Common/Logic/Common.Logic.Extensions.SQL/SQLReader.cs @@ -4,6 +4,7 @@ using System; using System.Data.SqlClient; + using System.Diagnostics; public class SQLReader : ISQLReader, IDisposable { @@ -34,9 +35,35 @@ type = typeof(T); } - readedValue = Convert.ChangeType(readedValue, type); + var tryParse = true; - if (readedValue is T expectedValue) + if (tryParse) + { + try + { + readedValue = Convert.ChangeType(readedValue, type); + tryParse = false; + } + catch (Exception e) + { + Debug.Print(e.ToString()); + } + } + + if (tryParse) + { + try + { + readedValue = Enum.Parse(type, $"{readedValue}", true); + tryParse = false; + } + catch (Exception e) + { + Debug.Print(e.ToString()); + } + } + + if (!tryParse && readedValue is T expectedValue) { value = expectedValue; } diff --git a/Common/Ui/Common.UI.WPF/App.xaml b/Common/Ui/Common.UI.WPF/App.xaml index a46f7539..da6b0821 100644 --- a/Common/Ui/Common.UI.WPF/App.xaml +++ b/Common/Ui/Common.UI.WPF/App.xaml @@ -1,6 +1,7 @@  + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + StartupUri="MainWindow.xaml"> diff --git a/Common/Ui/Common.UI.WPF/App.xaml.cs b/Common/Ui/Common.UI.WPF/App.xaml.cs index b03ad8cd..802d1d37 100644 --- a/Common/Ui/Common.UI.WPF/App.xaml.cs +++ b/Common/Ui/Common.UI.WPF/App.xaml.cs @@ -1,30 +1,77 @@ namespace Common.UI.WPF { + using Common.Logic.Extensions.SQL; + using Common.Logic.Extensions.SQL.Interfaces; + using System; using System.Configuration; + using System.Diagnostics; using System.Windows; public partial class App : Application { public static readonly AppConfig Appsettings = AppConfig.Current; - public static Boolean IsActivated; + public static readonly ISQLConnection SQL = SQLConnection.CreateSQLConnection(Appsettings["PS.ConnectionString"]); public static event Action Activate; public static event Action Deactivate; - protected override void OnExit(ExitEventArgs e) - => Deactivate?.Invoke(); + private static double secondsSinceLastEvent; - protected override void OnActivated(EventArgs e) + protected override void OnActivated(EventArgs args) { - base.OnActivated(e); + base.OnActivated(args); - if (!IsActivated) + if (DateTime.Now.TimeOfDay.TotalSeconds - secondsSinceLastEvent > 1) { Activate?.Invoke(); - - IsActivated = true; } + + secondsSinceLastEvent = DateTime.Now.TimeOfDay.TotalSeconds; + } + + protected override void OnExit(ExitEventArgs args) + { + + if (DateTime.Now.TimeOfDay.TotalSeconds - secondsSinceLastEvent > 1) + { + Deactivate?.Invoke(); + } + + secondsSinceLastEvent = DateTime.Now.TimeOfDay.TotalSeconds; + + base.OnExit(args); + } + + protected override void OnStartup(StartupEventArgs args) + { + var currentProcess = Process.GetCurrentProcess(); + var currentProcessName = currentProcess.ProcessName; + var currentProcessId = currentProcess.Id; + + try + { + foreach (var _process in Process.GetProcessesByName(currentProcessName)) + { + if (_process.Id != currentProcessId) + { + try + { + _process.Kill(); + } + catch (Exception e) + { + MessageBox.Show(e.StackTrace, e.Message); + } + } + } + } + catch (Exception e) + { + MessageBox.Show(e.StackTrace, e.Message); + } + + base.OnStartup(args); } public class AppConfig diff --git a/Common/Ui/Common.UI.WPF/Common.UI.WPF.csproj b/Common/Ui/Common.UI.WPF/Common.UI.WPF.csproj index fbc9b861..b4fe5019 100644 --- a/Common/Ui/Common.UI.WPF/Common.UI.WPF.csproj +++ b/Common/Ui/Common.UI.WPF/Common.UI.WPF.csproj @@ -23,7 +23,7 @@ DEBUG;TRACE prompt 4 - IDE0003;IDE0049; + IDE0003;IDE0049;IDE1006; AnyCPU @@ -55,27 +55,22 @@ MSBuild:Compile Designer - - EregisterInit.xaml - - - EregisterRunCommands.xaml - + + + - - - - + - - - MSBuild:Compile - Designer - + + eRegisterPruefungInitialisierungView.xaml + + + MainWindowView.xaml + MSBuild:Compile Designer @@ -88,9 +83,13 @@ MainWindow.xaml Code - - MSBuild:Compile + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile @@ -118,10 +117,18 @@ + + {F408DE9E-01E6-4CFF-AE79-B572B0674FA2} + Common.Hardware.Interfaces.Ports.SirtBroadcaster + {4E8BB839-D40A-488C-88CE-F21811F1F476} Common.Hardware.WaterMeter.eRegister + + {62490923-cd17-45a6-b79f-a027927c75b5} + Common.Logic.Extensions.SQL + \ No newline at end of file diff --git a/Common/Ui/Common.UI.WPF/EregisterInit.xaml b/Common/Ui/Common.UI.WPF/EregisterInit.xaml deleted file mode 100644 index c129cf7a..00000000 --- a/Common/Ui/Common.UI.WPF/EregisterInit.xaml +++ /dev/null @@ -1,174 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -