コード例 #1
0
        /// <summary>
        /// 发送内部通信
        /// </summary>
        /// <param name="Param"></param>
        /// <param name="Session"></param>
        public static void SendInternalInfo(SocketSerializeData SerializeData, ISocketSession Session = null)
        {
            ISocketResult Param = new SocketResultDefault()
            {
                Router = SerializeData.Route, SocketJsonData = SerializeData.Providor?.ToJson()
            };

            SocketClient.Send(SocketMiddleData.Middle(SendTypeEnum.InternalInfo, Param, Session, SocketConstConfig.ClientPort).ToJson());
        }
コード例 #2
0
        /// <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())));
        }