示例#1
0
        public void TestMapExpression()
        {
            Dictionary       test     = CreateDictionary("Test");
            NameSpace        n1       = CreateNameSpace(test, "N1");
            Structure        s1       = CreateStructure(n1, "S1");
            StructureElement el1      = CreateStructureElement(s1, "E1", "Boolean");
            Structure        s2       = CreateStructure(n1, "S2");
            StructureElement el2      = CreateStructureElement(s2, "E2", "S1");
            Function         function = CreateFunction(n1, "f", "S1");

            Collection collection = CreateCollection(n1, "Col", "S1", 10);
            Variable   v          = CreateVariable(n1, "V", "Col");

            Compiler.Compile_Synchronous(true, true);

            RuleCondition rc     = CreateRuleAndCondition(n1, "Rule1");
            Parser        parser = new Parser();

            {
                MapExpression expression = parser.Expression(rc, "MAP V | X. USING X IN X.E2", null, true, null, true, true) as MapExpression;
                Assert.IsNotNull(expression);

                DerefExpression deref = expression.Condition as DerefExpression;
                Assert.IsNotNull(deref);

                ITypedElement element = deref.Arguments[0].Ref as ITypedElement;
                Assert.IsNotNull(element);
                Assert.AreEqual(element.Type, s1);
            }
        }
示例#2
0
 /// <summary>
 ///     Visits a MAP expression
 /// </summary>
 /// <param name="mapExpression"></param>
 protected virtual void VisitMapExpression(MapExpression mapExpression)
 {
     if (mapExpression != null)
     {
         VisitExpressionBasedListExpression(mapExpression);
     }
 }
        private ResultSetBuilder VisitCall(MapExpression m)
        {
            var result = Visit(m.Body);

            result.ApplyMap(m.Columns);
            return(result);
        }
示例#4
0
 public StronkConfig()
 {
     From     = new SourceExpression(this);
     Write    = new WriterExpression(this);
     Map      = new MapExpression(this);
     Convert  = new ConversionExpression(this);
     Validate = new ValidationExpression(this);
     Log      = new LogExpression(this);
 }
        public void TestMapExpression()
        {
            Dictionary       test     = CreateDictionary("Test");
            NameSpace        n1       = CreateNameSpace(test, "N1");
            Structure        s1       = CreateStructure(n1, "S1");
            StructureElement el1      = CreateStructureElement(s1, "E1", "Boolean");
            Structure        s2       = CreateStructure(n1, "S2");
            StructureElement el2      = CreateStructureElement(s2, "E2", "S1");
            Function         function = CreateFunction(n1, "f", "S1");

            Collection collection = CreateCollection(n1, "Col", "S1", 10);
            Variable   v          = CreateVariable(n1, "V", "Col");

            Compiler.Compile_Synchronous(true, true);

            RuleCondition rc     = CreateRuleAndCondition(n1, "Rule1");
            Parser        parser = new Parser();

            {
                //                   0         1         2
                //                   012345678901234567890123456
                const string  text       = "MAP V | X. USING X IN X.E1";
                MapExpression expression = parser.Expression(rc, text, null, true, null, true, true) as MapExpression;
                Assert.IsNotNull(expression);
                ContextGrabber grabber = new ContextGrabber();
                Assert.IsNull(grabber.GetContext(0, expression));
                Assert.IsNull(grabber.GetContext(1, expression));
                Assert.IsNull(grabber.GetContext(2, expression));
                Assert.IsNull(grabber.GetContext(3, expression));
                Assert.AreEqual(v, grabber.GetContext(4, expression));
                Assert.AreEqual(v, grabber.GetContext(5, expression));
                Assert.IsNull(grabber.GetContext(6, expression));
                Assert.IsNull(grabber.GetContext(7, expression));
                Assert.AreEqual(expression.IteratorVariable, grabber.GetContext(8, expression));
                Assert.AreEqual(expression.IteratorVariable, grabber.GetContext(9, expression));
                Assert.IsNull(grabber.GetContext(10, expression));
                Assert.IsNull(grabber.GetContext(11, expression));
                Assert.IsNull(grabber.GetContext(12, expression));
                Assert.IsNull(grabber.GetContext(13, expression));
                Assert.IsNull(grabber.GetContext(14, expression));
                Assert.IsNull(grabber.GetContext(15, expression));
                Assert.IsNull(grabber.GetContext(16, expression));
                Assert.IsNull(grabber.GetContext(17, expression));
                Assert.IsNull(grabber.GetContext(18, expression));
                Assert.IsNull(grabber.GetContext(19, expression));
                Assert.IsNull(grabber.GetContext(20, expression));
                Assert.IsNull(grabber.GetContext(21, expression));
                Assert.AreEqual(expression.IteratorVariable, grabber.GetContext(22, expression));
                Assert.AreEqual(expression.IteratorVariable, grabber.GetContext(23, expression));
                Assert.AreEqual(el1, grabber.GetContext(24, expression));
                Assert.AreEqual(el1, grabber.GetContext(25, expression));
                Assert.AreEqual(el1, grabber.GetContext(26, expression));
                Assert.IsNull(grabber.GetContext(27, expression));
            }
        }
示例#6
0
        public void Accept(IModelMapVisitor modelMapVisitor)
        {
            modelMapVisitor.Visit(new BeginModelMap {
                ModelType = typeof(MODEL)
            });

            _mapExpression = new MapExpression <MODEL>(modelMapVisitor);

            MapDefinition();

            modelMapVisitor.Visit(new EndModelMap());
        }
        private void SetModelMappings(IMapper mapper)
        {
            if (typeof(TEntity) == typeof(TDto) || mapper == null)
            {
                return;
            }

            var map = mapper.ConfigurationProvider?.FindTypeMapFor <TEntity, TDto>();

            if (map == null)
            {
                return;
            }

            this._mappings = new Dictionary <string, MapExpression <TEntity> >();

            // Custom expressions because they do not map field to field
            foreach (var propertyMap in map.PropertyMaps.Where(pm => pm.CustomMapExpression == null))
            {
                if (propertyMap.CustomMapExpression != null)
                {
                    // Get the linq expression body
                    string body = propertyMap.CustomMapExpression.Body.ToString();

                    // Get the item tag
                    string tag = propertyMap.CustomMapExpression.Parameters[0].Name;

                    string destination = body.Replace($"{tag}.", string.Empty);
                    string source      = propertyMap.DestinationName /*.ToLower()*/;

                    var customExpression = new MapExpression <TEntity>
                    {
                        Path       = destination,
                        Expression = propertyMap.CustomMapExpression.ToTypedExpression <TEntity>()
                    };

                    if (!_mappings.ContainsKey(source))
                    {
                        _mappings.Add(source, customExpression);
                    }
                }
            }

            foreach (var propertyMap in map.PropertyMaps.Where(pm => pm.CustomMapExpression == null))
            {
                // TODO
                // Automatic Automapper mapping (eg: Department.Name -> DepartmentName)
            }
        }
        public void Convert()
        {
            var expected = new B[]
            {
                new B {
                    Context = int.MinValue,
                    Name    = "Mapped",
                    Value   = int.MaxValue
                }
            };

            var actual = new []
            {
                new A {
                    Context = int.MinValue,
                    Name    = "Mapped",
                    Value   = int.MaxValue
                }
            };

            var context = new object();

            var mapperProviderMock = new Mock <IMapperProvider>();

            mapperProviderMock
            .Setup(a => a.MapArray(It.IsAny <IEnumerable <A> >(), typeof(A), typeof(B)))
            .Returns(expected)
            .Verifiable();
            var result = MapExpression.Convert <MyContainer <A>, MyContainer <B> >(new MyContainer <A>
            {
                Context = context,
                Value   = 12345,
                Name    = "Axe",
                Result  = actual
            }, () => mapperProviderMock.Object);

            mapperProviderMock.Verify(a => a.MapArray(It.IsAny <IEnumerable <A> >(), typeof(A), typeof(B)), Times.Once);

            Assert.Equal("Axe", result.Name);
            Assert.Equal(12345, result.Value);
            Assert.Equal(context, result.Context);
            Assert.Same(expected, result.Result);
        }
示例#9
0
 public static StronkConfig PropertyNames(this MapExpression self)
 {
     return(self.With(new PropertyNamePropertyMapper()));
 }
示例#10
0
 public TDestination Map(TSource source)
 {
     return(MapExpression.Compile()(source));
 }
示例#11
0
        public override QlExpression VisitSelect_core(QlParser.Select_coreContext context)
        {
            QlExpression take      = null;
            QlToken      takeToken = null;
            QlExpression skip      = null;
            QlToken      skipToken = null;
            List <ColumnNameExpression> columns = null;

            for (int i = 0; i < context.ChildCount; i++)
            {
                var child    = context.GetChild(i);
                var terminal = child as TerminalNodeImpl;
                if (terminal != null)
                {
                    if (string.Equals(terminal.GetText(), KEYWORD_TOP, StringComparison.OrdinalIgnoreCase))
                    {
                        if (i < context.ChildCount - 1)
                        {
                            takeToken = context.ToQlToken();
                            take      = Visit(context.GetChild(++i));
                        }
                    }
                    if (string.Equals(terminal.GetText(), KEYWORD_SKIP, StringComparison.OrdinalIgnoreCase))
                    {
                        if (i < context.ChildCount - 1)
                        {
                            skipToken = context.ToQlToken();
                            skip      = Visit(context.GetChild(++i));
                        }
                    }
                }
                var col = child as QlParser.Result_columnContext;
                if (col != null)
                {
                    var column = (ColumnNameExpression)Visit(col);
                    if (column != null)
                    {
                        if (columns == null)
                        {
                            columns = new List <ColumnNameExpression>();
                        }
                        columns.Add(column);
                    }
                }
            }

            var result = Visit(context.GetRuleContext <QlParser.Table_or_subqueryContext>(0));

            var expWhere = context.GetRuleContext <QlParser.Where_exprContext>(0);

            if (expWhere != null)
            {
                result = new FilterExpression(Visit(expWhere), result, context.ToQlToken());
            }
            if (columns != null)
            {
                result = new MapExpression(result, columns,
                                           new QlToken(string.Join(",", columns.Select(c => c.ParseToken.Text)),
                                                       columns.Min(c => c.ParseToken.Line), columns.Min(c => c.ParseToken.Position)));
            }
            if (skip != null)
            {
                result = new SliceExpression(result, EJournalExpressionType.Skip, skip, skipToken);
            }
            if (take != null)
            {
                result = new SliceExpression(result, EJournalExpressionType.Take, take, takeToken);
            }
            return(result);
        }
示例#12
0
 public Properties(MapExpression members)
 {
     Members = members;
 }