public static IProjectionAttribute ValList(this IProjection projection, Func <IProjectionAttribute, IProjectionAttribute> itemFactory) { if (projection.Data == null) { throw ProjectionException.ValueNotFound(projection.Metadata); } IProjectionMetadata itemMetadata = projection.Metadata?.Item ?? projection.Metadata; using ProjectionReader reader = new ProjectionReader(projection.Data.Source, new[] { itemMetadata }); IProjectionAttribute attribute = new ProjectionAttribute(projection.Identity, projection.Context, itemMetadata, data: null); if (reader.Read()) { IProjectionData data = reader.GetData().First(); attribute = itemFactory(attribute.With(data: data)); } while (reader.Read()) { IProjectionData data = reader.GetData().First(); attribute = attribute.Append(", "); attribute = itemFactory(attribute.With(data: data)); } return(attribute); }
/// <summary> /// Create the projection from the attribute linked to the function parameter /// </summary> /// <param name="attribute"> /// The attribute describing which projection to run /// </param> public Projection(ProjectionAttribute attribute, string connectionStringName = "") { _domainName = attribute.DomainName; _aggregateTypeName = attribute.AggregateTypeName; _aggregateInstanceKey = attribute.InstanceKey; _projectionTypeName = attribute.ProjectionTypeName; if (string.IsNullOrWhiteSpace(connectionStringName)) { _connectionStringName = ConnectionStringNameAttribute.DefaultConnectionStringName(attribute); } else { _connectionStringName = connectionStringName; } if (null == _projectionProcessor) { // TODO : Allow for different backing technologies... currently just AppendBlob _projectionProcessor = CQRSAzure.EventSourcing.Azure.Blob.Untyped.BlobEventStreamReaderUntyped.CreateProjectionProcessor(attribute, ConnectionStringNameAttribute.DefaultBlobStreamSettings(_domainName, _aggregateTypeName)); } }
public Task <IBinding> TryCreateAsync(BindingProviderContext context) { if (context == null) { throw new ArgumentNullException("context"); } // Determine whether we should bind to the current parameter ParameterInfo parameter = context.Parameter; ProjectionAttribute attribute = parameter.GetCustomAttribute <ProjectionAttribute>(inherit: false); if (attribute == null) { return(Task.FromResult <IBinding>(null)); } // What data type(s) can this attribute be attached to? IEnumerable <Type> supportedTypes = new Type[] { typeof(Projection) }; if (!(parameter.ParameterType == typeof(Projection))) { throw new InvalidOperationException( $"Can't bind ProjectionAttribute to type '{parameter.ParameterType}'."); } return(Task.FromResult <IBinding>(new ProjectionAttributeBinding(parameter))); }
public static Task <Projection> BuildProjectionFromAttribute(ProjectionAttribute attribute, ValueBindingContext context) { // If possible get the connection string to use // Use this and the attribute to create a new classifier instance return(Task <Projection> .FromResult(new Projection(attribute))); }
/// <summary> /// Create a projection processor to run over the given event stream's backing store /// </summary> public IProjectionProcessor CreateProjectionProcessorForEventStream(ProjectionAttribute attribute) { string connectionStringName = GetConnectionStringName(attribute); if (GetBackingImplementationType(attribute).Equals(EventStreamSetting.EVENTSTREAMIMPLEMENTATIOIN_TABLE, StringComparison.OrdinalIgnoreCase)) { return(TableEventStreamReader.CreateProjectionProcessor(attribute, connectionStringName: connectionStringName)); } // Default to AppendBlob return(BlobEventStreamReader.CreateProjectionProcessor(attribute, connectionStringName)); }
/// <summary> /// Create the projection from the attribute linked to the function parameter /// </summary> /// <param name="attribute"> /// The attribute describing which projection to run /// </param> public Projection(ProjectionAttribute attribute, IEventStreamSettings settings = null, INotificationDispatcher dispatcher = null, IProjectionSnapshotReader snapshotReader = null, IProjectionSnapshotWriter snapshotWriter = null) { _domainName = attribute.DomainName; _entityTypeName = attribute.EntityTypeName; _instanceKey = attribute.InstanceKey; _projectionTypeName = attribute.ProjectionTypeName; if (null == settings) { _settings = new EventStreamSettings(); } else { _settings = settings; } _connectionStringName = _settings.GetConnectionStringName(attribute); if (null == _projectionProcessor) { _projectionProcessor = _settings.CreateProjectionProcessorForEventStream(attribute); } if (null == dispatcher) { // Create a new dispatcher _notificationDispatcher = NotificationDispatcherFactory.NotificationDispatcher; } else { _notificationDispatcher = dispatcher; } if (null != snapshotReader) { _snapshotReader = snapshotReader; } if (null != snapshotWriter) { _snapshortWriter = snapshotWriter; } }
public async Task <object> GetValueAsync() { object item = null; await ValidateParameter(_parameter); if (null != _parameter) { ProjectionAttribute attribute = _parameter.GetCustomAttribute <ProjectionAttribute>(inherit: false); if (null != attribute) { item = new Projection(attribute); } } return(item); }