Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 0 additions & 79 deletions src/Models/ValueUpdateEvent.cs

This file was deleted.

27 changes: 10 additions & 17 deletions src/Nomad/ModifiableAccentColor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using OwlCore.Kubo;
using OwlCore.Nomad;
using OwlCore.Nomad.Kubo;
using WindowsAppCommunity.Sdk.Models;
using OwlCore.Nomad.Kubo.Events;

namespace WindowsAppCommunity.Sdk.Nomad;

Expand All @@ -25,11 +25,11 @@ public class ModifiableAccentColor : NomadKuboEventStreamHandler<ValueUpdateEven
public event EventHandler<string?>? AccentColorUpdated;

/// <inheritdoc />
public override async Task ApplyEntryUpdateAsync(ValueUpdateEvent updateEvent, CancellationToken cancellationToken)
public override async Task ApplyEntryUpdateAsync(EventStreamEntry<DagCid> eventStreamEntry, ValueUpdateEvent updateEvent, CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();

if (updateEvent.TargetId != Id)
if (eventStreamEntry.TargetId != Id)
return;
Comment thread
Arlodotexe marked this conversation as resolved.

string? accentColor = null;
Expand All @@ -39,20 +39,21 @@ public override async Task ApplyEntryUpdateAsync(ValueUpdateEvent updateEvent, C
(accentColor, _) = await Client.ResolveDagCidAsync<string>(updateEvent.Value, nocache: !KuboOptions.UseCache, cancellationToken);
}

await ApplyEntryUpdateAsync(updateEvent, accentColor, cancellationToken);
await ApplyEntryUpdateAsync(eventStreamEntry, updateEvent, accentColor, cancellationToken);
}

/// <summary>
/// Applies an event stream update event and raises the relevant events.
/// </summary>
/// <param name="eventStreamEntry">The event stream entry to apply.</param>
/// <param name="updateEvent">The update event to apply.</param>
/// <param name="accentColor">The resolved accent color data for this event.</param>
/// <param name="cancellationToken">A token that can be used to cancel the ongoing operation.</param>
public Task ApplyEntryUpdateAsync(ValueUpdateEvent updateEvent, string? accentColor, CancellationToken cancellationToken)
public Task ApplyEntryUpdateAsync(EventStreamEntry<DagCid> eventStreamEntry, ValueUpdateEvent updateEvent, string? accentColor, CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();

if (updateEvent.EventId is not nameof(UpdateAccentColorAsync))
if (eventStreamEntry.EventId is not nameof(UpdateAccentColorAsync))
return Task.CompletedTask;

Inner.Inner.AccentColor = accentColor;
Expand All @@ -61,14 +62,6 @@ public Task ApplyEntryUpdateAsync(ValueUpdateEvent updateEvent, string? accentCo
return Task.CompletedTask;
}

/// <inheritdoc cref="INomadKuboEventStreamHandler{TEventEntryContent}.AppendNewEntryAsync" />
public override async Task<EventStreamEntry<Cid>> AppendNewEntryAsync(ValueUpdateEvent updateEvent, CancellationToken cancellationToken = default)
{
var localUpdateEventCid = await Client.Dag.PutAsync(updateEvent, pin: KuboOptions.ShouldPin, cancel: cancellationToken);
var newEntry = await this.AppendEventStreamEntryAsync(localUpdateEventCid, updateEvent.EventId, updateEvent.TargetId, cancellationToken);
return newEntry;
}

/// <inheritdoc />
public override Task ResetEventStreamPositionAsync(CancellationToken cancellationToken)
{
Expand All @@ -88,10 +81,10 @@ public async Task UpdateAccentColorAsync(string? accentColor, CancellationToken
valueCid = (DagCid)cid;
}

var updateEvent = new ValueUpdateEvent(Id, nameof(UpdateAccentColorAsync), null, valueCid, accentColor is null);
var updateEvent = new ValueUpdateEvent(null, valueCid, accentColor is null);

await ApplyEntryUpdateAsync(updateEvent, accentColor, cancellationToken);
var appendedEntry = await AppendNewEntryAsync(updateEvent, cancellationToken);
var appendedEntry = await AppendNewEntryAsync(targetId: Id, eventId: nameof(UpdateAccentColorAsync), updateEvent, DateTime.UtcNow, cancellationToken);
await ApplyEntryUpdateAsync(appendedEntry, updateEvent, accentColor, cancellationToken);

EventStreamPosition = appendedEntry;
}
Expand Down
36 changes: 15 additions & 21 deletions src/Nomad/ModifiableImagesCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using OwlCore.Kubo;
using OwlCore.Nomad;
using OwlCore.Nomad.Kubo;
using OwlCore.Nomad.Kubo.Events;
using OwlCore.Storage;
using WindowsAppCommunity.Sdk.Models;

Expand Down Expand Up @@ -38,10 +39,10 @@ public async Task AddImageAsync(IFile imageFile, CancellationToken cancellationT
var keyCid = await Client.Dag.PutAsync(newImage.Id, pin: KuboOptions.ShouldPin, cancel: cancellationToken);
var valueCid = await Client.Dag.PutAsync(newImage, pin: KuboOptions.ShouldPin, cancel: cancellationToken);

var updateEvent = new ValueUpdateEvent(Id, nameof(AddImageAsync), (DagCid)keyCid, (DagCid)valueCid, false);
var updateEvent = new ValueUpdateEvent((DagCid)keyCid, (DagCid)valueCid, false);

await ApplyEntryUpdateAsync(updateEvent, newImage, cancellationToken);
var appendedEntry = await AppendNewEntryAsync(updateEvent, cancellationToken);
var appendedEntry = await AppendNewEntryAsync(targetId: Id, eventId: nameof(AddImageAsync), updateEvent, DateTime.UtcNow, cancellationToken);
await ApplyEntryUpdateAsync(appendedEntry, updateEvent, newImage, cancellationToken);

EventStreamPosition = appendedEntry;
}
Expand All @@ -58,10 +59,10 @@ public async Task RemoveImageAsync(IFile imageFile, CancellationToken cancellati
var keyCid = await Client.Dag.PutAsync(image.Id, pin: KuboOptions.ShouldPin, cancel: cancellationToken);
var valueCid = await Client.Dag.PutAsync(image, pin: KuboOptions.ShouldPin, cancel: cancellationToken);

var updateEvent = new ValueUpdateEvent(Id, nameof(RemoveImageAsync), (DagCid)keyCid, (DagCid)valueCid, true);
var updateEvent = new ValueUpdateEvent((DagCid)keyCid, (DagCid)valueCid, true);

await ApplyEntryUpdateAsync(updateEvent, image, cancellationToken);
var appendedEntry = await AppendNewEntryAsync(updateEvent, cancellationToken);
var appendedEntry = await AppendNewEntryAsync(Id, nameof(RemoveImageAsync), updateEvent, DateTime.UtcNow, cancellationToken);
Comment thread
Arlodotexe marked this conversation as resolved.
await ApplyEntryUpdateAsync(appendedEntry, updateEvent, image, cancellationToken);

EventStreamPosition = appendedEntry;
}
Expand All @@ -81,35 +82,37 @@ public async Task RemoveImageAsync(IFile imageFile, CancellationToken cancellati
/// <remarks>
/// This method will call <see cref="ReadOnlyImagesCollection.GetAsync(string, CancellationToken)"/> and create a new instance to pass to the event handlers.
/// <para/>
/// If already have a resolved instance of <see cref="Image"/>, you should call <see cref="ApplyEntryUpdateAsync(ValueUpdateEvent, Image, CancellationToken)"/> instead.
/// If already have a resolved instance of <see cref="Image"/>, you should call <see cref="ApplyEntryUpdateAsync(EventStreamEntry{DagCid}, ValueUpdateEvent, Image, CancellationToken)"/> instead.
/// </remarks>
/// <param name="eventStreamEntry">The event stream entry to apply.</param>
/// <param name="updateEvent">The update event to apply.</param>
/// <param name="cancellationToken">A token that can be used to cancel the ongoing operation.</param>
public override async Task ApplyEntryUpdateAsync(ValueUpdateEvent updateEvent, CancellationToken cancellationToken)
public override async Task ApplyEntryUpdateAsync(EventStreamEntry<DagCid> eventStreamEntry, ValueUpdateEvent updateEvent, CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();

if (updateEvent.TargetId != Id)
if (eventStreamEntry.TargetId != Id)
return;

Guard.IsNotNull(updateEvent.Value);
var (image, _) = await Client.ResolveDagCidAsync<Image>(updateEvent.Value.Value, nocache: !KuboOptions.UseCache, cancellationToken);

Guard.IsNotNull(image);
await ApplyEntryUpdateAsync(updateEvent, image, cancellationToken);
await ApplyEntryUpdateAsync(eventStreamEntry, updateEvent, image, cancellationToken);
}

/// <summary>
/// Applies an event stream update event and raises the relevant events.
/// </summary>
/// <param name="eventStreamEntry">The event stream entry to apply.</param>
/// <param name="updateEvent">The update event to apply.</param>
/// <param name="image">The resolved image data for this event.</param>
/// <param name="cancellationToken">A token that can be used to cancel the ongoing operation.</param>
public async Task ApplyEntryUpdateAsync(ValueUpdateEvent updateEvent, Image image, CancellationToken cancellationToken)
public async Task ApplyEntryUpdateAsync(EventStreamEntry<DagCid> eventStreamEntry, ValueUpdateEvent updateEvent, Image image, CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();

switch (updateEvent.EventId)
switch (eventStreamEntry.EventId)
{
case nameof(AddImageAsync):
{
Comment thread
Arlodotexe marked this conversation as resolved.
Expand All @@ -128,15 +131,6 @@ public async Task ApplyEntryUpdateAsync(ValueUpdateEvent updateEvent, Image imag
}
}

/// <inheritdoc cref="INomadKuboEventStreamHandler{TEventEntryContent}.AppendNewEntryAsync" />
public override async Task<EventStreamEntry<Cid>> AppendNewEntryAsync(ValueUpdateEvent updateEvent, CancellationToken cancellationToken = default)
{
// Use extension method for code deduplication (can't use inheritance).
var localUpdateEventCid = await Client.Dag.PutAsync(updateEvent, pin: KuboOptions.ShouldPin, cancel: cancellationToken);
var newEntry = await this.AppendEventStreamEntryAsync(localUpdateEventCid, updateEvent.EventId, updateEvent.TargetId, cancellationToken);
return newEntry;
}

/// <inheritdoc />
public override Task ResetEventStreamPositionAsync(CancellationToken cancellationToken)
{
Expand Down
5 changes: 2 additions & 3 deletions src/WindowsAppCommunity.Sdk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,10 @@ Initial release of WindowsAppCommunity.Sdk.
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="9.0.0" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="9.0.2" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
<PackageReference Include="OwlCore.Kubo" Version="0.20.1" />
<PackageReference Include="OwlCore.Nomad" Version="0.9.0" />
<PackageReference Include="OwlCore.Nomad.Kubo" Version="0.14.0" />
<PackageReference Include="OwlCore.Nomad.Kubo" Version="0.15.1" />
<PackageReference Include="PolySharp" Version="1.15.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down