Beispiel #1
0
        async Task <GangState <TStateData> > RehydrateAsync <TStateData>(
            string gangId, TStateData initial
            )
            where TStateData : class
        {
            var data    = initial;
            var version = 0U;

            var keys = await _eventStore.TryGetIndexedKeys(gangId);

            foreach (var key in keys)
            {
                var e = await GetEventAsync(key);

                if (++version != e.Audit.Version)
                {
                    throw new GangStateVersionException(version, e.Audit);
                }

                var method = GangState <TStateData> .ApplyMethods[e.Data.GetType()];
                data = method(data, e.Data);
            }

            return(GangState.Create(data, version));
        }
Beispiel #2
0
        public static async Task <string> TryGetIndexedKeyAsync <TData>(
            this IGangStore <TData> store,
            object value
            )
        {
            var keys = await store
                       .TryGetIndexedKeys(value);

            return(keys.FirstOrDefault());
        }