Ejemplo n.º 1
0
        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());
            }
        }
Ejemplo n.º 2
0
        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());
            }
        }
Ejemplo n.º 3
0
 /// <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);
 }
Ejemplo n.º 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 });
        }