diff --git a/SightKeeper.Data/Binary/Replication/DataSetReplicator.cs b/SightKeeper.Data/Binary/Replication/DataSetReplicator.cs index 5a51d681..ad01aa22 100644 --- a/SightKeeper.Data/Binary/Replication/DataSetReplicator.cs +++ b/SightKeeper.Data/Binary/Replication/DataSetReplicator.cs @@ -3,6 +3,7 @@ using SightKeeper.Data.Binary.Model.DataSets; using SightKeeper.Data.Binary.Model.DataSets.Compositions; using SightKeeper.Data.Binary.Model.DataSets.Tags; +using SightKeeper.Data.Binary.Services; using SightKeeper.Domain.Model; using SightKeeper.Domain.Model.DataSets; using SightKeeper.Domain.Model.DataSets.Screenshots; @@ -12,12 +13,18 @@ namespace SightKeeper.Data.Binary.Replication; internal abstract class DataSetReplicator { + public DataSetReplicator(FileSystemScreenshotsDataAccess screenshotsDataAccess) + { + _screenshotsDataAccess = screenshotsDataAccess; + } + public DataSet Replicate(PackableDataSet packed, ReplicationSession session) { Guard.IsNotNull(session.Games); var game = packed.GameId == null ? null : session.Games[packed.GameId.Value]; var composition = ReplicateComposition(packed.Composition); var dataSet = CreateDataSet(packed.Name, packed.Description, game, composition); + ReplicateScreenshots(dataSet.Screenshots, packed.Screenshots); var tagsLookup = ReplicateTags(dataSet.Tags, packed.GetTags()); return dataSet; } @@ -36,6 +43,8 @@ protected virtual Tag ReplicateTag( return tag; } + private readonly FileSystemScreenshotsDataAccess _screenshotsDataAccess; + private static Composition ReplicateComposition(PackableComposition? composition) { return composition switch @@ -48,6 +57,16 @@ private static Composition ReplicateComposition(PackableComposition? composition }; } + private void ReplicateScreenshots(ScreenshotsLibrary library, ImmutableArray screenshots) + { + foreach (var packedScreenshot in screenshots) + { + var screenshot = library.CreateScreenshot(packedScreenshot.CreationDate, packedScreenshot.Resolution, out var removedScreenshots); + Guard.IsTrue(removedScreenshots.IsEmpty); + _screenshotsDataAccess.AssociateId(screenshot, packedScreenshot.Id); + } + } + private ImmutableDictionary<(byte, byte?), Tag> ReplicateTags(TagsLibrary library, ImmutableArray tags) { var lookupBuilder = ImmutableDictionary.CreateBuilder<(byte, byte?), Tag>();