intermediate broken

This commit is contained in:
Torben Nehmer 2024-10-04 19:05:23 +02:00
parent b1fb26db5a
commit c77ef68e70
No known key found for this signature in database
3 changed files with 45 additions and 2 deletions

View File

@ -21,6 +21,34 @@ public class FleetManager
public 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<IChangeSet<FleetSummary, string>>? _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<FleetSummary>.Ascending(f => f.Planet))
.AsObservableChangeSet(summary => summary.Planet);
*/
}
/// <summary> /// <summary>
/// Load the fleet records from the database and push them into our source cache. /// Load the fleet records from the database and push them into our source cache.
/// If the data has been freshly imported, call PostProcessImportedData first. /// If the data has been freshly imported, call PostProcessImportedData first.
@ -29,7 +57,12 @@ public class FleetManager
{ {
using var db = Locator.Current.GetService<StarsDatabase>()!; using var db = Locator.Current.GetService<StarsDatabase>()!;
var allFleets = db.Fleet.ToList(); var allFleets = db.Fleet.ToList();
_fleets.AddOrUpdate(allFleets); _fleets.Edit(innerCache =>
{
innerCache.Clear();
innerCache.AddOrUpdate(allFleets);
}
);
} }
/// <summary> /// <summary>

View File

@ -36,6 +36,15 @@ public class PlanetManager
{ {
using var db = Locator.Current.GetService<StarsDatabase>()!; using var db = Locator.Current.GetService<StarsDatabase>()!;
var allPlanets = db.Planet.ToList(); 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);
}
);
} }
} }

View File

@ -18,6 +18,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Avalonia.ReactiveUI" Version="11.1.3" /> <PackageReference Include="Avalonia.ReactiveUI" Version="11.1.3" />
<PackageReference Include="CsvHelper" Version="33.0.1" /> <PackageReference Include="CsvHelper" Version="33.0.1" />
<!-- PackageReference Include="DynamicData" Version="9.0.4" /-->
<PackageReference Include="Material.Icons.Avalonia" Version="2.1.10" /> <PackageReference Include="Material.Icons.Avalonia" Version="2.1.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.8" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.8" />