private void parse(ModelMap map, XDocument document, ModelMapCompilationReport report) { var root = document.Root; var context = new ParsingContext(_services, report); map.AddInstruction(new BeginModelMap(map.Name)); context.PushObject(map); root .Elements() .Each(_ => _elementService.Visit(_, map, context)); context.PopObject(); map.AddInstruction(new EndModelMap()); }
public void Visit(XElement element, ModelMap map, ParsingContext context) { var instruction = context.Serializer.Deserialize <BeginTransform>(element); map.AddInstruction(instruction); context.PushObject(instruction); }
public void ChildrenBound(ModelMap map, ParsingContext context) { var query = context.CurrentObject <IQueryContext>(); var instruction = query is BeginView ? (IModelMapInstruction) new EndView() : new EndTable(); map.AddInstruction(instruction); context.PopObject(); }
public void Visit(XElement element, ModelMap map, ParsingContext context) { var relationshipDef = context.Serializer.Deserialize <RelationshipDef>(element); if (relationshipDef.IsAdhoc) { map.AddInstruction(new BeginAdHocRelation { FromTableField = relationshipDef.Field, ToTableFieldName = relationshipDef.TargetField, ToTableName = relationshipDef.Table, Key = relationshipDef.Key }); return; } map.AddInstruction(new BeginRelation { RelationName = relationshipDef.Name, Key = relationshipDef.Key }); }
public void Visit(XElement element, ModelMap map, ParsingContext context) { var instruction = context.Serializer.Deserialize <IncludePartial>(element); foreach (var attribute in element.Attributes().Where(_ => !_.Name.ToString().EqualsIgnoreCase("name"))) { instruction.Attributes.Add(attribute.Name.ToString(), new DynamicValue(attribute.Value)); } map.AddInstruction(instruction); }
public void Visit(XElement element, ModelMap map, ParsingContext context) { var query = context.Serializer.Deserialize <QueryElement>(element); var queryContext = query.Type == "view" ? (IModelMapInstruction) new BeginView(query.From) : new BeginTable(query.From); map.AddInstruction(queryContext); context.PushObject(queryContext); }
public void Visit(XElement element, ModelMap map, ParsingContext context) { var registry = context.Service <IFilterPolicyRegistry>(); var policyType = registry.FindPolicy(element.Name.ToString()); var builder = context.Service <IObjectBuilder>(); var values = new Dictionary <string, string>(element .Attributes() .ToDictionary(_ => _.Name.ToString(), _ => context.Serializer.ValueFor(_).ToString())); var result = builder.Build(new BuildObjectContext(policyType, values)); if (result.HasErrors()) { var missingAttributes = result.Errors.Select(_ => _.Key); throw new ModelMapException("The {0} attribute(s) must be specified on the {1} element".ToFormat(missingAttributes.Join(","), element.Name)); } var policy = result.Result.As <IFilterPolicy>(); map.AddInstruction(new Instructions.AddFilter(policy.CreateFilter())); }
public void Visit(XElement element, ModelMap map, ParsingContext context) { var instruction = context.Serializer.Deserialize <Instructions.AddTag>(element); map.AddInstruction(instruction); }
public void Visit(XElement element, ModelMap map, ParsingContext context) { var prop = context.Serializer.Deserialize <Instructions.RemoveMappedCollection>(element); map.AddInstruction(prop); }
public void ChildrenBound(ModelMap map, ParsingContext context) { map.AddInstruction(new EndRelation()); }
public void ChildrenBound(ModelMap map, ParsingContext context) { map.AddInstruction(new EndMappedProperty()); }
public void Visit(XElement element, ModelMap map, ParsingContext context) { var prop = context.Serializer.Deserialize <BeginMappedProperty>(element); map.AddInstruction(prop); }
public void ChildrenBound(ModelMap map, ParsingContext context) { context.PopObject(); map.AddInstruction(new EndTransform()); }
public void expands_the_partial() { var model = new ModelMap("case", "case"); model.AddInstruction(new BeginProperty { Key = new PassThruValue("caseId") }); model.AddInstruction(new EndProperty()); model.AddInstruction(new BeginRelation()); model.AddInstruction(new IncludePartial { Name = "sitePartial", Attributes = new Dictionary <string, IDynamicValue> { { "propertyName", new PassThruValue("siteId") } } }); model.AddInstruction(new IncludePartial { Name = "reusablePartial", Attributes = new Dictionary <string, IDynamicValue> { { "propertyName", new PassThruValue("myProperty") } } }); model.AddInstruction(new EndRelation()); model.AddInstruction(new BeginRelation()); model.AddInstruction(new IncludePartial { Name = "addressPartial" }); model.AddInstruction(new EndRelation()); var p1 = new ModelMap("reusablePartial", null); p1.AddInstruction(new BeginProperty { Key = new PassThruValue("${propertyName}") }); p1.AddInstruction(new EndProperty()); var p2 = new ModelMap("sitePartial", null); p2.AddInstruction(new BeginProperty { Key = new PassThruValue("${propertyName}") }); p2.AddInstruction(new EndProperty()); p2.AddInstruction(new IncludePartial { Name = "reusablePartial", Attributes = new Dictionary <string, IDynamicValue> { { "propertyName", new PassThruValue("myOtherProperty") } } }); var p3 = new ModelMap("addressPartial", null); p3.AddInstruction(new BeginProperty { Key = new PassThruValue("addressId") }); p3.AddInstruction(new EndProperty()); var cache = new StubModelMapCache(); cache.ThePartials.Add(p1); cache.ThePartials.Add(p2); cache.ThePartials.Add(p3); model.As <IExpandableMap>().Expand(cache); var instructions = new List <IModelMapInstruction>(); var visitor = new RecordingVisitor(instructions); model.Accept(visitor); VerifyInstructions.Assert(instructions, _ => { _.Verify <BeginProperty>(__ => __.Key.ToString().ShouldEqual("caseId")); _.Is <EndProperty>(); _.Is <BeginRelation>(); // sitePartial _.Verify <PushVariableContext>(__ => __.Attributes["propertyName"].ToString().ShouldEqual("siteId")); _.Verify <BeginProperty>(__ => __.Key.ToString().ShouldEqual("${propertyName}")); _.Is <EndProperty>(); // sitePartial => reusablePartial _.Verify <PushVariableContext>(__ => __.Attributes["propertyName"].ToString().ShouldEqual("myOtherProperty")); _.Verify <BeginProperty>(__ => __.Key.ToString().ShouldEqual("${propertyName}")); _.Is <EndProperty>(); _.Is <PopVariableContext>(); _.Is <PopVariableContext>(); //end sitePartial // reusablePartial _.Verify <PushVariableContext>(__ => __.Attributes["propertyName"].ToString().ShouldEqual("myProperty")); _.Verify <BeginProperty>(__ => __.Key.ToString().ShouldEqual("${propertyName}")); _.Is <EndProperty>(); _.Is <PopVariableContext>(); //end reusablePartial _.Is <EndRelation>(); _.Is <BeginRelation>(); // addressPartial _.Is <PushVariableContext>(); _.Verify <BeginProperty>(__ => __.Key.ToString().ShouldEqual("addressId")); _.Is <EndProperty>(); _.Is <PopVariableContext>(); //end addressPartial _.Is <EndRelation>(); }); }