diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-08-28 16:35:16 +0300 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-08-28 16:35:16 +0300 |
| commit | f3fc87dd10b3d55591a84ecbfb0612769f0c09b9 (patch) | |
| tree | 640621ab876dd5368d91e44b07b4f2872752e5bb /Software/Visual_Studio/PPC/Tango.PPC.UI | |
| parent | 37fe17f09478a486dcd51f0edd8028724dc85c16 (diff) | |
| download | Tango-f3fc87dd10b3d55591a84ecbfb0612769f0c09b9.tar.gz Tango-f3fc87dd10b3d55591a84ecbfb0612769f0c09b9.zip | |
Working on BL Builders !
Working on making PPC work with builders..
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI')
10 files changed, 87 insertions, 91 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/App.xaml.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/App.xaml.cs index 4cffce960..625ad7e85 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/App.xaml.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/App.xaml.cs @@ -38,7 +38,7 @@ namespace Tango.PPC.UI StartupArgs = e.Args; - LogManager.RegisterLogger(new VSOutputLogger()); + LogManager.RegisterLogger(new ConsoleLogger("Tango PPC Debug")); LogManager.RegisterLogger(new FileLogger()); LogManager.Log("Application Started..."); 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 3dae9d05a..23761eb9b 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Authentication/DefaultAuthenticationProvider.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Authentication/DefaultAuthenticationProvider.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Tango.BL; +using Tango.BL.Builders; using Tango.BL.Entities; using Tango.Core; using Tango.Core.DI; @@ -50,24 +51,34 @@ namespace Tango.PPC.UI.Authentication /// <param name="email">The email.</param> /// <param name="password">The password.</param> /// <returns></returns> - public User Login(string email, string password) + public Task<User> Login(string email, string password) { - String hash = User.GetPasswordHash(password); - - LogManager.Log($"Logging in user {email}..."); - CurrentUser = ObservablesStaticCollections.Instance.Users.SingleOrDefault(x => x.Email.ToLower() == email && x.Password == hash); - - if (CurrentUser != null) - { - LogManager.Log($"Current user is now: {CurrentUser.Contact.FullName}."); - } - else + return Task.Factory.StartNew<User>(() => { - LogManager.Log("Login failed!"); - } + String hash = User.GetPasswordHash(password); - CurrentUserChanged?.Invoke(this, CurrentUser); - return CurrentUser; + LogManager.Log($"Logging in user {email}..."); + + using (var db = ObservablesContext.CreateDefault()) + { + CurrentUser = new UserBuilder(db).Set(x => x.Email.ToLower() == email && x.Password == hash) + .WithOrganization() + .WithRolesAndPermissions() + .Build(); + } + + if (CurrentUser != null) + { + LogManager.Log($"Current user is now: {CurrentUser.Contact.FullName}."); + } + else + { + LogManager.Log("Login failed!"); + } + + CurrentUserChanged?.Invoke(this, CurrentUser); + return CurrentUser; + }); } /// <summary> diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Connectivity/DefaultConnectivityProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Connectivity/DefaultConnectivityProvider.cs index d338b3ff1..c26219c34 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Connectivity/DefaultConnectivityProvider.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Connectivity/DefaultConnectivityProvider.cs @@ -83,7 +83,7 @@ namespace Tango.PPC.UI.Connectivity _wifi = new Wifi(); - applicationManager.Ready += ApplicationManager_Ready; + applicationManager.ApplicationReady += ApplicationManager_Ready; ConnectToWiFiCommand = new RelayCommand<WiFiNetwork>(async (x) => { diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Modules/DefaultStudioModuleLoader.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Modules/DefaultStudioModuleLoader.cs index 78ebd8ded..feb7e371f 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Modules/DefaultStudioModuleLoader.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Modules/DefaultStudioModuleLoader.cs @@ -14,6 +14,7 @@ using Tango.PPC.Common.Modules; using Tango.PPC.Common; using Tango.PPC.Jobs; using System.Windows.Data; +using Tango.Core.DI; namespace Tango.PPC.UI.Modules { 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 2d0ac96fa..906794f6e 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs @@ -21,6 +21,8 @@ using Tango.PMR.Connection; using Tango.PPC.Common.Connection; using Tango.SQLExaminer; using System.Data.SqlClient; +using Tango.BL.Builders; +using Tango.PPC.Common.Threading; namespace Tango.PPC.UI.PPCApplication { @@ -33,6 +35,8 @@ namespace Tango.PPC.UI.PPCApplication { private List<PPCViewModel> _notifiedViewModels; private IMachineProvider _machineProvider; + private Machine _machine; + private IDispatcherProvider _dispatcher; /// <summary> /// Occurs when the application has started. @@ -45,9 +49,9 @@ namespace Tango.PPC.UI.PPCApplication public event EventHandler ModulesInitialized; /// <summary> - /// Occurs when the all components are ready. + /// Occurs when the application is ready and all modules are views are loaded. /// </summary> - public event EventHandler Ready; + public event EventHandler ApplicationReady; /// <summary> /// Occurs when machine setup is required. @@ -90,9 +94,10 @@ namespace Tango.PPC.UI.PPCApplication /// <summary> /// Initializes a new instance of the <see cref="DefaultPPCApplicationManager"/> class. /// </summary> - public DefaultPPCApplicationManager(IMachineProvider machineProvider) + public DefaultPPCApplicationManager(IMachineProvider machineProvider, IDispatcherProvider dispatcherProvider) { _machineProvider = machineProvider; + _dispatcher = dispatcherProvider; if (!DesignMode) { @@ -146,8 +151,8 @@ namespace Tango.PPC.UI.PPCApplication if (settings.ApplicationState == ApplicationStates.Ready) { - LogManager.Log("Initializing ObservablesEntitiesAdapter..."); - ObservablesEntitiesAdapter.Instance.Initialize(); + LogManager.Log("Loading machine from database..."); + _machine = new MachineBuilder(ObservablesContext.CreateDefault()).SetFirst().WithOrganization().WithConfiguration().Build(); } }); @@ -190,22 +195,27 @@ namespace Tango.PPC.UI.PPCApplication loader.ModulesLoaded += (x, y) => { - LogManager.Log($"{loader.UserModules.Count} loaded. Waiting for last module initialization..."); - - if (loader.UserModules.Count > 0) + LogManager.Log("Loading modules views"); + _dispatcher.InvokeBlock(() => { - if (loader.UserModules.ToList().Exists(m => !m.IsInitialized)) + foreach (var module in TangoIOC.Default.GetInstance<IPPCModuleLoader>().UserModules) { - loader.UserModules.LastOrDefault().Initialized += (e, f) => + if (!Views.LayoutView.Instance.NavigationControl.Elements.ToList().Exists(m => m.GetType() == module.MainViewType)) { - FinalizeModuleInitialization(); - }; - } - else - { - FinalizeModuleInitialization(); + LogManager.Log("Loading module view " + module.Name + "..."); + FrameworkElement view = Activator.CreateInstance(module.MainViewType) as FrameworkElement; + SharedUI.Controls.NavigationControl.SetNavigationName(view, module.Name); + Views.LayoutView.Instance.NavigationControl.Elements.Add(view); + } } - } + }); + + LogManager.Log($"{loader.UserModules.Count} modules loaded."); + + LogManager.Log($"Invoking {nameof(ModulesInitialized)} event."); + ModulesInitialized?.Invoke(this, new EventArgs()); + + FinalizeModuleInitialization(); }; }); } @@ -217,6 +227,11 @@ namespace Tango.PPC.UI.PPCApplication { LogManager.Log("Finalizing application initialization..."); + LogManager.Log("Initializing Machine Provider..."); + _machineProvider.Init(_machine); + + LogManager.Log("Applications initialization completed!"); + LogManager.Log("Checking for un-notified PPC view models..."); foreach (var vm in TangoIOC.Default.GetAllInstancesByBase<PPCViewModel>()) { @@ -228,17 +243,18 @@ namespace Tango.PPC.UI.PPCApplication } } - LogManager.Log($"Invoking {nameof(ModulesInitialized)} event."); - - ModulesInitialized?.Invoke(this, new EventArgs()); - - LogManager.Log("Initializing Machine Provider..."); - _machineProvider.Init(); - - LogManager.Log("Applications initialization completed!"); + _dispatcher.Invoke(() => + { + LogManager.Log($"Invoking {nameof(ApplicationReady)} event."); + ApplicationReady?.Invoke(this, new EventArgs()); - LogManager.Log($"Invoking {nameof(Ready)} event."); - Ready?.Invoke(this, new EventArgs()); + LogManager.Log("Notifying view models about application ready..."); + foreach (var vm in TangoIOC.Default.GetAllInstancesByBase<PPCViewModel>()) + { + LogManager.Log($"Invoking {vm.GetType().Name}.OnApplicationReady..."); + vm.OnApplicationReady(); + } + }); } /// <summary> diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Threading/DefaultDispatcherProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Threading/DefaultDispatcherProvider.cs index 940c13052..58ab9c24a 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Threading/DefaultDispatcherProvider.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Threading/DefaultDispatcherProvider.cs @@ -38,7 +38,7 @@ namespace Tango.PPC.UI.Threading /// Invokes the specified action synchronously. /// </summary> /// <param name="action">The action.</param> - public void InvokeSync(Action action) + public void InvokeBlock(Action action) { _dispatcher.Invoke(action); } 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 3bcacc989..28692cdfa 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs @@ -192,7 +192,6 @@ namespace Tango.PPC.UI.ViewModels public override void OnApplicationStarted() { base.OnApplicationStarted(); - ModuleLoader.ModulesLoaded += ModuleLoader_ModulesLoaded; MachineProvider.MachineOperator.PrintingStarted += MachineOperator_PrintingStarted; } @@ -218,17 +217,6 @@ namespace Tango.PPC.UI.ViewModels _jobHandler = e.JobHandler; } - /// <summary> - /// Handles the ModulesLoaded event of the ModuleLoader. - /// </summary> - /// <param name="sender">The source of the event.</param> - /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> - private void ModuleLoader_ModulesLoaded(object sender, EventArgs e) - { - 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/LoginViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoginViewVM.cs index 812f10121..9d17a4a76 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoginViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoginViewVM.cs @@ -84,6 +84,16 @@ namespace Tango.PPC.UI.ViewModels AuthenticationProvider.CurrentUserChanged += AuthenticationProvider_CurrentUserChanged; } + public override async void OnApplicationReady() + { + base.OnApplicationReady(); + + await Task.Delay(500); + LogManager.Log("Application is ready! Navigating to home module..."); + await NavigationManager.NavigateTo(NavigationView.HomeModule); + IsLoading = false; + } + #endregion #region Event Handlers @@ -108,7 +118,7 @@ namespace Tango.PPC.UI.ViewModels /// <summary> /// Login to the application using the user name and password. /// </summary> - private void Login() + private async void Login() { LogManager.Log("Login command pressed."); @@ -117,21 +127,13 @@ namespace Tango.PPC.UI.ViewModels IsLoading = true; UIHelper.DoEvents(); - var user = AuthenticationProvider.Login(Email, Password); + var user = await AuthenticationProvider.Login(Email, Password); if (user == null) { IsLoading = false; - NotificationProvider.ShowWarning("Email or password are incorrect."); + await NotificationProvider.ShowWarning("Email or password are incorrect."); } - - ApplicationManager.ModulesInitialized += async (_, __) => - { - await Task.Delay(500); - LogManager.Log("Modules initialized. Navigating to home module..."); - await NavigationManager.NavigateTo(NavigationView.HomeModule); - IsLoading = false; - }; } else { 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 9b5c26984..50b9df550 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 @@ -33,23 +33,5 @@ namespace Tango.PPC.UI.Views InitializeComponent(); Instance = this; } - - public void ApplyModules(IEnumerable<IPPCModule> modules) - { - this.BeginInvoke(() => - { - foreach (var module in modules) - { - if (!NavigationControl.Elements.ToList().Exists(x => x.GetType() == module.MainViewType)) - { - 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); - module.Initialize(); - } - } - }); - } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewsContracts/ILayoutView.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewsContracts/ILayoutView.cs index f01785d57..72b981193 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewsContracts/ILayoutView.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewsContracts/ILayoutView.cs @@ -13,10 +13,6 @@ namespace Tango.PPC.UI.ViewsContracts /// <seealso cref="Tango.PPC.Common.IPPCView" /> public interface ILayoutView : IPPCView { - /// <summary> - /// Inserts the specified modules into the navigation system. - /// </summary> - /// <param name="modules">The modules.</param> - void ApplyModules(IEnumerable<IPPCModule> modules); + } } |
