예제 #1
0
        public void ARProxy_GetEntryListStatictisc_avg_qulifier_group_success()
        {
            ARLoginContext context = new ARLoginContext(TestServer, TestAdmin, TestAdminPwd);
            try
            {
                List<UInt32> groupIds = new List<UInt32>();
                groupIds.Add(TestCharacterFieldId);
                ARProxy<NRemedy_Test_Regular_Form> proxy = new ARProxy<NRemedy_Test_Regular_Form>(context);
                var retlist = proxy.GetListEntryStatictisc(
                    "'Character Field' LIKE \"%你好%\"",
                    ARStatictisc.STAT_OP_AVERAGE,
                    TestIntFieldId,
                    groupIds
                    );
                Assert.AreEqual(2, retlist.Count);
                Dictionary<String, int> assertTable = new Dictionary<string, int>();
                //assertTable.Add("Hello Remedy", 7);
                assertTable.Add("你好 RemedySet Something", 3);
                assertTable.Add("你好 Remedy", 2);

                Assert.AreEqual(assertTable[retlist[0].CharacterField], Convert.ToInt32(retlist[0].Statictisc));
                Assert.AreEqual(assertTable[retlist[1].CharacterField], Convert.ToInt32(retlist[1].Statictisc));

            }
            catch (Exception ex)
            {
                Assert.AreEqual(null, ex);

            }
            finally
            {
                context.Dispose();
            }
        }
예제 #2
0
        public void ARProxy_GetEntryListStatictisc_by_Properties_Str_avg_qulifier_group_success()
        {
            ARLoginContext context = new ARLoginContext(TestServer, TestAdmin, TestAdminPwd);

            try
            {
                ARProxy <NRemedy_Test_Regular_Form> proxy = new ARProxy <NRemedy_Test_Regular_Form>(context);
                var retlist = proxy.GetListEntryStatictisc(
                    "'Character Field' LIKE \"%你好%\"",

                    TestIntFieldId,
                    new string[] { "CharacterField" },
                    ARStatictisc.STAT_OP_AVERAGE
                    );
                Assert.AreEqual(2, retlist.Count);
                Dictionary <String, int> assertTable = new Dictionary <string, int>();
                //assertTable.Add("Hello Remedy", 7);
                assertTable.Add("你好 RemedySet Something", 3);
                assertTable.Add("你好 Remedy", 2);

                Assert.AreEqual(assertTable[retlist[0].CharacterField], Convert.ToInt32(retlist[0].Statictisc));
                Assert.AreEqual(assertTable[retlist[1].CharacterField], Convert.ToInt32(retlist[1].Statictisc));
            }
            catch (Exception ex)
            {
                Assert.AreEqual(null, ex);
            }
            finally
            {
                context.Dispose();
            }
        }
예제 #3
0
        public void ARProxy_GetEntryListStatictisc_count_noqulifier_group_success()
        {
            ARLoginContext context = new ARLoginContext(TestServer, TestAdmin, TestAdminPwd);

            try
            {
                List <UInt32> groupIds = new List <UInt32>();
                groupIds.Add(TestCharacterFieldId);
                ARProxy <NRemedy_Test_Regular_Form> proxy = new ARProxy <NRemedy_Test_Regular_Form>(context);
                var retlist = proxy.GetListEntryStatictisc(
                    null,
                    ARStatictisc.STAT_OP_COUNT,
                    null,
                    groupIds
                    );
                Assert.AreEqual(3, retlist.Count);
                Dictionary <String, int> assertTable = new Dictionary <string, int>();
                assertTable.Add("Hello Remedy", 7);
                assertTable.Add("你好 RemedySet Something", 2);
                assertTable.Add("你好 Remedy", 9);
                Assert.AreEqual(assertTable[retlist[0].CharacterField], Convert.ToInt32(retlist[0].Statictisc));
                Assert.AreEqual(assertTable[retlist[1].CharacterField], Convert.ToInt32(retlist[1].Statictisc));
                Assert.AreEqual(assertTable[retlist[2].CharacterField], Convert.ToInt32(retlist[2].Statictisc));
            }
            catch (Exception ex)
            {
                Assert.AreEqual(null, ex);
            }
            finally
            {
                context.Dispose();
            }
        }
예제 #4
0
        public void ARProxy_GetEntryListStatictisc_count_qulifier_nogroup_success()
        {
            ARLoginContext context = new ARLoginContext(TestServer, TestAdmin, TestAdminPwd);

            try
            {
                List <UInt32> groupIds = new List <UInt32>();
                ARProxy <NRemedy_Test_Regular_Form> proxy = new ARProxy <NRemedy_Test_Regular_Form>(context);
                groupIds.Add(TestCharacterFieldId);
                var retlist = proxy.GetListEntryStatictisc(
                    "'Character Field' = \"Hello Remedy\"",
                    ARStatictisc.STAT_OP_COUNT,
                    null,
                    null
                    );
                Assert.AreEqual(1, retlist.Count);
                Assert.AreEqual(7, Convert.ToInt32(retlist[0].Statictisc));
            }
            catch (Exception ex)
            {
                Assert.AreEqual(null, ex);
            }
            finally
            {
                context.Dispose();
            }
        }
예제 #5
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
        }
예제 #6
0
        public void ARProxy_GetEntryListStatictisc_count_qulifier_nogroup_success()
        {
            ARLoginContext context = new ARLoginContext(TestServer, TestAdmin, TestAdminPwd);
            try
            {
                List<UInt32> groupIds = new List<UInt32>();
                ARProxy<NRemedy_Test_Regular_Form> proxy = new ARProxy<NRemedy_Test_Regular_Form>(context);
                groupIds.Add(TestCharacterFieldId);
                var retlist = proxy.GetListEntryStatictisc(
                    "'Character Field' = \"Hello Remedy\"",
                    ARStatictisc.STAT_OP_COUNT,
                    null,
                    null
                    );
                Assert.AreEqual(1, retlist.Count);
                Assert.AreEqual(7, Convert.ToInt32(retlist[0].Statictisc));
            }
            catch (Exception ex)
            {
                Assert.AreEqual(null, ex);

            }
            finally
            {
                context.Dispose();
            }
        }