From ead172c9292326266b2c1622f058df5e2039bd05 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Mon, 30 Jul 2018 18:16:30 +0300 Subject: Working on PPC Machine Studio External Bridge ! --- .../ViewModels/ExternalBridgeViewVM.cs | 63 +++++++++++++++++++--- 1 file changed, 57 insertions(+), 6 deletions(-) (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/ExternalBridgeViewVM.cs') diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/ExternalBridgeViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/ExternalBridgeViewVM.cs index f0b6bbfdf..3c348c796 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/ExternalBridgeViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/ExternalBridgeViewVM.cs @@ -3,23 +3,74 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tango.BL.Entities; +using Tango.Core.Commands; using Tango.Core.DI; +using Tango.Integration.ExternalBridge; using Tango.PPC.Common; using Tango.PPC.Common.ExternalBridge; +using Tango.PPC.Common.Navigation; namespace Tango.PPC.UI.ViewModels { + [TangoCreateWhenRegistered] public class ExternalBridgeViewVM : PPCViewModel { - /// - /// Gets or sets the external bridge service. - /// - [TangoInject] - public IPPCExternalBridgeService ExternalBridgeService { get; set; } + private ExternalBridgeClientConnectedEventArgs _connection; + public ExternalBridgeClientConnectedEventArgs Connection + { + get { return _connection; } + set { _connection = value; RaisePropertyChangedAuto(); } + } + + private User _user; + public User User + { + get { return _user; } + set { _user = value; RaisePropertyChangedAuto(); } + } + + public RelayCommand CloseSessionCommand { get; set; } + + public ExternalBridgeViewVM() + { + CloseSessionCommand = new RelayCommand(CloseSession); + } + + private void CloseSession() + { + ExternalBridgeService.DisconnectSession(); + } public override void OnApplicationStarted() { - //throw new NotImplementedException(); + ExternalBridgeService.ClientConnected += ExternalBridgeService_ClientConnected; + ExternalBridgeService.ClientDisconnected += ExternalBridgeService_ClientDisconnected; + } + + private void ExternalBridgeService_ClientDisconnected(object sender, EventArgs e) + { + InvokeUI(() => + { + NavigationManager.NavigateTo(NavigationView.HomeModule); + }); + } + + private void ExternalBridgeService_ClientConnected(object sender, ExternalBridgeClientConnectedEventArgs e) + { + if (e.Request.Password == MachineProvider.Machine.ExternalBridgePassword) + { + e.Confirmed = true; + + Connection = e; + + User = Adapter.Users.SingleOrDefault(x => x.Guid == e.Request.UserGuid); + + InvokeUI(() => + { + NavigationManager.NavigateTo(NavigationView.ExternalBridgeView, false); + }); + } } } } -- cgit v1.3.1