aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2018-08-28 16:35:16 +0300
committerRoy Ben-Shabat <Roy@Twine-s.com>2018-08-28 16:35:16 +0300
commitf3fc87dd10b3d55591a84ecbfb0612769f0c09b9 (patch)
tree640621ab876dd5368d91e44b07b4f2872752e5bb /Software/Visual_Studio/PPC
parent37fe17f09478a486dcd51f0edd8028724dc85c16 (diff)
downloadTango-f3fc87dd10b3d55591a84ecbfb0612769f0c09b9.tar.gz
Tango-f3fc87dd10b3d55591a84ecbfb0612769f0c09b9.zip
Working on BL Builders !
Working on making PPC work with builders..
Diffstat (limited to 'Software/Visual_Studio/PPC')
-rw-r--r--Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobSummeryViewVM.cs16
-rw-r--r--Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs16
-rw-r--r--Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobsViewVM.cs11
-rw-r--r--Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/TwineCatalogViewVM.cs4
-rw-r--r--Software/Visual_Studio/PPC/Modules/Tango.PPC.MachineSettings/ViewModels/MainViewVM.cs6
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/Application/IPPCApplicationManager.cs8
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/Authentication/IAuthenticationProvider.cs2
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs16
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/IMachineProvider.cs8
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/Controls/TwineCatalogControl.xaml.cs2
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/ExternalBridge/PPCExternalBridgeService.cs2
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/IPPCModule.cs15
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/PPCModuleBase.cs42
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/PPCViewModel.cs8
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/Threading/IDispatcherProvider.cs2
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/App.xaml.cs2
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/Authentication/DefaultAuthenticationProvider.cs41
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/Connectivity/DefaultConnectivityProvider.cs2
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/Modules/DefaultStudioModuleLoader.cs1
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs70
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/Threading/DefaultDispatcherProvider.cs2
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs12
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoginViewVM.cs24
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml.cs18
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/ViewsContracts/ILayoutView.cs6
25 files changed, 164 insertions, 172 deletions
diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobSummeryViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobSummeryViewVM.cs
index d46646698..46c6d7ffd 100644
--- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobSummeryViewVM.cs
+++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobSummeryViewVM.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.Commands;
using Tango.PPC.Common;
@@ -74,18 +75,27 @@ namespace Tango.PPC.Jobs.ViewModels
/// <summary>
/// Starts the job.
/// </summary>
- private void StartJob()
+ private async void StartJob()
{
try
{
LogManager.Log("Start job command pressed. Starting job and navigating to job progress view...");
+
+ Job = await new JobBuilder(_context).Set(Job.Guid)
+ .WithConfiguration()
+ .WithRML()
+ .WithUser()
+ .WithSegments()
+ .WithBrushStops()
+ .BuildAsync();
+
PrintingManager.Print(Job, _context);
- NavigationManager.NavigateTo<JobsModule>(nameof(JobProgressView));
+ await NavigationManager.NavigateTo<JobsModule>(nameof(JobProgressView));
}
catch (Exception ex)
{
LogManager.Log(ex, "Could not start the current job.");
- NotificationProvider.ShowError($"Cannot start job.\n{ex.Message}.");
+ await NotificationProvider.ShowError($"Cannot start job.\n{ex.Message}.");
}
}
diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs
index a87340101..cda2ba96f 100644
--- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs
+++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs
@@ -29,6 +29,7 @@ using System.Collections.ObjectModel;
using Tango.PPC.Common.Models;
using Tango.Logging;
using Tango.PPC.Common.Messages;
+using Tango.BL.Builders;
namespace Tango.PPC.Jobs.ViewModels
{
@@ -365,12 +366,21 @@ namespace Tango.PPC.Jobs.ViewModels
_can_navigate_back = false;
_db = ObservablesContext.CreateDefault();
- var a = _db.Jobs.ToList();
- Job = await _db.Jobs.SingleOrDefaultAsync(x => x.Guid == _job_to_load.Guid);
+
+
+
+ Job = await new JobBuilder(_db).Set(_job_to_load.Guid)
+ .WithConfiguration()
+ .WithRML()
+ .WithUser()
+ .WithSegments()
+ .WithBrushStops()
+ .BuildAsync();
+
Job.ValidateOnPropertyChanged = true;
LogManager.Log("Loading RMLS...");
- Rmls = await _db.Rmls.ToListAsync();
+ Rmls = (await new RmlsCollectionBuilder(_db).Set().WithActiveParametersGroup().WithCAT(Job.MachineGuid).WithCCT().WithLiquidFactors().BuildAsync()).ToList();
LogManager.Log("Loading Color Spaces...");
ColorSpaces = await _db.ColorSpaces.ToListAsync();
LogManager.Log("Loading Spool Types...");
diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobsViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobsViewVM.cs
index 7b277ec2b..4115462dd 100644
--- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobsViewVM.cs
+++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobsViewVM.cs
@@ -19,6 +19,8 @@ using Tango.PPC.Common.Messages;
using Tango.PPC.Jobs.Dialogs;
using Tango.PPC.Jobs.Messages;
using Tango.PPC.Jobs.Views;
+using System.Data.Entity;
+using Tango.BL.Builders;
namespace Tango.PPC.Jobs.ViewModels
{
@@ -228,11 +230,11 @@ namespace Tango.PPC.Jobs.ViewModels
_db = ObservablesContext.CreateDefault();
- var jobs = _db.Jobs.Where(x => x.Machine.Guid == MachineProvider.Machine.Guid).ToObservableCollection();
+ var jobs = new JobsCollectionBuilder(_db).Set(x => x.MachineGuid == MachineProvider.Machine.Guid).WithSegments().WithBrushStops().Build();
InvokeUI(() =>
{
- Jobs = jobs.Where(x => x.Machine.Guid == MachineProvider.Machine.Guid).ToObservableCollection();
+ Jobs = jobs;
JobsCollectionView = CollectionViewSource.GetDefaultView(Jobs);
JobsCollectionView.SortDescriptions.Add(new SortDescription(nameof(Job.LastUpdated), ListSortDirection.Descending));
FilterJobCategory(FilterCategory);
@@ -441,6 +443,11 @@ namespace Tango.PPC.Jobs.ViewModels
LoadJobs();
}
+ public override void OnApplicationReady()
+ {
+ base.OnApplicationReady();
+ }
+
#endregion
}
}
diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/TwineCatalogViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/TwineCatalogViewVM.cs
index 079080f02..cd5553b77 100644
--- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/TwineCatalogViewVM.cs
+++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/TwineCatalogViewVM.cs
@@ -73,8 +73,8 @@ namespace Tango.PPC.Jobs.ViewModels
/// </summary>
public override void OnApplicationStarted()
{
- Catalog = CatalogLoader.LoadCatalog(BL.Enumerations.ColorSpaces.Twine, ObservablesEntitiesAdapter.Instance.Context);
- Recent = CatalogLoader.GetRecent(Catalog, SettingsManager.Default.GetOrCreate<JobsModuleSettings>().RecentTwineCatalogColors);
+ //Catalog = CatalogLoader.LoadCatalog(BL.Enumerations.ColorSpaces.Twine, ObservablesEntitiesAdapter.Instance.Context);
+ //Recent = CatalogLoader.GetRecent(Catalog, SettingsManager.Default.GetOrCreate<JobsModuleSettings>().RecentTwineCatalogColors);
}
/// <summary>
diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.MachineSettings/ViewModels/MainViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.MachineSettings/ViewModels/MainViewVM.cs
index 310a09846..0d0539152 100644
--- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.MachineSettings/ViewModels/MainViewVM.cs
+++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.MachineSettings/ViewModels/MainViewVM.cs
@@ -71,12 +71,12 @@ namespace Tango.PPC.MachineSettings.ViewModels
NavigationManager.NavigateBack();
}
- private void Save()
+ private async void Save()
{
Machine.SupportedJobTypes = SelectedJobTypes.SynchedSource.ToList();
Machine.ShallowCopyTo(MachineProvider.Machine);
- MachineProvider.Machine.SaveAsync(ObservablesEntitiesAdapter.Instance.Context);
- NavigationManager.NavigateBack();
+ await MachineProvider.SaveMachine();
+ await NavigationManager.NavigateBack();
RaiseMessage(new MachineSettingsSavedMessage() { Machine = MachineProvider.Machine });
}
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Application/IPPCApplicationManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Application/IPPCApplicationManager.cs
index cb2aeb6cf..0feb551b1 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Application/IPPCApplicationManager.cs
+++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Application/IPPCApplicationManager.cs
@@ -21,14 +21,14 @@ namespace Tango.PPC.Common.Application
event EventHandler ApplicationStarted;
/// <summary>
- /// Occurs when the main window content has been rendered.
+ /// Occurs when the application is ready and all modules are views are loaded.
/// </summary>
- event EventHandler ContentRendered;
+ event EventHandler ApplicationReady;
/// <summary>
- /// Occurs when the all components are ready.
+ /// Occurs when the main window content has been rendered.
/// </summary>
- event EventHandler Ready;
+ event EventHandler ContentRendered;
/// <summary>
/// Occurs when all PPC modules are ready and initialized.
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Authentication/IAuthenticationProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Authentication/IAuthenticationProvider.cs
index ef03e8ba5..dd7faae36 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Authentication/IAuthenticationProvider.cs
+++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Authentication/IAuthenticationProvider.cs
@@ -28,7 +28,7 @@ namespace Tango.PPC.Common.Authentication
/// <param name="email">The email.</param>
/// <param name="password">The password.</param>
/// <returns></returns>
- User Login(String email, String password);
+ Task<User> Login(String email, String password);
/// <summary>
/// Logs-out the current logged-in user.
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs
index e6050f761..b290f9513 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs
+++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs
@@ -12,6 +12,7 @@ using Tango.PMR.Connection;
using Tango.Transport.Adapters;
using Tango.Settings;
using Tango.Logging;
+using Tango.BL.Builders;
namespace Tango.PPC.Common.Connection
{
@@ -23,6 +24,7 @@ namespace Tango.PPC.Common.Connection
public class DefaultMachineProvider : ExtendedObject, IMachineProvider
{
private bool _isInitialized;
+ private ObservablesContext _db;
/// <summary>
/// Occurs when current <see cref="IMachineOperator" /> has changed.
@@ -86,7 +88,7 @@ namespace Tango.PPC.Common.Connection
/// <summary>
/// Initializes this machine provider start machine port scanning and connection.
/// </summary>
- public void Init()
+ public void Init(Machine machine)
{
if (!_isInitialized)
{
@@ -95,7 +97,8 @@ namespace Tango.PPC.Common.Connection
_isInitialized = true;
LogManager.Log("Retrieving first machine database entry...");
- Machine = ObservablesStaticCollections.Instance.Machines.FirstOrDefault();
+
+ Machine = machine;
if (Machine != null)
{
@@ -141,5 +144,14 @@ namespace Tango.PPC.Common.Connection
LogManager.Log(ex, "Error while trying to scan and connect to the machine.");
}
}
+
+ /// <summary>
+ /// Saves the machine settings.
+ /// </summary>
+ /// <returns></returns>
+ public Task SaveMachine()
+ {
+ return Machine.GetDbContext().SaveChangesAsync();
+ }
}
}
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/IMachineProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/IMachineProvider.cs
index 4d4d87570..df4a448f7 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/IMachineProvider.cs
+++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/IMachineProvider.cs
@@ -32,6 +32,12 @@ namespace Tango.PPC.Common.Connection
/// <summary>
/// Initializes this machine provider start machine port scanning and connection.
/// </summary>
- void Init();
+ void Init(Machine machine);
+
+ /// <summary>
+ /// Saves the machine settings.
+ /// </summary>
+ /// <returns></returns>
+ Task SaveMachine();
}
}
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Controls/TwineCatalogControl.xaml.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Controls/TwineCatalogControl.xaml.cs
index bf2e2f1a0..f786009f0 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Controls/TwineCatalogControl.xaml.cs
+++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Controls/TwineCatalogControl.xaml.cs
@@ -113,7 +113,7 @@ namespace Tango.PPC.Common.Controls
/// <param name="e">The <see cref="RoutedPropertyChangedEventArgs{System.Double}"/> instance containing the event data.</param>
private void TouchSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
- if (_catalog.Groups.Count == 0) return;
+ if (_catalog == null || _catalog.Groups.Count == 0) return;
if (!_preventChange)
{
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/ExternalBridge/PPCExternalBridgeService.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/ExternalBridge/PPCExternalBridgeService.cs
index 6228abcb3..2f2956e9b 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.Common/ExternalBridge/PPCExternalBridgeService.cs
+++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/ExternalBridge/PPCExternalBridgeService.cs
@@ -28,7 +28,7 @@ namespace Tango.PPC.Common.ExternalBridge
/// <param name="machineProvider">The machine provider.</param>
public PPCExternalBridgeService(IPPCApplicationManager applicationManager, IMachineProvider machineProvider)
{
- applicationManager.Ready += (_, __) =>
+ applicationManager.ApplicationReady += (_, __) =>
{
MachineOperator = machineProvider.MachineOperator;
Machine = machineProvider.Machine;
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/IPPCModule.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/IPPCModule.cs
index ba83d9b5d..7bee755a2 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.Common/IPPCModule.cs
+++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/IPPCModule.cs
@@ -17,11 +17,6 @@ namespace Tango.PPC.Common
public interface IPPCModule : IDisposable
{
/// <summary>
- /// Occurs when the module has been initialized.
- /// </summary>
- event EventHandler Initialized;
-
- /// <summary>
/// Gets the module name.
/// </summary>
String Name { get; }
@@ -45,15 +40,5 @@ namespace Tango.PPC.Common
/// Gets the permission required to see and load this module.
/// </summary>
Permissions Permission { get; }
-
- /// <summary>
- /// Gets a value indicating whether this module has been initialized.
- /// </summary>
- bool IsInitialized { get; }
-
- /// <summary>
- /// Perform any operations required to initialize this module.
- /// </summary>
- void Initialize();
}
}
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCModuleBase.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCModuleBase.cs
index 45428f542..316236626 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCModuleBase.cs
+++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCModuleBase.cs
@@ -17,13 +17,6 @@ namespace Tango.PPC.Common
/// <seealso cref="Tango.MachineStudio.Common.IStudioModule" />
public abstract class PPCModuleBase : ExtendedObject, IPPCModule
{
- private bool _isInitialized;
-
- /// <summary>
- /// Occurs when the module has been initialized.
- /// </summary>
- public event EventHandler Initialized;
-
/// <summary>
/// Gets the module name.
/// </summary>
@@ -50,43 +43,8 @@ namespace Tango.PPC.Common
public abstract Permissions Permission { get; }
/// <summary>
- /// Gets a value indicating whether this module has been initialized.
- /// </summary>
- public bool IsInitialized
- {
- get
- {
- return _isInitialized;
- }
- private set
- {
- _isInitialized = value;
- }
- }
-
- /// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public abstract void Dispose();
-
- /// <summary>
- /// Perform any operations required to initialize this module.
- /// </summary>
- public void Initialize()
- {
- if (!IsInitialized)
- {
- OnInitialized();
- IsInitialized = true;
- }
- }
-
- /// <summary>
- /// Called when machine studio initializes this module.
- /// </summary>
- protected virtual void OnInitialized()
- {
- Initialized?.Invoke(this, new EventArgs());
- }
}
}
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCViewModel.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCViewModel.cs
index b2ea6ac30..fdcaa9830 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCViewModel.cs
+++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCViewModel.cs
@@ -178,6 +178,14 @@ namespace Tango.PPC.Common
{
return Task.FromResult(true);
}
+
+ /// <summary>
+ /// Called when the application is ready and all modules views are loaded.
+ /// </summary>
+ public virtual void OnApplicationReady()
+ {
+
+ }
}
/// <summary>
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Threading/IDispatcherProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Threading/IDispatcherProvider.cs
index 27a5d1ab1..229d0d02b 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Threading/IDispatcherProvider.cs
+++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Threading/IDispatcherProvider.cs
@@ -21,6 +21,6 @@ namespace Tango.PPC.Common.Threading
/// Invokes the specified action synchronously.
/// </summary>
/// <param name="action">The action.</param>
- void InvokeSync(Action action);
+ void InvokeBlock(Action action);
}
}
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);
+
}
}