Exemple #1
0
        /// <summary>
        /// 新增容器中的外派方法,外派方法可被容器外部通过 Delive 方法调用
        /// </summary>
        public void Add <InterfaceT>(ResolveDelegate <InterfaceT> target, bool onlyOnce = false)
        {
            int statu = 0;

            MethodInfo method = target.Method;

            object[] attributes = method.GetCustomAttributes(callableAttrType, false);

            int               max = attributes.Length;
            string            resolverName, alias;
            CallableAttribute attribute;
            IResolvable       resolvable;

            for (int i = 0; i < max; i++)
            {
                attribute    = attributes[i] as CallableAttribute;
                resolverName = attribute.ResolverName;
                resolverName = string.IsNullOrEmpty(resolverName) ? method.Name : resolverName;
                alias        = attribute.Alias;
                resolvable   = ServersHolder.GetResolvable(ref alias, out statu);
                if (statu == 0)
                {
                    "error".Log(resolvable == default, "Resolvable is null, alias is " + alias);
                    resolvable.SetResolver(resolverName, target, out statu, onlyOnce);
                }
            }
        }
Exemple #2
0
        public InterfaceT Resolve <InterfaceT>(string alias, string resolverName = "")
        {
            int         resultError;
            InterfaceT  result     = default;
            IResolvable resolvable = ServersHolder.GetResolvable(ref alias, out resultError);

            if (resultError == 0)
            {
                IResolverHandler resolverHandler = resolvable.GetResolver <InterfaceT>(Resolvable.RESOLVER_DEF, out _);
                resolverHandler.InvokeResolver();
                result = (InterfaceT)resolverHandler.ResolverParam;

                resolverHandler = resolvable.GetResolver <InterfaceT>(Resolvable.RESOLVER_CRT, out _);
                resolverHandler.SetParam(ref result);
                resolverHandler.InvokeResolver();

                result = (InterfaceT)resolverHandler.ResolverParam;

                if ((result != default) && !string.IsNullOrEmpty(resolverName))
                {
                    resolverHandler = resolvable.GetResolver <InterfaceT>(resolverName, out _);
                    resolverHandler.SetParam(ref result);
                    resolverHandler.InvokeResolver();
                    if (resolverHandler.OnlyOnce)
                    {
                        resolvable.RemoveResolver <InterfaceT>(resolverName, out _);
                    }
                }
            }
            return(result);
        }
Exemple #3
0
        /// <summary>
        /// 撤销已定义在解析器中的一个解析器函数
        /// </summary>
        public int RevokeResolver <InterfaceT>(string alias, string resolverName, ResolveDelegate <InterfaceT> target)
        {
            int         statu      = 0;
            IResolvable resolvable = ServersHolder.GetResolvable(ref alias, out statu);

            if (statu == 0)
            {
                "error".Log(resolvable == default, "Resolvable is null when MakeResolver, alias is " + alias);
                resolvable.RevokeResolver(resolverName, target);
            }
            return(statu);
        }
Exemple #4
0
        public int MakeResolver <InterfaceT>(string alias, string resolverName, ResolveDelegate <InterfaceT> target)
        {
            int         statu      = 0;
            IResolvable resolvable = ServersHolder.GetResolvable(ref alias, out statu);

            if (statu == 0)
            {
                Tester.Instance.Log(TesterBaseApp.Instance, TesterBaseApp.LOG, resolvable == default, "error: Resolvable is null when MakeResolver, alias is " + alias);
                resolvable.SetResolver(resolverName, target, out statu, false, true);
            }
            return(statu);
        }
Exemple #5
0
        public override void InitServer()
        {
            base.InitServer();

            ServersHolder.AddResolvableConfig(ServerConfigs);

            Register <INotice>(NoticeResolver, Pooling <Notice> .Instance);
            Register <IParamNotice <int> >(IntParamerResolver, Pooling <ParamNotice <int> > .Instance);
            Register <IParamNotice <bool> >(BoolParamerResolver, Pooling <ParamNotice <bool> > .Instance);
            Register <IParamNotice <Vector3> >(V3ParamerResolver, Pooling <ParamNotice <Vector3> > .Instance);
            Register <IParamNotice <string> >(StringParamerResolver, Pooling <ParamNotice <string> > .Instance);
        }
Exemple #6
0
        public override void InitServer()
        {
            base.InitServer();

            ServersHolder.AddResolvableConfig(new ResolvableConfigItem <IConfigNotice, ConfigNotice>("ConfigNotice"));

            Register <IConfigNotice>(GetConfigNotice, Pooling <ConfigNotice> .Instance);

            if (hasLocalsConfig)
            {
                Register <IConfigHolder>(GetLocalCNConfig);
            }

            mHelper = new ConfigHelper();

            SetConfigCreater("Locals_CN");
        }
Exemple #7
0
        /// <summary>
        /// 注册一个新的解析器
        /// </summary>
        /// <typeparam name="InterfaceT">要解析对象的接口</typeparam>
        /// <param name="target">解析器函数</param>
        /// <param name="factory">解析对象的对象池或工厂对象</param>
        /// <returns></returns>
        public int Register <InterfaceT>(ResolveDelegate <InterfaceT> target, params IPoolBase[] factory)
        {
            IResolvable[] list = ServersHolder.SetResolvable(target, out int statu);
            int           max  = list != default ? list.Length : 0;

            if (max > 0)
            {
                IResolvable resolvable;
                IPoolBase   factoryItem;
                int         factoryCount = factory != default ? factory.Length : 0;
                for (int i = 0; i < max; i++)
                {
                    factoryItem = factoryCount > i ? factory[i] : default;
                    resolvable  = list[i];
                    resolvable.InitResolver <InterfaceT>(ServersHolder, factoryItem);
                }
            }
            return(statu);
        }
Exemple #8
0
        /// <summary>
        /// 通过接口及别名解析出一个对象的实例并根据解析器名调用解析器函数
        /// </summary>
        /// <typeparam name="InterfaceT">接口</typeparam>
        /// <param name="alias">别名</param>
        /// <param name="resolverName">解析器名,用于将解析得到的对象传入对应的加工函数,不传此参表示仅获取实例</param>
        /// <param name="customResolver">定制的解析器函数,在传入加工函数前预处理解析得到的对象</param>
        /// <returns>需要获得的实例对象</returns>
        public InterfaceT Resolve <InterfaceT>(string alias, string resolverName = "", ResolveDelegate <InterfaceT> customResolver = default)
        {
            int         resultError;
            InterfaceT  result     = default;
            IResolvable resolvable = ServersHolder.GetResolvable(ref alias, out resultError);

            "error:Resolvable is null, alias is {0}".Log(resolvable == default, alias);

            if (resultError == 0)
            {
                IResolverHandler resolverHandler;

                resolverHandler = resolvable.GetResolver <InterfaceT>(Resolvable.RESOLVER_CRT, out _);
                resolverHandler.InvokeResolver();
                result = (InterfaceT)resolverHandler.ResolverParam;

                resolverHandler = resolvable.GetResolver <InterfaceT>(Resolvable.RESOLVER_INIT, out _);
                resolverHandler.SetParam(ref result);
                resolverHandler.InvokeResolver();
                result = (InterfaceT)resolverHandler.ResolverParam;

                if (!result.Equals(default))