예제 #1
0
        /// <summary>
        /// The Send.
        /// </summary>
        /// <typeparam name="TQuery">.</typeparam>
        /// <typeparam name="TQueryResult">.</typeparam>
        /// <param name="query">The query <see cref="TQuery"/>.</param>
        /// <returns>The <see cref="TQueryResult"/>.</returns>
        public SimpleResponse <TQueryResult> Send <TQuery, TQueryResult>(TQuery query)
            where TQueryResult : class, IQueryResult
            where TQuery : class, IQuery <TQueryResult>
        {
            var handler =
                QueryHandlerFactory.GetQueryHandler <TQuery, TQueryResult>();

            var authorize = handler.Authorize(query);

            if (authorize.ResponseCode < 0)
            {
                return(new SimpleResponse <TQueryResult>
                {
                    ResponseCode = authorize.ResponseCode,
                    ResponseMessage = authorize.ResponseMessage,
                    RCode = authorize.RCode
                });
            }

            var queryResult = handler.Handle(query);

            return(queryResult);
        }
예제 #2
0
        public static object Query(HandlerConfig handlerConfig, object complexData, IDictionary <string, object> queryParams = null)
        {
            IQueryHandler queryHandler = QueryHandlerFactory.GetQueryHandler(handlerConfig.QueryType);

            if (handlerConfig.Configs == null || handlerConfig.Configs.Any() == false)
            {
                throw new ArgumentNullException("handlerConfig.Configs");
            }

            var context = new Context
            {
                HandlerConfig = handlerConfig,
                Configs       = handlerConfig.Configs,
                Params        = queryParams,
                ComplexData   = complexData,
            };

            ParamConvertUtil.DoConvert(context);
            var returnData = queryHandler.Query(context);

            //执行完查询后回调
            return(handlerConfig.OnQueryEnd(returnData, queryParams));
        }