From 810bbfab7a812a0d9f0e46ff60d45280594a6716 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Thu, 8 Oct 2020 05:07:41 +0300 Subject: Implemented auto reconnection for USB on MS. --- .../DefaultStudioApplicationManager.cs | 4 +- .../Tango.MachineStudio.UI.csproj | 6 +- .../ViewModels/MainViewVM.cs | 81 +++++++++++++--------- 3 files changed, 55 insertions(+), 36 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio') diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/StudioApplication/DefaultStudioApplicationManager.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/StudioApplication/DefaultStudioApplicationManager.cs index 56f2a2bc0..feed9e193 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/StudioApplication/DefaultStudioApplicationManager.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/StudioApplication/DefaultStudioApplicationManager.cs @@ -132,8 +132,6 @@ namespace Tango.MachineStudio.UI.StudioApplication { if (e == Transport.TransportComponentState.Disconnected || e == Transport.TransportComponentState.Failed) { - bool reconnect = ConnectedMachine is IExternalBridgeSecureClient; - ConnectedMachine = null; if (e == Transport.TransportComponentState.Failed) @@ -147,7 +145,7 @@ namespace Tango.MachineStudio.UI.StudioApplication ConnectionLostViewVM vm = new ConnectionLostViewVM() { Exception = failed_reason, - AutoReconnect = reconnect, + AutoReconnect = true, }; InvokeUI(() => diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj index 78125cd8c..3783b54f8 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj @@ -434,6 +434,10 @@ {63561e19-ff5a-414b-a5ef-e30711543e1d} Tango.Emulations + + {99081c0e-065c-4d68-bf60-f82330cca02d} + Tango.Git + {4206ac58-3b57-4699-8835-90bf6db01a61} Tango.Integration @@ -676,7 +680,7 @@ if $(ConfigurationName) == Release RD /S /Q "$(TargetDir)Roslyn\" - + \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs index 6ddfee545..4f8c8a9b1 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs @@ -58,8 +58,9 @@ namespace Tango.MachineStudio.UI.ViewModels private IEventLogger _eventLogger; private MachineStudioSettings _settings; private MachineStudioWebClient _machineStudioWebClient; - private IExternalBridgeSecureClient _reconnectionMachine; + private IExternalBridgeClient _reconnectionMachine; private MachineLoginViewVM _reconnectionMachineConfig; + private bool _lastUploadHardwareConfigLocal; /// /// Gets or sets the current loaded module. @@ -350,9 +351,16 @@ namespace Tango.MachineStudio.UI.ViewModels ApplicationManager.ReconnectionRequired += ApplicationManager_ReconnectionRequired; } - private void ApplicationManager_ReconnectionRequired(object sender, EventArgs e) + private async void ApplicationManager_ReconnectionRequired(object sender, EventArgs e) { - ConnectToMachineSecure(_reconnectionMachine, _reconnectionMachineConfig); + if (_reconnectionMachine is IExternalBridgeSecureClient client) + { + ConnectToMachineSecure(client, _reconnectionMachineConfig); + } + else + { + await ConnectToMachineLocal(_reconnectionMachine, _reconnectionMachine.Machine, _lastUploadHardwareConfigLocal); + } } private void MachineEventsStateProvider_EventsResolved(object sender, IEnumerable e) @@ -486,41 +494,15 @@ namespace Tango.MachineStudio.UI.ViewModels { if (vm.SelectedMachine != null) { - using (NotificationProvider.PushTaskItem("Connecting to " + x.SelectedMachine.ToString() + "...")) - { - try - { - await x.SelectedMachine.Connect(); - x.SelectedMachine.SerialNumber = vm.SelectedMachine.SerialNumber; - ApplicationManager.SetConnectedMachine(x.SelectedMachine); - - PostMessage(new MachineConnectionChangedMessage() { Machine = x.SelectedMachine }); - _settings.LastVirtualMachineSerialNumber = vm.SelectedMachine.SerialNumber; - _settings.Save(); - - if (x.UploadHardwareConfiguration) - { - UploadHardwareConfiguration(false); - } - } - catch (Exception ex) - { - LogManager.Log(ex); - - _notificationProvider.ShowError("Could not connect to the selected machine." + Environment.NewLine + ex.Message); - - } - - InvalidateRelayCommands(); - } + await ConnectToMachineLocal(x.SelectedMachine, vm.SelectedMachine, x.UploadHardwareConfiguration); } }); } - InvalidateRelayCommands(); + base.InvalidateRelayCommands(); } - InvalidateRelayCommands(); + base.InvalidateRelayCommands(); }); } else @@ -585,6 +567,41 @@ namespace Tango.MachineStudio.UI.ViewModels InvalidateRelayCommands(); } + private async Task ConnectToMachineLocal(IExternalBridgeClient client, Machine machine, bool uploadHardwareConfig) + { + using (NotificationProvider.PushTaskItem("Connecting to " + client.ToString() + "...")) + { + try + { + _reconnectionMachine = client; + + await client.Connect(); + client.SerialNumber = machine.SerialNumber; + ApplicationManager.SetConnectedMachine(client); + + PostMessage(new MachineConnectionChangedMessage() { Machine = client }); + _settings.LastVirtualMachineSerialNumber = machine.SerialNumber; + _settings.Save(); + + _lastUploadHardwareConfigLocal = uploadHardwareConfig; + + if (uploadHardwareConfig) + { + UploadHardwareConfiguration(false); + } + } + catch (Exception ex) + { + LogManager.Log(ex); + + _notificationProvider.ShowError("Could not connect to the selected machine." + Environment.NewLine + ex.Message); + + } + + InvalidateRelayCommands(); + } + } + private async void ConnectToMachineSecure(IExternalBridgeSecureClient machine, MachineLoginViewVM config) { using (NotificationProvider.PushTaskItem("Connecting to machine " + machine.ToString() + "...")) -- cgit v1.3.1