public async Task SetEventToDispatched <T>(EventId eventId) where T : EventStoreBase
        {
            try
            {
                var streamEvent = await this.Persister.GetByIdAsync <T>(eventId.GetValue());

                if (streamEvent == null || string.IsNullOrWhiteSpace(streamEvent.Id))
                {
                    return;
                }

                streamEvent.SetEventDispatched();
                await this.Persister.UpdateAsync(streamEvent);
            }
            catch (Exception ex)
            {
                this.Logger.LogError(CommonServices.GetDefaultErrorTrace(ex));
                throw new Exception(CommonServices.GetErrorMessage(ex));
            }
        }
        public async Task AppendEventAsync <T>(EventId eventId, StreamType streamType, StreamData streamData,
                                               DeviceId aggregateId, DeviceName aggregateName, StreamWhen streamWhen) where T : EventStoreBase
        {
            try
            {
                var streamEvent =
                    await this.Persister.GetByIdAsync <T>(eventId.GetValue());

                if (streamEvent != null && !string.IsNullOrEmpty(streamEvent.Id))
                {
                    return;
                }

                streamEvent = ConstructAggregate <T>(eventId, streamType, streamData, aggregateId, aggregateName, streamWhen);
                await this.Persister.InsertAsync(streamEvent);
            }
            catch (Exception ex)
            {
                this.Logger.LogError(CommonServices.GetDefaultErrorTrace(ex));
                throw new Exception(CommonServices.GetErrorMessage(ex));
            }
        }
 private static T ConstructAggregate <T>(EventId eventId, StreamType streamType, StreamData streamData,
                                         DeviceId aggregateId, DeviceName aggregateName, StreamWhen streamWhen)
 {
     return((T)Activator.CreateInstance(typeof(T), eventId, streamType, streamData, aggregateId, aggregateName,
                                        streamWhen));
 }