From c400fa026cdb2bc5c1c5c25f5bfae37461e87cab Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Wed, 11 Apr 2018 14:50:47 +0300 Subject: Added Disconnect & Connect requests. Fixed issue with Machine Connection View Scanning. Fixed issue with ShowModalDialog close event.. Added ConnectedMachineView. Added TransferRate for Adapters. --- .../EventLogging/DefaultEventLogger.cs | 2 +- .../Tango.MachineStudio.UI/Html/HtmlWindow.xaml | 2 +- .../Notifications/DefaultNotificationProvider.cs | 21 +++- .../Tango.MachineStudio.UI.csproj | 8 ++ .../Tango.MachineStudio.UI/ViewModelLocator.cs | 9 ++ .../ViewModels/ConnectedMachineViewVM.cs | 36 ++++++ .../ViewModels/MainViewVM.cs | 125 ++++++++++++--------- .../Views/ConnectedMachineView.xaml | 111 ++++++++++++++++++ .../Views/ConnectedMachineView.xaml.cs | 28 +++++ .../Views/MachineConnectionView.xaml | 2 +- 10 files changed, 281 insertions(+), 63 deletions(-) create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/ConnectedMachineViewVM.cs create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/ConnectedMachineView.xaml create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/ConnectedMachineView.xaml.cs (limited to 'Software/Visual_Studio/MachineStudio') diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/DefaultEventLogger.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/DefaultEventLogger.cs index f3ae1002b..2a5dcb3a0 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/DefaultEventLogger.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/DefaultEventLogger.cs @@ -206,7 +206,7 @@ namespace Tango.MachineStudio.Common.EventLogging } LogManager.Log("Logging event " + machineEvent.EventType.Name + " - " + machineEvent.Description); - machineEvent.MachineGuid = _application.ConnectedMachine.Guid; + machineEvent.MachineGuid = _application.ConnectedMachine.Machine.Guid; machineEvent.UserGuid = _authentication.CurrentUser.Guid; machineEvent.User = _authentication.CurrentUser; _events.Enqueue(machineEvent); diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Html/HtmlWindow.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Html/HtmlWindow.xaml index d7032cedc..f984a985f 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Html/HtmlWindow.xaml +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Html/HtmlWindow.xaml @@ -18,7 +18,7 @@ - + { dialog.Close(); onAccept(context); context.Accepted -= onAcceptAction; + context.Canceled -= onCancelAction; }); - Action onCancelAction = null; onCancelAction = new Action(() => { dialog.Close(); @@ -129,6 +131,7 @@ namespace Tango.MachineStudio.UI.Notifications onCancel(); } + context.Accepted -= onAcceptAction; context.Canceled -= onCancelAction; }); @@ -163,14 +166,16 @@ namespace Tango.MachineStudio.UI.Notifications dialog.DataContext = context; Action onAcceptAction = null; + Action onCancelAction = null; + onAcceptAction = new Action(() => { dialog.Close(); onAccept(context); context.Accepted -= onAcceptAction; + context.Canceled -= onCancelAction; }); - Action onCancelAction = null; onCancelAction = new Action(() => { dialog.Close(); @@ -180,6 +185,7 @@ namespace Tango.MachineStudio.UI.Notifications onCancel(); } + context.Accepted -= onAcceptAction; context.Canceled -= onCancelAction; }); @@ -213,14 +219,16 @@ namespace Tango.MachineStudio.UI.Notifications dialog.DataContext = context; Action onAcceptAction = null; + Action onCancelAction = null; + onAcceptAction = new Action(() => { dialog.Close(); onAccept(context); context.Accepted -= onAcceptAction; + context.Canceled -= onCancelAction; }); - Action onCancelAction = null; onCancelAction = new Action(() => { dialog.Close(); @@ -231,6 +239,7 @@ namespace Tango.MachineStudio.UI.Notifications } context.Canceled -= onCancelAction; + context.Accepted -= onAcceptAction; }); context.Accepted += onAcceptAction; @@ -279,15 +288,18 @@ namespace Tango.MachineStudio.UI.Notifications } dialog.DataContext = context; + Action onCancelAction = null; Action onAcceptAction = null; + onAcceptAction = new Action(() => { dialog.Close(); onAccept(context); + + context.Canceled -= onCancelAction; context.Accepted -= onAcceptAction; }); - Action onCancelAction = null; onCancelAction = new Action(() => { dialog.Close(); @@ -298,6 +310,7 @@ namespace Tango.MachineStudio.UI.Notifications } context.Canceled -= onCancelAction; + context.Accepted -= onAcceptAction; }); context.Accepted += onAcceptAction; 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 c13970674..eb4139936 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 @@ -159,6 +159,7 @@ MessageBoxWindow.xaml + @@ -169,6 +170,9 @@ + + ConnectedMachineView.xaml + LoadingView.xaml @@ -234,6 +238,10 @@ MSBuild:Compile Designer + + Designer + MSBuild:Compile + Designer MSBuild:Compile diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModelLocator.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModelLocator.cs index bbb916d02..97eb2913b 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModelLocator.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModelLocator.cs @@ -82,6 +82,7 @@ namespace Tango.MachineStudio.UI SimpleIoc.Default.Register(); SimpleIoc.Default.Register(); SimpleIoc.Default.Register(); + SimpleIoc.Default.Register(); SimpleIoc.Default.Register(); SimpleIoc.Default.Register(); @@ -133,6 +134,14 @@ namespace Tango.MachineStudio.UI } } + public ConnectedMachineViewVM ConnectedMachineViewVM + { + get + { + return ServiceLocator.Current.GetInstance(); + } + } + public MachineLoginViewVM MachineLoginViewVM { get 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..f78cc15be 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs @@ -384,70 +384,42 @@ namespace Tango.MachineStudio.UI.ViewModels /// private void ConnectToMachine() { - _notificationProvider.ShowModalDialog(async (x) => + if (ApplicationManager.ConnectedMachine == null) { - if (x.SelectedMachine != null) + _notificationProvider.ShowModalDialog(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(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().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(async (vm) => + } + + if (x.SelectedMachine.RequiresAuthentication) { - if (vm.SelectedMachine != null) + _notificationProvider.ShowModalDialog(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().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) { @@ -458,15 +430,55 @@ namespace Tango.MachineStudio.UI.ViewModels InvalidateRelayCommands(); } - } - }); + }); + } + else + { + _notificationProvider.ShowModalDialog(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(ex.Message); + } + + InvalidateRelayCommands(); + } + } + }); + } + + InvalidateRelayCommands(); } InvalidateRelayCommands(); - } + }); + } + else + { + _notificationProvider.ShowModalDialog((x) => + { + DisconnectFromMachine(); + }); + } - InvalidateRelayCommands(); - }); + InvalidateRelayCommands(); } /// @@ -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); } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/ConnectedMachineView.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/ConnectedMachineView.xaml new file mode 100644 index 000000000..797d4dcb0 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/ConnectedMachineView.xaml @@ -0,0 +1,111 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/ConnectedMachineView.xaml.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/ConnectedMachineView.xaml.cs new file mode 100644 index 000000000..cc8ac2237 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/ConnectedMachineView.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Tango.MachineStudio.UI.Views +{ + /// + /// Interaction logic for ConnectedMachineView.xaml + /// + public partial class ConnectedMachineView : UserControl + { + public ConnectedMachineView() + { + InitializeComponent(); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MachineConnectionView.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MachineConnectionView.xaml index 1626e67ef..6f0a74805 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MachineConnectionView.xaml +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MachineConnectionView.xaml @@ -70,7 +70,7 @@ IP Address: - Organization: + Organization: -- cgit v1.3.1