Beispiel #1
0
        public static string GetNugetVersion(string start = null, bool pre = false)
        {
            var Cache = GlobalServices.GetRequiredService <IDistributedCache>() as IDistributedCache;

            if (Cache.TryGetValue("nugetversion", out NugetInfo rv) == false || rv == null)
            {
                NugetInfo v    = APIHelper.CallAPI <NugetInfo>($"https://api-v2v3search-0.nuget.org/query?q=WalkingTec.Mvvm.Mvc&prerelease={pre.ToString().ToLower()}").Result;
                var       data = v;
                Cache.Add("nugetversion", data, new DistributedCacheEntryOptions()
                {
                    SlidingExpiration = new TimeSpan(0, 0, 36000)
                });
                rv = data;
            }

            if (string.IsNullOrEmpty(start))
            {
                return(rv.data[0]?.version);
            }
            else
            {
                return(rv.data[0].versions.Select(x => x.version).Where(x => x.StartsWith(start)).Last());
            }
        }
 /// <summary>
 /// 检查方法调用类型的表达式
 /// </summary>
 /// <param name="node">表达式节点</param>
 /// <returns>修改后的表达式</returns>
 protected override Expression VisitMethodCall(MethodCallExpression node)
 {
     //如果不是添加模式,那么删除所有的order
     if (_addMode == false)
     {
         var aType = node.Arguments[0].Type;
         //如果节点是order
         if (node != null && (node.Method.Name.ToLower() == "orderby" || node.Method.Name.ToLower() == "orderbydescending") && aType.GetTypeInfo().IsGenericType)
         {
             //继续往上找到不是where的节点
             return(GetParentExpNotOrder(node));
         }
     }
     //如果是添加模式
     else
     {
         var             modelType = node.Type.GenericTypeArguments[0];
         List <SortInfo> info      = new List <SortInfo>();
         var             temp      = APIHelper.JsonDeserialize <List <SortInfo> >(_sortinfo);
         info.AddRange(temp);
         Expression rv = null;
         foreach (var item in info)
         {
             ParameterExpression pe  = Expression.Parameter(modelType);
             Expression          pro = Expression.PropertyOrField(pe, item.Property);
             Type       proType      = modelType.GetProperty(item.Property).PropertyType;
             ChangePara cp           = new ChangePara();
             cp.Change(pro, pe);
             if (item.Direction == SortDir.Asc)
             {
                 if (rv == null)
                 {
                     rv = Expression.Call(
                         typeof(Queryable),
                         "OrderBy",
                         new Type[] { modelType, proType },
                         node,
                         Expression.Lambda(pro, new ParameterExpression[] { pe }));
                 }
                 else
                 {
                     rv = Expression.Call(
                         typeof(Queryable),
                         "ThenBy",
                         new Type[] { modelType, proType },
                         rv,
                         Expression.Lambda(pro, new ParameterExpression[] { pe }));
                 }
             }
             if (item.Direction == SortDir.Desc)
             {
                 if (rv == null)
                 {
                     rv = Expression.Call(
                         typeof(Queryable),
                         "OrderByDescending",
                         new Type[] { modelType, proType },
                         node,
                         Expression.Lambda(pro, new ParameterExpression[] { pe }));
                 }
                 else
                 {
                     rv = Expression.Call(
                         typeof(Queryable),
                         "ThenByDescending",
                         new Type[] { modelType, proType },
                         rv,
                         Expression.Lambda(pro, new ParameterExpression[] { pe }));
                 }
             }
         }
         return(rv);
     }
     return(base.VisitMethodCall(node));
 }