From d5c6067365e12674e95acaef4c4af45eaead8c3e Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Wed, 1 Aug 2018 10:29:09 +0300 Subject: Implemented notification for observables entities modification.. --- .../Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs') 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 a58757633..9ac78ccec 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 @@ -180,8 +180,8 @@ namespace Tango.MachineStudio.Developer.ViewModels if (_selectedMachine != null) { - _selectedMachine.Saved -= SelectedMachine_Saved; - _selectedMachine.Saved += SelectedMachine_Saved; + _selectedMachine.Modified -= SelectedMachine_Saved; + _selectedMachine.Modified += SelectedMachine_Saved; } } } -- cgit v1.3.1 From 00cfb0906e164487efed62bd6a65cdf681952bd1 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Wed, 1 Aug 2018 11:47:10 +0300 Subject: Implemented reloading of color lab module and research module when machine designer changes machine ! --- Software/DB/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/Tango_log.ldf | Bin 1835008 -> 1835008 bytes .../ViewModels/MainViewVM.cs | 22 +++- .../ViewModels/MainViewVM.cs | 27 +++- .../Views/MachineJobSelectionView.xaml | 26 ++-- .../Tango.MachineStudio.UI/App.xaml.cs | 143 +++++++++++---------- .../Tango.BL/ObservableModifiedEventArgs.cs | 8 ++ .../Tango.BL/ObservablesContextExtension.cs | 52 +++++++- 8 files changed, 190 insertions(+), 88 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs') diff --git a/Software/DB/Tango.mdf b/Software/DB/Tango.mdf index 2ce18547c..ece78a9cd 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 e76634d7b..6ec62ac2c 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.ColorLab/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ViewModels/MainViewVM.cs index 688f90817..5b317e6d2 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ViewModels/MainViewVM.cs @@ -425,6 +425,26 @@ namespace Tango.MachineStudio.ColorLab.ViewModels }).ToObservableCollection(); LiquidVolumes.ToList().ForEach(x => x.VolumeChanged += (s, e) => OnLiquidVolumeChanged()); + + InvalidateLiquidFactorsCalibrationData(); + + SelectedMachine.Modified -= SelectedMachine_Modified; + SelectedMachine.Modified += SelectedMachine_Modified; + } + } + + private void SelectedMachine_Modified(object sender, ObservableModifiedEventArgs e) + { + if (e.IsOtherContext) + { + InvokeUI(async () => + { + if (SelectedMachine != null) + { + await SelectedMachine.Reload(_dbContext); + OnSelectedMachineChanged(); + } + }); } } @@ -433,7 +453,7 @@ namespace Tango.MachineStudio.ColorLab.ViewModels try { if (LiquidsCalibrationData == null || _prevent_inverse_conversion) return; - + //TODO: This is temporary because of out of range volumes. if (LiquidVolumes.Where(x => x.IdsPack.IdsPackFormula.Code == IdsPackFormulas.StandardColor.ToInt32()).Sum(x => x.Volume) > 200) { 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 9ac78ccec..569359066 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 @@ -180,8 +180,8 @@ namespace Tango.MachineStudio.Developer.ViewModels if (_selectedMachine != null) { - _selectedMachine.Modified -= SelectedMachine_Saved; - _selectedMachine.Modified += SelectedMachine_Saved; + _selectedMachine.Modified -= SelectedMachine_Modified; + _selectedMachine.Modified += SelectedMachine_Modified; } } } @@ -627,6 +627,11 @@ namespace Tango.MachineStudio.Developer.ViewModels /// Gets or sets the display job embroidery file command. /// public RelayCommand DisplayJobEmbroideryFileCommand { get; set; } + + /// + /// Gets or sets the reload machines command. + /// + public RelayCommand ReloadMachinesCommand { get; set; } #endregion #region Constructors @@ -703,6 +708,7 @@ namespace Tango.MachineStudio.Developer.ViewModels PushProcessParametersCommand = new RelayCommand(PushProcessParameters, () => SelectedRML != null && SelectedRML.ProcessParametersTablesGroups.Count > 0 && SelectedProcessParametersTable != null && MachineOperator != null); ImportEmbroideryFileCommand = new RelayCommand(ImportEmbroideryFile, () => SelectedMachine != null); DisplayJobEmbroideryFileCommand = new RelayCommand(DisplayJobEmbroideryFile); + ReloadMachinesCommand = new RelayCommand(ReloadMachine); ApplicationManager.ConnectedMachineChanged += ApplicationManager_ConnectedMachineChanged; @@ -850,10 +856,21 @@ namespace Tango.MachineStudio.Developer.ViewModels /// /// The source of the event. /// The instance containing the event data. - private void SelectedMachine_Saved(object sender, EventArgs e) + private void SelectedMachine_Modified(object sender, ObservableModifiedEventArgs e) { - InvalidateLiquidFactorsAndProcessTables(); - SelectedMachine.Reload(_machineDbContext); + if (e.IsOtherContext) + { + InvokeUI(() => + { + SelectedMachine.Reload(_machineDbContext); + InvalidateLiquidFactorsAndProcessTables(); + + if (SelectedSegment != null) + { + OnSelectedSegmentChanged(); + } + }); + } } /// diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MachineJobSelectionView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MachineJobSelectionView.xaml index 4593ef259..c151b62bc 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MachineJobSelectionView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MachineJobSelectionView.xaml @@ -35,16 +35,22 @@ TARGET MACHINE - - - - - - - - - - + + + + + + + + + + + + + + public IObservableEntity NotifiedEntity { get; set; } + /// + /// Gets a value indicating whether the modified entity is not the notified entity. + /// + public bool IsOtherContext + { + get { return ModifiedEntity != NotifiedEntity; } + } + /// /// Initializes a new instance of the class. /// diff --git a/Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs b/Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs index 7c3ade821..e3575bfdc 100644 --- a/Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs +++ b/Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs @@ -6,6 +6,7 @@ using System.Data.SQLite; using System.IO; using System.Linq; using System.Text; +using System.Threading; using System.Threading.Tasks; using Tango.Core; using Tango.Settings; @@ -14,6 +15,8 @@ namespace Tango.BL { public partial class ObservablesContext { + private List _pending_notifications = new List(); + /// /// Initializes a new instance of the class. /// @@ -92,7 +95,48 @@ namespace Tango.BL /// public override int SaveChanges() { - return base.SaveChanges(); + var result = base.SaveChanges(); + RaisePendingNotifications(); + return result; + } + + /// + /// Asynchronously saves all changes made in this context to the underlying database. + /// + /// A to observe while waiting for the task to complete. + /// + /// A task that represents the asynchronous save operation. + /// The task result contains the number of objects written to the underlying database. + /// + /// + /// Multiple active operations on the same context instance are not supported. Use 'await' to ensure + /// that any asynchronous operations have completed before calling another method on this context. + /// + public override Task SaveChangesAsync(CancellationToken cancellationToken) + { + var result = base.SaveChangesAsync(cancellationToken); + RaisePendingNotifications(); + return result; + } + + /// + /// Raises the pending notifications. + /// + private void RaisePendingNotifications() + { + Task.Factory.StartNew(() => + { + foreach (var e in _pending_notifications.DistinctBy(x => x.NotifiedEntity)) + { + try + { + e.NotifiedEntity.RaiseModified(e.Context, e.ModifiedEntity, e.NotifiedEntity); + } + catch { } + } + + _pending_notifications.Clear(); + }); } /// @@ -109,10 +153,10 @@ namespace Tango.BL { IObservableEntity modified = entityEntry.Entity as IObservableEntity; - Parallel.ForEach(ObservableEntitiesContainer.RegisteredEntities.Where(x => x.Guid == modified.Guid), (toNotify) => + foreach (var toNotify in ObservableEntitiesContainer.RegisteredEntities.Where(x => x.Guid == modified.Guid)) { - toNotify.RaiseModified(this, modified, toNotify); - }); + _pending_notifications.Add(new ObservableModifiedEventArgs(this, modified, toNotify)); + } } return base.ShouldValidateEntity(entityEntry); -- cgit v1.3.1