Esempio n. 1
0
        private ProjectionElement CreateElement(XmlSchemaElement element)
        {
            ProjectionElement newElement;
            var nmspc = element.QualifiedName.Namespace;
            var name = element.QualifiedName.Name;
            var schemeType = GetResourceElementType(element);
            Type currentResourceType = null;
            if (schemeType!=null)
            {
               
                newElement = new ResourceProjectionElement
                                 {
                                     Name = name,
                                     Namespace = nmspc,
                                     ResourceType = schemeType,
                                     SchemeType = schemeType
                                 };
                currentResourceType = _innerCachier.GetTypeByName(schemeType);
            }
            else
            {
                newElement = new ProjectionElement
                {
                    Name = name,
                    Namespace = nmspc
                };
            }
            if (_projectionResources.ContainsKey(nmspc) && _projectionResources[nmspc].ContainsKey(name))
                newElement.PropertyFiller = _projectionResources[nmspc][name];
            newElement.FillingInfo = new FillingInfo();
            foreach(var property in (element.ElementSchemaType as XmlSchemaComplexType)
                .AttributeUses
                .Values
                .OfType<XmlSchemaAttribute>()
                .Where(k=>k.QualifiedName.Namespace != QueryStorage.QuerySpace)
                .Select(k => k.QualifiedName.Name))
            {
                if (currentResourceType != null
                && (currentResourceType.GetProperty(property) != null
                 || currentResourceType.GetField(property) != null))
                    newElement.FillingInfo.Add(property,FillingInfo.FillType.Native);
                else
                {
                    newElement.FillingInfo.Add(property, FillingInfo.FillType.ByFiller);
                }
            }

            if (element.ElementSchemaType.Name != null)
            {
                Debug.Assert(FindElement(element) == null);
                _globalElements.Add(newElement);
            }
            return newElement;
        }
        public void RecursiveCommendationTest()
        {
           

            var sElement = new ResourceProjectionElement
                               {
                                   Name = "Attribute",
                                   FillingInfo = new FillingInfo {{"Name", FillingInfo.FillType.Native}},
                                   ResourceType = "Attribute",
                                   Namespace = "Test"
                               };
            var sGroup = new ResourceProjectionElement
                             {
                                 Name = "Element",
                                 FillingInfo = new FillingInfo {{"Name", FillingInfo.FillType.Native}},
                                 ResourceType = "Element",
                                 Namespace = "Test",
                             };

            var gToGRelation = new Relation {ChildElement = sGroup, ParentElement = sGroup};
            var eFromEQuery = Query.CreateTestStubQuery(null,null,"element");
            gToGRelation.Queries = new[] {eFromEQuery};
            sGroup.UpRelations.Add(gToGRelation);
            sGroup.DownRelations.Add(gToGRelation);

            var eToGRelation = new Relation {ChildElement = sElement, ParentElement = sGroup};
            var aFromEQuery = Query.CreateTestStubQuery(null,null,"element");
            eToGRelation.Queries = new[] {aFromEQuery};
            sElement.UpRelations.Add(eToGRelation);
            sGroup.DownRelations.Add(eToGRelation);

            var cc = new CommendationCollection();
           
            var acc = GetAccumulator(gToGRelation, eFromEQuery);
            cc.AddNewStep(new PlanStep(sGroup, sGroup, new ParameterNames(), acc, new ParameterNames(), 0));
            acc = GetAccumulator(eToGRelation, aFromEQuery);
            cc.AddNewStep(new PlanStep(sGroup, sElement, new ParameterNames(), acc, new ParameterNames(), 0));

            var root = new FrameNodeGroup(sGroup,
                                          new[] {new FrameNode(Guid.Empty, sGroup, 0, new Dictionary<string, object>())},
                                          new ParameterNames());
            var nodes = cc.GetNewGroups(new[] {root});
            Assert.AreEqual(2,nodes.Count());
            nodes = cc.GetNewGroups(nodes);
            Assert.AreEqual(2, nodes.Count());
            nodes = cc.GetNewGroups(nodes);
            Assert.AreEqual(2, nodes.Count());
        }
Esempio n. 3
0
        public void SimplePlan1()
        {
           
            var sAttr = new ResourceProjectionElement
            {
                Name = "Attribute",
                FillingInfo = new FillingInfo { { "Name", FillingInfo.FillType.Native } },
                ResourceType = "Attribute",
                Namespace = "Test"
            };
            var sElement = new ResourceProjectionElement
            {
                Name = "Element",
                FillingInfo = new FillingInfo { { "Name", FillingInfo.FillType.Native } },
                ResourceType = "Element",
                Namespace = "Test",
            };

            var relation = new Relation {ChildElement = sAttr, ParentElement = sElement};
            sAttr.UpRelations.Add(relation);
            sElement.DownRelations.Add(relation);
            var query = MakeStubQuery(typeof(Attribute), "element"); 
            relation.Queries = new[]
                                   {
                                     query
                                   };

            var commendations = _tester.CheckVariantsForNodes(sElement, 2, new ParameterNames());

            Assert.AreEqual(1,commendations.Count());
          
            var elementCommendation = commendations.FirstOrDefault(k => k.MatchedElement == sElement) as TestPlanStep;         
            Assert.IsNotNull(elementCommendation);
          

            Assert.AreEqual(0, elementCommendation.UsedParameters.Count());
            Assert.AreEqual(sAttr, elementCommendation.ProducedChildElement);       
            Assert.AreEqual(query, elementCommendation.Query);
         
        }
Esempio n. 4
0
        private void TestSerialGetters(ParameterNames parameters,int depth = -1)
        {

            //             Е (Е)
            //         A (A) |
            //              V(V)   
            //            V (E)
            //

            var sAttr = new ResourceProjectionElement
            {
                Name = "Attribute",
                FillingInfo = new FillingInfo { { "Name", FillingInfo.FillType.Native } },
                ResourceType = "Attribute",
                Namespace = "Test"
            };
            var sElement = new ResourceProjectionElement
            {
                Name = "Element",
                FillingInfo = new FillingInfo { { "Name", FillingInfo.FillType.Native } },
                ResourceType = "Element",
                Namespace = "Test",
            };

            var sValue = new ResourceProjectionElement
            {
                Name = "Value",
                FillingInfo = new FillingInfo { { "Name", FillingInfo.FillType.Native } },
                ResourceType = "Value",
                Namespace = "Test",
            };

            var sValue2 = new ResourceProjectionElement
            {
                Name = "Value",
                FillingInfo = new FillingInfo { { "Name", FillingInfo.FillType.Native } },
                ResourceType = "Element",
                Namespace = "Test",
            };

            var attrFromElementQuery = MakeStubQuery("Element", typeof(Data.Attribute));
            var valueFromElementQuery = MakeStubQuery("Element", typeof(Data.Value));
            var valueFromAttrQuery = MakeStubQuery("Attribute", typeof(Data.Value));
            var elementFromValueQuery =  MakeStubQuery("Value",typeof(Element));


            var relation = new Relation { ChildElement = sAttr, ParentElement = sElement };
            sAttr.UpRelations.Add(relation);
            sElement.DownRelations.Add(relation);
          
            relation.Queries = new[] { attrFromElementQuery };

            relation = new Relation { ChildElement = sValue, ParentElement = sElement };
            sValue.UpRelations.Add(relation);
            sElement.DownRelations.Add(relation);
        
            relation.Queries = new[] { valueFromElementQuery };

            relation = new Relation { ChildElement = sValue, ParentElement = sAttr };
            sValue.UpRelations.Add(relation);
            sAttr.DownRelations.Add(relation);
          
            relation.Queries = new[] { valueFromAttrQuery };

            relation = new Relation { ChildElement = sValue2, ParentElement = sValue };
            sValue2.UpRelations.Add(relation);
            sValue.DownRelations.Add(relation);
          
            relation.Queries = new[] { elementFromValueQuery };

            var commendations = _tester.CheckVariantsForNodes(sElement, depth, parameters);

            Assert.AreEqual(4, commendations.Count());

            var elementCommendations = commendations.Where(k => k.MatchedElement == sElement).OfType<TestPlanStep>().ToArray();
            Assert.AreEqual(2,elementCommendations.Count());
            var aFromE = elementCommendations.FirstOrDefault(k => k.ProducedChildElement == sAttr);
            Assert.IsNotNull(aFromE);
            Assert.IsTrue(!aFromE.UsedParameters.Any());
            Assert.AreEqual(attrFromElementQuery, aFromE.Query);   
            var vFromE = elementCommendations.FirstOrDefault(k => k.ProducedChildElement == sValue);
            Assert.IsNotNull(vFromE);
            Assert.IsTrue(!vFromE.UsedParameters.Any());
            Assert.AreEqual(valueFromElementQuery, vFromE.Query);
               
            var attrCommendation = commendations.SingleOrDefault(k =>  k.MatchedElement == sAttr) as TestPlanStep;
            Assert.IsNotNull(attrCommendation);            
            Assert.IsTrue(!attrCommendation.UsedParameters.Any());
            Assert.AreEqual(valueFromAttrQuery, attrCommendation.Query);
            Assert.AreEqual(sValue, attrCommendation.ProducedChildElement);


            var value1Commendation = commendations.SingleOrDefault(k => k.MatchedElement == sValue) as TestPlanStep;
            Assert.IsNotNull(value1Commendation);
            Assert.IsTrue(!value1Commendation.UsedParameters.Any());
            Assert.AreEqual(elementFromValueQuery, value1Commendation.Query);
            Assert.AreEqual(sValue2, value1Commendation.ProducedChildElement);

  
        }
Esempio n. 5
0
        public void RecursivePlanWithSimpleGetters()
        {
            var sElement = new ResourceProjectionElement
            {
                Name = "Attribute",
                FillingInfo = new FillingInfo { { "Name", FillingInfo.FillType.Native } },
                ResourceType = "Attribute",
                Namespace = "Test"
            };
            var sGroup = new ResourceProjectionElement
            {
                Name = "Element",
                FillingInfo = new FillingInfo { { "Name", FillingInfo.FillType.Native } },
                ResourceType = "Element",
                Namespace = "Test",
            };

            var relation = new Relation { ChildElement = sGroup, ParentElement = sGroup };
            var eFromEQuery = MakeStubQuery(typeof (Element), "Element");
            relation.Queries = new[] { eFromEQuery };
            sGroup.UpRelations.Add(relation);
            sGroup.DownRelations.Add(relation);

            relation = new Relation { ChildElement = sElement, ParentElement = sGroup };
            var aFromEQuery = MakeStubQuery(typeof(Attribute), "element");
            relation.Queries = new[] { aFromEQuery };
            sElement.UpRelations.Add(relation);
            sGroup.DownRelations.Add(relation);

            var commendations = _tester.CheckVariantsForNodes(sGroup, -1, new ParameterNames());

            Assert.AreEqual(2, commendations.Count());

            var elementCommendations = commendations.Where(k => k.MatchedElement == sGroup).OfType<TestPlanStep>().ToArray();
            Assert.AreEqual(2, elementCommendations.Count());
            var eFromE = elementCommendations.FirstOrDefault(k => k.ProducedChildElement == sGroup);
            Assert.IsNotNull(eFromE);
            Assert.IsTrue(!eFromE.UsedParameters.Any());
            Assert.AreEqual(eFromEQuery, eFromE.Query);
            var aFromE = elementCommendations.FirstOrDefault(k => k.ProducedChildElement == sElement);
            Assert.IsNotNull(aFromE);
            Assert.IsTrue(!aFromE.UsedParameters.Any());
            Assert.AreEqual(aFromEQuery, aFromE.Query);

        }
Esempio n. 6
0
        public void SimplePlan()
        {
            var catalog = new AggregateCatalog(
                                    new AssemblyCatalog(typeof (ITypedPool).Assembly),
                                    new AssemblyCatalog(typeof (Element).Assembly));
            var container = new CompositionContainer(catalog);
            container.ComposeExportedValue(container);
            var cachier = container.GetExportedValue<ITypedPool>();
            var rootElement = new Element { Id = Guid.NewGuid(), Name = "Root" };
            var attr1 = new Data.Attribute { Id = Guid.NewGuid(), ElementId = rootElement.Id, Name = "Attr1" };
            var attr2 = new Data.Attribute { Id = Guid.NewGuid(), ElementId = rootElement.Id, Name = "Attr2" };
            cachier.Post(rootElement.Id, rootElement);
            cachier.Post(attr1.Id, attr1);
            cachier.Post(attr2.Id, attr2);


            var sAttr = new ResourceProjectionElement
            {
                Name = "Attribute",
                FillingInfo = new FillingInfo { { "Name", FillingInfo.FillType.Native } },
                ResourceType = "Attribute",
                Namespace = "Test"
            };
            var sElement = new ResourceProjectionElement
            {
                Name = "Element",
                FillingInfo = new FillingInfo { { "Name", FillingInfo.FillType.Native } },
                ResourceType = "Element",
                Namespace = "Test",
            };

            var steps = new TestCommendationCollection1(sAttr, new[] { attr1.Id, attr2.Id });
            var plan = new TestFramingPlan(sElement, steps);
            var builder = container.GetExportedValue<ProjectionBuilder>();
            var writer = new TestWriter();
            var sb = builder.RealisePlan(plan, rootElement.Id, "Test", 2, new Streamer<StringBuilder>(writer), new Dictionary<string, object>());

            var expWriter = new TestWriter();
            var expSb = expWriter.Open("Test");
            expWriter.StartWritingNode("Element", rootElement.Id);
            expWriter.WriteAttribute("Name", rootElement.Name);
            expWriter.StartWritingNode("Attribute", attr1.Id);
            expWriter.WriteAttribute("Name", attr1.Name);
            expWriter.WriteAttribute("DefinitlyNoChildren", "True");
            expWriter.EndWritingNode();
            expWriter.StartWritingNode("Attribute", attr2.Id);
            expWriter.WriteAttribute("Name", attr2.Name);
            expWriter.WriteAttribute("DefinitlyNoChildren", "True");
            expWriter.EndWritingNode();
            expWriter.EndWritingNode();
            Assert.AreEqual(expSb.ToString(), sb.ToString());
        }