diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-12-03 03:48:25 +0200 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-12-03 03:48:25 +0200 |
| commit | 3f2397750a3f5bbdf5ef78049c237ebeaff78319 (patch) | |
| tree | 3a8b325c1f04fa90c114893d84c65020fce7920d /Software/Visual_Studio | |
| parent | c873eb1c0324eb50428fc26cdb5f1c3d05c7d3ea (diff) | |
| download | Tango-3f2397750a3f5bbdf5ef78049c237ebeaff78319.tar.gz Tango-3f2397750a3f5bbdf5ef78049c237ebeaff78319.zip | |
DataStore fixes.
Diffstat (limited to 'Software/Visual_Studio')
3 files changed, 36 insertions, 2 deletions
diff --git a/Software/Visual_Studio/DataStore/Tango.DataStore.EF/EFDataStoreCollection.cs b/Software/Visual_Studio/DataStore/Tango.DataStore.EF/EFDataStoreCollection.cs index c1b45e37f..6ccc6d78a 100644 --- a/Software/Visual_Studio/DataStore/Tango.DataStore.EF/EFDataStoreCollection.cs +++ b/Software/Visual_Studio/DataStore/Tango.DataStore.EF/EFDataStoreCollection.cs @@ -57,6 +57,7 @@ namespace Tango.DataStore.EF item.Value = EFDataStoreHelper.CreateBytes(type, value); item.IsSynchronized = false; item.LastUpdated = DateTime.UtcNow; + item.IsDeleted = false; db.SaveChanges(); } @@ -91,7 +92,7 @@ namespace Tango.DataStore.EF { using (var db = ObservablesContext.CreateDefault()) { - var item = db.DataStoreItems.SingleOrDefault(x => x.CollectionName == Name && x.Key == key); + var item = db.DataStoreItems.SingleOrDefault(x => x.CollectionName == Name && x.Key == key && !x.IsDeleted); if (item == null) { @@ -123,7 +124,7 @@ namespace Tango.DataStore.EF { using (var db = ObservablesContext.CreateDefault()) { - var localItems = db.DataStoreItems.Where(x => x.CollectionName == Name).ToList(); + var localItems = db.DataStoreItems.Where(x => x.CollectionName == Name && !x.IsDeleted).ToList(); var globalItems = db.GlobalDataStoreItems.Where(x => x.CollectionName == Name).ToList(); foreach (var globalItem in globalItems.ToList()) diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/DataStoreViewVM.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/DataStoreViewVM.cs index 46f388461..16fe59f61 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/DataStoreViewVM.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/DataStoreViewVM.cs @@ -251,6 +251,7 @@ namespace Tango.FSE.MachineConfiguration.ViewModels if (SelectedCollection != null) { _selectedCollectionView = CollectionViewSource.GetDefaultView(SelectedCollection.Items); + _selectedCollectionView.SortDescriptions.Add(new SortDescription(nameof(DataStoreItemModel.Key), ListSortDirection.Ascending)); _selectedCollectionView.Filter = (x) => FilterItems(x as DataStoreItemModel); _selectedCollectionView.Refresh(); } @@ -292,7 +293,20 @@ namespace Tango.FSE.MachineConfiguration.ViewModels return; } + var selectedCollection = SelectedCollection; + var selectedItem = SelectedItem; + await LoadDataStore(); + + if (selectedCollection != null) + { + SelectedCollection = DataStore.Collections.FirstOrDefault(x => x.Name == selectedCollection.Name); + } + + if (SelectedCollection != null && selectedItem != null) + { + SelectedItem = SelectedCollection.Items.FirstOrDefault(x => x.Key == selectedItem.Key); + } } private async Task LoadDataStore() diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/DataStore/DefaultDataStoreService.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/DataStore/DefaultDataStoreService.cs index 4d2e9c1df..02539aed9 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/DataStore/DefaultDataStoreService.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/DataStore/DefaultDataStoreService.cs @@ -189,6 +189,8 @@ namespace Tango.PPC.Common.DataStore { var allItems = db.DataStoreItems.ToList(); + List<BL.Entities.DataStoreItem> deleted = new List<BL.Entities.DataStoreItem>(); + foreach (var guid in request.ToDelete) { var item = allItems.FirstOrDefault(x => x.Guid == guid); @@ -197,6 +199,7 @@ namespace Tango.PPC.Common.DataStore item.IsDeleted = true; item.IsSynchronized = true; item.LastUpdated = DateTime.UtcNow; + deleted.Add(item); } } @@ -246,6 +249,22 @@ namespace Tango.PPC.Common.DataStore Logging.LogManager.Default.Log(ex, $"Error notifying firmware about data store item change '{item.CollectionName}.{item.Key}'."); } } + + foreach (var item in deleted) + { + try + { + var response = _machineProvider.MachineOperator.SendRequest<DataStoreItemModifiedRequest, DataStoreItemModifiedResponse>(new DataStoreItemModifiedRequest() + { + Collection = item.CollectionName, + Key = item.Key + }).Result; + } + catch (Exception ex) + { + Logging.LogManager.Default.Log(ex, $"Error notifying firmware about data store item change '{item.CollectionName}.{item.Key}'."); + } + } }); } } |
