コード例 #1
0
ファイル: RpcServer.cs プロジェクト: cosmosbox/cosmos
        public RpcServer(IRpcService rpcService, string host = "*", int responsePort = -1) : base(responsePort, 0, host)
        {
            _rpcService = rpcService;

            foreach (var methodInfo in rpcService.GetType().GetMethods())
            {
                foreach (var attr in methodInfo.GetCustomAttributes(typeof(ServiceFuncAttribute)))
                {
                    var funcAttr = (ServiceFuncAttribute)attr;
                    var args = methodInfo.GetParameters();
                    var requestType = args[0].ParameterType;
                    var retType = methodInfo.ReturnType;

                    var info = new RpcServiceFuncInfo()
                    {
                        ArgType = requestType,
                        ReturnType = retType,
                        Method = methodInfo,
                    };
                    _serviceFuncs[requestType] = info;
                    Logger.Info("Register Service Func, RequestType: {0}, ResponseType: {1}", requestType, info.ReturnType);

                }
            }

            if (_serviceFuncs.Count <= 0)
            {
                Logger.Error("RpcServcice(Type:{0}), has no funcs mark with ServiceFuncAttribute", rpcService.GetType());
            }
        }
コード例 #2
0
ファイル: RpcServer.cs プロジェクト: ly774508966/cosmos
        public RpcServer(IRpcService rpcService, string host = "*", int responsePort = -1) : base(responsePort, 0, host)
        {
            _rpcService = rpcService;

            foreach (var methodInfo in rpcService.GetType().GetMethods())
            {
                foreach (var attr in methodInfo.GetCustomAttributes(typeof(ServiceFuncAttribute)))
                {
                    var funcAttr    = (ServiceFuncAttribute)attr;
                    var args        = methodInfo.GetParameters();
                    var requestType = args[0].ParameterType;
                    var retType     = methodInfo.ReturnType;

                    var info = new RpcServiceFuncInfo()
                    {
                        ArgType    = requestType,
                        ReturnType = retType,
                        Method     = methodInfo,
                    };
                    _serviceFuncs[requestType] = info;
                    Logger.Info("Register Service Func, RequestType: {0}, ResponseType: {1}", requestType, info.ReturnType);
                }
            }

            if (_serviceFuncs.Count <= 0)
            {
                Logger.Error("RpcServcice(Type:{0}), has no funcs mark with ServiceFuncAttribute", rpcService.GetType());
            }
        }
コード例 #3
0
ファイル: RpcServer.cs プロジェクト: apkbox/closetrpc
 /// <summary>
 /// Registers a service instance.
 /// </summary>
 /// <param name="service">Service instance.</param>
 public void RegisterService(IRpcService service)
 {
     this.log.InfoFormat(
         "Registered service '{0}' with name '{1}'",
         service.GetType().AssemblyQualifiedName,
         service.Name);
     this.objectManager.RegisterService(service);
 }
コード例 #4
0
        public void RegisterRpcService <TRequest, TResponse>(IRpcService <TRequest, TResponse> service)
            where TRequest : class, new()
            where TResponse : class, new()
        {
            MethodInfo addEndpointMethod =
                typeof(RpcModule)
                .GetMethod("AddEndpoint", BindingFlags.NonPublic | BindingFlags.Instance);

            var typeArguments =
                service
                .GetType()
                .GetInterfaces()
                .Where(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IRpcService <,>))
                .SelectMany(i => i.GetGenericArguments())
                .ToArray();

            addEndpointMethod
            .MakeGenericMethod(typeArguments)
            .Invoke(this, new object[] { _rpcServiceResolver });
        }