Beispiel #1
0
        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());
        }
Beispiel #2
0
        public ProjectionFrame MakeFrame(Guid id, int maxDepth, Dictionary <string, object> parameters)
        {
            if (parameters.ContainsKey(_rootElement.Name))
            {
                parameters[_rootElement.Name] = id;
            }
            else
            {
                parameters.Add(_rootElement.Name, id);
            }
            var root = new FrameNode(id, _rootElement, 1, parameters);
            IEnumerable <FrameNodeGroup> currentLevel = new[]
            {
                new FrameNodeGroup(_rootElement,
                                   new[] { root },
                                   new ParameterNames(parameters.Select(k => k.Key)))
            };

            if (maxDepth > 1 || maxDepth == -1)
            {
                while (currentLevel.Any())
                {
                    currentLevel = _commendations.GetNewGroups(currentLevel);
                    currentLevel = FilterByDepth(currentLevel, maxDepth);
                    currentLevel = FilterByCount(currentLevel);
                }
            }
            else
            {
                root.ChildNodes = new FrameNode[0];
            }
            foreach (var storage in _storages)
            {
                storage.Clear();
            }
            return(new ProjectionFrame(root));
        }