Exemple #1
0
        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 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.");
                }
            }
            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.");
                }

                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];
                    _AddTransform.MakeGenericMethod(tEvent, tView).Invoke(null, new[] { projections, instance });
                }
            }
            else
            {
                _AddAggregate.MakeGenericMethod(type).Invoke(null, new object[] { projections });
            }
        }
 public static void AddAsyncEventHandlers(this ProjectionCollection projectionCollection, Func <Type, IEnumerable <object> > handlerFactory)
 {
     projectionCollection.Add(new EventDispatcher(handlerFactory));
 }