From 858a2b114f78c87883510e3627874c7632f81177 Mon Sep 17 00:00:00 2001 From: Roy Date: Sun, 18 Feb 2018 09:23:15 +0200 Subject: Developer redesign.. --- .../Navigation/DeveloperNavigationManager.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Navigation/DeveloperNavigationManager.cs (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Navigation/DeveloperNavigationManager.cs') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Navigation/DeveloperNavigationManager.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Navigation/DeveloperNavigationManager.cs new file mode 100644 index 000000000..297caf2dc --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Navigation/DeveloperNavigationManager.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.MachineStudio.Common.Navigation; +using Tango.MachineStudio.Developer.Views; + +namespace Tango.MachineStudio.Developer.Navigation +{ + public class DeveloperNavigationManager + { + public void NavigateTo(DeveloperNavigationView view) + { + DeveloperView.Instance.TransitionControl.AutoNavigate(view.ToString()); + } + } +} -- cgit v1.3.1 From 160ec4042539e69a7494bcde5c893c6dffcbf1b6 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Mon, 19 Feb 2018 19:09:12 +0200 Subject: Working on developer module.. --- Software/DB/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/Tango_log.ldf | Bin 8388608 -> 8388608 bytes .../ViewModels/DbTableViewModel.cs | 8 +- .../DeveloperModule.cs | 2 +- .../Navigation/DeveloperNavigationManager.cs | 2 +- .../Tango.MachineStudio.Developer.csproj | 6 +- .../ViewModelLocator.cs | 2 +- .../ViewModels/MainViewVM.cs | 76 ++-- .../Views/DeveloperView.xaml | 414 --------------------- .../Views/DeveloperView.xaml.cs | 31 -- .../Views/JobView.xaml | 2 +- .../Views/MachineJobSelectionView.xaml | 30 +- .../Views/MainView.xaml | 414 +++++++++++++++++++++ .../Views/MainView.xaml.cs | 44 +++ .../ViewModels/MainViewVM.cs | 12 +- .../Observables/IObservableEntity.cs | 14 +- .../Observables/ObservableEntity.cs | 27 +- .../Observables/Partials/Configuration.cs | 4 +- .../Observables/Partials/Machine.cs | 10 +- .../Observables/Partials/MachineVersion.cs | 6 +- .../Observables/Partials/Segment.cs | 2 +- .../Tango.Integration/Printing/Job.cs | 4 +- .../Tango.Integration/Printing/Segment.cs | 2 +- .../Tango.SharedUI/Controls/MultiSelectDataGrid.cs | 11 +- .../DateTimeUTCToShortDateTimeConverter.cs | 11 +- .../Tango.UnitTesting/ColorLib_TST.cs | 4 +- 26 files changed, 595 insertions(+), 543 deletions(-) delete mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/DeveloperView.xaml delete mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/DeveloperView.xaml.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml.cs (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Navigation/DeveloperNavigationManager.cs') diff --git a/Software/DB/Tango.mdf b/Software/DB/Tango.mdf index 24b24abfc..ff1de2760 100644 Binary files a/Software/DB/Tango.mdf and b/Software/DB/Tango.mdf differ diff --git a/Software/DB/Tango_log.ldf b/Software/DB/Tango_log.ldf index 54bf7ba0d..661db54aa 100644 Binary files a/Software/DB/Tango_log.ldf and b/Software/DB/Tango_log.ldf differ diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/ViewModels/DbTableViewModel.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/ViewModels/DbTableViewModel.cs index a05df573c..62f768b9d 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/ViewModels/DbTableViewModel.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/ViewModels/DbTableViewModel.cs @@ -158,7 +158,7 @@ namespace Tango.MachineStudio.DB.ViewModels { try { - await SelectedEntity.DeleteAsync(); + await SelectedEntity.DeleteAsync(Adapter.Context); } catch (Exception ex) { @@ -220,18 +220,18 @@ namespace Tango.MachineStudio.DB.ViewModels { if (mode == DialogOpenMode.Adding) { - entity.Attach(); + entity.Attach(Adapter.Context); } try { - await entity.SaveAsync(); + await entity.SaveAsync(Adapter.Context); } catch (DbUpdateException ex) { if (mode == DialogOpenMode.Adding) { - entity.Detach(); + entity.Detach(Adapter.Context); } Adapter.Invalidate(); _notification.ShowError("Could not save entity." + Environment.NewLine + ex.InnerException.InnerException != null ? ex.InnerException.InnerException.Message : ex.InnerException.Message); diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/DeveloperModule.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/DeveloperModule.cs index 17c08adc4..6cdda4bc8 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/DeveloperModule.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/DeveloperModule.cs @@ -36,7 +36,7 @@ namespace Tango.MachineStudio.Developer /// /// Gets the module entry point view. /// - public override FrameworkElement MainView => new DeveloperView(); + public override FrameworkElement MainView => new MainView(); /// /// Gets the permission required to see and load this module. diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Navigation/DeveloperNavigationManager.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Navigation/DeveloperNavigationManager.cs index 297caf2dc..5be50231d 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Navigation/DeveloperNavigationManager.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Navigation/DeveloperNavigationManager.cs @@ -12,7 +12,7 @@ namespace Tango.MachineStudio.Developer.Navigation { public void NavigateTo(DeveloperNavigationView view) { - DeveloperView.Instance.TransitionControl.AutoNavigate(view.ToString()); + MainView.Instance.TransitionControl.AutoNavigate(view.ToString()); } } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj index 3253fc551..91a9602be 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj @@ -124,8 +124,8 @@ - - DeveloperView.xaml + + MainView.xaml @@ -148,7 +148,7 @@ MSBuild:Compile Designer - + Designer MSBuild:Compile diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModelLocator.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModelLocator.cs index b397f1912..c5ed7d385 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModelLocator.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModelLocator.cs @@ -20,7 +20,7 @@ namespace Tango.MachineStudio.Developer { ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default); - //SimpleIoc.Default.Register(() => MainView.Self); + SimpleIoc.Default.Register(() => MainView.Instance); SimpleIoc.Default.Register(); SimpleIoc.Default.Register(); } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs index 199183c12..62b742390 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs @@ -45,7 +45,7 @@ namespace Tango.MachineStudio.Developer.ViewModels /// Represents the developer module main view, view model. /// /// - public class MainViewVM : ViewModel, IShutdownRequestBlocker + public class MainViewVM : ViewModel, IShutdownRequestBlocker, IShutdownListener { private static object _syncLock = new object(); @@ -464,6 +464,14 @@ namespace Tango.MachineStudio.Developer.ViewModels } } + private String _jobFilter; + + public String JobFilter + { + get { return _jobFilter; } + set { _jobFilter = value; RaisePropertyChangedAuto(); OnJobFilterChanged(); } + } + #endregion #region Commands @@ -575,7 +583,7 @@ namespace Tango.MachineStudio.Developer.ViewModels /// /// Initializes a new instance of the class. /// - public MainViewVM() : base() + public MainViewVM(IMainView view) : base(view, true) { } @@ -586,16 +594,22 @@ namespace Tango.MachineStudio.Developer.ViewModels /// The application manager. /// The notification provider. [PreferredConstructor] - public MainViewVM(IStudioApplicationManager applicationManager, INotificationProvider notificationProvider, IDiagnosticsFrameProvider diagnosticsFrameProvider, IVideoCaptureProvider videoCaptureProvider, DeveloperNavigationManager navigation, IAuthenticationProvider authentication) : this() + public MainViewVM(IMainView view, IStudioApplicationManager applicationManager, INotificationProvider notificationProvider, IDiagnosticsFrameProvider diagnosticsFrameProvider, IVideoCaptureProvider videoCaptureProvider, DeveloperNavigationManager navigation, IAuthenticationProvider authentication) : this(view) { - using (var db = ObservablesContext.CreateDefault()) + SelectedJobs = new ObservableCollection(); + + _machineDBContext = ObservablesContext.CreateDefault(); + + if (SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedMachineGuid != null) { - Machines = db.Machines.ToObservableCollection(); + SelectedMachine = _machineDBContext.Machines.SingleOrDefault(x => x.Guid == SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedMachineGuid); } - _machineDBContext = ObservablesContext.CreateDefault(); + if (SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedJobGuid != null && SelectedMachine != null) + { + SelectedMachineJob = SelectedMachine.Jobs.SingleOrDefault(x => x.Guid == SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedJobGuid); + } - SelectedJobs = new ObservableCollection(); _authentication = authentication; @@ -748,7 +762,6 @@ namespace Tango.MachineStudio.Developer.ViewModels ReloadMachine(); JobsCollectionView = CollectionViewSource.GetDefaultView(SelectedMachine.Jobs); JobsCollectionView.SortDescriptions.Add(new SortDescription(nameof(Job.LastUpdated), ListSortDirection.Descending)); - InvalidateLiquidFactorsAndProcessTables(); } } @@ -757,7 +770,8 @@ namespace Tango.MachineStudio.Developer.ViewModels _machineDBContext.Dispose(); _machineDBContext = ObservablesContext.CreateDefault(); _machineDBContext.Configuration.LazyLoadingEnabled = true; - _selectedMachine = _machineDBContext.Machines.SingleOrDefault(x => x.Guid == _selectedMachine.Guid); + Machines = _machineDBContext.Machines.ToObservableCollection(); + _selectedMachine = Machines.SingleOrDefault(x => x.Guid == _selectedMachine.Guid); RaisePropertyChanged(nameof(SelectedMachine)); JobsCollectionView = CollectionViewSource.GetDefaultView(SelectedMachine.Jobs); @@ -768,6 +782,17 @@ namespace Tango.MachineStudio.Developer.ViewModels #region Private Methods + private void OnJobFilterChanged() + { + JobsCollectionView.Filter = (job) => + { + Job j = job as Job; + return String.IsNullOrWhiteSpace(JobFilter) + || + j.Name.ToLower().Contains(JobFilter.ToLower()); + }; + } + private void OnActiveJobChanged() { if (ActiveJob != null) @@ -998,7 +1023,7 @@ namespace Tango.MachineStudio.Developer.ViewModels { using (_notification.PushTaskItem("Saving Liquid Factors...")) { - await SelectedRML.SaveAsync(); + await SelectedRML.SaveAsync(_dbJobContext); InvalidateLiquidFactorsAndProcessTables(); } } @@ -1053,7 +1078,7 @@ namespace Tango.MachineStudio.Developer.ViewModels } SelectedRML.ProcessParametersTablesGroups.Add(group); - await SelectedRML.SaveAsync(); + await SelectedRML.SaveAsync(_dbJobContext); InvalidateLiquidFactorsAndProcessTables(); } @@ -1398,30 +1423,27 @@ namespace Tango.MachineStudio.Developer.ViewModels return Task.FromResult(false); } - SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedMachineGuid = SelectedMachine != null ? SelectedMachine.Guid : null; - SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedJobGuid = ActiveJob != null ? ActiveJob.Guid : null; - return Task.FromResult(true); } #endregion - #region IMainView + #region IShutdownListener + + public void OnShuttingDown() + { + SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedMachineGuid = SelectedMachine != null ? SelectedMachine.Guid : null; + SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedJobGuid = SelectedMachineJob != null ? SelectedMachineJob.Guid : null; + } - //protected override void OnViewAttached() - //{ - // base.OnViewAttached(); + #endregion - // //if (SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedMachineGuid != null) - // //{ - // // SelectedMachine = Adapter.Machines.SingleOrDefault(x => x.Guid == SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedMachineGuid); - // //} + #region IMainView - // //if (SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedJobGuid != null && SelectedMachine != null) - // //{ - // // ActiveJob = SelectedMachine.Jobs.SingleOrDefault(x => x.Guid == SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedJobGuid); - // //} - //} + protected override void OnViewAttached() + { + base.OnViewAttached(); + } #endregion } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/DeveloperView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/DeveloperView.xaml deleted file mode 100644 index 276f6c99a..000000000 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/DeveloperView.xaml +++ /dev/null @@ -1,414 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Transparent - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Job Completed Successfully - - - - - - - - - - - - - - - - - - - - - - - Job Failed To Complete - - - - - - - - - - - - - - - - - - - - - - - - - Job Aborted By User - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/DeveloperView.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/DeveloperView.xaml.cs deleted file mode 100644 index dfa7a2441..000000000 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/DeveloperView.xaml.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; - -namespace Tango.MachineStudio.Developer.Views -{ - /// - /// Interaction logic for DeveloperView.xaml - /// - public partial class DeveloperView : UserControl - { - public static DeveloperView Instance { get; set; } - - public DeveloperView() - { - InitializeComponent(); - Instance = this; - } - } -} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml index 580e2438b..4467b1f28 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml @@ -852,7 +852,7 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Job Completed Successfully + + + + + + + + + + + + + + + + + + + + + + + Job Failed To Complete + + + + + + + + + + + + + + + + + + + + + + + + + Job Aborted By User + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml.cs new file mode 100644 index 000000000..ab181e8dc --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; +using Tango.SharedUI; + +namespace Tango.MachineStudio.Developer.Views +{ + /// + /// Interaction logic for DeveloperView.xaml + /// + public partial class MainView : UserControl, IMainView + { + private bool _loaded; + public static MainView Instance { get; set; } + + public MainView() + { + InitializeComponent(); + Instance = this; + + Loaded += (x, y) => + { + if (!_loaded) + { + _loaded = true; + ViewAttached?.Invoke(this, this); + } + }; + } + + public event EventHandler ViewAttached; + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs index cedbcf9a6..6fbd5852d 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs @@ -529,7 +529,7 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels Configuration = Configuration, Machine = Machine, }); - await Machine.SaveAsync(); + await Machine.SaveAsync(Adapter.Context); Machine = Adapter.Machines.SingleOrDefault(x => x.Guid == Machine.Guid); Configuration = Machine.Configuration.CloneConfiguration(); @@ -558,12 +558,12 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels } else { - machine.Configuration.DefferedDelete(); + machine.Configuration.DefferedDelete(Adapter.Context); } machine.Configuration = Configuration; - await machine.SaveAsync(); + await machine.SaveAsync(Adapter.Context); Machine = Adapter.Machines.SingleOrDefault(x => x.Guid == machine.Guid); Configuration = Machine.Configuration.CloneConfiguration(); @@ -624,7 +624,7 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels { vm.SelectedVersion.DefaultConfiguration = Configuration.CloneConfiguration(); vm.SelectedVersion.DefaultConfigurationGuid = vm.SelectedVersion.DefaultConfiguration.Guid; - await vm.SelectedVersion.SaveAsync(); + await vm.SelectedVersion.SaveAsync(Adapter.Context); } else { @@ -634,7 +634,7 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels newVersion.DefaultConfiguration = Configuration.CloneConfiguration(); newVersion.DefaultConfigurationGuid = newVersion.DefaultConfiguration.Guid; - await newVersion.SaveAsync(); + await newVersion.SaveAsync(Adapter.Context); } } } @@ -662,7 +662,7 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels { if (module is MachineDesignerModule) { - SelectedMachine = args as Machine; + SelectedMachine = Adapter.Machines.SingleOrDefault(x => x.Guid == (args as Machine).Guid); } } diff --git a/Software/Visual_Studio/Tango.Integration/Observables/IObservableEntity.cs b/Software/Visual_Studio/Tango.Integration/Observables/IObservableEntity.cs index cd046ac2b..600258b84 100644 --- a/Software/Visual_Studio/Tango.Integration/Observables/IObservableEntity.cs +++ b/Software/Visual_Studio/Tango.Integration/Observables/IObservableEntity.cs @@ -43,37 +43,37 @@ namespace Tango.Integration.Observables /// /// Saves the changes on this entity to database. /// - void Save(ObservablesContext context = null); + void Save(ObservablesContext context); /// /// Attaches this observable to the proper DbSet. /// - void Attach(ObservablesContext context = null); + void Attach(ObservablesContext context); /// /// Detaches this observable from the proper DbSet. /// - void Detach(ObservablesContext context = null); + void Detach(ObservablesContext context); /// /// Saves the changes on this entity to database asynchronously. /// /// - Task SaveAsync(ObservablesContext context = null); + Task SaveAsync(ObservablesContext context); /// /// Deletes this entity from the database. /// - void Delete(ObservablesContext context = null); + void Delete(ObservablesContext context); /// /// Deletes this entity without saving changes to data base. /// - void DefferedDelete(ObservablesContext context = null); + void DefferedDelete(ObservablesContext context); /// /// Deletes this entity from the database. /// - Task DeleteAsync(ObservablesContext context = null); + Task DeleteAsync(ObservablesContext context); } } diff --git a/Software/Visual_Studio/Tango.Integration/Observables/ObservableEntity.cs b/Software/Visual_Studio/Tango.Integration/Observables/ObservableEntity.cs index d379945f3..3f05dffd3 100644 --- a/Software/Visual_Studio/Tango.Integration/Observables/ObservableEntity.cs +++ b/Software/Visual_Studio/Tango.Integration/Observables/ObservableEntity.cs @@ -114,9 +114,9 @@ namespace Tango.Integration.Observables /// /// Saves the changes on this entity to database. /// - public virtual void Save(ObservablesContext context = null) + public virtual void Save(ObservablesContext context) { - if (context == null) + if (context == ObservablesEntitiesAdapter.Instance.Context) { ObservablesEntitiesAdapter.Instance.SaveChanges(); } @@ -130,7 +130,7 @@ namespace Tango.Integration.Observables /// /// Attaches this entity to the proper DbSet. /// - public virtual void Attach(ObservablesContext context = null) + public virtual void Attach(ObservablesContext context) { GetDbSet(context).Add(this as T); } @@ -138,7 +138,7 @@ namespace Tango.Integration.Observables /// /// Detaches this observable from the proper DbSet. /// - public virtual void Detach(ObservablesContext context = null) + public virtual void Detach(ObservablesContext context) { GetDbSet(context).Remove(this as T); } @@ -147,7 +147,7 @@ namespace Tango.Integration.Observables /// Saves the changes on this entity to database asynchronously. /// /// - public Task SaveAsync(ObservablesContext context = null) + public Task SaveAsync(ObservablesContext context) { return Task.Factory.StartNew(() => { @@ -167,26 +167,26 @@ namespace Tango.Integration.Observables /// /// Deletes this entity from the database /// - public virtual void Delete(ObservablesContext context = null) + public virtual void Delete(ObservablesContext context) { var delProp = this.GetType().GetProperty("Deleted"); if (delProp != null) { delProp.SetValue(this, true); - Save(); + Save(context); } else { GetDbSet(context).Remove(this as T); - Save(); + Save(context); } } /// /// Deletes this entity without saving changes to data base. /// - public virtual void DefferedDelete(ObservablesContext context = null) + public virtual void DefferedDelete(ObservablesContext context) { GetDbSet(context).Remove(this as T); } @@ -194,7 +194,7 @@ namespace Tango.Integration.Observables /// /// Deletes this entity from the database /// - public Task DeleteAsync(ObservablesContext context = null) + public Task DeleteAsync(ObservablesContext context) { return Task.Factory.StartNew(() => { @@ -204,8 +204,6 @@ namespace Tango.Integration.Observables public DbSet GetDbSet(ObservablesContext context) { - context = GetContextOrDefault(context); - String tabelName = this.GetType().Name.PluralizeMVC(); var p = typeof(ObservablesContext).GetProperty(tabelName); if (p != null) @@ -268,11 +266,6 @@ namespace Tango.Integration.Observables return me == other; } - private ObservablesContext GetContextOrDefault(ObservablesContext context) - { - return context != null ? context : ObservablesEntitiesAdapter.Instance.Context; - } - #region Operator Overloading //public static bool operator ==(ObservableEntity observable1, ObservableEntity observable2) diff --git a/Software/Visual_Studio/Tango.Integration/Observables/Partials/Configuration.cs b/Software/Visual_Studio/Tango.Integration/Observables/Partials/Configuration.cs index fa489ded2..a5ddb0d14 100644 --- a/Software/Visual_Studio/Tango.Integration/Observables/Partials/Configuration.cs +++ b/Software/Visual_Studio/Tango.Integration/Observables/Partials/Configuration.cs @@ -8,7 +8,7 @@ namespace Tango.Integration.Observables { public partial class Configuration { - public override void DefferedDelete(ObservablesContext context = null) + public override void DefferedDelete(ObservablesContext context) { IdsPacks.ToList().ForEach(x => x.DefferedDelete(context)); var machine_configurations = context.MachinesConfigurations.Where(x => x.Configuration == this); @@ -17,7 +17,7 @@ namespace Tango.Integration.Observables IdsPacks.Clear(); } - public override void Delete(ObservablesContext context = null) + public override void Delete(ObservablesContext context) { IdsPacks.ToList().ForEach(x => x.DefferedDelete(context)); var machine_configurations = context.MachinesConfigurations.Where(x => x.Configuration == this); diff --git a/Software/Visual_Studio/Tango.Integration/Observables/Partials/Machine.cs b/Software/Visual_Studio/Tango.Integration/Observables/Partials/Machine.cs index 1669230d6..3026ff168 100644 --- a/Software/Visual_Studio/Tango.Integration/Observables/Partials/Machine.cs +++ b/Software/Visual_Studio/Tango.Integration/Observables/Partials/Machine.cs @@ -12,18 +12,18 @@ namespace Tango.Integration.Observables /// /// Deletes this entity from the database /// - public override void Delete(ObservablesContext context = null) + public override void Delete(ObservablesContext context) { foreach (var machine_config in MachinesConfigurations) { - machine_config.Delete(); - machine_config.Configuration.Delete(); + machine_config.Delete(context); + machine_config.Configuration.Delete(context); } - base.Delete(); + base.Delete(context); } - public override void Save(ObservablesContext context = null) + public override void Save(ObservablesContext context) { foreach (var job in Jobs) { diff --git a/Software/Visual_Studio/Tango.Integration/Observables/Partials/MachineVersion.cs b/Software/Visual_Studio/Tango.Integration/Observables/Partials/MachineVersion.cs index 4bd242c1b..73a6a8a4f 100644 --- a/Software/Visual_Studio/Tango.Integration/Observables/Partials/MachineVersion.cs +++ b/Software/Visual_Studio/Tango.Integration/Observables/Partials/MachineVersion.cs @@ -8,10 +8,10 @@ namespace Tango.Integration.Observables { public partial class MachineVersion { - public override void Delete(ObservablesContext context = null) + public override void Delete(ObservablesContext context) { - this.DefaultConfiguration.Delete(); - base.Delete(); + this.DefaultConfiguration.Delete(context); + base.Delete(context); } } } diff --git a/Software/Visual_Studio/Tango.Integration/Observables/Partials/Segment.cs b/Software/Visual_Studio/Tango.Integration/Observables/Partials/Segment.cs index 71a15b90c..eda1613ed 100644 --- a/Software/Visual_Studio/Tango.Integration/Observables/Partials/Segment.cs +++ b/Software/Visual_Studio/Tango.Integration/Observables/Partials/Segment.cs @@ -10,7 +10,7 @@ namespace Tango.Integration.Observables { public partial class Segment { - public override void Save(ObservablesContext context = null) + public override void Save(ObservablesContext context) { for (int i = 0; i < BrushStops.Count; i++) { diff --git a/Software/Visual_Studio/Tango.Integration/Printing/Job.cs b/Software/Visual_Studio/Tango.Integration/Printing/Job.cs index 29155be53..b80af84b8 100644 --- a/Software/Visual_Studio/Tango.Integration/Printing/Job.cs +++ b/Software/Visual_Studio/Tango.Integration/Printing/Job.cs @@ -120,7 +120,7 @@ namespace Tango.Integration.Observables /// /// Saves the changes on this entity to database. /// - public override void Save(ObservablesContext context = null) + public override void Save(ObservablesContext context) { for (int i = 0; i < Segments.Count; i++) { @@ -146,7 +146,7 @@ namespace Tango.Integration.Observables return cloned; } - public override void DefferedDelete(ObservablesContext context = null) + public override void DefferedDelete(ObservablesContext context) { Segments.ToList().ForEach(x => x.DefferedDelete(context)); Segments.Clear(); diff --git a/Software/Visual_Studio/Tango.Integration/Printing/Segment.cs b/Software/Visual_Studio/Tango.Integration/Printing/Segment.cs index d3e50ec37..999ef247b 100644 --- a/Software/Visual_Studio/Tango.Integration/Printing/Segment.cs +++ b/Software/Visual_Studio/Tango.Integration/Printing/Segment.cs @@ -68,7 +68,7 @@ namespace Tango.Integration.Observables return cloned; } - public override void DefferedDelete(ObservablesContext context = null) + public override void DefferedDelete(ObservablesContext context) { BrushStops.ToList().ForEach(x => x.DefferedDelete(context)); BrushStops.Clear(); diff --git a/Software/Visual_Studio/Tango.SharedUI/Controls/MultiSelectDataGrid.cs b/Software/Visual_Studio/Tango.SharedUI/Controls/MultiSelectDataGrid.cs index 0f3032e01..8f54a2ce4 100644 --- a/Software/Visual_Studio/Tango.SharedUI/Controls/MultiSelectDataGrid.cs +++ b/Software/Visual_Studio/Tango.SharedUI/Controls/MultiSelectDataGrid.cs @@ -26,11 +26,14 @@ namespace Tango.SharedUI.Controls { base.OnSelectionChanged(e); - SelectedItemsList.Clear(); - - foreach (var item in SelectedItems) + if (SelectedItemsList != null) { - SelectedItemsList.Add(item); + SelectedItemsList.Clear(); + + foreach (var item in SelectedItems) + { + SelectedItemsList.Add(item); + } } } } diff --git a/Software/Visual_Studio/Tango.SharedUI/Converters/DateTimeUTCToShortDateTimeConverter.cs b/Software/Visual_Studio/Tango.SharedUI/Converters/DateTimeUTCToShortDateTimeConverter.cs index 7c51139e0..5e02ec718 100644 --- a/Software/Visual_Studio/Tango.SharedUI/Converters/DateTimeUTCToShortDateTimeConverter.cs +++ b/Software/Visual_Studio/Tango.SharedUI/Converters/DateTimeUTCToShortDateTimeConverter.cs @@ -12,9 +12,16 @@ namespace Tango.SharedUI.Converters { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - DateTime date = (DateTime)value; + if (value != null) + { + DateTime date = (DateTime)value; - return date.ToLocalTime().ToString("MM/dd/yy HH:mm"); + return date.ToLocalTime().ToString("MM/dd/yy HH:mm"); + } + else + { + return null; + } } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) diff --git a/Software/Visual_Studio/Tango.UnitTesting/ColorLib_TST.cs b/Software/Visual_Studio/Tango.UnitTesting/ColorLib_TST.cs index f4940cdac..af875547f 100644 --- a/Software/Visual_Studio/Tango.UnitTesting/ColorLib_TST.cs +++ b/Software/Visual_Studio/Tango.UnitTesting/ColorLib_TST.cs @@ -53,7 +53,7 @@ namespace Tango.UnitTesting Assert.IsNotNull(rml); - List factors = configuration.IdsPacks.OrderBy(x => x.PackIndex).Select(x => x.LiquidType).SelectMany(x => x.LiquidTypesRmls).Where(x => x.Rml.Guid == RML.Guid).ToList(); + List factors = configuration.IdsPacks.OrderBy(x => x.PackIndex).Select(x => x.LiquidType).SelectMany(x => x.LiquidTypesRmls).Where(x => x.Rml.Guid == rml.Guid).ToList(); foreach (var idsPack in configuration.IdsPacks.OrderBy(x => x.PackIndex)) { @@ -109,7 +109,7 @@ namespace Tango.UnitTesting Assert.IsNotNull(rml); - List factors = configuration.IdsPacks.OrderBy(x => x.PackIndex).Select(x => x.LiquidType).SelectMany(x => x.LiquidTypesRmls).Where(x => x.Rml.Guid == RML.Guid).ToList(); + List factors = configuration.IdsPacks.OrderBy(x => x.PackIndex).Select(x => x.LiquidType).SelectMany(x => x.LiquidTypesRmls).Where(x => x.Rml.Guid == rml.Guid).ToList(); foreach (var idsPack in configuration.IdsPacks.OrderBy(x => x.PackIndex)) { -- cgit v1.3.1 From 1a573aaa346ec4b8bd58a0e35ab9df571a09b855 Mon Sep 17 00:00:00 2001 From: Roy Date: Tue, 20 Feb 2018 00:03:51 +0200 Subject: Added logs to developer module! --- Software/DB/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/Tango_log.ldf | Bin 8388608 -> 8388608 bytes .../Controls/IOMonitorControl.xaml | 115 ----- .../Controls/IOMonitorControl.xaml.cs | 109 ---- .../Navigation/DeveloperNavigationManager.cs | 2 + .../Tango.MachineStudio.Developer.csproj | 15 +- .../ViewModels/IOVM.cs | 47 -- .../ViewModels/MainViewVM.cs | 569 +++++++++++++-------- .../TechnicianDbContext.cs | 28 + .../Tango.Integration/Printing/Job.cs | 18 - Software/Visual_Studio/Tango.Logging/LogManager.cs | 9 + 11 files changed, 389 insertions(+), 523 deletions(-) delete mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Controls/IOMonitorControl.xaml delete mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Controls/IOMonitorControl.xaml.cs delete mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/IOVM.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechnicianDbContext.cs (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Navigation/DeveloperNavigationManager.cs') diff --git a/Software/DB/Tango.mdf b/Software/DB/Tango.mdf index ff1de2760..f943c0760 100644 Binary files a/Software/DB/Tango.mdf and b/Software/DB/Tango.mdf differ diff --git a/Software/DB/Tango_log.ldf b/Software/DB/Tango_log.ldf index 661db54aa..492b78f1b 100644 Binary files a/Software/DB/Tango_log.ldf and b/Software/DB/Tango_log.ldf differ diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Controls/IOMonitorControl.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Controls/IOMonitorControl.xaml deleted file mode 100644 index c40e69d98..000000000 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Controls/IOMonitorControl.xaml +++ /dev/null @@ -1,115 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Controls/IOMonitorControl.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Controls/IOMonitorControl.xaml.cs deleted file mode 100644 index bc408958d..000000000 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Controls/IOMonitorControl.xaml.cs +++ /dev/null @@ -1,109 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; -using Tango.Core.Commands; - -namespace Tango.MachineStudio.Developer.Controls -{ - /// - /// Interaction logic for IOMonitorControl.xaml - /// - public partial class IOMonitorControl : UserControl - { - public ICommand ForwardPressedCommand - { - get { return (ICommand)GetValue(ForwardPressedCommandProperty); } - set { SetValue(ForwardPressedCommandProperty, value); } - } - public static readonly DependencyProperty ForwardPressedCommandProperty = - DependencyProperty.Register("ForwardPressedCommand", typeof(ICommand), typeof(IOMonitorControl), new PropertyMetadata(null)); - - public ICommand ForwardReleasedCommand - { - get { return (ICommand)GetValue(ForwardReleasedCommandProperty); } - set { SetValue(ForwardReleasedCommandProperty, value); } - } - public static readonly DependencyProperty ForwardReleasedCommandProperty = - DependencyProperty.Register("ForwardReleasedCommand", typeof(ICommand), typeof(IOMonitorControl), new PropertyMetadata(null)); - - public ICommand BackwardPressedCommand - { - get { return (ICommand)GetValue(BackwardPressedCommandProperty); } - set { SetValue(BackwardPressedCommandProperty, value); } - } - public static readonly DependencyProperty BackwardPressedCommandProperty = - DependencyProperty.Register("BackwardPressedCommand", typeof(ICommand), typeof(IOMonitorControl), new PropertyMetadata(null)); - - public ICommand BackwardReleasedCommand - { - get { return (ICommand)GetValue(BackwardReleasedCommandProperty); } - set { SetValue(BackwardReleasedCommandProperty, value); } - } - public static readonly DependencyProperty BackwardReleasedCommandProperty = - DependencyProperty.Register("BackwardReleasedCommand", typeof(ICommand), typeof(IOMonitorControl), new PropertyMetadata(null)); - - public object CommandParameter - { - get { return (object)GetValue(CommandParameterProperty); } - set { SetValue(CommandParameterProperty, value); } - } - public static readonly DependencyProperty CommandParameterProperty = - DependencyProperty.Register("CommandParameter", typeof(object), typeof(IOMonitorControl), new PropertyMetadata(null)); - - public String Value - { - get { return (String)GetValue(ValueProperty); } - set { SetValue(ValueProperty, value); } - } - public static readonly DependencyProperty ValueProperty = - DependencyProperty.Register("Value", typeof(String), typeof(IOMonitorControl), new PropertyMetadata("0000")); - - public IOMonitorControl() - { - InitializeComponent(); - } - - private void OnForwardPressed(object sender, MouseButtonEventArgs e) - { - if (ForwardPressedCommand != null) - { - ForwardPressedCommand.Execute(CommandParameter); - } - } - - private void OnForwardReleased(object sender, MouseButtonEventArgs e) - { - if (ForwardReleasedCommand != null) - { - ForwardReleasedCommand.Execute(CommandParameter); - } - } - - private void OnBackwardPressed(object sender, MouseButtonEventArgs e) - { - if (BackwardPressedCommand != null) - { - BackwardPressedCommand.Execute(CommandParameter); - } - } - - private void OnBackwardReleased(object sender, MouseButtonEventArgs e) - { - if (BackwardReleasedCommand != null) - { - BackwardReleasedCommand.Execute(CommandParameter); - } - } - } -} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Navigation/DeveloperNavigationManager.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Navigation/DeveloperNavigationManager.cs index 5be50231d..03e022380 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Navigation/DeveloperNavigationManager.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Navigation/DeveloperNavigationManager.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tango.Logging; using Tango.MachineStudio.Common.Navigation; using Tango.MachineStudio.Developer.Views; @@ -12,6 +13,7 @@ namespace Tango.MachineStudio.Developer.Navigation { public void NavigateTo(DeveloperNavigationView view) { + LogManager.Log(String.Format("Navigating to view {0}...", view.ToString())); MainView.Instance.TransitionControl.AutoNavigate(view.ToString()); } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj index 91a9602be..364b8573a 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj @@ -100,9 +100,6 @@ - - IOMonitorControl.xaml - @@ -122,7 +119,6 @@ - MainView.xaml @@ -140,10 +136,6 @@ RunningJobView.xaml - - Designer - MSBuild:Compile - MSBuild:Compile Designer @@ -219,6 +211,10 @@ {4206ac58-3b57-4699-8835-90bf6db01a61} Tango.Integration + + {bc932dbd-7cdb-488c-99e4-f02cf441f55e} + Tango.Logging + {e4927038-348d-4295-aaf4-861c58cb3943} Tango.PMR @@ -314,5 +310,8 @@ + + + \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/IOVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/IOVM.cs deleted file mode 100644 index cc4170827..000000000 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/IOVM.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Tango.Core; -using Tango.Integration.Observables; - -namespace Tango.MachineStudio.Developer.ViewModels -{ - public class IOVM : ExtendedObject - { - private TechMonitor _io; - public TechMonitor IO - { - get { return _io; } - set { _io = value; RaisePropertyChangedAuto(); } - } - - private String _name; - public String Name - { - get { return _name; } - set { _name = value; } - } - - private bool _index; - public bool Index - { - get { return _index; } - set { _index = value; } - } - - private double _value; - public double Value - { - get { return _value; } - set { _value = value; RaisePropertyChanged(nameof(Value)); } - } - - public IOVM(TechMonitor io, String name) - { - IO = io; - Name = name; - } - } -} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs index 62b742390..cf66efbd6 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs @@ -1,43 +1,29 @@ using GalaSoft.MvvmLight.Ioc; -using RealTimeGraphEx.Controllers; -using RealTimeGraphEx.DataSeries; using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.ComponentModel; using System.Linq; -using System.Text; +using System.Runtime.CompilerServices; using System.Threading.Tasks; +using System.Windows.Data; using System.Windows.Media; using Tango.Core.Commands; using Tango.Integration.Observables; +using Tango.Integration.Operators; +using Tango.Integration.Services; +using Tango.Logging; +using Tango.MachineStudio.Common.Authentication; using Tango.MachineStudio.Common.Controls; +using Tango.MachineStudio.Common.Diagnostics; using Tango.MachineStudio.Common.Notifications; using Tango.MachineStudio.Common.StudioApplication; -using Tango.SharedUI; -using System.Runtime.CompilerServices; -using System.Windows.Threading; -using Tango.Settings; -using Tango.MachineStudio.Developer.Views; -using Tango.Video.DirectCapture; -using Tango.Integration.Operators; -using Tango.PMR.Diagnostics; -using System.Reflection; -using Tango.PMR.Common; -using Tango.SharedUI.Helpers; -using Tango.Transport; -using Tango.Integration.Printing; -using Tango.Integration.Diagnostics; -using Microsoft.Win32; -using Tango.MachineStudio.Technician.ViewModels; -using Tango.MachineStudio.Common.Diagnostics; using Tango.MachineStudio.Common.Video; -using Tango.Integration.Services; using Tango.MachineStudio.Developer.Navigation; -using System.Data.Entity; -using Tango.MachineStudio.Common.Authentication; -using DeepEqual.Syntax; -using System.ComponentModel; -using System.Windows.Data; +using Tango.MachineStudio.Developer.Views; +using Tango.Settings; +using Tango.SharedUI; +using Tango.Transport; namespace Tango.MachineStudio.Developer.ViewModels { @@ -53,10 +39,10 @@ namespace Tango.MachineStudio.Developer.ViewModels private TimeSpan _runningJobEstimatedDuration; private JobHandler _jobHandler; private DeveloperNavigationManager _navigation; - private ObservablesContext _dbJobContext; private bool _blockInvalidateCommands; private IAuthenticationProvider _authentication; - private ObservablesContext _machineDBContext; + private ObservablesContext _machineDbContext; + private ObservablesContext _activeJobDbContext; #region Properties @@ -91,14 +77,15 @@ namespace Tango.MachineStudio.Developer.ViewModels } private ObservableCollection _windingMethods; - + /// + /// Gets or sets the winding methods. + /// public ObservableCollection WindingMethods { get { return _windingMethods; } set { _windingMethods = value; RaisePropertyChangedAuto(); } } - /// /// Gets or sets the application manager. /// @@ -152,21 +139,6 @@ namespace Tango.MachineStudio.Developer.ViewModels { _rmlProcessParametersTablesGroup = value; RaisePropertyChangedAuto(); OnProcessParametersTableGroupChanged(); } } - public void OnDropSegment(Segment dragged, Segment dropped) - { - dragged.SegmentIndex = dropped.SegmentIndex; - dropped.SegmentIndex++; - - int index = 1; - - foreach (var segment in ActiveJob.Segments.OrderBy(x => x.SegmentIndex)) - { - segment.SegmentIndex = index++; - } - - SegmentsCollectionView.Refresh(); - } - private ObservableCollection _groupsHistory; /// /// Gets or sets the RML process parameters groups history. @@ -465,7 +437,9 @@ namespace Tango.MachineStudio.Developer.ViewModels } private String _jobFilter; - + /// + /// Gets or sets the job filter. + /// public String JobFilter { get { return _jobFilter; } @@ -598,15 +572,18 @@ namespace Tango.MachineStudio.Developer.ViewModels { SelectedJobs = new ObservableCollection(); - _machineDBContext = ObservablesContext.CreateDefault(); + LogManager.Log("Initializing machine Db context..."); + _machineDbContext = ObservablesContext.CreateDefault(); if (SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedMachineGuid != null) { - SelectedMachine = _machineDBContext.Machines.SingleOrDefault(x => x.Guid == SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedMachineGuid); + LogManager.Log("Setting last selected machine from settings..."); + SelectedMachine = _machineDbContext.Machines.SingleOrDefault(x => x.Guid == SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedMachineGuid); } if (SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedJobGuid != null && SelectedMachine != null) { + LogManager.Log("Setting last selected job from settings..."); SelectedMachineJob = SelectedMachine.Jobs.SingleOrDefault(x => x.Guid == SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedJobGuid); } @@ -618,6 +595,8 @@ namespace Tango.MachineStudio.Developer.ViewModels ApplicationManager = applicationManager; VideoCaptureProvider = videoCaptureProvider; + LogManager.Log("Initializing relay commands..."); + //Initialize Commands... EditMachineCommand = new RelayCommand(EditMachine, () => SelectedMachine != null); EditRMLCommand = new RelayCommand(EditRML, () => SelectedRML != null); @@ -630,12 +609,12 @@ namespace Tango.MachineStudio.Developer.ViewModels RemoveJobCommand = new RelayCommand(RemoveSelectedJobs, () => SelectedMachineJob != null); AddBrushStopCommand = new RelayCommand(AddBrushStop, () => SelectedSegment != null); RemoveBrushStopCommand = new RelayCommand(RemoveSelectedBrushStops, () => SelectedBrushStop != null); - SaveJobCommand = new RelayCommand(SaveJob, () => SelectedMachine != null); - DiscardJobCommand = new RelayCommand(DiscardJob, () => SelectedMachine != null); + SaveJobCommand = new RelayCommand(SaveActiveJob, () => SelectedMachine != null); + DiscardJobCommand = new RelayCommand(BackToJobs, () => SelectedMachine != null); StartJobCommand = new RelayCommand(StartJob, () => ActiveJob != null && !IsJobRunning); StopJobCommand = new RelayCommand(StopJob, () => IsJobRunning); CloseJobCompletionStatusCommand = new RelayCommand(CloseJobCompletionStatusBar); - LoadJobCommand = new RelayCommand(LoadJob, () => SelectedMachineJob != null); + LoadJobCommand = new RelayCommand(LoadSelectedJob, () => SelectedMachineJob != null); DuplicateJobCommand = new RelayCommand(DuplicateSelectedJobs, () => SelectedMachineJob != null); DuplicateSegmentCommand = new RelayCommand(DuplicateSelectedSegments, () => SelectedSegment != null); DuplicateBrushStopCommand = new RelayCommand(DuplicateSelectedBrushStops, () => SelectedBrushStop != null); @@ -665,7 +644,7 @@ namespace Tango.MachineStudio.Developer.ViewModels private void SelectedMachine_Saved(object sender, EventArgs e) { InvalidateLiquidFactorsAndProcessTables(); - SelectedMachine.Reload(_machineDBContext); + SelectedMachine.Reload(_machineDbContext); } /// @@ -698,32 +677,36 @@ namespace Tango.MachineStudio.Developer.ViewModels #endregion - #region Virtual Methods + #region Properties Changes + /// + /// Called when the selected parameters table has changed. + /// protected virtual void OnSelectedParametersTableChanged() { if (SelectedProcessParametersTable != null) { + LogManager.Log("Selected process parameters table changed."); SelectedProcessParametersTable.DyeingSpeedMinInkUptakeChanged -= SelectedProcessParametersTable_DyeingSpeedMinInkUptakeChanged; SelectedProcessParametersTable.DyeingSpeedMinInkUptakeChanged += SelectedProcessParametersTable_DyeingSpeedMinInkUptakeChanged; - } - - SetSegmentBrushStopsLiquidVolumes(SelectedSegment); - UpdateEstimatedDuration(); + SetSegmentBrushStopsLiquidVolumes(SelectedSegment); + UpdateEstimatedDuration(); + } } /// /// Called when the process parameters table group has been changed /// - private void OnProcessParametersTableGroupChanged() + protected virtual void OnProcessParametersTableGroupChanged() { if (RmlProcessParametersTableGroup != null && RmlProcessParametersTableGroup.ProcessParametersTables.Count > 0) { - SelectedProcessParametersTable = RmlProcessParametersTableGroup.ProcessParametersTables.First(); - } + LogManager.Log("Process parameters group changed..."); + SelectedProcessParametersTable = RmlProcessParametersTableGroup.ProcessParametersTables.OrderBy(x => x.TableIndex).FirstOrDefault(); - UpdateEstimatedDuration(); + UpdateEstimatedDuration(); + } } /// @@ -733,6 +716,7 @@ namespace Tango.MachineStudio.Developer.ViewModels { if (SelectedSegment != null) { + LogManager.Log("Selected segment changed..."); SetSegmentBrushStopsLiquidVolumes(SelectedSegment); SelectedBrushStop = SelectedSegment.BrushStops.FirstOrDefault(); @@ -748,6 +732,7 @@ namespace Tango.MachineStudio.Developer.ViewModels { if (SelectedGroupHistory != null) { + LogManager.Log(String.Format("Parameters group {0} selected from history.", SelectedGroupHistory.Name)); RmlProcessParametersTableGroup = SelectedGroupHistory.CloneGroup(); } } @@ -759,137 +744,96 @@ namespace Tango.MachineStudio.Developer.ViewModels { if (SelectedMachine != null) { + LogManager.Log(String.Format("Machine {0} changed.", SelectedMachine.SerialNumber)); ReloadMachine(); JobsCollectionView = CollectionViewSource.GetDefaultView(SelectedMachine.Jobs); JobsCollectionView.SortDescriptions.Add(new SortDescription(nameof(Job.LastUpdated), ListSortDirection.Descending)); } } - private void ReloadMachine() + /// + /// Called when the job filtering has changed. + /// + protected virtual void OnJobFilterChanged() { - _machineDBContext.Dispose(); - _machineDBContext = ObservablesContext.CreateDefault(); - _machineDBContext.Configuration.LazyLoadingEnabled = true; - Machines = _machineDBContext.Machines.ToObservableCollection(); - _selectedMachine = Machines.SingleOrDefault(x => x.Guid == _selectedMachine.Guid); - RaisePropertyChanged(nameof(SelectedMachine)); - - JobsCollectionView = CollectionViewSource.GetDefaultView(SelectedMachine.Jobs); - JobsCollectionView.SortDescriptions.Add(new SortDescription(nameof(Job.LastUpdated), ListSortDirection.Descending)); - } - - #endregion - - #region Private Methods + String filter = JobFilter.ToLower(); - private void OnJobFilterChanged() - { JobsCollectionView.Filter = (job) => { Job j = job as Job; - return String.IsNullOrWhiteSpace(JobFilter) + return String.IsNullOrWhiteSpace(filter) + || + j.Name.ToLower().Contains(filter) //Job name + || + j.User.Contact.FirstName.ToLower().Contains(filter) // User first name || - j.Name.ToLower().Contains(JobFilter.ToLower()); + j.Length.ToString().Contains(filter); //Job length }; } - private void OnActiveJobChanged() + /// + /// Called when the active job has changed. + /// + protected virtual void OnActiveJobChanged() { if (ActiveJob != null) { + LogManager.Log(String.Format("Active job {0} changed.", ActiveJob.Name)); SegmentsCollectionView = CollectionViewSource.GetDefaultView(ActiveJob.Segments); SegmentsCollectionView.SortDescriptions.Add(new SortDescription(nameof(Segment.SegmentIndex), ListSortDirection.Ascending)); } } - private void LoadJob() - { - if (SelectedMachineJob != null) - { - SelectedSegments = new ObservableCollection(); - SelectedBrushStops = new ObservableCollection(); - SelectedRML = null; - SelectedSegment = null; - SelectedGroupHistory = null; - SelectedBrushStop = null; - SelectedProcessParametersTable = null; - RmlProcessParametersTableGroup = null; - - using (_notification.PushTaskItem("Loading job details...")) - { - //await Task.Factory.StartNew(() => - //{ - _blockInvalidateCommands = false; - - _dbJobContext = ObservablesContext.CreateDefault(); - _dbJobContext.Configuration.LazyLoadingEnabled = true; - - ColorSpaces = _dbJobContext.ColorSpaces.ToObservableCollection(); - Rmls = _dbJobContext.Rmls.ToObservableCollection(); - WindingMethods = _dbJobContext.WindingMethods.ToObservableCollection(); - - _activeJob = _dbJobContext.Jobs.SingleOrDefault(x => x.Guid == SelectedMachineJob.Guid); - - _selectedRML = ActiveJob.Rml; - - _selectedSegment = ActiveJob.Segments.FirstOrDefault(); - - ActiveJob.LengthChanged -= ActiveJob_LengthChanged; - ActiveJob.LengthChanged += ActiveJob_LengthChanged; + #endregion - ActiveJob = _activeJob; + #region Drag & Drop - SelectedRML = _selectedRML; - SelectedSegment = _selectedSegment; + /// + /// Switch the segment position in the job. + /// + /// The dragged. + /// The dropped. + public void OnDropSegment(Segment dragged, Segment dropped) + { + LogManager.Log(String.Format("Segment {0} Dropped on segment {1}", dragged.SegmentIndex, dropped.SegmentIndex)); - UpdateEstimatedDuration(); + dragged.SegmentIndex = dropped.SegmentIndex; + dropped.SegmentIndex++; - _blockInvalidateCommands = false; - InvalidateRelayCommands(); + int index = 1; - InvokeUI(() => _navigation.NavigateTo(DeveloperNavigationView.JobView)); - //}); - } + foreach (var segment in ActiveJob.Segments.OrderBy(x => x.SegmentIndex)) + { + segment.SegmentIndex = index++; } + + SegmentsCollectionView.Refresh(); } - private async void SaveJob() + /// + /// Switch the brush stop position in the segment. + /// + /// The dragged stop. + /// The dropped stop. + public void OnDropBrushStop(BrushStop dragged, BrushStop dropped) { - if (ActiveJob != null) - { - using (_notification.PushTaskItem("Saving job to database...")) - { - ActiveJob.LastUpdated = DateTime.UtcNow; - ActiveJob.Rml = SelectedRML; + LogManager.Log(String.Format("BrushStop {0} Dropped on BrushStop {1}", dragged.StopIndex, dropped.StopIndex)); - await ActiveJob.SaveAsync(_dbJobContext); - ReloadMachine(); - SelectedMachineJob = SelectedMachine.Jobs.SingleOrDefault(x => x.Guid == ActiveJob.Guid); - } - } + dragged.SetStopIndex(dropped.StopIndex); + dropped.SetStopIndex(dropped.StopIndex + 1); + ArrangeBrushStopsIndices(); } - private void DiscardJob() - { - bool jobModified = !ActiveJob.CompareUsingJson(SelectedMachineJob); + #endregion - if (jobModified) - { - if (_notification.ShowQuestion("This will discard the current job changes. Are you sure?")) - { - _dbJobContext.Dispose(); - _navigation.NavigateTo(DeveloperNavigationView.MachineJobSelectionView); - } - } - else - { - _dbJobContext.Dispose(); - _navigation.NavigateTo(DeveloperNavigationView.MachineJobSelectionView); - } - } + #region Running Job Management + /// + /// Closes the job completion status bar. + /// private void CloseJobCompletionStatusBar() { + LogManager.Log("Closing job completion status bar..."); _navigation.NavigateTo(DeveloperNavigationView.JobView); IsJobCompleted = false; IsJobFailed = false; @@ -898,27 +842,43 @@ namespace Tango.MachineStudio.Developer.ViewModels RunningJob = null; } + /// + /// Stops the job. + /// private void StopJob() { + LogManager.Log("Stopping job..."); IsJobRunning = false; IsJobCanceled = true; _jobHandler.Cancel(); } - private void FailJob() + /// + /// Fails the job. + /// + private void SetJobFailed() { + LogManager.Log("Setting job failed state..."); IsJobRunning = false; IsJobFailed = true; } - private void CompleteJob() + /// + /// Completes the job. + /// + private void SetJobCompleted() { + LogManager.Log("Setting job completed state..."); IsJobRunning = false; IsJobCompleted = true; } + /// + /// Starts the job. + /// private void StartJob() { + LogManager.Log(String.Format("Starting job {0}...", ActiveJob.Name)); if (MachineOperator == null || MachineOperator.State != TransportComponentState.Connected) { _notification.ShowError("No machine connected. Could not execute the specified job."); @@ -945,6 +905,7 @@ namespace Tango.MachineStudio.Developer.ViewModels _navigation.NavigateTo(DeveloperNavigationView.RunningJobView); + LogManager.Log("Sending job to machine operator..."); _jobHandler = MachineOperator.Print(ActiveJob, SelectedProcessParametersTable); _jobHandler.StatusReceived += (x, status) => @@ -976,7 +937,8 @@ namespace Tango.MachineStudio.Developer.ViewModels _jobHandler.Failed += (x, ex) => { - FailJob(); + LogManager.Log(ex, String.Format("Job {0} has failed.", RunningJob.Name)); + SetJobFailed(); InvokeUI(() => { @@ -986,34 +948,58 @@ namespace Tango.MachineStudio.Developer.ViewModels _jobHandler.Completed += (x, e) => { - CompleteJob(); + LogManager.Log(String.Format("Job {0} has completed.", RunningJob.Name)); + SetJobCompleted(); }; _jobHandler.Canceled += (x, y) => { + LogManager.Log(String.Format("Job {0} has been canceled.", RunningJob.Name)); //Finally Canceled.. }; } - private void UpdateEstimatedDuration() + /// + /// Creates the running job effective segments. + /// + /// The job. + /// + private List CreateRunningJobEffectiveSegments(Job job) { - if (ActiveJob != null && SelectedProcessParametersTable != null && SelectedProcessParametersTable.DyeingSpeed > 0) - { - EstimatedDuration = TimeSpan.FromSeconds(ActiveJob.Length / (SelectedProcessParametersTable.DyeingSpeed / 100d)); - } - } + LogManager.Log("Creating job effective segments..."); - private void SetSegmentBrushStopsLiquidVolumes(Segment segment) - { - if (!DesignMode && segment != null) + List segments = new List(); + foreach (var s in job.Segments) { - foreach (var stop in segment.BrushStops) + s.Completed = false; + s.Started = false; + segments.Add(s); + + if (job.EnableInterSegment && job.Segments.IndexOf(s) != job.Segments.Count - 1) { - stop.SetLiquidVolumes(SelectedMachine.Configuration, SelectedRML, SelectedProcessParametersTable); + segments.Add(new Segment() + { + Length = job.InterSegmentLength, + BrushStops = new System.Collections.ObjectModel.ObservableCollection() + { + new BrushStop() + { + Color = Colors.White, + } + }, + Started = false, + Completed = false + }); } } + + return segments; } + #endregion + + #region RML + /// /// Saves the liquid factors. /// @@ -1023,7 +1009,8 @@ namespace Tango.MachineStudio.Developer.ViewModels { using (_notification.PushTaskItem("Saving Liquid Factors...")) { - await SelectedRML.SaveAsync(_dbJobContext); + LogManager.Log(String.Format("Saving liquid factors for RML {0}...", SelectedRML.Name)); + await SelectedRML.SaveAsync(_activeJobDbContext); InvalidateLiquidFactorsAndProcessTables(); } } @@ -1034,17 +1021,10 @@ namespace Tango.MachineStudio.Developer.ViewModels /// private void EditRML() { + LogManager.Log(String.Format("Requesting DB module for RML {0} editing...", SelectedRML.Name)); ApplicationManager.RequestModule("Data Base", SelectedRML); } - /// - /// Navigates to the Machine Designer Module in order to edit the selected machine. - /// - private void EditMachine() - { - ApplicationManager.RequestModule("Machine Designer", SelectedMachine); - } - /// /// Saves the process parameters group. /// @@ -1056,6 +1036,7 @@ namespace Tango.MachineStudio.Developer.ViewModels using (_notification.PushTaskItem("Saving Parameters Group...")) { + LogManager.Log(String.Format("Saving process parameters group under the name {0}...", response)); ProcessParametersTablesGroup group = new ProcessParametersTablesGroup(); List tables = new List(); @@ -1078,7 +1059,7 @@ namespace Tango.MachineStudio.Developer.ViewModels } SelectedRML.ProcessParametersTablesGroups.Add(group); - await SelectedRML.SaveAsync(_dbJobContext); + await SelectedRML.SaveAsync(_activeJobDbContext); InvalidateLiquidFactorsAndProcessTables(); } @@ -1091,10 +1072,11 @@ namespace Tango.MachineStudio.Developer.ViewModels { if (SelectedRML != null && SelectedMachine != null) { + LogManager.Log("Invalidating liquid factors, process parameters and process group history..."); LiquidTypesRmls = SelectedMachine.Configuration.IdsPacks.OrderBy(x => x.PackIndex).Select(x => x.LiquidType).SelectMany(x => x.LiquidTypesRmls).Where(x => x.Rml.Guid == SelectedRML.Guid).ToList(); RmlProcessParametersTableGroup = SelectedRML.ProcessParametersTablesGroups.ToList().SingleOrDefault(x => x.Active); - _selectedGroupHistory = RmlProcessParametersTableGroup; + var selectedHistory = RmlProcessParametersTableGroup; if (RmlProcessParametersTableGroup != null) { @@ -1104,44 +1086,173 @@ namespace Tango.MachineStudio.Developer.ViewModels GroupsHistory = SelectedRML.ProcessParametersTablesGroups.OrderByDescending(x => x.SaveDate).OrderBy(x => !x.Active).ToObservableCollection(); + _selectedGroupHistory = selectedHistory; + RaisePropertyChangedAuto(nameof(SelectedGroupHistory)); } } - private List CreateRunningJobEffectiveSegments(Job job) + #endregion + + #region Active Job Management + + /// + /// Loads the selected job. + /// + private void LoadSelectedJob() { - List segments = new List(); - foreach (var s in job.Segments) + if (SelectedMachineJob != null) { - s.Completed = false; - s.Started = false; - segments.Add(s); + using (_notification.PushTaskItem("Loading job details...")) + { + LogManager.Log(String.Format("Loading job {0}...", SelectedMachineJob.Name)); + SelectedSegments = new ObservableCollection(); + SelectedBrushStops = new ObservableCollection(); + SelectedRML = null; + SelectedSegment = null; + SelectedGroupHistory = null; + SelectedBrushStop = null; + SelectedProcessParametersTable = null; + RmlProcessParametersTableGroup = null; - if (job.EnableInterSegment && job.Segments.IndexOf(s) != job.Segments.Count - 1) + + _blockInvalidateCommands = false; + + LogManager.Log("Creating active job DB context..."); + _activeJobDbContext = ObservablesContext.CreateDefault(); + _activeJobDbContext.Configuration.LazyLoadingEnabled = true; + + LogManager.Log("Initializing available color spaces, RMLs & Winding methods..."); + ColorSpaces = _activeJobDbContext.ColorSpaces.ToObservableCollection(); + Rmls = _activeJobDbContext.Rmls.ToObservableCollection(); + WindingMethods = _activeJobDbContext.WindingMethods.ToObservableCollection(); + + LogManager.Log("Setting active job..."); + _activeJob = _activeJobDbContext.Jobs.SingleOrDefault(x => x.Guid == SelectedMachineJob.Guid); + + _selectedRML = ActiveJob.Rml; + + LogManager.Log("Setting selected segment..."); + _selectedSegment = ActiveJob.Segments.FirstOrDefault(); + + ActiveJob.LengthChanged -= ActiveJob_LengthChanged; + ActiveJob.LengthChanged += ActiveJob_LengthChanged; + + ActiveJob = _activeJob; + + SelectedRML = _selectedRML; + SelectedSegment = _selectedSegment; + + UpdateEstimatedDuration(); + + _blockInvalidateCommands = false; + InvalidateRelayCommands(); + + _navigation.NavigateTo(DeveloperNavigationView.JobView); + } + } + } + + /// + /// Saves the active job. + /// + private async void SaveActiveJob() + { + if (ActiveJob != null) + { + using (_notification.PushTaskItem("Saving job details...")) { - segments.Add(new Segment() - { - Length = job.InterSegmentLength, - BrushStops = new System.Collections.ObjectModel.ObservableCollection() - { - new BrushStop() - { - Color = Colors.White, - } - }, - Started = false, - Completed = false - }); + LogManager.Log(String.Format("Saving the active job {0}...", ActiveJob.Name)); + ActiveJob.LastUpdated = DateTime.UtcNow; + ActiveJob.Rml = SelectedRML; + + await ActiveJob.SaveAsync(_activeJobDbContext); + ReloadMachine(); + SelectedMachineJob = SelectedMachine.Jobs.SingleOrDefault(x => x.Guid == ActiveJob.Guid); } } + } - return segments; + private void BackToJobs() + { + LogManager.Log("User request for 'back to jobs'..."); + LogManager.Log("Comparing active job with selected job..."); + + bool jobModified = !ActiveJob.CompareUsingJson(SelectedMachineJob); + + if (jobModified) + { + LogManager.Log("Selected job has been modified. Invoking confirmation dialog..."); + if (_notification.ShowQuestion("This will discard the current job changes. Are you sure?")) + { + LogManager.Log("Disposing active job db context..."); + _activeJobDbContext.Dispose(); + _navigation.NavigateTo(DeveloperNavigationView.MachineJobSelectionView); + } + } + else + { + LogManager.Log("Disposing active job db context..."); + _activeJobDbContext.Dispose(); + _navigation.NavigateTo(DeveloperNavigationView.MachineJobSelectionView); + } + } + + #endregion + + #region Private Methods + + private void ReloadMachine() + { + LogManager.Log("Reloading selected machine..."); + _machineDbContext.Dispose(); + _machineDbContext = ObservablesContext.CreateDefault(); + _machineDbContext.Configuration.LazyLoadingEnabled = true; + String machineGuid = _selectedMachine.Guid; + Machines = _machineDbContext.Machines.ToObservableCollection(); + _selectedMachine = Machines.SingleOrDefault(x => x.Guid == machineGuid); + RaisePropertyChanged(nameof(SelectedMachine)); + + JobsCollectionView = CollectionViewSource.GetDefaultView(SelectedMachine.Jobs); + JobsCollectionView.SortDescriptions.Add(new SortDescription(nameof(Job.LastUpdated), ListSortDirection.Descending)); + } + + private void UpdateEstimatedDuration() + { + if (ActiveJob != null && SelectedProcessParametersTable != null && SelectedProcessParametersTable.DyeingSpeed > 0) + { + EstimatedDuration = TimeSpan.FromSeconds(ActiveJob.Length / (SelectedProcessParametersTable.DyeingSpeed / 100d)); + } + } + + private void SetSegmentBrushStopsLiquidVolumes(Segment segment) + { + if (!DesignMode && segment != null) + { + LogManager.Log("Setting segment brush stops liquid volumes..."); + foreach (var stop in segment.BrushStops) + { + stop.SetLiquidVolumes(SelectedMachine.Configuration, SelectedRML, SelectedProcessParametersTable); + } + } + } + + /// + /// Navigates to the Machine Designer Module in order to edit the selected machine. + /// + private void EditMachine() + { + LogManager.Log(String.Format("Requesting machine designer module for machine {0} editing...", SelectedMachine.SerialNumber)); + ApplicationManager.RequestModule("Machine Designer", SelectedMachine); } #endregion #region Add / Remove / Duplicate Jobs, Segments & Brush Stops + /// + /// Arranges the segments indices. + /// private void ArrangeSegmentsIndices() { int index = 1; @@ -1154,6 +1265,9 @@ namespace Tango.MachineStudio.Developer.ViewModels SegmentsCollectionView.Refresh(); } + /// + /// Arranges the brush stops indices. + /// private void ArrangeBrushStopsIndices() { int index = 0; @@ -1187,10 +1301,12 @@ namespace Tango.MachineStudio.Developer.ViewModels { if (_notification.ShowQuestion("Are you sure you want to delete the selected segments?")) { + LogManager.Log(String.Format("Removing {0} segments...", SelectedSegments.Count)); + SelectedSegments.ToList().ForEach(x => { ActiveJob.Segments.Remove(x); - x.DefferedDelete(_dbJobContext); + x.DefferedDelete(_activeJobDbContext); }); ArrangeSegmentsIndices(); @@ -1205,6 +1321,7 @@ namespace Tango.MachineStudio.Developer.ViewModels { if (ActiveJob != null) { + LogManager.LogFormat("Adding new segment to job {0}...", ActiveJob.Name); Segment seg = new Segment(); seg.Name = "Untitled Segment"; seg.Length = 10; @@ -1233,15 +1350,17 @@ namespace Tango.MachineStudio.Developer.ViewModels { if (_notification.ShowQuestion("Are you sure you want to delete the selected jobs?")) { + LogManager.Log(String.Format("Removing {0} jobs...", SelectedJobs.Count)); SelectedJobs.ToList().ForEach(x => { SelectedMachine.Jobs.Remove(x); - x.DefferedDelete(_machineDBContext); + x.DefferedDelete(_machineDbContext); }); using (_notification.PushTaskItem("Removing selected jobs...")) { - await SelectedMachine.SaveAsync(_machineDBContext); + LogManager.Log("Saving selected machine to database..."); + await SelectedMachine.SaveAsync(_machineDbContext); } } } @@ -1258,18 +1377,21 @@ namespace Tango.MachineStudio.Developer.ViewModels if (!String.IsNullOrWhiteSpace(jobName)) { + LogManager.Log(String.Format("Adding new job {0}...", jobName)); + Job newJob = new Job(); newJob.Name = jobName; newJob.CreationDate = DateTime.UtcNow; newJob.User = _authentication.CurrentUser; - newJob.Rml = _machineDBContext.Rmls.FirstOrDefault(); - newJob.WindingMethod = _machineDBContext.WindingMethods.FirstOrDefault(); + newJob.Rml = _machineDbContext.Rmls.FirstOrDefault(); + newJob.WindingMethod = _machineDbContext.WindingMethods.FirstOrDefault(); newJob.Machine = SelectedMachine; SelectedMachine.Jobs.Add(newJob); - await SelectedMachine.SaveAsync(_machineDBContext); + LogManager.Log("Saving selected machine to database..."); + await SelectedMachine.SaveAsync(_machineDbContext); SelectedMachineJob = newJob; - LoadJob(); + LoadSelectedJob(); AddSegment(); } } @@ -1284,10 +1406,12 @@ namespace Tango.MachineStudio.Developer.ViewModels { if (_notification.ShowQuestion("Are you sure you want to delete the selected colors?")) { + LogManager.Log(String.Format("Removing {0} brush stops...", SelectedBrushStops.Count)); + SelectedBrushStops.ToList().ForEach(x => { SelectedSegment.BrushStops.Remove(x); - x.DefferedDelete(_dbJobContext); + x.DefferedDelete(_activeJobDbContext); }); ArrangeBrushStopsIndices(); @@ -1302,6 +1426,8 @@ namespace Tango.MachineStudio.Developer.ViewModels { if (SelectedSegment != null) { + LogManager.LogFormat("Adding new brush stop to segment...", SelectedSegment.SegmentIndex.ToString()); + var stop = new BrushStop(); if (SelectedSegment.BrushStops.Count > 0) @@ -1315,7 +1441,7 @@ namespace Tango.MachineStudio.Developer.ViewModels stop.OffsetPercent = 100; stop.Segment = SelectedSegment; - stop.ColorSpace = _dbJobContext.ColorSpaces.FirstOrDefault(); + stop.ColorSpace = _activeJobDbContext.ColorSpaces.FirstOrDefault(); stop.Color = Colors.Black; stop.SetLiquidVolumes(SelectedMachine.Configuration, SelectedRML, SelectedProcessParametersTable); SelectedSegment.BrushStops.Add(stop); @@ -1329,6 +1455,8 @@ namespace Tango.MachineStudio.Developer.ViewModels /// private void DuplicateSelectedBrushStops() { + LogManager.LogFormat("Duplicating {0} brush stops...", SelectedBrushStops.Count); + foreach (var stop in SelectedBrushStops.OrderBy(x => x.StopIndex)) { var cloned = stop.Clone(); @@ -1344,6 +1472,8 @@ namespace Tango.MachineStudio.Developer.ViewModels /// private void DuplicateSelectedSegments() { + LogManager.LogFormat("Duplicating {0} segments...", SelectedSegments.Count); + foreach (var segment in SelectedSegments.OrderBy(x => x.SegmentIndex)) { var cloned = segment.Clone(); @@ -1363,6 +1493,8 @@ namespace Tango.MachineStudio.Developer.ViewModels { using (_notification.PushTaskItem("Cloning selected jobs...")) { + LogManager.LogFormat("Duplicating {0} jobs...", SelectedJobs.Count); + int index = SelectedMachine.Jobs.Max(x => x.JobIndex); foreach (var job in SelectedJobs) @@ -1372,7 +1504,8 @@ namespace Tango.MachineStudio.Developer.ViewModels SelectedMachine.Jobs.Add(cloned); } - await SelectedMachine.SaveAsync(_machineDBContext); + LogManager.Log("Saving selected machine to database..."); + await SelectedMachine.SaveAsync(_machineDbContext); } } } @@ -1393,22 +1526,6 @@ namespace Tango.MachineStudio.Developer.ViewModels #endregion - #region Public Methods - - /// - /// Switch the brush stop position in the segment. - /// - /// The dragged stop. - /// The dropped stop. - public void OnDropBrushStop(BrushStop draggedStop, BrushStop droppedStop) - { - draggedStop.SetStopIndex(droppedStop.StopIndex); - droppedStop.SetStopIndex(droppedStop.StopIndex + 1); - ArrangeBrushStopsIndices(); - } - - #endregion - #region IShutdownRequestBlocker public Task OnShutdownRequest() diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechnicianDbContext.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechnicianDbContext.cs new file mode 100644 index 000000000..a0314ab6b --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechnicianDbContext.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Integration.Observables; + +namespace Tango.MachineStudio.Technician +{ + public class TechnicianDbContext + { + private static ObservablesContext _context; + + public static ObservablesContext Context + { + get + { + if (_context == null) + { + _context = ObservablesContext.CreateDefault(); + } + + return _context; + } + private set { _context = value; } + } + } +} diff --git a/Software/Visual_Studio/Tango.Integration/Printing/Job.cs b/Software/Visual_Studio/Tango.Integration/Printing/Job.cs index b80af84b8..ea2a8cb57 100644 --- a/Software/Visual_Studio/Tango.Integration/Printing/Job.cs +++ b/Software/Visual_Studio/Tango.Integration/Printing/Job.cs @@ -117,24 +117,6 @@ namespace Tango.Integration.Observables } } - /// - /// Saves the changes on this entity to database. - /// - public override void Save(ObservablesContext context) - { - for (int i = 0; i < Segments.Count; i++) - { - Segments[i].SegmentIndex = i + 1; - - for (int j = 0; j < Segments[i].BrushStops.Count; j++) - { - Segments[i].BrushStops[j].StopIndex = j; - } - } - - base.Save(context); - } - public override Job Clone() { Job cloned = base.Clone(); diff --git a/Software/Visual_Studio/Tango.Logging/LogManager.cs b/Software/Visual_Studio/Tango.Logging/LogManager.cs index 60ccccc34..5518c520d 100644 --- a/Software/Visual_Studio/Tango.Logging/LogManager.cs +++ b/Software/Visual_Studio/Tango.Logging/LogManager.cs @@ -111,6 +111,15 @@ namespace Tango.Logging return e; } + /// + /// Add new message log item. + /// + /// Message. + public static String LogFormat(String message, object argument, [CallerMemberName] string caller = null, [CallerFilePath] string file = null, [CallerLineNumber] int lineNumber = 0) + { + return Log(String.Format(message, argument), LogCategory.General, caller, file, lineNumber); + } + /// /// Add new message log item. /// -- cgit v1.3.1