public async Task <Dictionary <string, TState> > Dispatch <TProjection, TState>(string streamId) where TProjection : ProjectionBase <TProjection, TState>, new() where TState : new()
        {
            Dictionary <string, TState> result;
            long version;

            if (SnapshotProjection <TState> .TryGetSnapshot(streamId, out var snapshot))
            {
                result  = snapshot.State;
                version = snapshot.Version;
            }
            else
            {
                result  = new Dictionary <string, TState>();
                version = 0;
            }

            var actualVersion = await Dispatch <TProjection, TState>(streamId, version, result).ConfigureAwait(false);

            if (actualVersion > version && actualVersion > _configuration.SnapchotLimit)
            {
                SnapshotProjection <TState> .AddSnapshot(streamId, new SnapshotProjection <Dictionary <string, TState> >(result, actualVersion));
            }
            return(result);
        }
Пример #2
0
 public static void AddSnapshot(string key, SnapshotProjection <Dictionary <string, TState> > snapshot) => _snapshotDictionary.AddOrUpdate(key, snapshot, (_, __) => snapshot);
Пример #3
0
 public static bool TryGetSnapshot(string key, out SnapshotProjection <Dictionary <string, TState> > snapshot) => _snapshotDictionary.TryGetValue(key, out snapshot);