Beispiel #1
0
        private static void _DetectClass_Coder(Type cls, ref ServiceRegHolderClass holderCls)
        {
            if (cls.GetInterface(typeof(ICoder).Name) == null &&
                cls.GetCustomAttribute(typeof(CoderAttribute), false) == null)
            {
                return;
            }

            _CreateHolderClass(cls, ref holderCls);

            holderCls.asCoder     = true;
            holderCls.coderOpcode = GetCoderOpcode(cls);
        }
Beispiel #2
0
        private static ServiceRegHolderMethod _GetHolderMethod(ServiceRegHolderClass holderCls, MethodInfo mi)
        {
            ServiceRegHolderMethod holderMethod;

            if (holderCls.methods.TryGetValue(mi, out holderMethod))
            {
                return(holderMethod);
            }

            holderMethod = new ServiceRegHolderMethod(mi);
            holderCls.methods.Add(mi, holderMethod);

            return(holderMethod);
        }
Beispiel #3
0
        private static void _DetectMethod_FrameExcHandler(Type cls, MethodInfo mi, ServiceRegHolderClass holderCls)
        {
            FrameExcHandlerAttribute attr = mi.GetCustomAttribute(
                typeof(FrameExcHandlerAttribute), false) as FrameExcHandlerAttribute;

            if (attr == null)
            {
                return;
            }

            ServiceRegHolderMethod holderMethod = _GetHolderMethod(holderCls, mi);

            holderMethod.asFrameExcHandler = true;
        }
Beispiel #4
0
        private static void _CollectMethods(Type cls, ServiceRegHolderClass holderCls, ref MethodInfo[] clsMethods)
        {
            _GetClassMethods(cls, ref clsMethods);
            for (int i = 0; i < clsMethods.Length; i++)
            {
                MethodInfo clsMethod = clsMethods[i];
                _DetectMethod_Handler(cls, clsMethod, PacketHandlePhase.Handle, holderCls);
                _DetectMethod_Handler(cls, clsMethod, PacketHandlePhase.PreHandle, holderCls);
                _DetectMethod_Handler(cls, clsMethod, PacketHandlePhase.UnifyPreHandle, holderCls);

                _DetectMethod_PacketExcHandler(cls, clsMethod, holderCls);

                _DetectMethod_FrameExcHandler(cls, clsMethod, holderCls);
            }
        }
Beispiel #5
0
        private static ServiceRegHolderClass _CollectClass(Type cls)
        {
            ServiceRegHolderClass holderCls = null;

            _DetectClass_Facade(cls, ref holderCls);      // Facade detect.
            _DetectClass_Coder(cls, ref holderCls);       // ICoder detect.
            _DetectClass_GlobalCoder(cls, ref holderCls); // Global coder detect.

            // Collect all methods, only IFacade subclass can become service handlers.
            if (holderCls == null || !holderCls.asFacade)
            {
                return(holderCls);
            }

            MethodInfo[] clsMethods = null;
            _CollectMethods(cls, holderCls, ref clsMethods);

            return(holderCls);
        }
Beispiel #6
0
        private static void _DetectMethod_PacketExcHandler(Type cls, MethodInfo mi, ServiceRegHolderClass holderCls)
        {
            object[] attrs = mi.GetCustomAttributes(typeof(PacketExcHandlerAttribute), false);
            for (int i = 0; i < attrs.Length; i++)
            {
                PacketExcHandlerAttribute attr = attrs[i] as PacketExcHandlerAttribute;

                ServiceRegHolderMethod holderMethod = _GetHolderMethod(holderCls, mi);
                if (attr.phase == PacketHandlePhase.Handle)
                {
                    if (attr.asDefault)
                    {
                        holderMethod.asDftExcHandler = true;
                    }
                    else
                    {
                        holderMethod.asExcHandler = true;
                        _MergeOpcodes(ref holderMethod.excHandlerOpcodes, attr.opcodes);
                    }
                }
                else if (attr.phase == PacketHandlePhase.PreHandle)
                {
                    if (attr.asDefault)
                    {
                        holderMethod.asDftExcPreHandler = true;
                    }
                    else
                    {
                        holderMethod.asExcPreHandler = true;
                        _MergeOpcodes(ref holderMethod.excPreHandlerOpcodes, attr.opcodes);
                    }
                }
                else
                {
                    holderMethod.asExcUnifyPreHandler = true;
                }
            }
        }
Beispiel #7
0
        private static void _DetectMethod_Handler(Type cls, MethodInfo mi, PacketHandlePhase phase, ServiceRegHolderClass holderCls)
        {
            Type attrTy = (phase == PacketHandlePhase.Handle ? typeof(HandlerAttribute) : (
                               phase == PacketHandlePhase.PreHandle ? typeof(PreHandlerAttribute) : typeof(UnifyPreHandlerAttribute)));
            Attribute attr = mi.GetCustomAttribute(attrTy, false);

            if (attr == null)
            {
                return;
            }

            if (phase == PacketHandlePhase.Handle)
            {
                ServiceRegHolderMethod holderMethod = _GetHolderMethod(holderCls, mi);
                holderMethod.asHandler     = true;
                holderMethod.handlerOpcode = (attr as HandlerAttribute).opcode;
            }
            else if (phase == PacketHandlePhase.PreHandle)
            {
                ServiceRegHolderMethod holderMethod = _GetHolderMethod(holderCls, mi);
                holderMethod.asPreHandler     = true;
                holderMethod.preHandlerOpcode = (attr as PreHandlerAttribute).opcode;
            }
            else
            {
                ServiceRegHolderMethod holderMethod = _GetHolderMethod(holderCls, mi);
                holderMethod.asUnifyPreHandler = true;
            }
        }