Пример #1
0
 public static List <MetaDataResult> AllMetaDataResult()
 {
     if (ResultList == null)
     {
         ResultList = new List <MetaDataResult>();
         foreach (var item in CacheRouteMappingGenrator.AllTypes)
         {
             CacheRouteMapping mapping;
             if (!CacheRouteMappingGenrator.TryGetValue(item, out mapping))
             {
                 continue;
             }
             foreach (var route in mapping.AllRoutes)
             {
                 CacheRouteInfo value;
                 if (!mapping.TryGetQueryCache(route, out value))
                 {
                     continue;
                 }
                 MetaDataResult entity = new MetaDataResult()
                 {
                     TypeName    = item.FullName,
                     RouteName   = route,
                     Description = value.RightsName,
                 };
                 ResultList.Add(entity);
             }
         }
         ResultList = ResultList.OrderBy(q => q.RouteName).ToList();
     }
     return(ResultList);
 }
Пример #2
0
        public bool PreExcete(ReaderErrorEventHandler OnReaderError)
        {
            CacheRouteMapping mapping;

            if (!CacheRouteMappingGenrator.TryGetValue(this._type, out mapping))
            {
                if (OnReaderError != null)
                {
                    OnReaderError(EnumAjaxParams.ReqCode.NotFoundRouteInfo, "未找到路由设置信息");
                }

                return(false);
            }
            string         routeName = Reader.RouteName.ToLower();
            CacheRouteInfo value;

            if (!mapping.TryGetQueryCache(routeName, out value))
            {
                if (OnReaderError != null)
                {
                    OnReaderError(EnumAjaxParams.ReqCode.NotFoundCacheAPI, "未找到相匹配的API信息");
                }
                return(false);
            }
            if (value.Parameters == null)
            {
                value.Parameters = new Dictionary <string, ParameterInfo>();
                ParameterInfo[] parameterInfos = value.Method.GetParameters();
                foreach (ParameterInfo item in parameterInfos)
                {
                    value.Parameters.Add(item.Name, item);
                }
                mapping.SetQueryCache(routeName, value);
            }
            Func <Func <Dictionary <string, object>, ServiceExchangeData> > cacheParamReader = () =>
            {
                value.ParamReader = CacheRouteMappingGenrator.GetParamReader(OnReaderError, value.ClassType, value.Method, value.Parameters);
                mapping.SetQueryCache(routeName, value);
                return(value.ParamReader);
            };

            if (!Reader.ParseMethod() || !Reader.ParseQuery())
            {
                if (OnReaderError != null)
                {
                    OnReaderError(EnumAjaxParams.ReqCode.MethodOrArgrumentIsNull, "方法和参数未定义");
                }
                return(false);
            }
            if (value.ParamReader == null)
            {
                cacheParamReader();
            }
            if (value.RouteFlags != RouteFlags.Default && this._Filters.Count > 0)
            {
                foreach (var item in this._Filters)
                {
                    if ((item.RouteFlags & value.RouteFlags) == item.RouteFlags)
                    {
                        var data = new ServiceFilterParam()
                        {
                            RightsName = value.RightsName
                        };
                        if (!item.Excute(data))
                        {
                            if (OnReaderError != null)
                            {
                                OnReaderError(EnumAjaxParams.ReqCode.FiltersError, "没有授权访问此方法!" + item.Name);
                            }
                            return(false);
                        }
                    }
                }
            }
            this.RouteValue = value;
            return(true);
        }
Пример #3
0
 public virtual void Initialize(Type type, string[] assemblyNames, params string[] modulePattern)
 {
     CacheRouteMappingGenrator.Initialize(type, assemblyNames, modulePattern);
 }