internal void Translate(Expression expression,TranslateResult translateResult)
 {
     if (expression == null || translateResult == null)
         return;
     this.Visit(expression);
     translateResult.NoQueryableResult = sr; ;
 }
        internal void Translate(Expression expression,TranslateResult translateResult)
        {
            if (expression == null || translateResult == null)
                return;
            this.Visit(expression);

            translateResult.ConditionResult = tr;
        }
示例#3
0
 internal void Translate(Expression expression, TranslateResult translateResult)
 {
     if (expression == null || translateResult == null)
     {
         return;
     }
     this.Visit(expression);
     translateResult.NoQueryableResult = sr;;
 }
        internal void Translate(Expression expression, TranslateResult translateResult)
        {
            if (expression == null || translateResult == null)
            {
                return;
            }
            this.Visit(expression);

            translateResult.ConditionResult = tr;
        }
        internal void Translate(LambdaExpression expression,TranslateResult translateResult)
        {
            if (expression == null || translateResult == null)
                return;
            this.Visit(expression.Body);//get selected properties

            tr.TargetType = expression.ReturnType;
            tr.SelectExpression = expression;
            translateResult.SelectResult = tr;
        }
示例#6
0
        internal void Translate(LambdaExpression expression, TranslateResult translateResult)
        {
            if (expression == null || translateResult == null)
            {
                return;
            }
            this.Visit(expression.Body);//get selected properties

            tr.TargetType                = expression.ReturnType;
            tr.SelectExpression          = expression;
            translateResult.SelectResult = tr;
        }
 internal void Translate(Expression expression, TranslateResult translateResult)
 {
     if (expression == null || translateResult == null)
         return;
     this.Visit(expression);
     if (translateResult.OrderByResult == null)
         translateResult.OrderByResult = sr;
     else
     {
         foreach (var i in sr.OrderByList)
         {
             translateResult.OrderByResult.OrderByList.Add(i);
         }
     }
 }
 internal void Translate(Expression expression, TranslateResult translateResult)
 {
     if (expression == null || translateResult == null)
     {
         return;
     }
     this.Visit(expression);
     if (translateResult.OrderByResult == null)
     {
         translateResult.OrderByResult = sr;
     }
     else
     {
         foreach (var i in sr.OrderByList)
         {
             translateResult.OrderByResult.OrderByList.Add(i);
         }
     }
 }
示例#9
0
        public override object Execute(Expression expression)
        {
            //translate expression
            //visit Evalable expression
            expression = Evaluator.PartialEval(expression);
            //translate
            TranslateResult tr = this.Translate(expression);

            //T is model of AR,cache the id and property name map
            //if(!_Cache.ContainsKey(typeof(T).FullName))
            //{
            //    Dictionary<string,uint> propertry = new Dictionary<string,uint>();
            //    _Cache.Add(typeof(T).FullName,propertry);
            //    foreach (PropertyInfo prop in typeof(T).GetProperties
            //    //unbinder need at least readable property
            //   (BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.Instance))
            //    {
            //        var fieldAttribute = GetARAttributeField(prop, ModelBinderAccessLevel.OnlyUnBind | ModelBinderAccessLevel.OnlyBind);
            //        if (fieldAttribute == null) continue;
            //        propertry.Add(prop.Name,fieldAttribute.DatabaseID);
            //    }
            //}
            //string formName = typeof(T).FullName;

            //get metadata
            var properties = metaProvider.GetPropertyInfoes(
                (BindingFlags.SetProperty | BindingFlags.Public | BindingFlags.Instance),
                null);

            //if no statictisc
            //we should invoke GetEntryList
            if (tr.HasStatictisc == false)
            {
                ARProxy <T> proxy = new ARProxy <T>((ARLoginContext)context);
                //get select
                List <uint> fieldIds = new List <uint>();

                if (tr.SelectResult != null && tr.SelectResult.SelectedProperties.Count > 0)
                {
                    foreach (var p in properties)
                    {
                        if (tr.SelectResult.SelectedProperties.Find(s => s == p.Property.Name) == null)
                        {
                            continue;
                        }
                        fieldIds.Add(p.DatabaseId);
                    }
                }
                else
                {
                    foreach (var p in properties)
                    {
                        fieldIds.Add(p.DatabaseId);
                    }
                }


                //if(tr.HasSelect && tr.SelectedProperties.Count > 0){
                //    foreach(var s in tr.SelectedProperties){
                //        fieldIds.Add(_Cache[formName][s.SourceMemberName]);
                //    }
                //}
                //else{
                //    foreach(var d in _Cache[formName])
                //        fieldIds.Add(d.Value);
                //}

                //get paged
                uint StartIndex    = 0;
                uint?RetrieveCount = null;
                if (tr.NoQueryableResult != null && tr.NoQueryableResult.HasSkip)
                {
                    StartIndex = (uint)tr.NoQueryableResult.Skip.Value;
                }
                if (tr.NoQueryableResult != null && tr.NoQueryableResult.HasTake)
                {
                    RetrieveCount = (uint)tr.NoQueryableResult.Take.Value;
                }

                //get order by
                List <ARSortInfo> sort = new List <ARSortInfo>();
                if (tr.OrderByResult != null && tr.OrderByResult.OrderByList.Count > 0)
                {
                    foreach (var p in properties)
                    {
                        var ss = tr.OrderByResult.OrderByList.Find(s => s.Property == p.Property.Name);
                        if (ss == null)
                        {
                            continue;
                        }
                        sort.Add(new ARSortInfo
                        {
                            FieldId = p.DatabaseId,
                            Order   = ss.Method == "OrderBy" ? SortOrder.SORT_ASCENDING : SortOrder.SORT_DESCENDING
                        });
                    }
                }

                IList <T> resultList = proxy.GetEntryList(
                    tr.ConditionResult == null ? null : tr.ConditionResult.Qulification.ToString(),
                    fieldIds,
                    StartIndex,
                    RetrieveCount,
                    null,
                    sort
                    );

                if (tr.SelectResult == null || tr.SelectResult.TargetType == null) //means no explict select clause
                {
                    return(resultList);
                }
                else
                {
                    Type[] typeArgs = { tr.SelectResult.TargetType, typeof(T) };
                    return((IEnumerable)Activator.CreateInstance(
                               typeof(Enumerator <,>).MakeGenericType(typeArgs),
                               resultList,
                               tr.SelectResult.SelectExpression));
                }
            }
            else if (tr.HasStatictisc && tr.StatictiscVerb == "Count")
            {
                ARProxy <T>   proxy  = new ARProxy <T>((ARLoginContext)context);
                List <UInt32> groups = null;
                var           list   = proxy.GetListEntryStatictisc(
                    tr.ConditionResult == null ? null : tr.ConditionResult.Qulification.ToString(),
                    ARStatictisc.STAT_OP_COUNT,
                    null,
                    groups);
                if (list.Count != 1)
                {
                    throw new Exception("GetListEntryStatictisc returns invalid result.");
                }
                T entry = list[0];
                return(Convert.ToInt32((entry as ARBaseForm).Statictisc));
            }
            else
            {
                throw new NotImplementedException("Group by and statictisc is not support yet.Please use ARProxy API");

                /*
                 * ARStatictisc stat = ARStatictisc.STAT_OP_COUNT;
                 * uint? targetFieldId = null;
                 * List<uint> groupByList = null;
                 *
                 * if(tr.HasStatictisc)
                 * {
                 *  switch (tr.StatictiscVerb)
                 *  {
                 *      case "Sum":
                 *          stat = ARStatictisc.STAT_OP_SUM;
                 *          break;
                 *      case "Max":
                 *          stat = ARStatictisc.STAT_OP_MAXIMUM;
                 *          break;
                 *      case "Min":
                 *          stat = ARStatictisc.STAT_OP_MINIMUM;
                 *          break;
                 *      case "Count":
                 *          stat = ARStatictisc.STAT_OP_COUNT;
                 *          break;
                 *      case "Average":
                 *          stat = ARStatictisc.STAT_OP_AVERAGE;
                 *          break;
                 *      default:
                 *          throw new NotImplementedException(tr.StatictiscVerb + " is not support.");
                 *  }
                 *
                 *  if(tr.StatictiscTarget == null && tr.StatictiscVerb != "Count")
                 *     throw new InvalidOperationException("TargetFieldId must not null if ARStat is not COUNT");
                 *
                 *  targetFieldId = _Cache[formName][tr.StatictiscTarget.SourceMemberName];
                 * }
                 *
                 * if(tr.HasGroupBy)
                 * {
                 *  groupByList = new List<uint>();
                 *  foreach(var g in tr.GroupedProperties){
                 *      groupByList.Add(_Cache[formName][g.SourceMemberName]);
                 *  }
                 * }
                 *
                 *
                 *
                 * ARProxy<T> proxy = new ARProxy<T>((ARLoginContext)context, (IARServerFactory)factory);
                 * IList<T> resultList = proxy.GetListEntryStatictisc(
                 *  tr.Qulification.ToString(),
                 *  stat,
                 *  targetFieldId,
                 *  groupByList);
                 *
                 * if (groupByList == null || groupByList.Count == 0)
                 *  return (resultList[0] as ARBaseForm).Statictisc;
                 * else
                 * {
                 *  Type[] typeArgs = { tr.GroupType, typeof(T) ,tr.TargetType };
                 *  return (IEnumerable)Activator.CreateInstance(
                 *          typeof(Groupor<,>).MakeGenericType(typeArgs),
                 *          resultList,
                 *          tr.GroupExpression);
                 *
                 *
                 * }
                 */
            }

            #region code dropped

            ////two mainly type of query
            ////one with statictisc another without statictisc
            ////the flag is tr.HasStatictisc
            //if (tr.HasStatictisc)
            //{
            //    ARStatictisc stat;
            //    switch (tr.StatictiscVerb)
            //    {
            //        case "Sum":
            //            stat = ARStatictisc.STAT_OP_SUM;
            //            break;
            //        case "Max":
            //            stat = ARStatictisc.STAT_OP_MAXIMUM;
            //            break;
            //        case "Min":
            //            stat = ARStatictisc.STAT_OP_MINIMUM;
            //            break;
            //        case "Count":
            //            stat = ARStatictisc.STAT_OP_COUNT;
            //            break;
            //        case "Average":
            //            stat = ARStatictisc.STAT_OP_AVERAGE;
            //            break;
            //        default:
            //            throw new NotImplementedException(tr.StatictiscVerb + " is not support.");

            //    }
            //    if (tr.HasGroupBy)
            //    {

            //    }
            //    else
            //    {

            //    }
            //    ARProxy<T> proxy = new ARProxy<T>((ARLoginContext)context);
            //    IList<T> list = proxy.GetListEntryStatictisc(
            //        tr.Qulification.ToString(),
            //        stat,
            //        Convert.ToUInt32(tr.StatictiscTarget.SourceMemberName),
            //        null);
            //    //two sub type of query
            //    //one with group by another without group by
            //    //the flag is tr.HasGroupBy

            //}
            //else
            //{

            //}

            //if (tr.HasGroupBy)
            //{
            //    ARProxy<T> proxy = new ARProxy<T>((ARLoginContext)context);
            //    IList<T> list = proxy.GetListEntryStatictisc(
            //        tr.Qulification.ToString(),
            //        ARStatictisc.STAT_OP_SUM,
            //        Convert.ToUInt32(tr.StatictiscTarget.SourceMemberName),
            //        null);

            //}

            //if (tr.Count)
            //{
            //    ARProxy4Linq<T> proxy = (ARProxy4Linq<T>)Activator.CreateInstance(
            //       typeof(ARProxy4Linq<T>), context, factory);
            //    return proxy.GetEntryCountByQuery(tr.Qulification.ToString());
            //}

            ////special "Select" clause apply
            //else if (tr.Select)
            //{
            //    tr.TargetType = TypeSystem.GetElementType(expression.Type);
            //    ARProxy4Linq<T> proxy = (ARProxy4Linq<T>)Activator.CreateInstance
            //        (typeof(ARProxy4Linq<T>), context, factory);

            //    return proxy.GetEntryByQuery(
            //        tr.Qulification.ToString(),
            //        tr.SelectedProperties,
            //        tr.TargetType,
            //        tr.SelectExpression
            //        );
            //}
            //else
            //{
            //    ARProxy4Linq<T> proxy = (ARProxy4Linq<T>)Activator.CreateInstance(
            //        typeof(ARProxy4Linq<T>), context, factory);
            //    return proxy.GetEntryByQuery(tr.Qulification.ToString());
            //}

            #endregion
        }
示例#10
0
 public QueryVisitor()
 {
     tr = new TranslateResult();
 }
示例#11
0
 public QueryVisitor()
 {
     tr = new TranslateResult();
 }