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 ++++++++++++++++++- .../PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs | 92 ++++++++++++++++------ .../PPC/Tango.PPC.UI/ViewModels/LoadingViewVM.cs | 1 + .../PPC/Tango.PPC.UI/ViewModels/LoginViewVM.cs | 54 ++++++++++++- .../Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs | 81 ++++++++++++++++++- .../PPC/Tango.PPC.UI/ViewModels/MainViewVM.cs | 3 + 6 files changed, 281 insertions(+), 32 deletions(-) (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels') 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 } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs index 268f42ce9..3bcacc989 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs @@ -28,6 +28,8 @@ namespace Tango.PPC.UI.ViewModels [TangoInject] public IPPCModuleLoader ModuleLoader { get; set; } + #region Properties + private bool _isMenuOpened; /// /// Gets or sets a value indicating whether the side menu is opened. @@ -48,6 +50,10 @@ namespace Tango.PPC.UI.ViewModels set { _isNotificationsOpened = value; RaisePropertyChangedAuto(); } } + #endregion + + #region Commands + /// /// Gets or sets the module navigation command. /// @@ -78,6 +84,10 @@ namespace Tango.PPC.UI.ViewModels /// public RelayCommand SignOutCommand { get; set; } + #endregion + + #region Constructors + /// /// Initializes a new instance of the class. /// @@ -92,8 +102,17 @@ namespace Tango.PPC.UI.ViewModels SignOutCommand = new RelayCommand(SignOut); } + #endregion + + #region Private Methods + + /// + /// Stops the printing. + /// private void StopPrinting() { + LogManager.Log("Stop printing layout command pressed!"); + if (_jobHandler != null) { _jobHandler.Cancel(); @@ -107,10 +126,12 @@ namespace Tango.PPC.UI.ViewModels { if (NavigationManager.CanNavigateBack) { + LogManager.Log("Back command pressed."); NavigationManager.NavigateBack(); } else { + LogManager.Log("Menu command pressed."); IsMenuOpened = true; } } @@ -121,6 +142,7 @@ namespace Tango.PPC.UI.ViewModels /// Name of the module. private void NavigateToModule(string moduleName) { + LogManager.Log("Navigate to module command pressed."); IsMenuOpened = false; NavigationManager.NavigateTo(moduleName); } @@ -130,33 +152,48 @@ namespace Tango.PPC.UI.ViewModels /// private void NavigateHome() { + LogManager.Log("Navigate home command pressed."); IsMenuOpened = false; NavigationManager.NavigateTo(NavigationView.HomeModule); } /// - /// Called when the application has been started. + /// Represents an event that is raised when the sign-out operation is complete. /// - public override void OnApplicationStarted() + private void SignOut() { - base.OnApplicationStarted(); - ModuleLoader.ModulesLoaded += ModuleLoader_ModulesLoaded; - MachineProvider.MachineOperator.PrintingStarted += MachineOperator_PrintingStarted; + LogManager.Log("SignOut command pressed."); + AuthenticationProvider.LogOut(); + IsMenuOpened = false; } - private void MachineOperator_PrintingStarted(object sender, PrintingEventArgs e) + /// + /// Opens the first notification or display all. + /// + private void OpenFirstNotificationOrDisplayAll() { - _jobHandler = e.JobHandler; + if (NotificationProvider.NotificationItems.Count == 1) + { + //Open first + } + else + { + IsNotificationsOpened = true; + } } + #endregion + + #region Override Methods + /// - /// Handles the ModulesLoaded event of the ModuleLoader. + /// Called when the application has been started. /// - /// The source of the event. - /// The instance containing the event data. - private void ModuleLoader_ModulesLoaded(object sender, EventArgs e) + public override void OnApplicationStarted() { - View.ApplyModules(ModuleLoader.UserModules); + base.OnApplicationStarted(); + ModuleLoader.ModulesLoaded += ModuleLoader_ModulesLoaded; + MachineProvider.MachineOperator.PrintingStarted += MachineOperator_PrintingStarted; } /// @@ -167,28 +204,31 @@ namespace Tango.PPC.UI.ViewModels } + #endregion + + #region Event Handlers + /// - /// Represents an event that is raised when the sign-out operation is complete. + /// Handles the PrintingStarted event of the MachineOperator. /// - private void SignOut() + /// The source of the event. + /// The instance containing the event data. + private void MachineOperator_PrintingStarted(object sender, PrintingEventArgs e) { - AuthenticationProvider.LogOut(); - IsMenuOpened = false; + _jobHandler = e.JobHandler; } /// - /// Opens the first notification or display all. + /// Handles the ModulesLoaded event of the ModuleLoader. /// - private void OpenFirstNotificationOrDisplayAll() + /// The source of the event. + /// The instance containing the event data. + private void ModuleLoader_ModulesLoaded(object sender, EventArgs e) { - if (NotificationProvider.NotificationItems.Count == 1) - { - //Open first - } - else - { - IsNotificationsOpened = true; - } + LogManager.Log("Modules loaded. Applying modules to main navigation control..."); + View.ApplyModules(ModuleLoader.UserModules); } + + #endregion } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoadingViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoadingViewVM.cs index 77767d588..852997f87 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoadingViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoadingViewVM.cs @@ -61,6 +61,7 @@ namespace Tango.PPC.UI.ViewModels public override void OnApplicationStarted() { IsLoading = false; + LogManager.Log("Application started. Navigating to LoginView..."); NavigationManager.NavigateTo(NavigationView.LoginView); } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoginViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoginViewVM.cs index 022efd9b8..812f10121 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoginViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoginViewVM.cs @@ -9,14 +9,25 @@ using Tango.PPC.Common.Navigation; using SimpleValidator.Extensions; using System.ComponentModel.DataAnnotations; using Tango.SharedUI.Helpers; +using Tango.PPC.Common.Authentication; +using Tango.BL.Entities; namespace Tango.PPC.UI.ViewModels { + /// + /// Represents the PPC login view ViewModel. + /// + /// public class LoginViewVM : PPCViewModel { public RelayCommand LoginCommand { get; set; } + #region Properties + private String _email; + /// + /// Gets or sets the email. + /// [Required(ErrorMessage = "Email is required")] [EmailAddress(ErrorMessage = "Please enter a valid email address")] public String Email @@ -26,6 +37,9 @@ namespace Tango.PPC.UI.ViewModels } private String _password; + /// + /// Gets or sets the password. + /// [Required(ErrorMessage = "Password is required")] public String Password { @@ -43,7 +57,13 @@ namespace Tango.PPC.UI.ViewModels set { _isLoading = value; RaisePropertyChangedAuto(); } } + #endregion + + #region Constructors + /// + /// Initializes a new instance of the class. + /// public LoginViewVM() { LoginCommand = new RelayCommand(Login); @@ -52,12 +72,28 @@ namespace Tango.PPC.UI.ViewModels Password = "1234"; } + #endregion + + #region Override Methods + + /// + /// Called when the application has been started. + /// public override void OnApplicationStarted() { AuthenticationProvider.CurrentUserChanged += AuthenticationProvider_CurrentUserChanged; } - private void AuthenticationProvider_CurrentUserChanged(object sender, BL.Entities.User user) + #endregion + + #region Event Handlers + + /// + /// Handles the event. + /// + /// The sender. + /// The user. + private void AuthenticationProvider_CurrentUserChanged(object sender, User user) { if (user == null) { @@ -65,8 +101,17 @@ namespace Tango.PPC.UI.ViewModels } } + #endregion + + #region Private Methods + + /// + /// Login to the application using the user name and password. + /// private void Login() { + LogManager.Log("Login command pressed."); + if (Validate()) { IsLoading = true; @@ -83,10 +128,17 @@ namespace Tango.PPC.UI.ViewModels ApplicationManager.ModulesInitialized += async (_, __) => { await Task.Delay(500); + LogManager.Log("Modules initialized. Navigating to home module..."); await NavigationManager.NavigateTo(NavigationView.HomeModule); IsLoading = false; }; } + else + { + LogManager.Log("Invalid user credentials."); + } } + + #endregion } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs index 2877d52b3..a81db331c 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs @@ -19,8 +19,15 @@ using Tango.SQLExaminer; namespace Tango.PPC.UI.ViewModels { + /// + /// Represents the machine setup view ViewModel. + /// + /// public class MachineSetupViewVM : PPCViewModel { + /// + /// Represents the various machine setup view states. + /// public enum MachineSetupStates { None, @@ -31,9 +38,17 @@ namespace Tango.PPC.UI.ViewModels private MachineSetupResult _setup_result; + #region Properties + + /// + /// Gets or sets the machine setup manager. + /// public IMachineSetupManager MachineSetupManager { get; set; } private String _serialNumber; + /// + /// Gets or sets the serial number. + /// public String SerialNumber { get { return _serialNumber; } @@ -41,6 +56,9 @@ namespace Tango.PPC.UI.ViewModels } private String _hostAddress; + /// + /// Gets or sets the host address. + /// public String HostAddress { get { return _hostAddress; } @@ -48,6 +66,9 @@ namespace Tango.PPC.UI.ViewModels } private String _log; + /// + /// Gets or sets the log. + /// public String Log { get { return _log; } @@ -55,16 +76,38 @@ namespace Tango.PPC.UI.ViewModels } private MachineSetupStates _state; + /// + /// Gets or sets the state. + /// public MachineSetupStates State { get { return _state; } set { _state = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); } } + #endregion + + #region Commands + + /// + /// Gets or sets the start command. + /// public RelayCommand StartCommand { get; set; } + /// + /// Gets or sets the complete command. + /// public RelayCommand CompleteCommand { get; set; } + #endregion + + #region Constructors + + /// + /// Initializes a new instance of the class. + /// + /// The application manager. + /// The machine setup manager. public MachineSetupViewVM(IPPCApplicationManager applicationManager, IMachineSetupManager machineSetupManager) { MachineSetupManager = machineSetupManager; @@ -80,11 +123,29 @@ namespace Tango.PPC.UI.ViewModels applicationManager.SetupRequired += ApplicationManager_SetupRequired; } + #endregion + + #region Event Handlers + + /// + /// Handles the SetupRequired event of the ApplicationManager. + /// + /// The source of the event. + /// The instance containing the event data. private void ApplicationManager_SetupRequired(object sender, EventArgs e) { + LogManager.Log("SetupRequired event received. Navigating to MachineSetupView..."); NavigationManager.NavigateTo(NavigationView.MachineSetupView); } + #endregion + + #region Private Methods + + /// + /// Appends the log. + /// + /// The MSG. private void AppendLog(String msg) { if (msg != null && !msg.Contains("SQL Examiner")) @@ -96,8 +157,13 @@ namespace Tango.PPC.UI.ViewModels } } + /// + /// Starts the setup. + /// private async void StartSetup() { + LogManager.Log("Starting machine setup..."); + State = MachineSetupStates.Working; try @@ -106,18 +172,31 @@ namespace Tango.PPC.UI.ViewModels Settings.ApplicationState = ApplicationStates.SemiSetup; Settings.Save(); State = MachineSetupStates.Completed; + + LogManager.Log("Machine setup completed."); } catch (Exception ex) { + LogManager.Log(ex, "Machine setup failed."); State = MachineSetupStates.Failed; await NotificationProvider.ShowInfo(ex.Message); } } + /// + /// Completes the setup. + /// private void CompleteSetup() { - Process.Start(AssemblyHelper.GetCurrentAssemblyFolder() + "\\Tango.PPC.Updater.exe", _setup_result.UpdatePackagePath); + String updater_exe = AssemblyHelper.GetCurrentAssemblyFolder() + "\\Tango.PPC.Updater.exe"; + + LogManager.Log("Completing machine setup..."); + LogManager.Log($"Executing '{updater_exe}' with arguments '{_setup_result.UpdatePackagePath}'..."); + Process.Start(updater_exe, _setup_result.UpdatePackagePath); + LogManager.Log("Terminating application process!"); Environment.Exit(0); } + + #endregion } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MainViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MainViewVM.cs index 67d885685..e207c30b3 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MainViewVM.cs @@ -22,6 +22,9 @@ namespace Tango.PPC.UI.ViewModels /// public class MainViewVM : PPCViewModel { + /// + /// Called when the application has been started. + /// public override void OnApplicationStarted() { } -- cgit v1.3.1