From a63d5d019d26fb24ac5cf764d63da10d482d4823 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Sun, 8 Sep 2019 18:28:08 +0300 Subject: Implemented KeepAlive retries. Fixed issue with catalog recents. Fixed issue with trimmed catalog selection. --- .../Dialogs/CatalogSelectionView.xaml | 2 +- .../Modules/Tango.PPC.Jobs/JobsModuleSettings.cs | 51 ++++++++++++++++++---- .../ViewModels/TwineCatalogViewVM.cs | 42 ++++++++++++++++-- 3 files changed, 83 insertions(+), 12 deletions(-) (limited to 'Software/Visual_Studio/PPC/Modules') diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/CatalogSelectionView.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/CatalogSelectionView.xaml index e1edb66f2..ded395e08 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/CatalogSelectionView.xaml +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/CatalogSelectionView.xaml @@ -33,7 +33,7 @@ - + diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/JobsModuleSettings.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/JobsModuleSettings.cs index 3d72509e0..85278d692 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/JobsModuleSettings.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/JobsModuleSettings.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tango.BL.Entities; using Tango.BL.Enumerations; using Tango.Settings; @@ -14,15 +15,21 @@ namespace Tango.PPC.Jobs /// public class JobsModuleSettings : SettingsBase { - /// - /// Gets or sets the recent twine catalog colors. - /// - public List RecentTwineCatalogColors { get; set; } + public class RecentCatalog + { + public String Guid { get; set; } + public List RecentItems { get; set; } + + public RecentCatalog() + { + RecentItems = new List(); + } + } /// - /// Gets or sets the recent coats catalog colors. + /// Gets or sets the recent catalogs items. /// - public List RecentCoatsCatalogColors { get; set; } + public List RecentCatalogsItems { get; set; } /// /// Gets or sets the last job color space. @@ -39,13 +46,41 @@ namespace Tango.PPC.Jobs /// public String LastSelectedCatalogGuid { get; set; } + /// + /// Adds a catalog item to the recent list. + /// + /// The catalog. + /// The catalog item. + public void AddRecentCatalogItem(ColorCatalog catalog, ColorCatalogsItem item) + { + var recentCatalog = RecentCatalogsItems.FirstOrDefault(x => x.Guid == catalog.Guid); + + if (recentCatalog == null) + { + recentCatalog = new RecentCatalog(); + recentCatalog.Guid = catalog.Guid; + RecentCatalogsItems.Add(recentCatalog); + } + + if (recentCatalog.RecentItems.Exists(x => x == item.Guid)) + { + recentCatalog.RecentItems.Remove(item.Guid); + } + + recentCatalog.RecentItems.Insert(0, item.Guid); + + if (recentCatalog.RecentItems.Count > 20) + { + recentCatalog.RecentItems.RemoveAt(recentCatalog.RecentItems.Count - 1); + } + } + /// /// Initializes a new instance of the class. /// public JobsModuleSettings() { - RecentTwineCatalogColors = new List(); - RecentCoatsCatalogColors = new List(); + RecentCatalogsItems = new List(); } } } 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 d7d720434..b2e16c5eb 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 @@ -105,8 +105,12 @@ namespace Tango.PPC.Jobs.ViewModels /// private void Confirm() { - SettingsManager.Default.GetOrCreate().RecentTwineCatalogColors.Add(SelectedItem.Guid); - SettingsManager.Default.Save(); + if (SelectedItem != null) + { + var settings = SettingsManager.Default.GetOrCreate(); + settings.AddRecentCatalogItem(Catalog, SelectedItem); + SettingsManager.Default.Save(); + } _confirmed = true; NavigationManager.NavigateBack(); @@ -137,7 +141,39 @@ namespace Tango.PPC.Jobs.ViewModels IsFree = false; Catalog = obj.Catalog; - //Recent = CatalogLoader.GetRecent(Catalog, SettingsManager.Default.GetOrCreate().RecentTwineCatalogColors); + + ColorCatalog recentCatalog = new ColorCatalog(); + recentCatalog.Name = Catalog.Name; + + var settings = SettingsManager.Default.GetOrCreate(); + + var settingsCatalog = settings.RecentCatalogsItems.SingleOrDefault(x => x.Guid == Catalog.Guid); + if (settingsCatalog != null) + { + var allItems = Catalog.ColorCatalogsGroups.SelectMany(x => x.ColorCatalogsItems).ToList(); + + foreach (var itemGuid in settingsCatalog.RecentItems) + { + var realItem = allItems.SingleOrDefault(x => x.Guid == itemGuid); + + if (realItem != null) + { + var group = recentCatalog.ColorCatalogsGroups.SingleOrDefault(x => x.Guid == realItem.ColorCatalogsGroup.Guid); + if (group == null) + { + group = new ColorCatalogsGroup(); + group.Guid = realItem.ColorCatalogsGroup.Guid; + group.Name = realItem.ColorCatalogsGroup.Name; + group.GroupIndex = realItem.ColorCatalogsGroup.GroupIndex; + recentCatalog.ColorCatalogsGroups.Add(group); + } + + group.ColorCatalogsItems.Add(realItem); + } + } + } + + Recent = recentCatalog; SelectedItem = obj.SelectedItem; -- cgit v1.3.1