示例#1
0
        public static ServiceInstanceContainer GetService(RpcAction action)
        {
            if (action == null) throw new ArgumentNullException(nameof(action));
            if (action.ServiceCreator == null) throw new ArgumentException("action.ServiceCreator can't be null");

            var container = Pool.GetOrAdd(action, (k) =>
                new ServiceInstanceContainerPool(action.ServiceCreator) { Size = 1000 });
            return container.GetInstanceContainer();
        }
示例#2
0
        public static ServiceInstanceContainer GetService(RpcAction action)
        {
            if (action == null)
            {
                throw new ArgumentNullException(nameof(action));
            }
            if (action.ServiceCreator == null)
            {
                throw new ArgumentException("action.ServiceCreator can't be null");
            }

            var container = Pool.GetOrAdd(action, (k) =>
                                          new ServiceInstanceContainerPool(action.ServiceCreator)
            {
                Size = 1000
            });

            return(container.GetInstanceContainer());
        }
示例#3
0
        private RpcAction GetActionInternal(Type serviceType, string actionName)
        {
            var method = MethodHelper.GetActionMethod(serviceType, actionName, _ignoreCase);

            if (method == null)
            {
                string tryName;
                if (actionName.EndsWith("Async", StringComparison.OrdinalIgnoreCase))
                {
                    tryName = actionName.Substring(0, actionName.Length - 5);
                }
                else
                {
                    tryName = actionName + "Async";
                }

                method = MethodHelper.GetActionMethod(serviceType, tryName, _ignoreCase);

                //method = MethodHelper.GetActionMethod(serviceType, "Begin" + actionName);
                //var endMethod = MethodHelper.GetActionMethod(serviceType, "End" + actionName);
                //if (method == null && endMethod == null)
                //{
                //	return null;
                //}
            }

            if (method == null)
                return null;

            var hasReturn = method.ReturnType.FullName != "System.Void";

            var arguments = method.GetParameters();
            var argumentType = TypeCreator.GetParameterType(method);

            Delegate methodFunc;
            var isTask = false;
            #if NETCORE
            if (method.ReturnType == typeof(Task)
                || (method.ReturnType.GetTypeInfo().IsGenericType && method.ReturnType.GetTypeInfo().BaseType == typeof(Task)))
            #else
            if (method.ReturnType == typeof(Task)
                || (method.ReturnType.IsGenericType && method.ReturnType.BaseType == typeof(Task)))
            #endif
            {
                isTask = true;
                //isAsync = true;
                methodFunc = MethodHelper.GetCallMethodFunc(serviceType, argumentType, arguments, method, hasReturn);
            }
            else
            {
                //argumentType = TypeCreator.GetParameterType(method);
                methodFunc = MethodHelper.GetCallMethodFunc(serviceType, argumentType, arguments, method, hasReturn);
            }

            var action = new RpcAction
            {
                Name = actionName,
                ArgumentCount = arguments.Length,
                ArgumentType = argumentType,
                DefaultArgument = GetDefaultValue(argumentType),
                MethodInfo = method,
                HasReturnValue = hasReturn,
                ServiceCreator = TypeCreator.GetCreateInstanceFunc(serviceType),
                IsStatic = method.IsStatic,
                IsTask = isTask,
                Service = _service,
            };

            if (isTask)
            {
                action.InvokeTask = methodFunc as Func<object, object, object>;
                action.TaskResultType = method.ReturnType.GetGenericArguments().FirstOrDefault();
                action.ResultType = action.TaskResultType;
            }
            else if (hasReturn)
            {
                action.Func = methodFunc as Func<object, object, object>;
                action.ResultType = method.ReturnType;
            }
            else
            {
                action.Action = methodFunc as Action<object, object>;
            }

            return action;
        }
示例#4
0
        private RpcAction GetActionInternal(Type serviceType, string actionName)
        {
            var method = MethodHelper.GetActionMethod(serviceType, actionName, _ignoreCase);

            if (method == null)
            {
                string tryName;
                if (actionName.EndsWith("Async", StringComparison.OrdinalIgnoreCase))
                {
                    tryName = actionName.Substring(0, actionName.Length - 5);
                }
                else
                {
                    tryName = actionName + "Async";
                }

                method = MethodHelper.GetActionMethod(serviceType, tryName, _ignoreCase);

                //method = MethodHelper.GetActionMethod(serviceType, "Begin" + actionName);
                //var endMethod = MethodHelper.GetActionMethod(serviceType, "End" + actionName);
                //if (method == null && endMethod == null)
                //{
                //	return null;
                //}
            }

            if (method == null)
            {
                return(null);
            }

            var hasReturn = method.ReturnType.FullName != "System.Void";

            var arguments    = method.GetParameters();
            var argumentType = TypeCreator.GetParameterType(method);

            Delegate methodFunc;
            var      isTask = false;

#if NETCORE
            if (method.ReturnType == typeof(Task) ||
                (method.ReturnType.GetTypeInfo().IsGenericType&& method.ReturnType.GetTypeInfo().BaseType == typeof(Task)))
#else
            if (method.ReturnType == typeof(Task) ||
                (method.ReturnType.IsGenericType && method.ReturnType.BaseType == typeof(Task)))
#endif
            {
                isTask = true;
                //isAsync = true;
                methodFunc = MethodHelper.GetCallMethodFunc(serviceType, argumentType, arguments, method, hasReturn);
            }
            else
            {
                //argumentType = TypeCreator.GetParameterType(method);
                methodFunc = MethodHelper.GetCallMethodFunc(serviceType, argumentType, arguments, method, hasReturn);
            }

            var action = new RpcAction
            {
                Name            = actionName,
                ArgumentCount   = arguments.Length,
                ArgumentType    = argumentType,
                DefaultArgument = GetDefaultValue(argumentType),
                MethodInfo      = method,
                HasReturnValue  = hasReturn,
                ServiceCreator  = TypeCreator.GetCreateInstanceFunc(serviceType),
                IsStatic        = method.IsStatic,
                IsTask          = isTask,
                Service         = _service,
            };

            if (isTask)
            {
                action.InvokeTask     = methodFunc as Func <object, object, object>;
                action.TaskResultType = method.ReturnType.GetGenericArguments().FirstOrDefault();
                action.ResultType     = action.TaskResultType;
            }
            else if (hasReturn)
            {
                action.Func       = methodFunc as Func <object, object, object>;
                action.ResultType = method.ReturnType;
            }
            else
            {
                action.Action = methodFunc as Action <object, object>;
            }

            return(action);
        }