From 998cc8d4d91a7f85389cd0918f127257576c2c13 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Mon, 13 Aug 2018 16:12:45 +0300 Subject: Logs and comments for PPC.UI ! --- .../ViewModels/ExternalBridgeViewVM.cs | 82 ++++++++++++++++++++-- 1 file changed, 78 insertions(+), 4 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 a5a8d9ac3..3b672411d 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/ExternalBridgeViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/ExternalBridgeViewVM.cs @@ -13,12 +13,21 @@ using Tango.PPC.Common.Navigation; namespace Tango.PPC.UI.ViewModels { + /// + /// Represents the external bridge view ViewModel. + /// + /// [TangoCreateWhenRegistered] public class ExternalBridgeViewVM : PPCViewModel { private bool _disconnecting; + #region Properties + private ExternalBridgeClientConnectedEventArgs _connection; + /// + /// Gets or sets the last client connection event arguments. + /// public ExternalBridgeClientConnectedEventArgs Connection { get { return _connection; } @@ -26,26 +35,58 @@ namespace Tango.PPC.UI.ViewModels } private User _user; + /// + /// Gets or sets the user connected user. + /// public User User { get { return _user; } - set { _user = value; RaisePropertyChangedAuto(); } + set { _user = value; RaisePropertyChangedAuto(); } } + #endregion + + #region Commands + + /// + /// Gets or sets the close session command. + /// public RelayCommand CloseSessionCommand { get; set; } + #endregion + + #region Constructors + + /// + /// Initializes a new instance of the class. + /// public ExternalBridgeViewVM() { - CloseSessionCommand = new RelayCommand(CloseSession,() => !_disconnecting); + CloseSessionCommand = new RelayCommand(CloseSession, () => !_disconnecting); } + #endregion + + #region Private Methods + + /// + /// Closes the current session. + /// private void CloseSession() { + LogManager.Log("Disconnecting current external bridge session."); _disconnecting = true; InvalidateRelayCommands(); ExternalBridgeService.DisconnectSession(); } + #endregion + + #region Override Methods + + /// + /// Called when the navigation system has navigated to this VM view. + /// public override void OnNavigatedTo() { base.OnNavigatedTo(); @@ -54,22 +95,43 @@ namespace Tango.PPC.UI.ViewModels InvalidateRelayCommands(); } + /// + /// Called when the application has been started. + /// public override void OnApplicationStarted() { - ExternalBridgeService.ConnectionRequest += ExternalBridgeService_ClientConnected; + ExternalBridgeService.ConnectionRequest += ExternalBridgeService_ConnectionRequest; ExternalBridgeService.ClientDisconnected += ExternalBridgeService_ClientDisconnected; } + #endregion + + #region Event Handlers + + /// + /// Handles the event. + /// + /// The sender. + /// The instance containing the event data. private void ExternalBridgeService_ClientDisconnected(object sender, EventArgs e) { + LogManager.Log("External bridge client disconnected. Navigating to home module..."); + InvokeUI(() => { NavigationManager.NavigateTo(NavigationView.HomeModule); }); } - private void ExternalBridgeService_ClientConnected(object sender, ExternalBridgeClientConnectedEventArgs e) + /// + /// Handles the event. + /// + /// The sender. + /// The instance containing the event data. + private void ExternalBridgeService_ConnectionRequest(object sender, ExternalBridgeClientConnectedEventArgs e) { + LogManager.Log($"External bridge connection request received.\n{e.ToJsonString()}"); + if (e.Request.Password == MachineProvider.Machine.ExternalBridgePassword) { e.Confirmed = true; @@ -78,11 +140,23 @@ namespace Tango.PPC.UI.ViewModels User = Adapter.Users.SingleOrDefault(x => x.Guid == e.Request.UserGuid); + if (User != null) + { + LogManager.Log($"External bridge connection user has been identified as {User.Contact.FullName}"); + } + + LogManager.Log("Navigating to external bridge view..."); InvokeUI(() => { NavigationManager.NavigateTo(NavigationView.ExternalBridgeView, false); }); } + else + { + LogManager.Log("Connection password did not match the machine external bridge password."); + } } + + #endregion } } -- cgit v1.3.1