public override void AppendWith <TSource, TSnapshotState>(string streamName, int streamVersion, TSource source, Metadata metadata, TSnapshotState snapshot, IAppendResultInterest interest, object @object) { var entry = _entryAdapterProvider.AsEntry <TSource, IEntry>(source, streamVersion, metadata); Insert(streamName, streamVersion, entry); IState?raw; Optional <TSnapshotState> snapshotResult; if (snapshot != null) { raw = _stateAdapterProvider.AsRaw <TSnapshotState, IState>(streamName, snapshot, streamVersion); _snapshots.Add(streamName, raw); snapshotResult = Optional.Of(snapshot); } else { raw = null; snapshotResult = Optional.Empty <TSnapshotState>(); } Dispatch(streamName, streamVersion, new List <IEntry> { entry }, raw); interest.AppendResultedIn(Success.Of <StorageException, Result>(Result.Success), streamName, streamVersion, source, snapshotResult, @object); }
private TState Persist(StateObject stateObject, Metadata metadata) { var raw = _stateAdapterProvider.AsRaw <StateObject, TState>(stateObject.PersistenceId.ToString(), stateObject, 1, metadata); var store = _stores.ComputeIfAbsent(stateObject.GetType(), type => new Dictionary <long, TState>()); var persistenceId = stateObject.PersistenceId == -1L ? _nextId++ : stateObject.PersistenceId; store.Add(persistenceId, raw); stateObject.SetPersistenceId(persistenceId); return(raw); }