diff options
| author | Avi Levkovich <avi@twine-s.com> | 2018-04-16 09:27:48 +0300 |
|---|---|---|
| committer | Avi Levkovich <avi@twine-s.com> | 2018-04-16 09:27:48 +0300 |
| commit | eafb576fe1bf76898b9cc17671a89d1585e2c8e4 (patch) | |
| tree | d833a983eb84c53b35b19a45af475aa3e88953c0 /Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels | |
| parent | cf441513c1010eb4363e985b3b7af61a8503456e (diff) | |
| parent | 53f93d7fd2d2aa4571bad6e93e0c519fce242753 (diff) | |
| download | Tango-eafb576fe1bf76898b9cc17671a89d1585e2c8e4.tar.gz Tango-eafb576fe1bf76898b9cc17671a89d1585e2c8e4.zip | |
Merge branch 'master' of https://twinetfs.visualstudio.com/_git/Tango
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels')
2 files changed, 106 insertions, 57 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/ConnectedMachineViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/ConnectedMachineViewVM.cs new file mode 100644 index 000000000..9f84cfb53 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/ConnectedMachineViewVM.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.BL.Entities; +using Tango.Core.Commands; +using Tango.MachineStudio.Common.Notifications; +using Tango.MachineStudio.Common.StudioApplication; +using Tango.SharedUI; + +namespace Tango.MachineStudio.UI.ViewModels +{ + public class ConnectedMachineViewVM : DialogViewVM + { + private IStudioApplicationManager _applicationManager; + public IStudioApplicationManager ApplicationManager + { + get { return _applicationManager; } + set { _applicationManager = value; RaisePropertyChangedAuto(); } + } + + public RelayCommand DisconnectCommand { get; set; } + + public ConnectedMachineViewVM(IStudioApplicationManager application) + { + ApplicationManager = application; + DisconnectCommand = new RelayCommand(Disconnect); + } + + private void Disconnect() + { + Accept(); + } + } +} 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 f9bffae29..8e451cdce 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs @@ -384,89 +384,101 @@ namespace Tango.MachineStudio.UI.ViewModels /// </summary> private void ConnectToMachine() { - _notificationProvider.ShowModalDialog<MachineConnectionViewVM>(async (x) => + if (ApplicationManager.ConnectedMachine == null) { - if (x.SelectedMachine != null) + _notificationProvider.ShowModalDialog<MachineConnectionViewVM>(async (x) => { - if (ApplicationManager.IsMachineConnected) + if (x.SelectedMachine != null) { - using (_notificationProvider.PushTaskItem("Disconnecting...")) + if (ApplicationManager.IsMachineConnected) { - await ApplicationManager.ConnectedMachine.Disconnect(); - await Task.Delay(1000); - } - } - - if (x.SelectedMachine.RequiresAuthentication) - { - _notificationProvider.ShowModalDialog<MachineLoginViewVM>(async (login) => - { - using (NotificationProvider.PushTaskItem("Connecting to machine " + x.SelectedMachine.ToString() + "...")) + using (_notificationProvider.PushTaskItem("Disconnecting...")) { - try - { - await x.SelectedMachine.Connect(); - - var authenticated = await x.SelectedMachine.As<IExternalBridgeSecureClient>().Authenticate(login.Password); - if (!authenticated) - { - _notificationProvider.ShowError("It seems like you are not authorized to access the selected machine."); - } - else - { - ApplicationManager.ConnectedMachine = x.SelectedMachine; - PostMessage(new MachineConnectionChangedMessage() { Machine = x.SelectedMachine }); - _eventLogger.Log(String.Format("Successfully connected to machine {0} via TCP", x.SelectedMachine.SerialNumber)); - } - } - catch (Exception ex) - { - LogManager.Log(ex); - _eventLogger.Log(ex, "Error connecting to machine " + x.SelectedMachine.SerialNumber); - _notificationProvider.ShowError(ex.Message); - } - - InvalidateRelayCommands(); + await ApplicationManager.ConnectedMachine.Disconnect(); + await Task.Delay(1000); } - }); - } - else - { - _notificationProvider.ShowModalDialog<MachineSerialViewVM>(async (vm) => + } + + if (x.SelectedMachine.RequiresAuthentication) { - if (vm.SelectedMachine != null) + _notificationProvider.ShowModalDialog<MachineLoginViewVM>(async (login) => { - using (NotificationProvider.PushTaskItem("Connecting to " + x.SelectedMachine.ToString() + "...")) + using (NotificationProvider.PushTaskItem("Connecting to machine " + x.SelectedMachine.ToString() + "...")) { try { await x.SelectedMachine.Connect(); - x.SelectedMachine.SerialNumber = vm.SelectedMachine.SerialNumber; - ApplicationManager.ConnectedMachine = x.SelectedMachine; - PostMessage(new MachineConnectionChangedMessage() { Machine = x.SelectedMachine }); - _eventLogger.Log(String.Format("Successfully connected to machine {0} via USB", x.SelectedMachine.SerialNumber)); - SettingsManager.Default.MachineStudio.LastVirtualMachineSerialNumber = vm.SelectedMachine.SerialNumber; - SettingsManager.SaveDefaultSettings(); + var authenticated = await x.SelectedMachine.As<IExternalBridgeSecureClient>().Authenticate(login.Password); + if (!authenticated) + { + _notificationProvider.ShowError("It seems like you are not authorized to access the selected machine."); + } + else + { + ApplicationManager.ConnectedMachine = x.SelectedMachine; + PostMessage(new MachineConnectionChangedMessage() { Machine = x.SelectedMachine }); + _eventLogger.Log(String.Format("Successfully connected to machine {0} via TCP", x.SelectedMachine.SerialNumber)); + } } catch (Exception ex) { LogManager.Log(ex); _eventLogger.Log(ex, "Error connecting to machine " + x.SelectedMachine.SerialNumber); - _notificationProvider.ShowError(ex.Message); + _notificationProvider.ShowError("Could not connect to the selected machine." + Environment.NewLine + ex.Message); } InvalidateRelayCommands(); } - } - }); + }); + } + else + { + _notificationProvider.ShowModalDialog<MachineSerialViewVM>(async (vm) => + { + if (vm.SelectedMachine != null) + { + using (NotificationProvider.PushTaskItem("Connecting to " + x.SelectedMachine.ToString() + "...")) + { + try + { + await x.SelectedMachine.Connect(); + x.SelectedMachine.SerialNumber = vm.SelectedMachine.SerialNumber; + ApplicationManager.ConnectedMachine = x.SelectedMachine; + + PostMessage(new MachineConnectionChangedMessage() { Machine = x.SelectedMachine }); + _eventLogger.Log(String.Format("Successfully connected to machine {0} via USB", x.SelectedMachine.SerialNumber)); + SettingsManager.Default.MachineStudio.LastVirtualMachineSerialNumber = vm.SelectedMachine.SerialNumber; + SettingsManager.SaveDefaultSettings(); + } + catch (Exception ex) + { + LogManager.Log(ex); + _eventLogger.Log(ex, "Error connecting to machine " + x.SelectedMachine.SerialNumber); + _notificationProvider.ShowError("Could not connect to the selected machine." + Environment.NewLine + ex.Message); + } + + InvalidateRelayCommands(); + } + } + }); + } + + InvalidateRelayCommands(); } InvalidateRelayCommands(); - } + }); + } + else + { + _notificationProvider.ShowModalDialog<ConnectedMachineViewVM>((x) => + { + DisconnectFromMachine(); + }); + } - InvalidateRelayCommands(); - }); + InvalidateRelayCommands(); } /// <summary> @@ -581,6 +593,7 @@ namespace Tango.MachineStudio.UI.ViewModels { if (ApplicationManager.ConnectedMachine != null && machineEvent.EventType.Resolvable) { + _eventLogger.Log(String.Format("Event '{0}' resolved by user.", machineEvent.EventType.Name)); await ApplicationManager.ConnectedMachine.ResolveEvent((PMR.Diagnostics.EventType)machineEvent.Type); } } |
