Пример #1
0
 /// <summary>
 /// 请求上下文
 /// </summary>
 /// <param name="session">当前会话对象</param>
 /// <param name="packet">数据包对象</param>
 /// <param name="allSessions">所有会话对象</param>
 internal RequestContext(JsonWebSocketSession session, JsonPacket packet, ISessionProvider allSessions)
 {
     this.Session = session;
     this.Packet = packet;
     this.AllSessions = allSessions;
 }
Пример #2
0
 /// <summary>
 /// 请求上下文
 /// </summary>
 /// <param name="session">当前会话对象</param>
 /// <param name="packet">数据包对象</param>
 /// <param name="allSessions">所有会话对象</param>
 internal RequestContext(JsonWebSocketSession session, JsonPacket packet, IEnumerable<JsonWebSocketSession> allSessions)
 {
     this.Session = session;
     this.Packet = packet;
     this.AllSessions = allSessions;
 }
 /// <summary>
 /// 尝试获取数据包
 /// </summary>     
 /// <param name="context">上下文</param>
 /// <param name="content">内容</param>        
 /// <returns></returns>
 private JsonPacket TryGetJsonPacket(IContenxt context, string content)
 {
     try
     {
         var packet = this.JsonSerializer.Deserialize(content);
         var jsonPacket = new JsonPacket
         {
             api = packet.api,
             id = packet.id ?? 0,
             state = packet.state ?? true,
             fromClient = packet.fromClient ?? true,
             body = packet.body
         };
         return jsonPacket;
     }
     catch (Exception ex)
     {
         var session = context.Session.Wrapper as JsonWebSocketSession;
         var requestContext = new RequestContext(session, null, context.AllSessions);
         var exceptionConext = new ExceptionContext(requestContext, ex);
         this.ExecGlobalExceptionFilters(exceptionConext);
         return null;
     }
 }