Esempio n. 1
0
        private Getter FormGetterByRelation(Relation relation, BoundingParameter[] parameters, out ParameterNames parameterNames,out Query query)
        {
            Getter getter;
            if (relation.HasTrivialQuery)
            {
                getter =
                    (keys, parPairs) =>
                    keys.Select(k => new KeyValuePair<Guid, IEnumerable<Guid>>(k, new[] {k})).ToArray();
                parameterNames = new ParameterNames(new string[0]);
                query = null;
            }
            else
            {
                var targetQuery =
                    relation.SelectTheBestQuery(parameters)
                        .FirstOrDefault();

                if (targetQuery == null)
                    throw new InvalidOperationException(
                        string.Format("Нет запроса для построения дерева: род. {0}, доч. {1} ",
                                      relation.ParentElement.Name,
                                      relation.ChildElement.Name));

                query = targetQuery;
                getter = (keys, parPairs) =>
                           targetQuery.GetMultipleChildResourceQuery(relation.ParentElement.Name,
                                                             parPairs.Keys.ToArray())(keys,parPairs.Values.ToArray());
                parameterNames = new ParameterNames(targetQuery.Arguments.Where(k=>!StringComparer.InvariantCultureIgnoreCase.Equals(k,relation.ParentElement.Name)));
            }
            return getter;
        }
 private Accumulator<FrameNode, IEnumerable<Guid>> GetAccumulator(Relation relation,Query query)
 {
     var factory = new AccumulatorFactory();
     var plan = new FramingPlan(relation.ParentElement);
     var acc = factory.GetOrCreateAccumulator(plan,
                                 (keys, parPairs) =>
                                     query.GetMultipleChildResourceQuery(relation.ParentElement.Name,parPairs.Select(k=>k.Key).ToArray())(keys,parPairs.Select(k=>k.Value).ToArray()),
                               relation.ParentElement, relation.ChildElement, new ParameterNames());
     return acc;
 }
Esempio n. 3
0
        private static double CalcQueryRank(Query query, string parentName, BoundingParameter[] parameters)
        {

            Func<string, string, bool> equals =
                (a, b) => string.Equals(a, b, StringComparison.InvariantCultureIgnoreCase);

            //отсев запросов, у которых есть параметры, не являющиеся родительским параметром или одним параметром из списка
            if (query.Arguments
                     .Where(k => !equals(k, parentName))
                     .Any(k => parameters.All(k2 => !equals(k2.Name, k))))
                return -1;

            double rank = 0.1;


            if (query.Arguments.Contains(parentName) && query.ArgCount == 1)
            {
                rank = 0.5;
            }
            else if (parameters.Length != 0)
            {
                var correctiveFloor = parameters.Max(k => k.Depth);
                //нужно перевести глубину параметров от текущей точки в рейтинг для текущей точки, т.е. перевернуть их все
                rank =
                   query.Arguments.Where(k => !equals(k, parentName)).Select(
                       k => correctiveFloor - parameters.Single(k2 => equals(k2.Name, k)).Depth + 1).Sum();
            }

            if (query.Arguments.Contains(parentName))
            {


                rank *= 2;

                if (query.SerialQueryIsPreferred(parentName))
                    rank += 1;
            }

            if (!string.IsNullOrEmpty(query.Namespace))
                rank *= 100;
            return rank;
        }
Esempio n. 4
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;
 }
Esempio n. 5
0
 internal static Query CreateFromQueryWithArgReorder(Query query,int[] order)
 {
   var newQuery =  new Query(
           query.QueryInfo,
           order.Select(k=>query._types[k]).ToArray(),
           query._returnType)
     {                
         _queryMethod =
             qr => query._queryMethod(order.Select(k => qr[k]).ToArray()),
            _orderedArguments = order.Select(k => query._orderedArguments[k]).ToArray(),   
     };
   return newQuery;
 }
Esempio n. 6
0
 public static Query CreateFromMethod(Guid key,string nmspace,object owner,MethodInfo method)
 {
     Debug.Assert(method !=null);
     var query = new Query(
         new QueryInfo(key, new ParameterNames(method.GetParameters().Select(k => k.Name)), nmspace,method),
         method.GetParameters().Select(k => k.ParameterType).ToArray(),
         method.ReturnType)
                     {
                         _queryMethod = args=>method.Invoke(owner,args),
                         _orderedArguments = method.GetParameters().Select(k => k.Name).ToArray()
                     };
     return query;
 }
Esempio n. 7
0
 internal static Query CreateFromFactory(Guid key,string resName, string nmspace, ParameterNames parameters,IResourceQuerierFactory querierFactory)
 {
     var query = new Query(new QueryInfo(key, new ParameterNames(parameters), nmspace,null),
                           Enumerable.Repeat(typeof(string),parameters.Count()).ToArray(),
                           typeof(IEnumerable<Guid>))
     {
         _orderedArguments = parameters.ToArray(),
         _queryMethod = k=> querierFactory.CreateQuerier(resName, nmspace,
                                           parameters.ToArray())(k),              
     };
   
     return query;
 }
Esempio n. 8
0
        internal static Query CreateTestStubMultipleQuery(string resource,params string[] pars)
        {
            var query = new Query(new QueryInfo(Guid.NewGuid(), new ParameterNames(new[]{resource}.Concat(pars)), "",null),
                                  new[]{ typeof(IEnumerable<Guid>)}.Concat(Enumerable.Repeat(typeof(string), pars.Count())).ToArray(),
                                  typeof(MultKeys))
            {
                _orderedArguments = new[]{resource}.Concat(pars).ToArray(),
                _queryMethod = k => new KeyPair(Guid.Empty,new[]{Guid.Empty })
            };
            return query;

        }
Esempio n. 9
0
 internal static Query CreateTestStubQuery(string nmspc = null,Func<object[],object> func = null,params string[] pars)
 {
     var query = new Query(new QueryInfo(Guid.NewGuid(), new ParameterNames(pars), nmspc,null),
                           Enumerable.Repeat(typeof(string), pars.Count()).ToArray(),
                           typeof(IEnumerable<Guid>))
     {
         _orderedArguments = pars.ToArray(),
         _queryMethod = func?? (k => new[] { Guid.Empty }),
     };
     return query;
     
 }