@@ -80,6 +80,38 @@ public async Task<String> GetPartitionResultFromProjection(String projectionName
8080
8181 }
8282
83+ /// <summary>
84+ /// Gets the events backwards asynchronous.
85+ /// </summary>
86+ /// <param name="streamName">Name of the stream.</param>
87+ /// <param name="maxNumberOfEventsToRetrieve">The maximum number of events to retrieve.</param>
88+ /// <param name="cancellationToken">The cancellation token.</param>
89+ /// <returns></returns>
90+ public async Task < IList < ResolvedEvent > > GetEventsBackwardAsync ( String streamName ,
91+ Int32 maxNumberOfEventsToRetrieve ,
92+ CancellationToken cancellationToken )
93+ {
94+ List < ResolvedEvent > resolvedEvents = new ( ) ;
95+
96+ EventStoreClient . ReadStreamResult response = this . EventStoreClient . ReadStreamAsync ( Direction . Backwards ,
97+ streamName ,
98+ StreamPosition . End ,
99+ maxNumberOfEventsToRetrieve ,
100+ resolveLinkTos : true ,
101+ cancellationToken : cancellationToken ) ;
102+
103+ if ( await response . ReadState == ReadState . StreamNotFound )
104+ {
105+ return resolvedEvents ;
106+ }
107+
108+ List < ResolvedEvent > events = await response . ToListAsync ( cancellationToken ) ;
109+
110+ resolvedEvents . AddRange ( events ) ;
111+
112+ return resolvedEvents ;
113+ }
114+
83115 /// <summary>
84116 /// Gets the partition state from projection.
85117 /// </summary>
@@ -162,7 +194,7 @@ public async Task InsertEvents(String streamName,
162194 this . LogInformation ( $ "About to append { aggregateEvents . Count } to Stream { streamName } ") ;
163195 await this . EventStoreClient . AppendToStreamAsync ( streamName , StreamRevision . FromInt64 ( expectedVersion ) , aggregateEvents . AsEnumerable ( ) , cancellationToken : cancellationToken ) ;
164196 }
165-
197+
166198 /// <summary>
167199 /// Reads the events.
168200 /// </summary>
0 commit comments