77using OwlCore . Kubo ;
88using OwlCore . Nomad ;
99using OwlCore . Nomad . Kubo ;
10+ using OwlCore . Nomad . Kubo . Events ;
1011using OwlCore . Storage ;
1112using WindowsAppCommunity . Sdk . Models ;
1213
@@ -38,10 +39,10 @@ public async Task AddImageAsync(IFile imageFile, CancellationToken cancellationT
3839 var keyCid = await Client . Dag . PutAsync ( newImage . Id , pin : KuboOptions . ShouldPin , cancel : cancellationToken ) ;
3940 var valueCid = await Client . Dag . PutAsync ( newImage , pin : KuboOptions . ShouldPin , cancel : cancellationToken ) ;
4041
41- var updateEvent = new ValueUpdateEvent ( Id , nameof ( AddImageAsync ) , ( DagCid ) keyCid , ( DagCid ) valueCid , false ) ;
42+ var updateEvent = new ValueUpdateEvent ( ( DagCid ) keyCid , ( DagCid ) valueCid , false ) ;
4243
43- await ApplyEntryUpdateAsync ( updateEvent , newImage , cancellationToken ) ;
44- var appendedEntry = await AppendNewEntryAsync ( updateEvent , cancellationToken ) ;
44+ var appendedEntry = await AppendNewEntryAsync ( targetId : Id , eventId : nameof ( AddImageAsync ) , updateEvent , DateTime . UtcNow , cancellationToken ) ;
45+ await ApplyEntryUpdateAsync ( appendedEntry , updateEvent , newImage , cancellationToken ) ;
4546
4647 EventStreamPosition = appendedEntry ;
4748 }
@@ -58,10 +59,10 @@ public async Task RemoveImageAsync(IFile imageFile, CancellationToken cancellati
5859 var keyCid = await Client . Dag . PutAsync ( image . Id , pin : KuboOptions . ShouldPin , cancel : cancellationToken ) ;
5960 var valueCid = await Client . Dag . PutAsync ( image , pin : KuboOptions . ShouldPin , cancel : cancellationToken ) ;
6061
61- var updateEvent = new ValueUpdateEvent ( Id , nameof ( RemoveImageAsync ) , ( DagCid ) keyCid , ( DagCid ) valueCid , true ) ;
62+ var updateEvent = new ValueUpdateEvent ( ( DagCid ) keyCid , ( DagCid ) valueCid , true ) ;
6263
63- await ApplyEntryUpdateAsync ( updateEvent , image , cancellationToken ) ;
64- var appendedEntry = await AppendNewEntryAsync ( updateEvent , cancellationToken ) ;
64+ var appendedEntry = await AppendNewEntryAsync ( Id , nameof ( RemoveImageAsync ) , updateEvent , DateTime . UtcNow , cancellationToken ) ;
65+ await ApplyEntryUpdateAsync ( appendedEntry , updateEvent , image , cancellationToken ) ;
6566
6667 EventStreamPosition = appendedEntry ;
6768 }
@@ -81,35 +82,37 @@ public async Task RemoveImageAsync(IFile imageFile, CancellationToken cancellati
8182 /// <remarks>
8283 /// This method will call <see cref="ReadOnlyImagesCollection.GetAsync(string, CancellationToken)"/> and create a new instance to pass to the event handlers.
8384 /// <para/>
84- /// If already have a resolved instance of <see cref="Image"/>, you should call <see cref="ApplyEntryUpdateAsync(ValueUpdateEvent, Image, CancellationToken)"/> instead.
85+ /// If already have a resolved instance of <see cref="Image"/>, you should call <see cref="ApplyEntryUpdateAsync(EventStreamEntry{DagCid}, ValueUpdateEvent, Image, CancellationToken)"/> instead.
8586 /// </remarks>
87+ /// <param name="eventStreamEntry">The event stream entry to apply.</param>
8688 /// <param name="updateEvent">The update event to apply.</param>
8789 /// <param name="cancellationToken">A token that can be used to cancel the ongoing operation.</param>
88- public override async Task ApplyEntryUpdateAsync ( ValueUpdateEvent updateEvent , CancellationToken cancellationToken )
90+ public override async Task ApplyEntryUpdateAsync ( EventStreamEntry < DagCid > eventStreamEntry , ValueUpdateEvent updateEvent , CancellationToken cancellationToken )
8991 {
9092 cancellationToken . ThrowIfCancellationRequested ( ) ;
9193
92- if ( updateEvent . TargetId != Id )
94+ if ( eventStreamEntry . TargetId != Id )
9395 return ;
9496
9597 Guard . IsNotNull ( updateEvent . Value ) ;
9698 var ( image , _) = await Client . ResolveDagCidAsync < Image > ( updateEvent . Value . Value , nocache : ! KuboOptions . UseCache , cancellationToken ) ;
9799
98100 Guard . IsNotNull ( image ) ;
99- await ApplyEntryUpdateAsync ( updateEvent , image , cancellationToken ) ;
101+ await ApplyEntryUpdateAsync ( eventStreamEntry , updateEvent , image , cancellationToken ) ;
100102 }
101103
102104 /// <summary>
103105 /// Applies an event stream update event and raises the relevant events.
104106 /// </summary>
107+ /// <param name="eventStreamEntry">The event stream entry to apply.</param>
105108 /// <param name="updateEvent">The update event to apply.</param>
106109 /// <param name="image">The resolved image data for this event.</param>
107110 /// <param name="cancellationToken">A token that can be used to cancel the ongoing operation.</param>
108- public async Task ApplyEntryUpdateAsync ( ValueUpdateEvent updateEvent , Image image , CancellationToken cancellationToken )
111+ public async Task ApplyEntryUpdateAsync ( EventStreamEntry < DagCid > eventStreamEntry , ValueUpdateEvent updateEvent , Image image , CancellationToken cancellationToken )
109112 {
110113 cancellationToken . ThrowIfCancellationRequested ( ) ;
111114
112- switch ( updateEvent . EventId )
115+ switch ( eventStreamEntry . EventId )
113116 {
114117 case nameof ( AddImageAsync ) :
115118 {
@@ -128,15 +131,6 @@ public async Task ApplyEntryUpdateAsync(ValueUpdateEvent updateEvent, Image imag
128131 }
129132 }
130133
131- /// <inheritdoc cref="INomadKuboEventStreamHandler{TEventEntryContent}.AppendNewEntryAsync" />
132- public override async Task < EventStreamEntry < Cid > > AppendNewEntryAsync ( ValueUpdateEvent updateEvent , CancellationToken cancellationToken = default )
133- {
134- // Use extension method for code deduplication (can't use inheritance).
135- var localUpdateEventCid = await Client . Dag . PutAsync ( updateEvent , pin : KuboOptions . ShouldPin , cancel : cancellationToken ) ;
136- var newEntry = await this . AppendEventStreamEntryAsync ( localUpdateEventCid , updateEvent . EventId , updateEvent . TargetId , cancellationToken ) ;
137- return newEntry ;
138- }
139-
140134 /// <inheritdoc />
141135 public override Task ResetEventStreamPositionAsync ( CancellationToken cancellationToken )
142136 {
0 commit comments