public static ItemWithType ToItemWithType(this ResolvedEvent resolvedEvent, ICreateStateInstances stateFactory) { var serializedEvent = System.Text.Encoding.UTF8.GetString(resolvedEvent.Event.Data); Type type = ReadTypeFromMetadata(resolvedEvent); object @event; if (type.IsInterface) { @event = stateFactory.GetState(type); var switchable = @event as ICanSwitchBackAndToReadOnly; if (switchable != null) { switchable.CanEdit = true; } JsonConvert.PopulateObject(serializedEvent, @event); if (switchable != null) { switchable.CanEdit = false; } } else { @event = JsonConvert.DeserializeObject(serializedEvent, type); } return(new ItemWithType(@event, type)); }
public static StoredEvent ToStoredEvent(this EventRecord resolvedEvent, ICreateStateInstances stateFactory) { var serializedEvent = System.Text.Encoding.UTF8 .GetString(resolvedEvent.Data.Span); var(metadata, type) = ReadTypeFromMetadata(resolvedEvent); object @event; if (type.IsInterface) { @event = stateFactory.GetState(type); var switchable = @event as ICanSwitchBackAndToReadOnly; if (switchable != null) { switchable.CanEdit = true; } JsonConvert.PopulateObject(serializedEvent, @event); if (switchable != null) { switchable.CanEdit = false; } } else { @event = JsonConvert.DeserializeObject(serializedEvent, type); } return(new StoredEvent(@event, type, resolvedEvent.EventStreamId, metadata, resolvedEvent.EventNumber.ToInt64())); }
private static StoredEvent ToStoredEvent(string streamId, long eventNumber, ReadOnlyMemory <byte> data, ReadOnlyMemory <byte> meta, string eventType, ICreateStateInstances stateFactory) { var serializedEvent = System.Text.Encoding.UTF8.GetString(data.Span); var(metadata, type) = ReadTypeFromMetadata(eventType, meta); object @event; if (type.IsInterface) { @event = stateFactory.GetState(type); var switchable = @event as ICanSwitchBackAndToReadOnly; if (switchable != null) { switchable.CanEdit = true; } JsonConvert.PopulateObject(serializedEvent, @event); if (switchable != null) { switchable.CanEdit = false; } } else { @event = JsonConvert.DeserializeObject(serializedEvent, type); } return(new StoredEvent(@event, type, streamId, metadata, Convert.ToInt64(eventNumber))); }
public static StoredEvent ToStoredEvent(this RecordedEvent resolvedEvent, ICreateStateInstances stateFactory) => ToStoredEvent( resolvedEvent.EventStreamId, resolvedEvent.EventNumber, resolvedEvent.Data, resolvedEvent.Metadata, resolvedEvent.EventType, stateFactory );
IConfigureThreadSafety IConfigureStateFactory.WithStateFactory(ICreateStateInstances stateFactory) { StateFactory = stateFactory; return(this); }
public TcpEventReader(IEventStoreConnection client, IHoldAllConfiguration configuration, int pageSize = 4096) { stateFactory = configuration?.StateFactory ?? throw new ArgumentNullException(nameof(configuration)); this.connection = client ?? throw new ArgumentNullException(nameof(client)); this.pageSize = pageSize; }
public EventReader(IEventStoreConnection connection, IHoldAllConfiguration configuration) { stateFactory = configuration?.StateFactory ?? throw new ArgumentNullException(nameof(configuration)); eventStoreConnection = connection ?? throw new ArgumentNullException(nameof(connection)); }
public EventReader(EventStoreClient client, IHoldAllConfiguration configuration) { stateFactory = configuration?.StateFactory ?? throw new ArgumentNullException(nameof(configuration)); this.client = client ?? throw new ArgumentNullException(nameof(client)); }