From dcf222f6811d4a4dcda7f517f61e22e3c5ac0e7e Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Fri, 18 Dec 2020 07:09:51 +0200 Subject: Stubs Utils. --- .../Tango.StubsUtils.Client.CLI/Program.cs | 2 +- .../Tango.StubsUtils.PerformanceTest.CLI.csproj | 6 +++--- .../Tango.StubsUtils.Service.UI/App.xaml.cs | 7 ++++++ .../Resources/Styles.xaml | 10 +++++++++ .../ViewModels/MainViewVM.cs | 25 ++++++++++++++++++++++ .../Views/MainView.xaml | 2 ++ .../Tango.StubsUtils.Service/StubsService.cs | 17 +++++++++++++++ 7 files changed, 65 insertions(+), 4 deletions(-) (limited to 'Software/Visual_Studio') 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 4c93c2196..b975093d1 100644 --- a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Client.CLI/Program.cs +++ b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Client.CLI/Program.cs @@ -57,7 +57,7 @@ namespace Tango.StubsUtils.Client.CLI private static void ExitError(String error) { Console.ForegroundColor = ConsoleColor.Red; - Console.Error.WriteLine($"{error}"); + Console.WriteLine($"{error}"); Console.ForegroundColor = ConsoleColor.Gray; Environment.Exit(-1); } diff --git a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.PerformanceTest.CLI/Tango.StubsUtils.PerformanceTest.CLI.csproj b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.PerformanceTest.CLI/Tango.StubsUtils.PerformanceTest.CLI.csproj index f4575043f..3020836d2 100644 --- a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.PerformanceTest.CLI/Tango.StubsUtils.PerformanceTest.CLI.csproj +++ b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.PerformanceTest.CLI/Tango.StubsUtils.PerformanceTest.CLI.csproj @@ -7,7 +7,7 @@ {F423324C-7D0A-4512-BEBA-DF3A931A09F6} Exe Tango.StubsUtils.PerformanceTest.CLI - Tango.StubsUtils.PerformanceTest.CLI + tangostub_perf v4.6.1 512 true @@ -18,7 +18,7 @@ true full false - bin\Debug\ + ..\..\Build\StubsUtils\Debug\ DEBUG;TRACE prompt 4 @@ -27,7 +27,7 @@ AnyCPU pdbonly true - bin\Release\ + ..\..\Build\StubsUtils\Release\ TRACE prompt 4 diff --git a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service.UI/App.xaml.cs b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service.UI/App.xaml.cs index 2f7861a97..d223c6067 100644 --- a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service.UI/App.xaml.cs +++ b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service.UI/App.xaml.cs @@ -77,6 +77,13 @@ namespace Tango.StubsUtils.Service.UI "The calling thread must be STA, because many UI components require this." }; + String exceptionString = e.Exception.ToStringSafe(); + + if (ignoredExceptions.Exists(x => exceptionString.Contains(x))) + { + return; + } + LogManager.Log(e.Exception, LogCategory.Critical, "Unexpected Application Error."); Application.Current.Dispatcher.Invoke(() => diff --git a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service.UI/Resources/Styles.xaml b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service.UI/Resources/Styles.xaml index e47e4594c..2698c7bc7 100644 --- a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service.UI/Resources/Styles.xaml +++ b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service.UI/Resources/Styles.xaml @@ -13,4 +13,14 @@ + + \ No newline at end of file diff --git a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service.UI/ViewModels/MainViewVM.cs b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service.UI/ViewModels/MainViewVM.cs index 16078fc47..361f85e41 100644 --- a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service.UI/ViewModels/MainViewVM.cs @@ -1,6 +1,7 @@ using Notifications.Wpf; using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO.Ports; using System.Linq; using System.Text; @@ -73,6 +74,7 @@ namespace Tango.StubsUtils.Service.UI.ViewModels public RelayCommand RefreshPortsCommand { get; set; } public RelayCommand ToggleConnectionCommand { get; set; } public RelayCommand ClearLogCommand { get; set; } + public RelayCommand StartPerformanceTesterCommand { get; set; } public MainViewVM() { @@ -82,6 +84,7 @@ namespace Tango.StubsUtils.Service.UI.ViewModels AvailablePorts = new List(); RefreshPortsCommand = new RelayCommand(RefreshPorts); ToggleConnectionCommand = new RelayCommand(ToggleConnection); + StartPerformanceTesterCommand = new RelayCommand(StartPerformanceTester); ClearLogCommand = new RelayCommand(ClearLog); _logsQueue = new ProducerConsumerQueue(); @@ -110,6 +113,7 @@ namespace Tango.StubsUtils.Service.UI.ViewModels RefreshPorts(); Service = new StubsService(); + Service.CommunicationFailed += Service_CommunicationFailed; await Service.Start(); if (Settings.AutoConnect) @@ -124,6 +128,22 @@ namespace Tango.StubsUtils.Service.UI.ViewModels } } + private void Service_CommunicationFailed(object sender, EventArgs e) + { + if (IsTrayIconVisible) + { + InvokeUI(() => + { + _notification.Show(new NotificationContent() + { + Title = "Tango Stubs Service", + Message = $"Communication Error", + Type = NotificationType.Error + }); + }); + } + } + private void Logger_LogReceived(object sender, LogItemBase e) { String message = e.TimeStamp.ToString("HH:mm:ss.ff") + ": " + e.Message; @@ -269,5 +289,10 @@ namespace Tango.StubsUtils.Service.UI.ViewModels Settings.USBPort = SelectedPort; Settings.Save(); } + + private void StartPerformanceTester() + { + Process.Start("tangostub_perf.exe"); + } } } diff --git a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service.UI/Views/MainView.xaml b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service.UI/Views/MainView.xaml index 667a25502..6eaf8d3a7 100644 --- a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service.UI/Views/MainView.xaml +++ b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service.UI/Views/MainView.xaml @@ -111,6 +111,8 @@ Auto Connect on Startup + + diff --git a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/StubsService.cs b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/StubsService.cs index 58af2d8ff..13a8b38e5 100644 --- a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/StubsService.cs +++ b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/StubsService.cs @@ -37,6 +37,12 @@ namespace Tango.StubsUtils.Service private Dictionary _stubsLookup; private Thread _communicationThread; + #region Events + + public event EventHandler CommunicationFailed; + + #endregion + #region Properties private ITransporter _transporter; @@ -147,8 +153,10 @@ namespace Tango.StubsUtils.Service if (!IsConnected) { Transporter = new BasicTransporter(new UsbTransportAdapter(comPort)); + Transporter.FailsWithAdapter = true; Transporter.ComponentName = $"Transporter {transporterCount++}"; Transporter.UseKeepAlive = false; + Transporter.StateChanged += Transporter_StateChanged; await Transporter.Connect(); IsConnected = true; } @@ -163,6 +171,15 @@ namespace Tango.StubsUtils.Service } } + private void Transporter_StateChanged(object sender, TransportComponentState state) + { + if (state == TransportComponentState.Failed) + { + IsConnected = false; + CommunicationFailed?.Invoke(this, new EventArgs()); + } + } + #endregion #region Communication -- cgit v1.3.1