コード例 #1
0
        public void LoadTest1()
        {
            var id = Guid.NewGuid();
            var parent = new ProjectionElement {Name = "Parent"};
            var relation = new Relation
                               {
                                   ParentElement = parent,
                                   Queries = new[]
                                                 {
                                                     Query.CreateTestStubQuery(null,k2=>new[]{id},"Parent")
                                                 }
                               };
            ParameterNames names;
            var q = _tester.FormGetter(relation, new BoundingParameter[0],out names); 
            var k = Guid.NewGuid();
            Assert.AreEqual(k, q(new[] { k }, new Dictionary<string, object>()).First().Key);
            Assert.AreEqual(id,q(new[] { k },new Dictionary<string, object>()).First().Value.First());
            Assert.IsTrue(names.SequenceEqual(new string[0]));

            q = _tester.FormGetter(relation, new[]{new BoundingParameter("sdsad",0) },out names);
            k = Guid.NewGuid();
            Assert.AreEqual(k, q(new[] { k }, new Dictionary<string, object>()).First().Key);
            Assert.AreEqual(id, q(new[] { k }, new Dictionary<string, object>()).First().Value.First());
            Assert.IsTrue(names.SequenceEqual(new string[0]));
        }
コード例 #2
0
        public FramingPlan MakePlan(ProjectionElement root, int depth, ParameterNames pars)
        {
            var plan = new FramingPlan(root, _settingsHolder.Settings.CheckMode);

            CheckNodeVariants(plan, root, depth, pars);
            return(plan);
        }
コード例 #3
0
        public Provider GetOrCreateAccumulator(FramingPlan plan, Getter getter, ProjectionElement parent, ProjectionElement child, ParameterNames parameters)
        {
            var alreadyCreated =
                _cache.FirstOrDefault(k => k.Child == child &&
                                      k.Parent == parent &&
                                      k.Parameters == parameters);

            if (alreadyCreated != null)
            {
                return(alreadyCreated.Provider);
            }

            var storage = new GroupStorage(FrameNode.InPlanComparer);

            plan.AddTempStorage(storage);
            var pusher    = CreatePusher(storage);
            var checker   = CreateChecker(storage);
            var taker     = CreateGetter(storage);
            var packTaker = CreatePackagerGetter(getter, parameters);

            var acc = new Provider(pusher, checker,
                                   taker, packTaker,
                                   FrameNode.InPlanComparer);
            var node = new FactoryNode
            {
                Parent     = parent,
                Child      = child,
                Parameters = parameters,
                Provider   = acc
            };

            _cache.Add(node);
            return(acc);
        }
コード例 #4
0
        public void ChoiceBetweenPhysicalAndNot()
        {
            var id = Guid.NewGuid();
            var id2= Guid.NewGuid();
            var parent = new ProjectionElement { Name = "Parent",Namespace = "T" };
            var relation = new Relation
                               {
                                   ParentElement = parent,
                                   Queries = new[]
                                                 {
                                                     Query.CreateTestStubQuery("T", k2=>new[]{id},"Parent"),
                                                     Query.CreateTestStubQuery("",k2=>new[]{id2}, "Parent"),
                                                 }

                               };
            ParameterNames names;
            var q = _tester.FormGetter(relation, new BoundingParameter[0], out names);
            var k = Guid.NewGuid();
            var res = q(new[] {k}, new Dictionary<string, object>()).First();
            Assert.AreEqual(k, res.Key);
            Assert.AreEqual(id, res.Value.First());
            Assert.IsTrue(names.SequenceEqual(new string[0]));

            q = _tester.FormGetter(relation, new[] { new BoundingParameter("sdsad", 0) }, out names);
            k = Guid.NewGuid();
            Assert.AreEqual(k, q(new[] { k }, new Dictionary<string, object>()).First().Key);
            Assert.AreEqual(id, q(new[] { k }, new Dictionary<string, object>()).First().Value.First());
            Assert.IsTrue(names.SequenceEqual(new string[0]));
        }
コード例 #5
0
        private ProjectionElement ProcessElement(XmlSchemaElement element, ProjectionElement taggedElement)
        {
            var node = (element.ElementSchemaType.Name != null ? FindElement(element) : taggedElement)
                       ?? CreateElement(element);

            Debug.Assert(node != null);
            var childElements = GetAllowedChilds(element.ElementSchemaType.CastSingle <XmlSchemaComplexType>());

            foreach (var childElement in childElements)
            {
                var childNode = (childElement.ElementSchemaType.Name != null
                                ? FindElement(childElement)
                                : null)
                                ?? CreateElement(childElement);
                Debug.Assert(childElement != null);
                var relation = (element.ElementSchemaType.Name != null && childElement.ElementSchemaType.Name != null)
                                    ? FindRelation(node, childNode):null;
                if (relation == null)
                {
                    relation = CreateRelation(node, childNode);
                    Debug.Assert(relation.HasTrivialQuery ||
                                 relation.Queries != null);
                    node.DownRelations.Add(relation);
                    childNode.UpRelations.Add(relation);
                    ProcessElement(childElement, childNode);
                }
            }
            return(node);
        }
コード例 #6
0
        private void CheckNodeVariants(FramingPlan plan, ProjectionElement element, int depth, ParameterNames orderedParameters)
        {
            Contract.Requires(element != null);
            Contract.Requires(plan != null);
            Contract.Requires(orderedParameters != null);

            var nodes            = MakeAllPossibleWays(element, orderedParameters, depth);
            var nodesWithQueries = FindMatchedQueries(nodes);

            foreach (var secondaryFrameNode in nodesWithQueries)
            {
                foreach (var source in secondaryFrameNode.UsingParameters
                         .ParameterNames)
                {
                    if (orderedParameters.Any(k => string.Equals(k, source, StringComparison.InvariantCultureIgnoreCase)))
                    {
                        //   Debug.Assert(secondaryFrameNode.Query.Conversions.ContainsKey(source), "secondaryFrameNode.Query.Conversions.ContainsKey(source), source:"+source);
                        plan.AddConversion(source, secondaryFrameNode.Query.GetConversionForParameter(source));
                    }
                }
            }
            nodesWithQueries = FillPriorityGroupAndCleanDuplicates(nodesWithQueries);
            var factory = new AccumulatorFactory();

            foreach (var secondaryFrameNode in nodesWithQueries)
            {
                MakePlanStepFromSecondary(plan, factory, secondaryFrameNode);
            }
        }
コード例 #7
0
            public IEnumerable <PlanStep> CheckVariantsForNodes(ProjectionElement root, int depth, ParameterNames parameters)
            {
                var testBuilder = new FramingPlanBuilder();
                var plan        = new TestFramingPlan(root);

                testBuilder.CheckNodeVariants(plan, root, depth, parameters);
                return(plan.ReturnPlanningResults());
            }
コード例 #8
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);
        }
コード例 #9
0
        private IEnumerable <PrimaryFrameNode> MakeAllPossibleWays(ProjectionElement root, ParameterNames orderedParameters, int depth)
        {
            var processed  = new List <string>();
            var parameters = new SortedSet <BoundingParameter>(
                orderedParameters.Select(k => new BoundingParameter(k, 0)),//-1 - потому что при старте корня они сразу поимеют глубину 0.
                new BoundingParameter.Comparer());
            var ways = MakeAllPossibleWaysRec(processed, root, parameters, depth);

            Debug.Assert(processed.Count == 0);
            return(ways);
        }
コード例 #10
0
        public double GetSizeOfProjection(ProjectionElement projection)
        {
            double sizeOfRelation   = 0;
            double sizeOfProjection = 0;

            IEnumerable <Relation> relations = projection.Columns.Select(x => x.Relation).Distinct();

            foreach (Relation relation in relations)
            {
                sizeOfRelation   += GetTotalSizeOfTuple(relation, relation);
                sizeOfProjection += GetTotalSizeOfTuple(relation, projection.Columns.Where(x => x.Relation == relation).Select(x => x.AttributeDefinition).ToList());
            }

            return(sizeOfProjection / sizeOfRelation);
        }
コード例 #11
0
 public PlanStep(ProjectionElement matchedElement,
                 ProjectionElement producedChildElement,
                 ParameterNames parameterNames,
                 PackFactory accumulator,
                 ParameterNames wholeParameters,
                 int priorityGroup,
                 bool check = true)
 {
     MatchedElement       = matchedElement;
     _packGetter          = accumulator;
     PriorityGroup        = priorityGroup;
     ProducedChildElement = producedChildElement;
     UsedParameters       = parameterNames;
     WholeParameters      = wholeParameters;
     _getterCheck         = check;
 }
コード例 #12
0
ファイル: PlanStep.cs プロジェクト: kayanme/Dataspace
        public PlanStep(ProjectionElement matchedElement,
                        ProjectionElement producedChildElement,
                        ParameterNames parameterNames,
                        PackFactory accumulator,
                        ParameterNames wholeParameters,
                        int priorityGroup,
                        bool check = true)
        {
            MatchedElement = matchedElement;
            _packGetter = accumulator;
            PriorityGroup = priorityGroup;
            ProducedChildElement = producedChildElement;
            UsedParameters = parameterNames;
            WholeParameters = wholeParameters;
            _getterCheck = check;

        }
コード例 #13
0
        private Relation CreateRelation(ProjectionElement parent, ProjectionElement child)
        {
            var newRelation = new Relation {
                ChildElement = child, ParentElement = parent
            };

            if (child.SchemeType != null)
            {
                var queries = _queries.FindAppropriateQueries(parent.Namespace, parent.Name, child.SchemeType);
                newRelation.Queries = queries;
            }
            else
            {
                newRelation.Queries = null;
            }
            _relations.Add(newRelation);
            return(newRelation);
        }
コード例 #14
0
        public void QuerySelectionForParentWithNoQuery()
        {
            var parent = new ProjectionElement {
                Name = "parent"
            };
            var child = new ProjectionElement {
                Name = "child"
            };
            var query1   = Query.CreateTestStubQuery("", null);
            var relation = new Relation
            {
                ParentElement = parent,
                ChildElement  = child,
                Queries       = new[]
                {
                    query1
                }
            };
            var bestQuery = relation.SelectTheBestQuery(new BoundingParameter[0]).First();

            Assert.AreSame(query1, bestQuery);
        }
コード例 #15
0
        public void ChoiceBetweenPhysicalAndNotWithParameters()
        {
            var id = Guid.NewGuid();
            var id2 = Guid.NewGuid();
            var parent = new ProjectionElement { Name = "Parent",Namespace = "T" };
            var relation = new Relation
                               {
                                   ParentElement = parent,
                                   Queries = new[]
                                                 {
                                                     Query.CreateTestStubQuery("T", k2=>new[]{id},"Parent"),                                               
                                                     Query.CreateTestStubQuery("", k2=>k2.OfType<Guid>(),"Parent", "Option2", "Option")
                                                 }
                               };
            ParameterNames names;
            var q = _tester.FormGetter(relation, new BoundingParameter[0], out names);
            var k = Guid.NewGuid();
            Assert.AreEqual(k, q(new[] { k }, new Dictionary<string, object>()).First().Key);
            Assert.AreEqual(id, q(new[] { k }, new Dictionary<string, object>()).First().Value.First());
            Assert.IsTrue(names.SequenceEqual(new string[0]));

            q = _tester.FormGetter(relation,new[] {new BoundingParameter( "Option",0)}, out names);            
            Assert.AreEqual(k, q(new[] { k }, new Dictionary<string, object>()).First().Key);
            Assert.AreEqual(id, q(new[] { k }, new Dictionary<string, object>()).First().Value.First());
            Assert.IsTrue(names.SequenceEqual(new string[0]));
            
            q = _tester.FormGetter(relation, new[] { new BoundingParameter("Option", 2), new BoundingParameter("Option2", 2) }, out names);
            k = Guid.NewGuid();
            var result = q(new[] {k}, new Dictionary<string, object> {{"Option2", id2},
                                                                      {"Option", id}}).First();

            Assert.AreEqual(k,result.Key);
            Assert.AreEqual(id, result.Value.First());
            //Assert.AreEqual(id2, result.Value.Skip(1).First());
            //Assert.AreEqual(id, result.Value.Skip(2).First());
            Assert.IsTrue(names.SequenceEqual(new string[0]));
            
        }
コード例 #16
0
        public void QuerySelectionWithParamsAndNot2()
        {
            var parent = new ProjectionElement {
                Name = "parent"
            };
            var child = new ProjectionElement {
                Name = "child"
            };
            var query1   = Query.CreateTestStubQuery("", null, "parent");
            var query2   = Query.CreateTestStubMultipleQuery(parent.Name);
            var relation = new Relation
            {
                ParentElement = parent,
                ChildElement  = child,
                Queries       = new[]
                {
                    query1, query2
                }
            };
            var bestQuery = relation.SelectTheBestQuery(new[] { new BoundingParameter("name", 1) }).First();

            Assert.AreSame(query2, bestQuery);
        }
コード例 #17
0
        public void QuerySelectionWithParamsAtDifferentDepths()
        {
            var parent = new ProjectionElement {
                Name = "parent"
            };
            var child = new ProjectionElement {
                Name = "child"
            };
            var query1   = Query.CreateTestStubQuery("", null, "parent", "closer");
            var query2   = Query.CreateTestStubQuery("", null, "parent", "further");
            var relation = new Relation
            {
                ParentElement = parent,
                ChildElement  = child,
                Queries       = new[]
                {
                    query1, query2
                }
            };
            var bestQuery = relation.SelectTheBestQuery(new[] { new BoundingParameter("closer", 1), new BoundingParameter("further", 2) }).First();

            Assert.AreSame(query1, bestQuery);
        }
コード例 #18
0
ファイル: TestDescription.cs プロジェクト: kayanme/Dataspace
 public TestRecord(ProjectionElement element, string[] orderedBoundingParameters)
 {
     Element            = element;
     BoundingParameters = orderedBoundingParameters;
 }
コード例 #19
0
            public TestCommendationCollection1(ProjectionElement attribute, Guid[] attrIds)
            {
                _attrIds = attrIds;

                _attribute = attribute;
            }
コード例 #20
0
 //внутренний дл¤ тестировани¤
 internal FramingPlan ChoosePlan(ProjectionElement root, int depth, ParameterNames pars)
 {
     return(_planBuilder.MakePlan(root, depth, pars));
 }
コード例 #21
0
 private Relation FindRelation(ProjectionElement parent, ProjectionElement child)
 {
     return(_relations.SingleOrDefault(k => k.ParentElement == parent && k.ChildElement == child));
 }
コード例 #22
0
        private IEnumerable <PrimaryFrameNode> MakeAllPossibleWaysRec(List <string> processed, ProjectionElement element, SortedSet <BoundingParameter> orderedParameters, int depth)
        {
            if (depth == int.MinValue)
            {
                throw new InvalidOperationException("Ошибка при построении плана - слишком глубокая схема для разбора");
            }
            if (depth == 0)
            {
                return(new PrimaryFrameNode[0]);
            }

            #region Проверка - был ли проверен текущий элемент, и добавление его к проверенным

            var hash = GetHashForElementAndParameters(element, new ParameterNames(orderedParameters.Select(k => k.Name)));


            if (processed.Contains(hash))
            {
                return(new PrimaryFrameNode[0]);
            }

            processed.Add(hash);


            #endregion

            #region Добавление текущего элемента к родительским параметрам или обнуление глубины уже существующего параметра с данным именем

            foreach (var p in orderedParameters)
            {
                p.Depth++;
            }

            var parameter = orderedParameters.FirstOrDefault(k => k.Name == element.Name);
            int oldDepth;
            if (parameter == null)
            {
                parameter = new BoundingParameter(element.Name, 1);
                orderedParameters.Add(parameter);
                oldDepth = 0;
            }
            else
            {
                oldDepth        = parameter.Depth;
                parameter.Depth = 1;
            }

            #endregion

            #region Обход детей дочерних нод

            var childElements = element.DownRelations
                                .Select(k => new
            {
                relation = k,
                k.ChildElement,
                children =
                    MakeAllPossibleWaysRec(processed, k.ChildElement, orderedParameters, depth - 1)
            }).ToArray();

            #endregion



            processed.Remove(hash);

            if (oldDepth == 0)
            {
                orderedParameters.Remove(parameter);
            }
            else
            {
                parameter.Depth = oldDepth;
            }


            #region Формирование списка нод вместе с дочерними

            var allNodes = childElements.Select(k =>
                                                new PrimaryFrameNode
            {
                Current           = k.ChildElement,
                OrderedParameters =
                    orderedParameters.Where(k2 => !StringComparer.InvariantCultureIgnoreCase.Equals(k2.Name, element.Name))
                    .Select(k2 => new BoundingParameter(k2.Name, k2.Depth))
                    .ToArray(),
                Parent   = element,
                Relation = k.relation
            })
                           .Concat(childElements.SelectMany(k => k.children))
                           .ToArray();

            #endregion


            foreach (var p in orderedParameters)
            {
                p.Depth--;
            }

            return(allNodes);
        }
コード例 #23
0
 private string GetHashForElement(ProjectionElement element)
 {
     return(string.Intern(string.Format("{0}-{1}:{2}", element.Name, element.SchemeType, element.GetHashCode())));
 }
コード例 #24
0
 private string GetHashForElementAndParameters(ProjectionElement element, ParameterNames orderedParameters)
 {
     return(string.Intern(string.Join(";", new[] { GetHashForElement(element) }.Concat(orderedParameters))));
 }