/// <summary> /// 逆向解析方法 /// </summary> /// <param name="Param"></param> /// <returns></returns> public virtual ISocketResult ExecuteCallFuncHandler(SocketMiddleData Param) { //一定是其它服务 List <Type> SourceTypes = DependencyLibrary.Dependency.Where(item => item.GetCustomAttribute(typeof(SocketRouteAttribute)) != null).ToList(); var Routes = Param.MiddleResult.Router.Split("/").ToList();//接受的数据路由 foreach (var Items in SourceTypes) { SocketRouteAttribute SocketRoute = (Items.GetCustomAttribute(typeof(SocketRouteAttribute)) as SocketRouteAttribute); //比较接受的路由和当前程序的路由是否一直 //全部得小写 if (SocketRoute.InternalServer.ToLower() == Routes[0] && (SocketRoute.ControllerName.IsNullOrEmpty() ? Items.Name.ToLower().Contains(Routes[1]) : Items.Name.ToLower().Contains(SocketRoute.ControllerName.ToLower()))) { //查询到了这个类 //开始处理所有方法 var SoucreMethods = Items.GetMethods().Where(x => x.GetCustomAttribute(typeof(SocketMethodAttribute)) != null).ToList(); foreach (var Item in SoucreMethods) { SocketMethodAttribute SocketMethod = (Item.GetCustomAttribute(typeof(SocketMethodAttribute)) as SocketMethodAttribute); //找到对应方法 if (SocketMethod.MethodName.IsNullOrEmpty() ? Routes[2] == Item.Name.ToLower() : SocketMethod.MethodName.ToLower() == Routes[2]) { //路由数量大于等于4说明有版本号 if (Routes.Count >= 4 && !SocketMethod.MethodVersion.IsNullOrEmpty() && SocketMethod.MethodVersion.ToLower() == Routes.LastOrDefault()) { //1.如果启用了Session需要用户实现ISocketSessionHandler处理 //2.Invoke方法 if (!ExecuteCallSessionHandler(Item, Param.Session)) { return new SocketResultDefault { SocketJsonData = ExecuteNoAuthor().ToJson() } } ; return(ExecuteCallDataHandler(Items, Item, Param.MiddleResult)); } else { //1.如果启用了Session需要用户实现ISocketSessionHandler处理 //2.Invoke方法 if (!ExecuteCallSessionHandler(Item, Param.Session)) { return new SocketResultDefault { SocketJsonData = ExecuteNoAuthor().ToJson() } } ; else { return(ExecuteCallDataHandler(Items, Item, Param.MiddleResult)); } } } } } } return(null); }
/// <summary> /// 查询需要生成APIJson的接口 /// </summary> public SocketMiddleData FindLibrary() { List <Type> SourceType = DependencyLibrary.Dependency.Where(item => item.GetCustomAttribute(typeof(SocketRouteAttribute)) != null).ToList(); foreach (var Items in SourceType) { List <string> Route = new List <string>(); SocketRouteAttribute SocketRoute = (Items.GetCustomAttribute(typeof(SocketRouteAttribute)) as SocketRouteAttribute); string ControllerName = string.Empty; if (SocketRoute.ControllerName.IsNullOrEmpty()) { ControllerName = Items.Name; } else { ControllerName = SocketRoute.ControllerName; } Items.GetMethods().Where(x => x.GetCustomAttribute(typeof(SocketMethodAttribute)) != null).ToList().ForEach(Item => { SocketMethodAttribute SocketMethod = (Item.GetCustomAttribute(typeof(SocketMethodAttribute)) as SocketMethodAttribute); string SocketUrl = string.Empty; if (SocketMethod.MethodName.IsNullOrEmpty()) { SocketUrl = $"{SocketRoute.InternalServer}/{ControllerName}/{Item.Name}"; } else { SocketUrl = $"{SocketRoute.InternalServer}/{ControllerName}/{SocketMethod.MethodName}"; } if (!SocketMethod.MethodVersion.IsNullOrEmpty()) { SocketUrl = SocketUrl + "/" + SocketMethod.MethodVersion; } Route.Add(SocketUrl.ToLower()); }); XPlusEx.XTry(() => { var Key = SocketRoute.InternalServer.ToLower(); if (SocketJson.ContainsKey(Key)) { SocketJson[Key].AddRange(Route); } else { SocketJson.Add(Key, Route); } }, Ex => throw Ex); } CreateSocketApiJsonScript(); return(SocketMiddleData.Middle(SendTypeEnum.Init, SocketResultDefault.SetValue(null, SocketJson.ToJson()))); }