Exemplo n.º 1
0
        private void InitServiceMetadata()
        {
            Type[] types = ReflectionHelper.GetAssembly(_section.ServiceDLL).GetTypes();

            foreach (Type type in types)
            {
                if (!type.IsInterface)
                {
                    continue;
                }

                RpcServiceAttribute serviceAttribute = (RpcServiceAttribute)type.GetCustomAttribute(typeof(RpcServiceAttribute), false);
                if (serviceAttribute != null)
                {
                    ServiceMetadata serviceMetadata = new ServiceMetadata()
                    {
                        ServiceName     = type.FullName,
                        ServiceType     = type,
                        ServiceImplType = ReflectionHelper.GetServiceImplType(types, type),
                    };

                    foreach (MethodInfo method in type.GetMembers())
                    {
                        RpcMethodAttribute methodAttribute = (RpcMethodAttribute)method.GetCustomAttribute(typeof(RpcMethodAttribute), false);
                        if (methodAttribute != null)
                        {
                            MethodMetadata methodMetadata = new MethodMetadata()
                            {
                                MethodName = methodAttribute.MethodName,
                                Method     = method
                            };

                            serviceMetadata.MethodMetadatas.Add(methodMetadata);
                        }
                    }

                    _cacheContainer.Application.ServiceMetadatas.Add(serviceMetadata);
                }
            }
        }
Exemplo n.º 2
0
        private void AddHttpServiceRouter(Type type, MethodInfo m, RpcServiceAttribute sAttr, RpcMethodAttribute mAttr,
                                          RouterAttribute rAttr, HttpRouteOptions options)
        {
            var item = new RouteItem
            {
                Path         = rAttr.Path,
                AcceptVerb   = rAttr.AcceptVerb,
                Category     = rAttr.Category,
                InvokeMethod = m,
                MessageId    = mAttr.MessageId,
                ServiceId    = sAttr.ServiceId
            };

            //special MessageId;
            var args = new object[] { this.specialMessageId };

            item.InvokeService = this._proxyCreate.MakeGenericMethod(type).Invoke(this._proxy, args);

            if (rAttr.PluginType != null)
            {
                item.Plugin = ActivatorUtilities.CreateInstance(this._provider, rAttr.PluginType) as IHttpPlugin;
            }
            options.Items.Add(item);

            _logger.LogDebug("url:{0},verb:{1},service:{2},method:{3}",
                             item.Path, item.AcceptVerb, type.Name.Split('.').Last(), m.Name);
        }