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 | |
| parent | 37fe17f09478a486dcd51f0edd8028724dc85c16 (diff) | |
| download | Tango-f3fc87dd10b3d55591a84ecbfb0612769f0c09b9.tar.gz Tango-f3fc87dd10b3d55591a84ecbfb0612769f0c09b9.zip | |
Working on BL Builders !
Working on making PPC work with builders..
49 files changed, 883 insertions, 192 deletions
diff --git a/Software/DB/Tango.mdf b/Software/DB/Tango.mdf Binary files differindex 46345ed6e..cf46dddff 100644 --- a/Software/DB/Tango.mdf +++ b/Software/DB/Tango.mdf diff --git a/Software/DB/Tango_log.ldf b/Software/DB/Tango_log.ldf Binary files differindex 46bf2c219..7111bd87f 100644 --- a/Software/DB/Tango_log.ldf +++ b/Software/DB/Tango_log.ldf diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/StudioApplication/DefaultStudioApplicationManager.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/StudioApplication/DefaultStudioApplicationManager.cs index 7c7e18276..17bf57f56 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/StudioApplication/DefaultStudioApplicationManager.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/StudioApplication/DefaultStudioApplicationManager.cs @@ -181,7 +181,7 @@ namespace Tango.MachineStudio.UI.StudioApplication LogManager.Log(ex, "Error saving settings."); } - _navigationManager.NavigateTo(NavigationView.ShutdownView); + await _navigationManager.NavigateTo(NavigationView.ShutdownView); Thread.Sleep(1500); 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); + } } diff --git a/Software/Visual_Studio/Tango.BL/Builders/ConfigurationBuilder.cs b/Software/Visual_Studio/Tango.BL/Builders/ConfigurationBuilder.cs new file mode 100644 index 000000000..f0d59320e --- /dev/null +++ b/Software/Visual_Studio/Tango.BL/Builders/ConfigurationBuilder.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.BL.Entities; +using System.Data.Entity; + +namespace Tango.BL.Builders +{ + public class ConfigurationBuilder : EntityBuilderBase<Configuration, ConfigurationBuilder> + { + public ConfigurationBuilder(ObservablesContext context) : base(context) + { + + } + + protected override IQueryable<Configuration> OnSetQuery(IQueryable<Configuration> query) + { + return query.Include(x => x.HardwareVersion); + } + + public virtual ConfigurationBuilder WithIdsPacks() + { + return AddStep(1, () => + { + Context.IdsPacks.Where(x => x.ConfigurationGuid == Entity.Guid) + .Include(x => x.LiquidType) + .Include(x => x.DispenserType) + .Include(x => x.CartridgeType) + .Include(x => x.DispenserType) + .Include(x => x.IdsPackFormula).OrderBy(x => x.PackIndex).ToList(); + }); + } + + public virtual ConfigurationBuilder WithHardwareVersion() + { + return AddStep(2, () => + { + HardwareVersionBuilder builder = new HardwareVersionBuilder(Context); + builder.Set(Entity.HardwareVersionGuid); + builder.WithHardwareComponents().Build(); + }); + } + } +} diff --git a/Software/Visual_Studio/Tango.BL/Builders/EntityBuilderBase.cs b/Software/Visual_Studio/Tango.BL/Builders/EntityBuilderBase.cs new file mode 100644 index 000000000..37ec2ae5c --- /dev/null +++ b/Software/Visual_Studio/Tango.BL/Builders/EntityBuilderBase.cs @@ -0,0 +1,116 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Text; +using System.Threading.Tasks; +using System.Data.Entity; + +namespace Tango.BL.Builders +{ + public abstract class EntityBuilderBase<T, TBuilder> : IEntityBuilder<T> where T : ObservableEntity<T> where TBuilder : EntityBuilderBase<T, TBuilder> + { + private List<KeyValuePair<int, Action>> _steps; + private bool _entity_set; + + protected T Entity { get; set; } + protected ObservablesContext Context { get; set; } + + public EntityBuilderBase(ObservablesContext context) + { + _steps = new List<KeyValuePair<int, Action>>(); + Context = context; + } + + public virtual TBuilder Set(Expression<Func<T, bool>> condition) + { + ThrowIfEntitySet(); + + AddStep(0, () => + { + IQueryable<T> query = Context.Set<T>().Where(condition); + query = OnSetQuery(query); + Entity = query.FirstOrDefault(); + }); + + _entity_set = true; + + return this as TBuilder; + } + + public virtual TBuilder SetFirst() + { + ThrowIfEntitySet(); + + AddStep(0, () => + { + IQueryable<T> query = Context.Set<T>(); + query = OnSetQuery(query); + Entity = query.FirstOrDefault(); + }); + + _entity_set = true; + + return this as TBuilder; + } + + public virtual TBuilder Set(T entity) + { + ThrowIfEntitySet(); + + Entity = entity; + _entity_set = true; + return this as TBuilder; + } + + public TBuilder Set(string guid) + { + return Set(x => x.Guid == guid); + } + + private void ThrowIfEntitySet() + { + if (_entity_set) throw new InvalidOperationException("Could not set entity. Entity was already set."); + } + + protected virtual IQueryable<T> OnSetQuery(IQueryable<T> query) + { + return query; + } + + protected TBuilder AddStep(int index, Action action) + { + _steps.Add(new KeyValuePair<int, Action>(index, action)); + return this as TBuilder; + } + + protected void CommitSteps() + { + foreach (var step in _steps.ToList().DistinctBy(x => x.Key).OrderBy(x => x.Key)) + { + step.Value(); + _steps.Remove(step); + } + } + + public virtual T Build() + { + if (!_entity_set) + { + throw new InvalidOperationException("Could not build entity. Entity was not set."); + } + + CommitSteps(); + + return Entity; + } + + public Task<T> BuildAsync() + { + return Task.Factory.StartNew<T>(() => + { + return Build(); + }); + } + } +} diff --git a/Software/Visual_Studio/Tango.BL/Builders/EntityCollectionBuilderBase.cs b/Software/Visual_Studio/Tango.BL/Builders/EntityCollectionBuilderBase.cs new file mode 100644 index 000000000..9ed42cab6 --- /dev/null +++ b/Software/Visual_Studio/Tango.BL/Builders/EntityCollectionBuilderBase.cs @@ -0,0 +1,95 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Text; +using System.Threading.Tasks; +using Tango.Core; + +namespace Tango.BL.Builders +{ + public class EntityCollectionBuilderBase<T, TBuilder> : IEntityCollectionBuilder<T> where T : ObservableEntity<T> where TBuilder : EntityCollectionBuilderBase<T, TBuilder> + { + private List<KeyValuePair<int, Action>> _steps; + private bool _entity_set; + + protected IEnumerable<T> Entities { get; set; } + + protected ObservablesContext Context { get; set; } + + public EntityCollectionBuilderBase(ObservablesContext context) + { + Entities = new List<T>(); + _steps = new List<KeyValuePair<int, Action>>(); + Context = context; + } + + public virtual TBuilder Set() + { + AddStep(0, () => + { + IQueryable<T> query = Context.Set<T>(); + query = OnSetQuery(query); + Entities = query.ToList(); + }); + + _entity_set = true; + + return this as TBuilder; + } + + public virtual TBuilder Set(Expression<Func<T, bool>> condition) + { + AddStep(0, () => + { + IQueryable<T> query = Context.Set<T>().Where(condition); + query = OnSetQuery(query); + Entities = query.ToList(); + }); + + _entity_set = true; + + return this as TBuilder; + } + + protected virtual IQueryable<T> OnSetQuery(IQueryable<T> query) + { + return query; + } + + protected void CommitSteps() + { + foreach (var step in _steps.ToList().DistinctBy(x => x.Key).OrderBy(x => x.Key)) + { + step.Value(); + _steps.Remove(step); + } + } + + protected TBuilder AddStep(int index, Action action) + { + _steps.Add(new KeyValuePair<int, Action>(index, action)); + return this as TBuilder; + } + + public SynchronizedObservableCollection<T> Build() + { + if (!_entity_set) + { + throw new InvalidOperationException("Could not build entity. Entity was not set."); + } + + CommitSteps(); + + return Entities.ToSynchronizedObservableCollection(); + } + + public Task<SynchronizedObservableCollection<T>> BuildAsync() + { + return Task.Factory.StartNew<SynchronizedObservableCollection<T>>(() => + { + return Build(); + }); + } + } +} diff --git a/Software/Visual_Studio/Tango.BL/Builders/HardwareVersionBuilder.cs b/Software/Visual_Studio/Tango.BL/Builders/HardwareVersionBuilder.cs new file mode 100644 index 000000000..84c32507f --- /dev/null +++ b/Software/Visual_Studio/Tango.BL/Builders/HardwareVersionBuilder.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.BL.Entities; +using System.Data.Entity; + +namespace Tango.BL.Builders +{ + public class HardwareVersionBuilder : EntityBuilderBase<HardwareVersion, HardwareVersionBuilder> + { + public HardwareVersionBuilder(ObservablesContext context) : base(context) + { + } + + public virtual HardwareVersionBuilder WithHardwareComponents() + { + return AddStep(1, () => + { + Context.HardwareBlowers.Where(x => x.HardwareVersionGuid == Entity.Guid).Include(x => x.HardwareBlowerType).ToList().OrderBy(x => x.HardwareBlowerType.Code).ToList(); + Context.HardwareBreakSensors.Where(x => x.HardwareVersionGuid == Entity.Guid).Include(x => x.HardwareBreakSensorType).ToList().OrderBy(x => x.HardwareBreakSensorType.Code).ToList(); + Context.HardwareDancers.Where(x => x.HardwareVersionGuid == Entity.Guid).Include(x => x.HardwareDancerType).ToList().OrderBy(x => x.HardwareDancerType.Code).ToList(); + Context.HardwareMotors.Where(x => x.HardwareVersionGuid == Entity.Guid).Include(x => x.HardwareMotorType).ToList().OrderBy(x => x.HardwareMotorType.Code).ToList(); + Context.HardwarePidControls.Where(x => x.HardwareVersionGuid == Entity.Guid).Include(x => x.HardwarePidControlType).ToList().OrderBy(x => x.HardwarePidControlType.Code).ToList(); + Context.HardwareSpeedSensors.Where(x => x.HardwareVersionGuid == Entity.Guid).Include(x => x.HardwareSpeedSensorType).ToList().OrderBy(x => x.HardwareSpeedSensorType.Code).ToList(); + Context.HardwareWinders.Where(x => x.HardwareVersionGuid == Entity.Guid).Include(x => x.HardwareWinderType).ToList().OrderBy(x => x.HardwareWinderType.Code).ToList(); + }); + } + } +} diff --git a/Software/Visual_Studio/Tango.BL/Builders/IEntityBuilder.cs b/Software/Visual_Studio/Tango.BL/Builders/IEntityBuilder.cs new file mode 100644 index 000000000..910412307 --- /dev/null +++ b/Software/Visual_Studio/Tango.BL/Builders/IEntityBuilder.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.BL.Builders +{ + public interface IEntityBuilder<T> where T : ObservableEntity<T> + { + T Build(); + Task<T> BuildAsync(); + } +} diff --git a/Software/Visual_Studio/Tango.BL/Builders/IEntityCollectionBuilder.cs b/Software/Visual_Studio/Tango.BL/Builders/IEntityCollectionBuilder.cs new file mode 100644 index 000000000..c960b414f --- /dev/null +++ b/Software/Visual_Studio/Tango.BL/Builders/IEntityCollectionBuilder.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core; + +namespace Tango.BL.Builders +{ + public interface IEntityCollectionBuilder<T> where T : ObservableEntity<T> + { + SynchronizedObservableCollection<T> Build(); + Task<SynchronizedObservableCollection<T>> BuildAsync(); + } +} diff --git a/Software/Visual_Studio/Tango.BL/Builders/JobBuilder.cs b/Software/Visual_Studio/Tango.BL/Builders/JobBuilder.cs new file mode 100644 index 000000000..0d5affa24 --- /dev/null +++ b/Software/Visual_Studio/Tango.BL/Builders/JobBuilder.cs @@ -0,0 +1,79 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Text; +using System.Threading.Tasks; +using Tango.BL.Entities; +using System.Data.Entity; + +namespace Tango.BL.Builders +{ + public class JobBuilder : EntityBuilderBase<Job, JobBuilder> + { + public JobBuilder(ObservablesContext context) : base(context) + { + + } + + protected override IQueryable<Job> OnSetQuery(IQueryable<Job> query) + { + return query. + Include(x => x.Machine). + Include(x => x.Rml). + Include(x => x.ColorSpace). + Include(x => x.SpoolType). + Include(x => x.WindingMethod); + } + + public virtual JobBuilder WithSegments() + { + return AddStep(1, () => + { + Context.Segments.Where(x => x.JobGuid == Entity.Guid).OrderBy(x => x.SegmentIndex).ToList(); + }); + } + + public virtual JobBuilder WithBrushStops() + { + return AddStep(2, () => + { + foreach (var segment in Entity.Segments.ToList()) + { + Context.BrushStops.Where(x => x.SegmentGuid == segment.Guid).Include(x => x.ColorSpace).OrderBy(x => x.StopIndex).ToList(); + } + }); + } + + public virtual JobBuilder WithConfiguration() + { + return AddStep(3, () => + { + new ConfigurationBuilder(Context) + .Set(Entity.Machine.ConfigurationGuid) + .WithIdsPacks().Build(); + }); + } + + public virtual JobBuilder WithRML() + { + return AddStep(4, () => + { + new RmlBuilder(Context). + Set(Entity.RmlGuid). + WithActiveParametersGroup(). + WithCCT(). + WithCAT(Entity.MachineGuid). + WithLiquidFactors().Build(); + }); + } + + public virtual JobBuilder WithUser() + { + return AddStep(5, () => + { + new UserBuilder(Context).Set(Entity.UserGuid).Build(); + }); + } + } +} diff --git a/Software/Visual_Studio/Tango.BL/Builders/JobsCollectionBuilder.cs b/Software/Visual_Studio/Tango.BL/Builders/JobsCollectionBuilder.cs new file mode 100644 index 000000000..5750f8c1c --- /dev/null +++ b/Software/Visual_Studio/Tango.BL/Builders/JobsCollectionBuilder.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.BL.Entities; +using System.Data.Entity; + +namespace Tango.BL.Builders +{ + public class JobsCollectionBuilder : EntityCollectionBuilderBase<Job, JobsCollectionBuilder> + { + public JobsCollectionBuilder(ObservablesContext context) : base(context) + { + + } + + public virtual JobsCollectionBuilder WithSegments() + { + return AddStep(1, () => + { + foreach (var job in Entities.ToList()) + { + Context.Segments.Where(x => x.JobGuid == job.Guid).OrderBy(x => x.SegmentIndex).ToList(); + } + }); + } + + public virtual JobsCollectionBuilder WithBrushStops() + { + return AddStep(2, () => + { + foreach (var segment in Entities.SelectMany(x => x.Segments).ToList()) + { + Context.BrushStops.Where(x => x.SegmentGuid == segment.Guid).OrderBy(x => x.StopIndex).ToList(); + } + }); + } + } +} diff --git a/Software/Visual_Studio/Tango.BL/Builders/MachineBuilder.cs b/Software/Visual_Studio/Tango.BL/Builders/MachineBuilder.cs new file mode 100644 index 000000000..fa18a9f3b --- /dev/null +++ b/Software/Visual_Studio/Tango.BL/Builders/MachineBuilder.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.BL.Entities; +using System.Data.Entity; + +namespace Tango.BL.Builders +{ + public class MachineBuilder : EntityBuilderBase<Machine, MachineBuilder> + { + public MachineBuilder(ObservablesContext context) : base(context) + { + + } + + public virtual MachineBuilder WithOrganization() + { + return AddStep(1, () => + { + Context.Organizations.Where(x => x.Guid == Entity.OrganizationGuid) + .Include(x => x.Address) + .Include(x => x.Contact).FirstOrDefault(); + }); + } + + public virtual MachineBuilder WithConfiguration() + { + return AddStep(2, () => + { + new ConfigurationBuilder(Context) + .Set(Entity.ConfigurationGuid) + .WithIdsPacks() + .WithHardwareVersion() + .Build(); + }); + } + } +} diff --git a/Software/Visual_Studio/Tango.BL/Builders/RmlBuilder.cs b/Software/Visual_Studio/Tango.BL/Builders/RmlBuilder.cs new file mode 100644 index 000000000..3d288e470 --- /dev/null +++ b/Software/Visual_Studio/Tango.BL/Builders/RmlBuilder.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.BL.Entities; +using System.Data.Entity; +using System.Linq.Expressions; + +namespace Tango.BL.Builders +{ + public class RmlBuilder : EntityBuilderBase<Rml, RmlBuilder> + { + public RmlBuilder(ObservablesContext context) : base(context) + { + + } + + public virtual RmlBuilder WithAllParametersGroup() + { + return AddStep(1, () => + { + var groups = Context.ProcessParametersTablesGroups.Where(x => x.RmlGuid == Entity.Guid).ToList(); + + foreach (var group in groups) + { + Context.ProcessParametersTables.Where(x => x.ProcessParametersTablesGroupGuid == group.Guid).OrderBy(x => x.TableIndex).ToList(); + } + }); + } + + public virtual RmlBuilder WithActiveParametersGroup() + { + return AddStep(2, () => + { + Context.ProcessParametersTablesGroups.Where(x => x.RmlGuid == Entity.Guid && x.Active).Include(x => x.ProcessParametersTables).FirstOrDefault(); + }); + } + + public virtual RmlBuilder WithCCT() + { + return AddStep(3, () => + { + Context.Ccts.FirstOrDefault(x => x.RmlGuid == Entity.Guid); + }); + } + + public virtual RmlBuilder WithCAT(String machineGuid) + { + return AddStep(4, () => + { + Context.Cats.Where(x => x.MachineGuid == machineGuid && x.RmlGuid == Entity.Guid).ToList(); + }); + } + + public virtual RmlBuilder WithLiquidFactors() + { + return AddStep(5, () => + { + Context.LiquidTypesRmls.Where(x => x.RmlGuid == Entity.Guid).ToList(); + }); + } + } +} diff --git a/Software/Visual_Studio/Tango.BL/Builders/RmlsCollectionBuilder.cs b/Software/Visual_Studio/Tango.BL/Builders/RmlsCollectionBuilder.cs new file mode 100644 index 000000000..9fb84fcc0 --- /dev/null +++ b/Software/Visual_Studio/Tango.BL/Builders/RmlsCollectionBuilder.cs @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.BL.Entities; +using System.Data.Entity; + +namespace Tango.BL.Builders +{ + public class RmlsCollectionBuilder : EntityCollectionBuilderBase<Rml, RmlsCollectionBuilder> + { + public RmlsCollectionBuilder(ObservablesContext context) : base(context) + { + } + + public virtual RmlsCollectionBuilder WithAllParametersGroup() + { + return AddStep(1, () => + { + foreach (var rml in Entities.ToList()) + { + var groups = Context.ProcessParametersTablesGroups.Where(x => x.RmlGuid == rml.Guid).ToList(); + + foreach (var group in groups) + { + Context.ProcessParametersTables.Where(x => x.ProcessParametersTablesGroupGuid == group.Guid).OrderBy(x => x.TableIndex).ToList(); + } + } + }); + } + + public virtual RmlsCollectionBuilder WithActiveParametersGroup() + { + return AddStep(2, () => + { + foreach (var rml in Entities.ToList()) + { + Context.ProcessParametersTablesGroups.Where(x => x.RmlGuid == rml.Guid && x.Active).Include(x => x.ProcessParametersTables).FirstOrDefault(); + } + }); + } + + public virtual RmlsCollectionBuilder WithCCT() + { + return AddStep(3, () => + { + foreach (var rml in Entities.ToList()) + { + Context.Ccts.FirstOrDefault(x => x.RmlGuid == rml.Guid); + } + }); + } + + public virtual RmlsCollectionBuilder WithCAT(String machineGuid) + { + return AddStep(4, () => + { + foreach (var rml in Entities.ToList()) + { + Context.Cats.Where(x => x.MachineGuid == machineGuid && x.RmlGuid == rml.Guid).ToList(); + } + }); + } + + public virtual RmlsCollectionBuilder WithLiquidFactors() + { + return AddStep(5, () => + { + foreach (var rml in Entities.ToList()) + { + Context.LiquidTypesRmls.Where(x => x.RmlGuid == rml.Guid).ToList(); + } + }); + } + } +} diff --git a/Software/Visual_Studio/Tango.BL/Builders/UserBuilder.cs b/Software/Visual_Studio/Tango.BL/Builders/UserBuilder.cs new file mode 100644 index 000000000..9da682e27 --- /dev/null +++ b/Software/Visual_Studio/Tango.BL/Builders/UserBuilder.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.BL.Entities; +using System.Data.Entity; + +namespace Tango.BL.Builders +{ + public class UserBuilder : EntityBuilderBase<User, UserBuilder> + { + public UserBuilder(ObservablesContext context) : base(context) + { + + } + + protected override IQueryable<User> OnSetQuery(IQueryable<User> query) + { + return query.Include(x => x.Address).Include(x => x.Contact); + } + + public virtual UserBuilder WithOrganization() + { + return AddStep(1, () => + { + Context.Organizations.SingleOrDefault(x => x.Guid == Entity.OrganizationGuid); + }); + } + + public virtual UserBuilder WithRolesAndPermissions() + { + return AddStep(2, () => + { + Context.UsersRoles.Where(x => x.UserGuid == Entity.Guid) + .Include(x => x.Role) + .Include(x => x.Role.RolesPermissions) + .Include(x => x.Role.RolesPermissions.Select(y => y.Permission)) + .ToList(); + }); + } + } +} diff --git a/Software/Visual_Studio/Tango.BL/EntitiesExtensions/Job.cs b/Software/Visual_Studio/Tango.BL/EntitiesExtensions/Job.cs index a5b19b221..d71658317 100644 --- a/Software/Visual_Studio/Tango.BL/EntitiesExtensions/Job.cs +++ b/Software/Visual_Studio/Tango.BL/EntitiesExtensions/Job.cs @@ -12,6 +12,7 @@ using System.Windows.Media.Imaging; using Tango.BL.Attributes; using Tango.BL.Enumerations; using Tango.Core; +using Tango.Logging; namespace Tango.BL.Entities { @@ -97,7 +98,15 @@ namespace Tango.BL.Entities { get { - return typeof(JobStatuses).GetField(JobStatus.ToString()).GetCustomAttribute<JobStatusAttribute>().Categories; + try + { + return typeof(JobStatuses).GetField(JobStatus.ToString()).GetCustomAttribute<JobStatusAttribute>().Categories; + } + catch + { + //LogManager.Log(ex, LogCategory.Warning); + return new List<JobCategories>() { Enumerations.JobCategories.Draft }; + } } } diff --git a/Software/Visual_Studio/Tango.BL/ObservableEntity.cs b/Software/Visual_Studio/Tango.BL/ObservableEntity.cs index 1b69a8bdb..5c8718f47 100644 --- a/Software/Visual_Studio/Tango.BL/ObservableEntity.cs +++ b/Software/Visual_Studio/Tango.BL/ObservableEntity.cs @@ -374,6 +374,11 @@ Maybe you have deleted an entity that was no yet inserted into database?", LogCa return GetObjectContextFromEntity(this); } + public DbContext GetDbContext() + { + return GetDbContextFromEntity(this); + } + #endregion #region Private Methods diff --git a/Software/Visual_Studio/Tango.BL/ObservablesContextAdapter.cs b/Software/Visual_Studio/Tango.BL/ObservablesContextAdapter.cs index 33a252b8a..03e4f3c47 100644 --- a/Software/Visual_Studio/Tango.BL/ObservablesContextAdapter.cs +++ b/Software/Visual_Studio/Tango.BL/ObservablesContextAdapter.cs @@ -194,9 +194,15 @@ namespace Tango.BL .FirstOrDefault(); } + /// <summary> + /// Gets the job with all its segments and brush stops. + /// </summary> + /// <param name="jobGuid">The job unique identifier.</param> + /// <returns></returns> public Job GetJob(String jobGuid) { Job job = _db.Jobs.Where(x => x.Guid == jobGuid) + .Include(x => x.Machine) .Include(x => x.Rml) .Include(x => x.ColorSpace) .Include(x => x.WindingMethod) @@ -209,10 +215,30 @@ namespace Tango.BL segment.BrushStops = _db.BrushStops.Where(x => x.SegmentGuid == segment.Guid).OrderBy(x => x.StopIndex).ToSynchronizedObservableCollection(); } + GetMachine(job.Machine.SerialNumber); + + GetRmlActiveProcessParametersTablesGroup(job.RmlGuid); + return job; } /// <summary> + /// Gets the machine with its configuration and organization. + /// </summary> + /// <param name="serialNumber">The serial number.</param> + /// <returns></returns> + public Machine GetMachine(String serialNumber) + { + var machine = _db.Machines.SingleOrDefault(x => x.SerialNumber == serialNumber); + + machine.Organization = _db.Organizations.SingleOrDefault(x => x.Guid == machine.OrganizationGuid); + machine.Configuration = GetConfiguration(x => x.Guid == machine.ConfigurationGuid); + machine.Configuration.HardwareVersion = GetHardwareVersion(x => x.Guid == machine.Configuration.HardwareVersionGuid); + + return machine; + } + + /// <summary> /// Disposes the underlying <see cref="ObservablesContext"/>. /// </summary> public void Dispose() diff --git a/Software/Visual_Studio/Tango.BL/Tango.BL.csproj b/Software/Visual_Studio/Tango.BL/Tango.BL.csproj index b3d7ff2a0..897f74b89 100644 --- a/Software/Visual_Studio/Tango.BL/Tango.BL.csproj +++ b/Software/Visual_Studio/Tango.BL/Tango.BL.csproj @@ -82,6 +82,18 @@ <Link>GlobalVersionInfo.cs</Link> </Compile> <Compile Include="Attributes\JobStatusAttribute.cs" /> + <Compile Include="Builders\ConfigurationBuilder.cs" /> + <Compile Include="Builders\EntityBuilderBase.cs" /> + <Compile Include="Builders\EntityCollectionBuilderBase.cs" /> + <Compile Include="Builders\HardwareVersionBuilder.cs" /> + <Compile Include="Builders\IEntityBuilder.cs" /> + <Compile Include="Builders\IEntityCollectionBuilder.cs" /> + <Compile Include="Builders\JobBuilder.cs" /> + <Compile Include="Builders\JobsCollectionBuilder.cs" /> + <Compile Include="Builders\MachineBuilder.cs" /> + <Compile Include="Builders\RmlBuilder.cs" /> + <Compile Include="Builders\RmlsCollectionBuilder.cs" /> + <Compile Include="Builders\UserBuilder.cs" /> <Compile Include="Catalogs\Catalog.cs" /> <Compile Include="Catalogs\CatalogGroup.cs" /> <Compile Include="Catalogs\CatalogItem.cs" /> @@ -323,7 +335,7 @@ </Target> <ProjectExtensions> <VisualStudio> - <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UseGlobalSettings="False" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" /> + <UserProperties BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UseGlobalSettings="False" BuildVersion_StartDate="2000/1/1" /> </VisualStudio> </ProjectExtensions> </Project>
\ No newline at end of file diff --git a/Software/Visual_Studio/Tango.SharedUI/Controls/HexagonControl.cs b/Software/Visual_Studio/Tango.SharedUI/Controls/HexagonControl.cs index 75e753306..c4bebbbe7 100644 --- a/Software/Visual_Studio/Tango.SharedUI/Controls/HexagonControl.cs +++ b/Software/Visual_Studio/Tango.SharedUI/Controls/HexagonControl.cs @@ -95,10 +95,12 @@ namespace Tango.SharedUI.Controls Typeface typeface = new Typeface("Times New Roman"); double em_size = 16; +#pragma warning disable CS0618 // Type or member is obsolete FormattedText formatted_text = new FormattedText( Row + "," + Column, CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, typeface, em_size, Brushes.Black); +#pragma warning restore CS0618 // Type or member is obsolete // Center the text horizontally. formatted_text.TextAlignment = TextAlignment.Center; diff --git a/Software/Visual_Studio/Tango.Transport/Servers/TcpServer.cs b/Software/Visual_Studio/Tango.Transport/Servers/TcpServer.cs index c8453fb25..d6e2ad1d0 100644 --- a/Software/Visual_Studio/Tango.Transport/Servers/TcpServer.cs +++ b/Software/Visual_Studio/Tango.Transport/Servers/TcpServer.cs @@ -15,7 +15,6 @@ namespace Tango.Transport.Servers /// </summary> public class TcpServer { - private TaskScheduler scheduler; private LogManager LogManager = LogManager.Default; /// <summary> @@ -58,11 +57,6 @@ namespace Tango.Transport.Servers { if (!IsStarted) { - if (scheduler == null) - { - scheduler = TaskScheduler.FromCurrentSynchronizationContext(); - } - Listener = new TcpListener(System.Net.IPAddress.Any, Port); Listener.Start(); IsStarted = true; @@ -117,13 +111,7 @@ namespace Tango.Transport.Servers protected virtual void OnClientConnected(TcpClient socket) { LogManager.Log("New client connected."); - - Task.Factory.StartNew(() => - { - - ClientConnected?.Invoke(this, new ClientConnectedEventArgs(socket)); - - },CancellationToken.None,TaskCreationOptions.None,scheduler); + ClientConnected?.Invoke(this, new ClientConnectedEventArgs(socket)); } #endregion diff --git a/Software/Visual_Studio/Tango.WiFi/AuthRequest.cs b/Software/Visual_Studio/Tango.WiFi/AuthRequest.cs index bb40591d2..5ef181085 100644 --- a/Software/Visual_Studio/Tango.WiFi/AuthRequest.cs +++ b/Software/Visual_Studio/Tango.WiFi/AuthRequest.cs @@ -58,7 +58,6 @@ namespace Tango.WiFi { get { - #warning Robin: Not sure that Enterprise networks have the same requirements on the password complexity as standard ones. return PasswordHelper.IsValid(_password, _network.dot11DefaultCipherAlgorithm); } } diff --git a/Software/Visual_Studio/Tango.WiFi/EapUserFactory.cs b/Software/Visual_Studio/Tango.WiFi/EapUserFactory.cs index 26f5c1852..d29941200 100644 --- a/Software/Visual_Studio/Tango.WiFi/EapUserFactory.cs +++ b/Software/Visual_Studio/Tango.WiFi/EapUserFactory.cs @@ -15,8 +15,6 @@ namespace Tango.WiFi /// </summary> internal static string Generate(Dot11CipherAlgorithm cipher, string username, string password, string domain) { - #warning Robin: Probably not properly implemented, only supports WPA- and WPA-2 Enterprise with PEAP-MSCHAPv2 - string profile = string.Empty; string template = string.Empty; diff --git a/Software/Visual_Studio/Tango.WiFi/ProfileFactory.cs b/Software/Visual_Studio/Tango.WiFi/ProfileFactory.cs index ca9b3740b..3905f46e9 100644 --- a/Software/Visual_Studio/Tango.WiFi/ProfileFactory.cs +++ b/Software/Visual_Studio/Tango.WiFi/ProfileFactory.cs @@ -46,7 +46,6 @@ namespace Tango.WiFi } break; case Dot11CipherAlgorithm.TKIP: - #warning Robin: Not sure WPA uses RSNA if (authAlgo == Dot11AuthAlgorithm.RSNA) { template = GetTemplate("WPA-Enterprise-PEAP-MSCHAPv2"); |
