async Task <GangState <TStateData> > IGangStateStore .CommitAsync <TStateData>(string gangId, GangState <TStateData> state, GangAudit audit) { var version = state.Version - (uint)state.Uncommitted.Count; foreach (var eventData in state.Uncommitted) { var e = GangStateEvent.From(eventData, audit); var wrapper = new GangStateEventWrapper( eventData, GangStateEventMap.GetName <TStateData>(eventData.GetType()), audit.SetVersion(++version) ); _events.OnNext(e); var key = GetEventKey(++_sequenceNumber); await _eventStore.SetAsync( key, wrapper, overwrite : false ); } await _cache.SetAsync(gangId, new { state.Data, state.Version } ); await _sequenceNumberStore.SetAsync(KEY_SEQUENCE_NUMBER, _sequenceNumber); return(GangState.Create(state.Data, state.Version)); }
async Task <IGangStateEvent> GetEventAsync(string key) { var wrapper = await _eventStore.TryGetAsync(key); var type = _eventMap.GetType(wrapper.Type); return(GangStateEvent.From( _serializer.Map(wrapper.Data, type), wrapper.Audit )); }