aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels
diff options
context:
space:
mode:
authorRoy <roy.mail.net@gmail.com>2017-12-24 02:27:16 +0200
committerRoy <roy.mail.net@gmail.com>2017-12-24 02:27:16 +0200
commit53db041e636bb3802dbe3cb911de6ef6ef41446c (patch)
tree9be0b0961a31fea4a60f5a9c1741363fa313a13b /Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels
parentceac40d058a8554638aa3fa39d4697f3fbfe62f8 (diff)
downloadTango-53db041e636bb3802dbe3cb911de6ef6ef41446c.tar.gz
Tango-53db041e636bb3802dbe3cb911de6ef6ef41446c.zip
Continue for last commit.
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels')
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MachineConnectionViewVM.cs55
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs73
2 files changed, 127 insertions, 1 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MachineConnectionViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MachineConnectionViewVM.cs
new file mode 100644
index 000000000..b8b888e86
--- /dev/null
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MachineConnectionViewVM.cs
@@ -0,0 +1,55 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.Core.Commands;
+using Tango.Integration.Services;
+using Tango.MachineStudio.Common.Notifications;
+using Tango.SharedUI;
+
+namespace Tango.MachineStudio.UI.ViewModels
+{
+ public class MachineConnectionViewVM : DialogViewVM
+ {
+ private ExternalBridgeScanner _scanner;
+
+ public ExternalBridgeScanner Scanner
+ {
+ get { return _scanner; }
+ set { _scanner = value; RaisePropertyChangedAuto(); }
+ }
+
+ private IExternalBridgeClient _selectedMachine;
+
+ public IExternalBridgeClient SelectedMachine
+ {
+ get { return _selectedMachine; }
+ set { _selectedMachine = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); }
+ }
+
+ public RelayCommand ConnectCommand { get; set; }
+
+ public MachineConnectionViewVM(ExternalBridgeScanner scanner)
+ {
+ Scanner = scanner;
+ ConnectCommand = new RelayCommand(Connect,(x) => SelectedMachine != null);
+ Scanner.Start();
+ }
+
+ private void Connect()
+ {
+ if (SelectedMachine != null)
+ {
+ Accept();
+ }
+ }
+
+ public override void OnShow()
+ {
+ base.OnShow();
+
+ Scanner.AvailableMachines.Clear();
+ }
+ }
+}
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 a12156d60..6c44c8480 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs
@@ -7,18 +7,24 @@ using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Tango.Core.Commands;
+using Tango.Logging;
using Tango.MachineStudio.Common;
using Tango.MachineStudio.Common.Authentication;
using Tango.MachineStudio.Common.Modules;
using Tango.MachineStudio.Common.Notifications;
+using Tango.MachineStudio.Common.StudioApplication;
using Tango.MachineStudio.UI.SupervisingController;
+using Tango.MachineStudio.UI.Views;
+using Tango.PMR.Stubs;
using Tango.SharedUI;
+using Tango.Transport.Adapters;
namespace Tango.MachineStudio.UI.ViewModels
{
public class MainViewVM : ViewModel<IMainView>
{
private IStudioModule _currentModule;
+ private bool _isDisconnecting;
public IStudioModule CurrentModule
{
@@ -47,6 +53,10 @@ namespace Tango.MachineStudio.UI.ViewModels
public RelayCommand HomeCommand { get; set; }
+ public RelayCommand ConnectCommand { get; set; }
+
+ public RelayCommand DisconnectCommand { get; set; }
+
private IAuthenticationProvider _authenticationProvider;
public IAuthenticationProvider AuthenticationProvider
{
@@ -70,20 +80,81 @@ namespace Tango.MachineStudio.UI.ViewModels
set { _notificationProvider = value; RaisePropertyChangedAuto(); }
}
+ private IStudioApplicationManager _applicationManager;
+
+ public IStudioApplicationManager ApplicationManager
+ {
+ get { return _applicationManager; }
+ set { _applicationManager = value; RaisePropertyChangedAuto(); }
+ }
+
+
public MainViewVM(
IMainView view,
IAuthenticationProvider authenticationProvider,
IStudioModuleLoader studioModuleLoader,
- INotificationProvider notificationProvider) : base(view)
+ INotificationProvider notificationProvider,
+ IStudioApplicationManager applicationManager) : base(view)
{
AuthenticationProvider = authenticationProvider;
StudioModuleLoader = studioModuleLoader;
NotificationProvider = notificationProvider;
+ ApplicationManager = applicationManager;
StartModuleCommand = new RelayCommand<IStudioModule>(StartModule);
HomeCommand = new RelayCommand(Home);
+ ConnectCommand = new RelayCommand(ConnectToMachine);
+ DisconnectCommand = new RelayCommand(DisconnectFromMachine,(x) => ApplicationManager.IsMachineConnected && !_isDisconnecting);
+ }
+
+ private async void DisconnectFromMachine()
+ {
+ using (_notificationProvider.PushTaskItem("Disconnecting from machine..."))
+ {
+ _isDisconnecting = true;
+ InvalidateRelayCommands();
+ await ApplicationManager.ConnectedMachine.Disconnect();
+ ApplicationManager.ConnectedMachine = null;
+ _isDisconnecting = false;
+ InvalidateRelayCommands();
+ }
+ }
+
+ private void ConnectToMachine()
+ {
+ _notificationProvider.ShowModalDialog<MachineConnectionViewVM>(async (x) =>
+ {
+ if (x.SelectedMachine != null)
+ {
+ using (NotificationProvider.PushTaskItem("Connecting to machine " + x.SelectedMachine.SerialNumber + "..."))
+ {
+ try
+ {
+ await x.SelectedMachine.Connect();
+ var authenticated = await x.SelectedMachine.Authenticate();
+ if (!authenticated)
+ {
+ _notificationProvider.ShowError("It seems like you are not authorized to access the selected machine.");
+ }
+ else
+ {
+ ApplicationManager.ConnectedMachine = x.SelectedMachine;
+ var response = await x.SelectedMachine.SendRequest<CalculateRequest, CalculateResponse>(new CalculateRequest() { A = 10, B = 5 });
+ _notificationProvider.ShowInfo(response.ToString());
+ }
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex);
+ _notificationProvider.ShowError(ex.Message);
+ }
+ }
+ }
+
+ InvalidateRelayCommands();
+ });
}
private void Home()