diff --git a/Stars Assistant/Services/FleetManager.cs b/Stars Assistant/Services/FleetManager.cs index 2d364dc..2601593 100644 --- a/Stars Assistant/Services/FleetManager.cs +++ b/Stars Assistant/Services/FleetManager.cs @@ -21,6 +21,34 @@ public class FleetManager public FleetManager() {} + public class FleetSummary + { + public string Destination { get; set; } = string.Empty; + public int TotalIronium { get; set; } + public int TotalBoranium { get; set; } + public int TotalGermanium { get; set; } + public int TotalColonists { get; set; } + } + private IObservable>? _fleetSummaries; + + public void test() + { + /* + _fleetSummaries = _fleets.Connect() + .Group(fleet => fleet.TrueDestination) + .Transform(grouping => new FleetSummary + { + Destination = grouping.Key, + TotalIronium = grouping.Items.Sum(f => f.Ironium), + TotalBoranium = grouping.Items.Sum(f => f.Boranium), + TotalGermanium = grouping.Items.Sum(f => f.Germanium), + TotalColonists = grouping.Items.Sum(f => f.Colonists) + }) + .Sort(SortExpressionComparer.Ascending(f => f.Planet)) + .AsObservableChangeSet(summary => summary.Planet); + */ + } + /// /// Load the fleet records from the database and push them into our source cache. /// If the data has been freshly imported, call PostProcessImportedData first. @@ -29,7 +57,12 @@ public class FleetManager { using var db = Locator.Current.GetService()!; var allFleets = db.Fleet.ToList(); - _fleets.AddOrUpdate(allFleets); + _fleets.Edit(innerCache => + { + innerCache.Clear(); + innerCache.AddOrUpdate(allFleets); + } + ); } /// diff --git a/Stars Assistant/Services/PlanetManager.cs b/Stars Assistant/Services/PlanetManager.cs index 1ded2da..19605da 100644 --- a/Stars Assistant/Services/PlanetManager.cs +++ b/Stars Assistant/Services/PlanetManager.cs @@ -36,6 +36,15 @@ public class PlanetManager { using var db = Locator.Current.GetService()!; var allPlanets = db.Planet.ToList(); - _planets.AddOrUpdate(allPlanets); + var cacheKeys = _planets.Keys.ToList(); + var planetNames = from p in allPlanets select p.Name; + var planetsToDelete = cacheKeys.Except(planetNames); + _planets.Edit(innerCache => + { + foreach (var name in planetsToDelete) + innerCache.RemoveKey(name); + innerCache.AddOrUpdate(allPlanets); + } + ); } } diff --git a/Stars Assistant/Stars Assistant.csproj b/Stars Assistant/Stars Assistant.csproj index 9ceef65..a073113 100644 --- a/Stars Assistant/Stars Assistant.csproj +++ b/Stars Assistant/Stars Assistant.csproj @@ -18,6 +18,7 @@ +