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 ! --- .../DefaultAuthenticationProvider.cs | 13 ++ .../Controls/HeaderLoadingControl.xaml | 16 -- .../Controls/HeaderLoadingControl.xaml.cs | 28 ---- .../Navigation/DefaultNavigationManager.cs | 19 ++- .../Tango.PPC.UI/Notifications/DialogAndView.cs | 17 +++ .../Notifications/PendingNotification.cs | 19 +++ .../PPCApplication/DefaultPPCApplicationManager.cs | 161 ++++++++++++++------- .../PPC/Tango.PPC.UI/Tango.PPC.UI.csproj | 18 +-- .../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 + .../PPC/Tango.PPC.UI/Views/LayoutView.xaml | 1 - .../PPC/Tango.PPC.UI/Views/LayoutView.xaml.cs | 2 +- .../ViewsContracts/IMachineSetupView.cs | 8 + 17 files changed, 462 insertions(+), 153 deletions(-) delete mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/Controls/HeaderLoadingControl.xaml delete mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/Controls/HeaderLoadingControl.xaml.cs (limited to 'Software/Visual_Studio/PPC') diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Authentication/DefaultAuthenticationProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Authentication/DefaultAuthenticationProvider.cs index 0bae5a237..4096abc24 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Authentication/DefaultAuthenticationProvider.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Authentication/DefaultAuthenticationProvider.cs @@ -53,7 +53,19 @@ namespace Tango.PPC.UI.Authentication public User Login(string email, string password) { String hash = User.GetPasswordHash(password); + + LogManager.Log($"Logging in user {email}..."); CurrentUser = ObservablesEntitiesAdapter.Instance.Users.SingleOrDefault(x => x.Email.ToLower() == email && x.Password == hash); + + if (CurrentUser != null) + { + LogManager.Log($"Current user is now: {CurrentUser.Contact.FullName}."); + } + else + { + LogManager.Log("Login failed!"); + } + CurrentUserChanged?.Invoke(this, CurrentUser); return CurrentUser; } @@ -63,6 +75,7 @@ namespace Tango.PPC.UI.Authentication /// public void LogOut() { + LogManager.Log("Logging out current user."); CurrentUser = null; CurrentUserChanged?.Invoke(this, CurrentUser); NavigationManager.NavigateTo(NavigationView.LoginView); diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Controls/HeaderLoadingControl.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/Controls/HeaderLoadingControl.xaml deleted file mode 100644 index 5b07e1fa2..000000000 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Controls/HeaderLoadingControl.xaml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - Loading... - - - diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Controls/HeaderLoadingControl.xaml.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Controls/HeaderLoadingControl.xaml.cs deleted file mode 100644 index 540e829c9..000000000 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Controls/HeaderLoadingControl.xaml.cs +++ /dev/null @@ -1,28 +0,0 @@ -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.PPC.UI.Controls -{ - /// - /// Interaction logic for HeaderLoadingControl.xaml - /// - public partial class HeaderLoadingControl : UserControl - { - public HeaderLoadingControl() - { - InitializeComponent(); - } - } -} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Navigation/DefaultNavigationManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Navigation/DefaultNavigationManager.cs index a05d5fc5c..eee37b2e0 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Navigation/DefaultNavigationManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Navigation/DefaultNavigationManager.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; +using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; using System.Windows; @@ -102,6 +103,8 @@ namespace Tango.PPC.UI.Navigation } else { + + LogManager.Log($"Navigating to: {view.ToString()}..."); MainView.Instance.NavigationControl.NavigateTo(view.ToString()); return Task.FromResult(true); } @@ -116,8 +119,9 @@ namespace Tango.PPC.UI.Navigation /// public Task NavigateWithObject(NavigationView view, TPass obj, bool pushToHistory = true) { + LogManager.Log($"Navigating to: {view.ToString()}, with object {typeof(TPass).Name}..."); MainView.Instance.NavigationControl.NavigateTo(view.ToString()); - INavigationObjectReceiver receiver = MainView.Instance.NavigationControl.Elements.FirstOrDefault(x => (x.GetType().Name == view.ToString() || NavigationControl.GetNavigationName(x) == view.ToString()) && x.DataContext is INavigationObjectReceiver).DataContext as INavigationObjectReceiver; + INavigationObjectReceiver receiver = MainView.Instance.NavigationControl.Elements.FirstOrDefault(x => (x.GetType().Name == view.ToString() || NavigationControl.GetNavigationName(x) == view.ToString()) && x.DataContext is INavigationObjectReceiver).DataContext as INavigationObjectReceiver; if (receiver != null) { @@ -168,6 +172,8 @@ namespace Tango.PPC.UI.Navigation if (path.Length == 1 && path[0] == CurrentModule.Name) return true; + LogManager.Log($"Navigating to: {fullPath}..."); + var fromVM = _currentVM; if (_currentVM != null && _currentVM is INavigationBlocker) @@ -225,7 +231,7 @@ namespace Tango.PPC.UI.Navigation } else { - throw new ArgumentNullException("Could not navigate to " + fullPath); + throw LogManager.Log(new ArgumentNullException("Could not navigate to " + fullPath)); } } @@ -345,6 +351,8 @@ namespace Tango.PPC.UI.Navigation /// public async Task NavigateBack() { + LogManager.Log("Navigating back..."); + _navigating_back = true; String first = _navigationHistory.Pop(); @@ -373,12 +381,19 @@ namespace Tango.PPC.UI.Navigation /// public void ClearHistory() { + LogManager.Log("Navigation history cleared."); _navigationHistory.Clear(); RaisePropertyChanged(nameof(CanNavigateBack)); } + /// + /// Clears the navigation back history except the specified view type. + /// + /// public void ClearHistoryExcept() { + LogManager.Log($"Navigation history cleared except for {typeof(T).Name}."); + var history_list = _navigationHistory.ToList(); history_list = history_list.Where(x => x.Contains(typeof(T).Name)).Distinct().ToList(); _navigationHistory.Clear(); diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DialogAndView.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DialogAndView.cs index ea622ee48..2a85e2cb6 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DialogAndView.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DialogAndView.cs @@ -8,17 +8,34 @@ using Tango.SharedUI; namespace Tango.PPC.UI.Notifications { + /// + /// Represents a dialog and view couple. + /// public class DialogAndView { + /// + /// Gets or sets the vm. + /// public DialogViewVM VM { get; set; } + /// + /// Gets or sets the view. + /// public FrameworkElement View { get; set; } + /// + /// Initializes a new instance of the class. + /// public DialogAndView() { } + /// + /// Initializes a new instance of the class. + /// + /// The vm. + /// The view. public DialogAndView(DialogViewVM vm, FrameworkElement view) : this() { VM = vm; diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/PendingNotification.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/PendingNotification.cs index 791577964..cf76e90d9 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/PendingNotification.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/PendingNotification.cs @@ -6,17 +6,36 @@ using System.Threading.Tasks; namespace Tango.PPC.UI.Notifications { + /// + /// Represents a pending notification item. + /// + /// + /// The type of the result. public class PendingNotification { + /// + /// Gets or sets the item. + /// public T Item { get; set; } + /// + /// Gets or sets the completion source. + /// public TaskCompletionSource CompletionSource { get; set; } + /// + /// Initializes a new instance of the class. + /// public PendingNotification() { } + /// + /// Initializes a new instance of the class. + /// + /// The item. + /// The completion source. public PendingNotification(T item, TaskCompletionSource completionSource) : this() { Item = item; diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs index f2fba05fe..e984b7452 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs @@ -44,6 +44,21 @@ namespace Tango.PPC.UI.PPCApplication /// public event EventHandler ModulesInitialized; + /// + /// Occurs when the all components are ready. + /// + public event EventHandler Ready; + + /// + /// Occurs when machine setup is required. + /// + public event EventHandler SetupRequired; + + /// + /// Occurs when the main window content has been rendered. + /// + public event EventHandler ContentRendered; + /// /// Gets a value indicating whether the application is shutting down. /// @@ -61,6 +76,17 @@ namespace Tango.PPC.UI.PPCApplication } } + /// + /// Gets the application build date. + /// + public String BuildDate + { + get + { + return AssemblyHelper.GetCurrentAssemblyBuildDate().ToShortDateString(); + } + } + /// /// Initializes a new instance of the class. /// @@ -72,78 +98,95 @@ namespace Tango.PPC.UI.PPCApplication { _notifiedViewModels = new List(); - PPCSettings settings = null; - - MainWindow.Instance.ContentRendered += async (_, __) => + MainWindow.Instance.ContentRendered += (_, __) => { - ContentRendered?.Invoke(this, new EventArgs()); + OnMainWindowContentRendered(); + }; + } + } - await Task.Factory.StartNew(() => - { - //TODO: Use this in the future. + /// + /// Called when the main window content has been rendered + /// + private async void OnMainWindowContentRendered() + { + LogManager.Log("Main window content rendered."); - //#if DEBUG - // DataSource = "localhost\\SQLEXPRESS"; - //#else - // DataBaseSettings.DefaultDataSource = Path.Combine(PathHelper.GetUserTangoFolder(), "DB", "Tango.db"); - //#endif + PPCSettings settings = null; - if (!File.Exists(CoreSettings.DefaultDataBaseSource)) - { - Directory.CreateDirectory(Path.GetDirectoryName(CoreSettings.DefaultDataBaseSource)); - File.Copy(Path.Combine(PathHelper.GetStartupPath(), "DB", "Tango.mdf"), CoreSettings.DefaultDataBaseSource); - } + ContentRendered?.Invoke(this, new EventArgs()); - settings = SettingsManager.Default.GetOrCreate(); - var coreSettings = SettingsManager.Default.GetOrCreate(); + await Task.Factory.StartNew(() => + { + LogManager.Log("Reading PPC settings..."); + settings = SettingsManager.Default.GetOrCreate(); - if (!SettingsManager.Default.IsFileExists()) - { - settings.Save(); - } + LogManager.Log(settings.ToJsonString()); - if (App.StartupArgs.Contains("-update_ok")) - { - settings.ApplicationState = ApplicationStates.Default; - settings.Save(); - } + LogManager.Log("Reading Core settings..."); + var coreSettings = SettingsManager.Default.GetOrCreate(); - if (settings.ApplicationState == ApplicationStates.Default) - { - ObservablesEntitiesAdapter.Instance.Initialize(); - } - }); + if (!SettingsManager.Default.IsFileExists()) + { + LogManager.Log("Settings file does not exists. creating..."); + settings.Save(); + } + if (App.StartupArgs.Contains("-update_ok")) + { + LogManager.Log("Application started with '-update_ok' startup arguments. The application has been successfully updated."); + settings.ApplicationState = ApplicationStates.Default; + settings.Save(); + } - if (settings.ApplicationState == ApplicationStates.PreSetup || settings.ApplicationState == ApplicationStates.SemiSetup) - { - SetupRequired?.Invoke(this, new EventArgs()); - } - else - { - PostSetup(); - } - }; + if (settings.ApplicationState == ApplicationStates.Default) + { + LogManager.Log("Initializing ObservablesEntitiesAdapter..."); + ObservablesEntitiesAdapter.Instance.Initialize(); + } + }); + + + if (settings.ApplicationState == ApplicationStates.PreSetup || settings.ApplicationState == ApplicationStates.SemiSetup) + { + LogManager.Log($"The application is in {settings.ApplicationState} state. database initialization skipped. Invoking setup required event!"); + SetupRequired?.Invoke(this, new EventArgs()); + } + else + { + OnDbInitialized(); } } - private void PostSetup() + /// + /// Called when the database has been initialized + /// + private void OnDbInitialized() { + LogManager.Log($"Raising {nameof(ApplicationStarted)} event..."); + ApplicationStarted?.Invoke(this, new EventArgs()); + LogManager.Log("Invoking PPC view models OnApplicationStarted methods..."); foreach (var vm in TangoIOC.Default.GetAllInstancesByBase()) { if (!_notifiedViewModels.Contains(vm)) { + LogManager.Log($"Invoking {vm.GetType().Name}.OnApplicationStarted..."); vm.OnApplicationStarted(); _notifiedViewModels.Add(vm); } } + LogManager.Log("Waiting for IPPCModuleLoader instance injection..."); TangoIOC.Default.GetInstanceWhenAvailable((loader) => { + LogManager.Log("Module loader instance has been registered. Registering for the ModulesLoaded event..."); + loader.ModulesLoaded += (x, y) => { + LogManager.Log($"{loader.UserModules.Count} loaded. Waiting for last module initialization..."); + if (loader.UserModules.Count > 0) { if (loader.UserModules.ToList().Exists(m => !m.IsInitialized)) @@ -162,19 +205,34 @@ namespace Tango.PPC.UI.PPCApplication }); } + /// + /// Finalizes the module initialization. + /// private void FinalizeModuleInitialization() { + LogManager.Log("Finalizing application initialization..."); + + LogManager.Log("Checking for un-notified PPC view models..."); foreach (var vm in TangoIOC.Default.GetAllInstancesByBase()) { if (!_notifiedViewModels.Contains(vm)) { + LogManager.Log($"Invoking {vm.GetType().Name}.OnApplicationStarted..."); vm.OnApplicationStarted(); _notifiedViewModels.Add(vm); } } + LogManager.Log($"Invoking {nameof(ModulesInitialized)} event."); + ModulesInitialized?.Invoke(this, new EventArgs()); + + LogManager.Log("Initializing Machine Provider..."); _machineProvider.Init(); + + LogManager.Log("Applications initialization completed!"); + + LogManager.Log($"Invoking {nameof(Ready)} event."); Ready?.Invoke(this, new EventArgs()); } @@ -183,6 +241,10 @@ namespace Tango.PPC.UI.PPCApplication /// public void ShutDown() { + //TODO: Needs some work on logging and shutdown procedures! Do I really need this? + + LogManager.Log("Shutting down application..."); + IsShuttingDown = true; foreach (var vm in TangoIOC.Default.GetAllInstancesByBase()) @@ -190,18 +252,5 @@ namespace Tango.PPC.UI.PPCApplication vm.OnApplicationShuttingDown(); } } - - public event EventHandler Ready; - public event EventHandler SetupRequired; - public event EventHandler ContentRendered; - - public String BuildDate - { - get - { - return AssemblyHelper.GetCurrentAssemblyBuildDate().ToShortDateString(); - } - } - } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj b/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj index 594afcc86..d3e28de8d 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj @@ -112,9 +112,6 @@ GlobalVersionInfo.cs - - HeaderLoadingControl.xaml - @@ -151,10 +148,6 @@ MainView.xaml - - Designer - MSBuild:Compile - MSBuild:Compile Designer @@ -335,15 +328,6 @@ - - DB\Tango.mdf - PreserveNewest - - - DB\Tango_log.ldf - Always - Tango.mdf - Tango.ColorLib.dll PreserveNewest @@ -420,7 +404,7 @@ copy /Y "$(SolutionDir)Referenced Assemblies\vcruntime140d.dll" "$(TargetDir)" - + \ No newline at end of file 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() { } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml index 9900a5b27..92b029b26 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml @@ -4,7 +4,6 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:Tango.PPC.UI.Views" - xmlns:localControls="clr-namespace:Tango.PPC.UI.Controls" xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:fa="http://schemas.fontawesome.io/icons/" xmlns:vm="clr-namespace:Tango.PPC.UI.ViewModels" diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml.cs index 9ef698656..9b5c26984 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml.cs @@ -42,7 +42,7 @@ namespace Tango.PPC.UI.Views { if (!NavigationControl.Elements.ToList().Exists(x => x.GetType() == module.MainViewType)) { - LogManager.Default.Log("Loading module " + module.Name + "..."); + LogManager.Default.Log("Loading module view " + module.Name + "..."); FrameworkElement view = Activator.CreateInstance(module.MainViewType) as FrameworkElement; SharedUI.Controls.NavigationControl.SetNavigationName(view, module.Name); NavigationControl.Elements.Add(view); diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewsContracts/IMachineSetupView.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewsContracts/IMachineSetupView.cs index 3926f07be..c9ff93280 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewsContracts/IMachineSetupView.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewsContracts/IMachineSetupView.cs @@ -7,8 +7,16 @@ using Tango.PPC.Common; namespace Tango.PPC.UI.ViewsContracts { + /// + /// Represents the machine setup view contract. + /// + /// public interface IMachineSetupView : IPPCView { + /// + /// Appends the log. + /// + /// The log. void AppendLog(String log); } } -- cgit v1.3.1