示例#1
0
        /// <summary>
        /// 获取请求消息。
        /// </summary>
        /// <param name="context">处理上下文。</param>
        /// <exception cref="ArgumentNullException"><paramref name="context"/> 为 null。</exception>
        /// <exception cref="Exception">在当前上下文中找不到请求消息。</exception>
        /// <returns>请求消息实例。</returns>
        public static IRequestMessageBase GetRequestMessage(this IHandlerContext context)
        {
            var requestMessage = context.NotNull("content").Get <IRequestMessageBase>("Rabbit.WeiXin.RequestMessage");

            if (requestMessage == null)
            {
                throw new Exception("在当前上下文中找不到请求消息,请确保注册的处理中间件中有包含对请求消息创建的处理动作。");
            }
            return(requestMessage);
        }
示例#2
0
        /// <summary>
        /// 获取消息处理基本信息。
        /// </summary>
        /// <param name="context">处理上下文。</param>
        /// <exception cref="ArgumentNullException"><paramref name="context"/> 为 null。</exception>
        /// <exception cref="Exception">在当前上下文中找不到消息处理基本信息。</exception>
        /// <returns>消息处理基本信息。</returns>
        public static MessageHandlerBaseInfo GetMessageHandlerBaseInfo(this IHandlerContext context)
        {
            var info = context.NotNull("context").Get <MessageHandlerBaseInfo>("Rabbit.WeiXin.MessageHandlerBaseInfo");

            if (info == null)
            {
                throw new Exception("在当前上下文中找不到消息处理基本信息,请确保向处理上下文注册了消息处理基本信息。");
            }
            return(info);
        }
示例#3
0
        /// <summary>
        /// 获取依赖解析器。
        /// </summary>
        /// <param name="context">处理上下文。</param>
        /// <exception cref="ArgumentNullException"><paramref name="context"/> 为 null。</exception>
        /// <exception cref="Exception">在当前上下文中找不到依赖解析器。</exception>
        /// <returns>依赖解析器。</returns>
        public static IDependencyResolver GetDependencyResolver(this IHandlerContext context)
        {
            var dependencyResolver = context.NotNull("context").Get <IDependencyResolver>("Rabbit.WeiXin.DependencyResolver");

            if (dependencyResolver == null)
            {
                throw new Exception("在当前上下文中找不到依赖解析器,您可以通过 SetDependencyResolver 方法设置一个依赖解析器。");
            }

            return(dependencyResolver);
        }
示例#4
0
        /// <summary>
        /// 获取请求参数。
        /// </summary>
        /// <param name="context">处理上下文。</param>
        /// <exception cref="ArgumentNullException"><paramref name="context"/> 为 null。</exception>
        /// <returns>请求参数。</returns>
        public static IDictionary <string, string> GetRequestParameters(this IHandlerContext context)
        {
            var parameters = context
                             .NotNull(nameof(context))
                             .Get <IDictionary <string, string> >("Rabbit.WeiXin.RequestParameters");

            if (parameters != null)
            {
                return(parameters);
            }
            parameters = new Dictionary <string, string>();
            context.SetRequestParameters(parameters);
            return(parameters);
        }
示例#5
0
        /// <summary>
        /// 设置消息处理基本信息。
        /// </summary>
        /// <param name="context">处理上下文。</param>
        /// <param name="baseInfo">消息处理基本信息。</param>
        /// <exception cref="ArgumentNullException"><paramref name="context"/> 为 null。</exception>
        /// <exception cref="ArgumentNullException"><paramref name="baseInfo"/> 为 null。</exception>
        /// <returns>处理上下文。</returns>
        public static IHandlerContext SetMessageHandlerBaseInfo(this IHandlerContext context, MessageHandlerBaseInfo baseInfo)
        {
            context.NotNull("context").Environment["Rabbit.WeiXin.MessageHandlerBaseInfo"] = baseInfo.NotNull("baseInfo");

            return(context);
        }
示例#6
0
        /// <summary>
        /// 设置响应消息。
        /// </summary>
        /// <param name="context">处理上下文。</param>
        /// <param name="responseMessage">响应消息。</param>
        /// <exception cref="ArgumentNullException"><paramref name="context"/> 为 null。</exception>
        /// <returns>处理上下文。</returns>
        public static IHandlerContext SetResponseMessage(this IHandlerContext context, IResponseMessage responseMessage)
        {
            context.NotNull("context").Environment["Rabbit.WeiXin.ResponseMessage"] = responseMessage;

            return(context);
        }
示例#7
0
        /// <summary>
        /// 获取响应消息。
        /// </summary>
        /// <param name="context">处理上下文。</param>
        /// <exception cref="ArgumentNullException"><paramref name="context"/> 为 null。</exception>
        /// <exception cref="Exception">在当前上下文中找不到响应消息。</exception>
        /// <returns>响应消息实例。</returns>
        public static IResponseMessage GetResponseMessage(this IHandlerContext context)
        {
            var responseMessage = context.NotNull("context").Get <IResponseMessage>("Rabbit.WeiXin.ResponseMessage");

            return(responseMessage);
        }
示例#8
0
        /// <summary>
        /// 设置请求消息。
        /// </summary>
        /// <param name="context">处理上下文。</param>
        /// <param name="requestMessage">请求消息。</param>
        /// <exception cref="ArgumentNullException"><paramref name="context"/> 为 null。</exception>
        /// <exception cref="ArgumentNullException"><paramref name="requestMessage"/> 为 null。</exception>
        /// <returns>处理上下文。</returns>
        internal static IHandlerContext SetRequestMessage(this IHandlerContext context, IRequestMessageBase requestMessage)
        {
            context.NotNull("context").Environment["Rabbit.WeiXin.RequestMessage"] = requestMessage.NotNull("requestMessage");

            return(context);
        }
示例#9
0
        /// <summary>
        /// 设置依赖解析器。
        /// </summary>
        /// <param name="context">处理上下文。</param>
        /// <param name="dependencyResolver">依赖解析器实例。</param>
        /// <exception cref="ArgumentNullException"><paramref name="context"/> 为 null。</exception>
        /// <exception cref="ArgumentNullException"><paramref name="dependencyResolver"/> 为 null。</exception>
        /// <returns>处理上下文。</returns>
        public static IHandlerContext SetDependencyResolver(this IHandlerContext context, IDependencyResolver dependencyResolver)
        {
            context.NotNull("context").Environment["Rabbit.WeiXin.DependencyResolver"] = dependencyResolver.NotNull("dependencyResolver");

            return(context);
        }
示例#10
0
 /// <summary>
 /// 设置请求参数。
 /// </summary>
 /// <param name="context">处理上下文。</param>
 /// <param name="parameters">请求参数。</param>
 /// <exception cref="ArgumentNullException"><paramref name="context"/> 为 null。</exception>
 /// <returns>处理上下文。</returns>
 public static IHandlerContext SetRequestParameters(this IHandlerContext context,
                                                    IDictionary <string, string> parameters)
 {
     return(context.NotNull(nameof(context)).Set("Rabbit.WeiXin.RequestParameters", parameters ?? new Dictionary <string, string>()));
 }
示例#11
0
 /// <summary>
 /// 设置当前用户的会话。
 /// </summary>
 /// <param name="context">处理上下文。</param>
 /// <param name="session">用户会话。</param>
 /// <returns>处理上下文。</returns>
 internal static IHandlerContext SetSession(this IHandlerContext context, IUserSession session)
 {
     context.NotNull("handlerContext").Environment["Rabbit.WeiXin.Session"] = session;
     return(context);
 }
示例#12
0
 /// <summary>
 /// 获取当前用户的会话。
 /// </summary>
 /// <param name="context">处理上下文。</param>
 /// <returns>用户会话。</returns>
 public static IUserSession GetSession(this IHandlerContext context)
 {
     return(context.NotNull("handlerContext").Environment["Rabbit.WeiXin.Session"] as IUserSession);
 }