/** * Adds the given projection. * * @param projection the projection to add * @return this */ public IExitOperationsCollector AddProjection(IProjection projection) { if (projection.GetType().IsAssignableFrom(distinct.GetType())) { this.distinct = (Distinct)projection; //TODO: Distinct doesn't work yet log.Error("Distinct is not ready yet"); throw new NotSupportedException(); } if (projection.GetType().IsAssignableFrom(rowCountProjection.GetType())) { rowCountProjection = (RowCountProjection)projection; } if (projection.GetType().IsAssignableFrom(aggregateProjection.GetType())) { if (projection.ToString().ToLower().StartsWith("avg")) { this.avgProjection = (AggregateProjection)projection; } else { this.aggregateProjection = (AggregateProjection)projection; } } else { log.Error("Adding an unsupported Projection: " + projection.GetType().Name); throw new NotSupportedException(); } return(this); }
/** * Adds the given projection. * * @param projection the projection to add * @return this */ public IExitOperationsCollector AddProjection(IProjection projection) { if (projection.GetType().IsAssignableFrom(distinct.GetType())) { this.distinct = (Distinct) projection; //TODO: Distinct doesn't work yet log.Error("Distinct is not ready yet"); throw new NotSupportedException(); } if (projection.GetType().IsAssignableFrom(rowCountProjection.GetType())) { rowCountProjection = (RowCountProjection) projection; } if (projection.GetType().IsAssignableFrom(aggregateProjection.GetType())) { if (projection.ToString().ToLower().StartsWith("avg")) { this.avgProjection = (AggregateProjection)projection; } else { this.aggregateProjection = (AggregateProjection)projection; } } else { log.Error("Adding an unsupported Projection: " + projection.GetType().Name); throw new NotSupportedException(); } return this; }
public IProjectionExitOperation GetProjectionExitOperation(IProjection projection, ISessionFactoryImplementor sessionFactoryImplementor) { if (projection.GetType().IsAssignableFrom(typeof(RowCountExitOperation))) { return(new RowCountExitOperation(projection)); } if (projection.GetType().IsAssignableFrom(typeof(AggregateProjection))) { return(new AggregateExitOperation(projection)); } throw new NotSupportedException("This project is not supported: " + projection.GetType()); }
public IProjectionExitOperation GetProjectionExitOperation(IProjection projection, ISessionFactoryImplementor sessionFactoryImplementor) { if (projection.GetType().IsAssignableFrom(typeof(RowCountExitOperation))) { return new RowCountExitOperation(projection); } if (projection.GetType().IsAssignableFrom(typeof(AggregateProjection))) { return new AggregateExitOperation(projection); } throw new NotSupportedException("This project is not supported: " + projection.GetType()); }
void StartProjection(IProjection projection) { var checkpoint = GetPosition(projection.GetType()); var sub = eventStoreConnection.SubscribeToAllFrom( checkpoint, new CatchUpSubscriptionSettings(500, 100, true, false), EventAppeared(projection), LiveProcessingStarted(projection), SubDropped(), userCredentials: new UserCredentials("admin", "changeit") ); Console.WriteLine("Started Projection: " + projection.GetType().Name); }
public InlineProjectionSource(IProjection projection) { _projection = projection; // TODO -- this probably gets fancier later ProjectionName = projection.GetType().FullName; }
public static IProjection <int, T> Create <T>(int countFirst, IProjection <int, T> first, IProjection <int, T> second) { var typeArgs = new[] { typeof(T), first.GetType(), second.GetType(), }; var constructorArgs = new object[] { countFirst, first, second, }; return(Instantiate <IProjection <int, T> >(typeof(SequentialProjection <, ,>), typeArgs, constructorArgs)); }
private Action <StreamSubscription, SubscriptionDroppedReason, Exception> ConnectionDropped( IProjection projection) { return((_, reason, exc) => Console.WriteLine( $"Projection {projection.GetType().Name} dropped with {reason}, Exception: {exc.Message} {exc.StackTrace}")); }
static Tuple <Type, Type> GetKey(IProjection projection) { var types = projection.GetType().GetInterfaces() .Single(i => i.Name == typeof(IProjection <,>).Name) .GetGenericArguments(); return(Tuple.Create(types[0], types[1])); }
Func <StreamSubscription, ResolvedEvent, CancellationToken, Task> EventAppeared(IProjection projection) { return(async(s, e, ct) => { Console.WriteLine( $"Handling Projection {projection.GetType().Name} event {e.Event.EventType} id: {e.Event.EventId}"); if (!projection.CanHandle(e.Event.EventType)) { return; } var deserializedEvent = e.Deserialize(); await projection.HandleAsync(e.Event.EventType, deserializedEvent, ct); await UpdatePositionAsync(projection.GetType(), e.OriginalPosition !.Value, ct); }); }
public ICriteria SetProjection(IProjection projectionValue) { criteriaCollector.AddProjection(projectionValue); if (projectionValue.GetType().IsAssignableFrom(typeof(AvgProjection))) { SetAvgProjection(projectionValue); } //TODO - handle ProjectionList return(this); }
public static Type[] GetEvents(this IProjection projection) { var type = projection.GetType(); var events = type.GetInterfaces() .Where(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IEventHandler <>)) .SelectMany(i => i.GetGenericArguments()) .ToArray(); return(events); }
void StartProjection(IProjection projection) { var checkpoint = GetPosition(projection.GetType()); _eventStoreConnection.SubscribeToAllFrom( checkpoint, CatchUpSubscriptionSettings.Default, EventAppeared(projection), LiveProcessingStarted(projection)); }
/// <summary> /// Initializes a new instance of the <see cref="BaseDataColumn{T}" /> /// class. /// </summary> /// <param name="configuration"> /// The configuration of this column. /// </param> /// <param name="projection"> /// The projection that projects the data in the column. /// </param> /// <exception cref="System.ArgumentNullException"> /// <paramref name="configuration"/> is <c>null</c>. /// - or - /// <paramref name="projection"/> is <c>null</c>. /// </exception> public BaseDataColumn( ColumnConfiguration configuration, IProjection <int, T> projection) { Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(projection, nameof(projection)); this.Configuration = configuration; this.ProjectorInterface = projection.GetType(); this.Projector = projection; }
public static IProjection <int, T> CreateFromOffset <T>(IProjection <int, T> projection, int offset) { if (!(projection is IMapListToStream)) { throw new InvalidOperationException("The projection being based in must have been constructed using SequentialColumn.CreateComputedColumn"); } var typeArgs = new[] { typeof(T), projection.GetType(), }; var constructorArgs = new object[] { projection, offset, }; return(Instantiate <IProjection <int, T> >(typeof(SequentialProjectionFromOffset <,>), typeArgs, constructorArgs)); }
Action <EventStoreCatchUpSubscription, ResolvedEvent> EventAppeared(IProjection projection) { return((s, e) => { if (!projection.CanHandle(e.Event.EventType)) { UpdatePosition(projection.GetType(), e.OriginalPosition.Value); return; } Console.WriteLine("Processing"); Console.WriteLine(e.Event.EventStreamId); Console.WriteLine(e.Event.EventNumber); Console.WriteLine(e.Event.EventType); var deserializedEvent = e.Deserialize(); projection.Handle(e.Event.EventType, deserializedEvent); UpdatePosition(projection.GetType(), e.OriginalPosition.Value); }); }
public static string CalculateMD5(IProjection projection) { var typeSource = projection as ITrackStructureChanges; var dtoTypes = (typeSource == null) ? new Type[0] : typeSource.TrackTypes; var hashSource = new StringBuilder(100); AddTypeHash(projection.GetType(), hashSource); hashSource.Append(dtoTypes.Length); foreach (var type in dtoTypes.OrderBy(x => x.Name).ToList()) AddTypeHash(type, hashSource); return ToMD5(hashSource.ToString()); }
Action <EventStoreCatchUpSubscription, ResolvedEvent> EventAppeared(IProjection projection) { return((s, e) => { if (!projection.CanHandle(e.Event.EventType)) { return; } var deserializedEvent = e.Deserialize(); projection.Handle(e.Event.EventType, deserializedEvent); UpdatePosition(projection.GetType(), e.OriginalPosition.Value); }); }
public static string CalculateMD5(IProjection projection) { var typeSource = projection as ITrackStructureChanges; var dtoTypes = (typeSource == null) ? new Type[0] : typeSource.TrackTypes; var hashSource = new StringBuilder(100); AddTypeHash(projection.GetType(), hashSource); hashSource.Append(dtoTypes.Length); foreach (var type in dtoTypes.OrderBy(x => x.Name).ToList()) { AddTypeHash(type, hashSource); } return(ToMD5(hashSource.ToString())); }
/// <summary> /// Creates a projection that returns the TimestampDelta in nanoseconds as a <see cref="double"/>. /// </summary> /// <param name="column"> /// Projection that returns a <see cref="TimestampDelta"/>. /// </param> /// <returns> /// Projection that returns a nanosecond count as a double. /// </returns> public static IProjection <int, double> Create(IProjection <int, TimestampDelta> column) { Guard.NotNull(column, nameof(column)); var typeArgs = new[] { column.GetType(), }; var constructorArgs = new object[] { column, }; var type = typeof(TimestampDeltaToDoubleColumnGenerator <>).MakeGenericType(typeArgs); var instance = Activator.CreateInstance(type, constructorArgs); return((IProjection <int, double>)instance); }
private static void AddProjectionEvents(IDictionary <Type, List <IProjection> > projectionsByEventType, IProjection projection) { var interfaces = projection.GetType().GetInterfaces().Where(x => x.Name == typeof(IEventListener <>).Name); foreach (var @interface in interfaces) { var eventType = @interface.GetGenericArguments()[0]; if (projectionsByEventType.TryGetValue(eventType, out var projections)) { projections.Add(projection); } else { projectionsByEventType.Add(eventType, new List <IProjection> { projection }); } } }
public static IProjection <int, TimeRange> CreatePercent(IProjection <int, TimeRange> timeRangeColumn) { Guard.NotNull(timeRangeColumn, nameof(timeRangeColumn)); var typeArgs = new[] { timeRangeColumn.GetType(), }; var constructorArgs = new object[] { timeRangeColumn, }; var type = typeof(ClipTimeToViewportTimeRangePercentColumnGenerator <>).MakeGenericType(typeArgs); var instance = Activator.CreateInstance(type, constructorArgs); return((IProjection <int, TimeRange>)instance); }
public virtual ReplayDefinition UseProjection(IProjection projection) { var contractId = projection.GetType().GetContractId(); // Ignore using projections which are not registered var projectionWithEvents = registeredProjections.FirstOrDefault(x => x.Projection.GetType().GetContractId() == contractId); if (ReferenceEquals(null, projectionWithEvents) == true) { return(this); } // Ignore adding projections that are already added if (availableForReplayProjections.Any(x => x.Projection.GetType().GetContractId() == contractId) == true) { return(this); } availableForReplayProjections.Add(projectionWithEvents); return(this); }
/// <summary> /// Creates a projector that results in a dividing the value of the numerator projection /// by the value of the denominator projection. /// </summary> /// <param name="numeratorColumn"> /// Numerator projection. /// </param> /// <param name="divisorColumn"> /// Denominator projection. /// </param> /// <returns> /// Projection of the computed division. /// </returns> public static IProjection <int, double> Create( IProjection <int, double> numeratorColumn, IProjection <int, double> divisorColumn) { Guard.NotNull(numeratorColumn, nameof(numeratorColumn)); Guard.NotNull(divisorColumn, nameof(divisorColumn)); var typeArgs = new[] { numeratorColumn.GetType(), divisorColumn.GetType(), }; var constructorArgs = new object[] { numeratorColumn, divisorColumn, }; var type = typeof(PercentGenerator <,>).MakeGenericType(typeArgs); var instance = Activator.CreateInstance(type, constructorArgs); return((IProjection <int, double>)instance); }
async Task StartProjectionAsync(IProjection projection, CancellationToken ct) { var checkpoint = await GetPositionAsync(projection.GetType(), ct); if (checkpoint.HasValue) { await _eventStore.SubscribeToAllAsync( checkpoint.Value, EventAppeared(projection), false, ConnectionDropped(projection) !, cancellationToken : ct ); } else { await _eventStore.SubscribeToAllAsync( EventAppeared(projection), false, ConnectionDropped(projection) !, cancellationToken : ct ); } }
Action <EventStoreCatchUpSubscription> LiveProcessingStarted(IProjection projection) { return(s => Console.WriteLine($"Projection {projection.GetType().Name} has caught up, now processing live")); }
public static Type ProjectedType(this IProjection projection) { return((projection as IDocumentProjection)?.Produces ?? projection.GetType()); }
private static string GetName(IProjection projection) { return projection.GetType().FullName; }
public string GetModifiedReason(IProjection projection) { return(modifiedReasons[projection.GetType()]); }
public ProjectionWrapper(IProjection projection, ProjectionLifecycle lifecycle) : base(projection.GetType().FullNameInCode()) { _projection = projection; Lifecycle = lifecycle; }
private static string GetName(IProjection projection) { return(projection.GetType().FullName); }
public void MarkAsUnmodified(IProjection projection) { modifiedReasons[projection.GetType()] = string.Empty; }