//------------------------------------------------------------------------------ static public object ConvertUsingTypeConverter(Type destinationType, object value) { if (s_ConverterRegistry == null) { IConverterRegistry converterRegistry = new ConverterRegistry(); converterRegistry.RegisterConverter <object, bool>(() => new ObjectToBoolConverter()); converterRegistry.RegisterConverter <object, DateTime>(() => new ObjectToDateTimeConverter()); s_ConverterRegistry = converterRegistry; } object result = s_ConverterRegistry.Convert(destinationType, value); return(result); }
public async Task <EventStream <TSnapshotData> > GetAsync(string orderNumber, CancellationToken cancellationToken) { var container = await _eventRepository.ReadRecordsAsync(orderNumber, cancellationToken); var events = container.RawEvents; var query = new Queue <IDomainEvent>(); foreach (var dataWithVersion in events) { var domainEvent = _messageDeserializer.DeserializeEvent(dataWithVersion.Type, dataWithVersion.Data); var convertedEvent = _converterRegistry.Convert(domainEvent); query.Enqueue(convertedEvent); } var snapshot = container.RawSnapshot is null? default : new Snapshot <TSnapshotData>(container.RawSnapshot.LastVersion, container.RawSnapshot.Raw.ToObject <TSnapshotData>()); return(new EventStream <TSnapshotData> (events.Any() ? events.Max(x => x.Version) : snapshot?.LastVersion ?? 0, snapshot, query)); }