Пример #1
0
 public FrameNode(Guid key, ProjectionElement type, int depth, Dictionary <string, object> boundingParameters)
 {
     Key                = key;
     Depth              = depth;
     MatchedElement     = type;
     BoundingParameters = new Dictionary <string, object>(boundingParameters, StringComparer.InvariantCultureIgnoreCase);
 }
Пример #2
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]));
        }
Пример #3
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]));
        }
Пример #4
0
 public FilledProjectionFrame(ProjectionElement element,Guid key)
 {         
     _key = key;
     _matchedElement = element;
     Debug.Assert(_matchedElement.FillingInfo.PropertyNames.All(k => _matchedElement.FillingInfo.GetFillType(k) == FillingInfo.FillType.ByFiller));
   
 }
Пример #5
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();
 }
Пример #6
0
 public FrameNodeGroup(ProjectionElement descriptor, FrameNode[] nodes, ParameterNames boundingParameters)
 {
     MatchedElement     = descriptor;
     Nodes              = nodes;
     BoundingParameters = boundingParameters;
     Debug.Assert(nodes.All(k => k.MatchedElement == descriptor));
     Debug.Assert(nodes.All(k => new ParameterNames(k.BoundingParameters.Select(k2 => k2.Key)) == BoundingParameters));
 }
Пример #7
0
 public FrameNodeGroup(ProjectionElement descriptor, FrameNode[] nodes, ParameterNames boundingParameters)
 {
     MatchedElement = descriptor;
     Nodes = nodes;
     BoundingParameters = boundingParameters;
     Debug.Assert(nodes.All(k => k.MatchedElement == descriptor));
     Debug.Assert(nodes.All(k => new ParameterNames(k.BoundingParameters.Select(k2=>k2.Key)) == BoundingParameters ));
 }
Пример #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
 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);
 }
Пример #10
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);
 }
Пример #11
0
 private Relation FindRelation(ProjectionElement parent, ProjectionElement child)
 {
     return _relations.SingleOrDefault(k => k.ParentElement == parent && k.ChildElement == child);
 }
Пример #12
0
        public void AddNewStep(ProjectionElement parent, ProjectionElement child, ParameterNames pars, ParameterNames allPars, Provider provider, int priorGroup, Query func)
        {
            var step = CreateStep(parent, child, pars, allPars, provider, priorGroup, func);

            _commendations.AddNewStep(step);
        }
Пример #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 FramingPlan(ProjectionElement root, bool checkMode = true)
 {
     _rootElement = root;
     _checkMode   = checkMode;
 }
Пример #15
0
        protected virtual PlanStep CreateStep(ProjectionElement parent, ProjectionElement child, ParameterNames pars, ParameterNames allPars, Provider provider, int priorGroup, Query func)
        {
            var step = new PlanStep(parent, child, pars, provider, allPars, priorGroup, _checkMode);

            return(step);
        }
Пример #16
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;
 }
Пример #17
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]));
            
        }
Пример #18
0
        public TestFramingPlan(ProjectionElement root)
            : base(root)
        {

        }
Пример #19
0
 protected override PlanStep CreateStep(ProjectionElement parent, ProjectionElement child, Plan.ParameterNames pars, Plan.ParameterNames allPars, Utility.Accumulator<FrameNode, IEnumerable<Guid>> provider, int priorGroup, Query func)
 {
     var step = new TestPlanStep(parent, child, pars, allPars,priorGroup,func);
     return step;
 }
Пример #20
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;
        }
Пример #21
0
 public TestFramingPlan(ProjectionElement root, CommendationCollection collection)
     : base(root)
 {
     _commendations = collection;
 }
Пример #22
0
 private string GetHashForElementAndParameters(ProjectionElement element, ParameterNames orderedParameters)
 {
     return string.Intern(string.Join(";", new[]{GetHashForElement(element)}.Concat(orderedParameters)));
 }
Пример #23
0
 private string GetHashForElement(ProjectionElement element)
 {
     return string.Intern(string.Format("{0}-{1}:{2}", element.Name, element.SchemeType,element.GetHashCode()));
 }
Пример #24
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;
 }
Пример #25
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;
        }
Пример #26
0
 public FilledProjectionFrame(ProjectionElement element, Guid key, Lazy <object> resourceFiller)
 {
     _key            = key;
     _matchedElement = element;
     _resource       = resourceFiller;
 }
Пример #27
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);
 }
Пример #28
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);
     }          
 }
Пример #29
0
 public TestFramingPlan(ProjectionElement root, CommendationCollection collection)
     : base(root)
 {
     _commendations = collection;
 }
Пример #30
0
 public FilledProjectionFrame(ProjectionElement element, Guid key,Lazy<object> resourceFiller)
 {
     _key = key;
     _matchedElement = element;
     _resource = resourceFiller;
   
 }
Пример #31
0
 public TestFramingPlan(ProjectionElement root)
     : base(root)
 {
 }
Пример #32
0
 public FilledProjectionFrame(ProjectionElement element, Guid key)
 {
     _key            = key;
     _matchedElement = element;
     Debug.Assert(_matchedElement.FillingInfo.PropertyNames.All(k => _matchedElement.FillingInfo.GetFillType(k) == FillingInfo.FillType.ByFiller));
 }
Пример #33
0
        protected override PlanStep CreateStep(ProjectionElement parent, ProjectionElement child, Plan.ParameterNames pars, Plan.ParameterNames allPars, Utility.Accumulator <FrameNode, IEnumerable <Guid> > provider, int priorGroup, Query func)
        {
            var step = new TestPlanStep(parent, child, pars, allPars, priorGroup, func);

            return(step);
        }
Пример #34
0
 public TestCommendationCollection1(ProjectionElement attribute, Guid[] attrIds)
 {
     _attrIds = attrIds;
     
     _attribute = attribute;
 }