diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-12-18 07:09:51 +0200 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-12-18 07:09:51 +0200 |
| commit | dcf222f6811d4a4dcda7f517f61e22e3c5ac0e7e (patch) | |
| tree | d492cbde97b4d4c6893f4217b07336edc077dec5 /Software/Visual_Studio/StubsUtils | |
| parent | 3cdb90407e360a8b820058d8b10651b24bf70599 (diff) | |
| download | Tango-dcf222f6811d4a4dcda7f517f61e22e3c5ac0e7e.tar.gz Tango-dcf222f6811d4a4dcda7f517f61e22e3c5ac0e7e.zip | |
Stubs Utils.
Diffstat (limited to 'Software/Visual_Studio/StubsUtils')
7 files changed, 65 insertions, 4 deletions
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 @@ <ProjectGuid>{F423324C-7D0A-4512-BEBA-DF3A931A09F6}</ProjectGuid> <OutputType>Exe</OutputType> <RootNamespace>Tango.StubsUtils.PerformanceTest.CLI</RootNamespace> - <AssemblyName>Tango.StubsUtils.PerformanceTest.CLI</AssemblyName> + <AssemblyName>tangostub_perf</AssemblyName> <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion> <FileAlignment>512</FileAlignment> <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> @@ -18,7 +18,7 @@ <DebugSymbols>true</DebugSymbols> <DebugType>full</DebugType> <Optimize>false</Optimize> - <OutputPath>bin\Debug\</OutputPath> + <OutputPath>..\..\Build\StubsUtils\Debug\</OutputPath> <DefineConstants>DEBUG;TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> @@ -27,7 +27,7 @@ <PlatformTarget>AnyCPU</PlatformTarget> <DebugType>pdbonly</DebugType> <Optimize>true</Optimize> - <OutputPath>bin\Release\</OutputPath> + <OutputPath>..\..\Build\StubsUtils\Release\</OutputPath> <DefineConstants>TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> 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 @@ </Style.Triggers> </Style> + <Style x:Key="FSE_FlatButton_OpacityHover" TargetType="Button" BasedOn="{StaticResource MaterialDesignToolForegroundButton}"> + <Setter Property="FocusVisualStyle" Value="{x:Null}"></Setter> + <Setter Property="Foreground" Value="{StaticResource FSE_PrimaryAccentBrush}"></Setter> + <Style.Triggers> + <Trigger Property="IsMouseOver" Value="True"> + <Setter Property="Opacity" Value="0.6"></Setter> + </Trigger> + </Style.Triggers> + </Style> + </ResourceDictionary>
\ 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<string>(); RefreshPortsCommand = new RelayCommand(RefreshPorts); ToggleConnectionCommand = new RelayCommand(ToggleConnection); + StartPerformanceTesterCommand = new RelayCommand(StartPerformanceTester); ClearLogCommand = new RelayCommand(ClearLog); _logsQueue = new ProducerConsumerQueue<string>(); @@ -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 </TextBlock> </CheckBox> + + <Button Margin="20 -1 0 0" IsEnabled="{Binding Service.IsConnected}" Command="{Binding StartPerformanceTesterCommand}" Height="Auto" Style="{StaticResource FSE_FlatButton_OpacityHover}" FontSize="{StaticResource FSE_SmallFontSize}">Start Performance Tester</Button> </StackPanel> <DockPanel Margin="0 10 0 0" > 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<String, StubReflection> _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 |
