private void InferProjectionType(ProjectionCollection projections, object instance) { var type = instance.GetType().GetTypeInfo(); if (instance is IProjection projection) { projections.Add(projection); } else if (type.GetInterfaces() .Any( z => z.GetTypeInfo().IsGenericType&& z.GetTypeInfo().GetGenericTypeDefinition() == typeof(ITransform <,>) )) { foreach (var @interface in type.GetInterfaces() .Where( z => z.GetTypeInfo().IsGenericType&& z.GetTypeInfo().GetGenericTypeDefinition() == typeof(ITransform <,>) )) { var tEvent = @interface.GetGenericArguments()[0]; var tView = @interface.GetGenericArguments()[1]; AddTransformMethod.MakeGenericMethod(tEvent, tView).Invoke(null, new[] { projections, instance }); } } else { throw new NotSupportedException( $"The project instance of type '{type.FullName}' is not a supported projection or transform." ); } }
public Treenode(Type nodetype, Treenode father, Treenode oper1, Treenode oper2, CompositeCondition cCondition, ProjectionCollection projCollection) { NodeType = nodetype; Parent = father; Operand1 = oper1; Operand2 = oper2; Condition = cCondition; ProjectionColl = projCollection; IntData = new IntermediateData(0, 0, 0, 0); }
public static void pushDown(List<ConditionElement> elements, Treenode node) { if (node.NodeType == Treenode.Type.proj) { ProjectionCollection pcollection = node.ProjectionColl; foreach (ProjectionElement pelement in pcollection) elements.Add(new ConditionElement(pelement.RelationName + '.' + pelement.Attribute)); } else if (node.NodeType == Treenode.Type.join) { AtomicCondition atcond = node.Condition[0]; elements.Add(atcond.Attribute1); elements.Add(atcond.Attribute2); } else if (node.NodeType == Treenode.Type.relation) { string relName = node.RelationName; ProjectionCollection pcollection = new ProjectionCollection(); foreach (ConditionElement celement in elements) if (relName.Equals(celement.RelationName)) pcollection.Add(new ProjectionElement(celement.RelationName, celement.Attribute)); Treenode newproj = new Treenode(Treenode.Type.proj, node.Parent, node, null, null, pcollection); if (node.Parent.NodeType == Treenode.Type.sel) { if (node.Parent.Parent.Operand1 == node.Parent) node.Parent.Parent.Operand1 = newproj; else if (node.Parent.Parent.Operand2 == node.Parent) node.Parent.Parent.Operand2 = newproj; node.Parent.Parent = newproj; newproj.Operand1 = node.Parent; } else { if (node.Parent.Operand1 == node) node.Parent.Operand1 = newproj; else if (node.Parent.Operand2 == node) node.Parent.Operand2 = newproj; node.Parent = newproj; newproj.Operand1 = node; } } if (node.Operand1 != null) pushDown(elements, node.Operand1); if (node.Operand2 != null) pushDown(elements, node.Operand2); }
private void InferProjectionType(ProjectionCollection projections, Type type) { if (typeof(IProjection).IsAssignableFrom(type)) { try { projections.Add((IProjection)Activator.CreateInstance(type) !); } catch (Exception e) { throw new InvalidOperationException( $"Could not create an instance of '{type.FullName}'. If you need to register it through Dependency Injection use the IInlineProjection or IAsyncProjection interfaces.", e ); } } else if (type.GetInterfaces() .Any( z => z.GetTypeInfo().IsGenericType&& z.GetTypeInfo().GetGenericTypeDefinition() == typeof(ITransform <,>) )) { object instance; try { instance = Activator.CreateInstance(type) !; } catch (Exception e) { throw new InvalidOperationException( $"Could not create an instance of '{type.FullName}'. If you need to register it through Dependency Injection use the IInlineProjection or IAsyncProjection interfaces.", e ); } foreach (var @interface in type.GetInterfaces() .Where( z => z.GetTypeInfo().IsGenericType&& z.GetTypeInfo().GetGenericTypeDefinition() == typeof(ITransform <,>) )) { var tEvent = @interface.GetGenericArguments()[0]; var tView = @interface.GetGenericArguments()[1]; AddTransformMethod.MakeGenericMethod(tEvent, tView).Invoke(null, new[] { projections, instance }); } } else { AddAggregateMethod.MakeGenericMethod(type).Invoke(null, new object[] { projections }); } }
public EventGraph(StoreOptions options) { Options = options; _aggregatorLookup = new AggregatorLookup(); _events.OnMissing = eventType => { var mapping = typeof(EventMapping <>).CloseAndBuildAs <EventMapping>(this, eventType); Options.Storage.AddMapping(mapping); return(mapping); }; _byEventName.OnMissing = name => { return(AllEvents().FirstOrDefault(x => x.EventTypeName == name)); }; InlineProjections = new ProjectionCollection(options); AsyncProjections = new ProjectionCollection(options); }
public EventGraph(StoreOptions options) { Options = options; _events.OnMissing = eventType => { var mapping = typeof(EventMapping <>).CloseAndBuildAs <EventMapping>(this, eventType); Options.AddMapping(mapping); return(mapping); }; _byEventName.OnMissing = name => { return(AllEvents().FirstOrDefault(x => x.EventTypeName == name)); }; SchemaObjects = new EventStoreDatabaseObjects(this); InlineProjections = new ProjectionCollection(options); AsyncProjections = new ProjectionCollection(options); }
public EventGraph(StoreOptions options) { Options = options; _events.OnMissing = eventType => { var mapping = typeof(EventMapping <>).CloseAndBuildAs <EventMapping>(this, eventType); Options.Storage.AddMapping(mapping); return(mapping); }; _byEventName.OnMissing = name => { return(AllEvents().FirstOrDefault(x => x.EventTypeName == name)); }; _inlineProjections = new Lazy <IProjection[]>(() => Projections.BuildInlineProjections(_store)); _establishTombstone = new Lazy <EstablishTombstoneStream>(() => new EstablishTombstoneStream(this)); Projections = new ProjectionCollection(options); _aggregateTypeByName = new Cache <string, Type>(name => findAggregateType(name)); }
public EventGraph(StoreOptions options) { Options = options; _aggregatorLookup = new AggregatorLookup(); _events.OnMissing = eventType => { var mapping = typeof(EventMapping <>).CloseAndBuildAs <EventMapping>(this, eventType); Options.Storage.AddMapping(mapping); return(mapping); }; _byEventName.OnMissing = name => { return(AllEvents().FirstOrDefault(x => x.EventTypeName == name)); }; InlineProjections = new ProjectionCollection(options); AsyncProjections = new ProjectionCollection(options); // TODO -- this will change when we switch all the way over to the new V4 model _inlineProjections = new Lazy <IInlineProjection[]>(() => InlineProjections.Select(x => new TemporaryV4InlineShim(x)).OfType <IInlineProjection>().ToArray()); _establishTombstone = new Lazy <EstablishTombstoneStream>(() => new EstablishTombstoneStream(this)); }
public static void AddAsyncEventHandlers(this ProjectionCollection projectionCollection, Func <Type, IEnumerable <object> > handlerFactory) { projectionCollection.Add(new EventDispatcher(handlerFactory)); }
private static void AddAggregate <T>(ProjectionCollection projections) where T : class, new() { projections.AggregateStreamsWith <T>(); }
private static void AddTransform <TEvent, TView>(ProjectionCollection projections, ITransform <TEvent, TView> transform) { projections.TransformEvents(transform); }