Skip to content

Commit

Permalink
Screenshots replication
Browse files Browse the repository at this point in the history
  • Loading branch information
Neakita committed Sep 6, 2024
1 parent 2d2ff9d commit 7f842d2
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions SightKeeper.Data/Binary/Replication/DataSetReplicator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -36,6 +43,8 @@ protected virtual Tag ReplicateTag(
return tag;
}

private readonly FileSystemScreenshotsDataAccess _screenshotsDataAccess;

private static Composition ReplicateComposition(PackableComposition? composition)
{
return composition switch
Expand All @@ -48,6 +57,16 @@ private static Composition ReplicateComposition(PackableComposition? composition
};
}

private void ReplicateScreenshots(ScreenshotsLibrary library, ImmutableArray<PackableScreenshot> 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<PackableTag> tags)
{
var lookupBuilder = ImmutableDictionary.CreateBuilder<(byte, byte?), Tag>();
Expand Down

0 comments on commit 7f842d2

Please sign in to comment.