/// <summary> /// 命令分发 /// </summary> /// <param name="request"></param> /// <returns></returns> public static string Dispatch(HttpListenerRequest request) { var executeResult = ""; var msgtype = ""; try { var provider = new RequestDataProvider(request); var input = provider.BuildInputArgs(); msgtype = input.MsgType; if (string.IsNullOrEmpty(msgtype)) { throw new Exception("msgtype 不能为空"); } CmdExecuting(provider, input); executeResult = TechSvrApplication.Instance.GetCommand(msgtype).Excute(input).ToJson(); CmdExecuted(msgtype, executeResult); } catch (Exception ex) { TechSvrApplication.Instance.Log("已处理请求:" + msgtype + ",执行失败,错误信息:" + ex.Message, msgtype); throw ex; } return(executeResult); }
/// <summary> /// 命令执行前 日志记录 /// </summary> /// <param name="provider"></param> /// <param name="input"></param> private static void CmdExecuting(RequestDataProvider provider, InputArgs input) { TechSvrApplication.Instance.ShowToUI("接收到请求:" + input.MsgType, input.MsgType); TechSvrApplication.Instance.Log("QueryString参数:" + provider.QueryString, input.MsgType); if (!string.IsNullOrEmpty(input.PostBody)) { TechSvrApplication.Instance.Log("PostBody参数:" + input.PostBody, input.MsgType); } }
public void Should_do_nothing_when_trying_to_set_the_SessionState_when_the_current_session_is_null() { _httpContext.Stub(x => x.Session).Return(null); _requestDataProvider = new RequestDataProvider(_httpContext); _requestDataProvider.Store(_flashViewModelForTesting); _requestDataProvider.Load <FlashViewModelForTesting>().ShouldBeNull(); _httpContext.VerifyAllExpectations(); }
public void Should_be_able_to_load_model_when_Session_is_not_null() { _httpContext.Stub(x => x.Session).Return(_sessionState); _sessionState.Expect(c => c[RequestDataProvider.REQUESTDATA_PREFIX_KEY + "Property1"]).Return( _flashViewModelForTesting.Property1); _sessionState.Expect(c => c[RequestDataProvider.REQUESTDATA_PREFIX_KEY + "Property2"]).Return( _flashViewModelForTesting.Property2); _sessionState.Expect(c => c[RequestDataProvider.REQUESTDATA_PREFIX_KEY + "Property3"]).Return( _flashViewModelForTesting.Property3); var testing = new RequestDataProvider(_httpContext).Load <FlashViewModelForTesting>(); _httpContext.VerifyAllExpectations(); _sessionState.VerifyAllExpectations(); testing.Property1.ShouldEqual(_flashViewModelForTesting.Property1); testing.Property2.ShouldEqual(_flashViewModelForTesting.Property2); testing.Property3.ShouldEqual(_flashViewModelForTesting.Property3); }
public void Should_be_able_to_load_model_when_Session_is_not_null() { _httpContext.Stub(x => x.Session).Return(_sessionState); _sessionState.Expect(c => c[RequestDataProvider.REQUESTDATA_PREFIX_KEY + "Property1"]).Return( _flashViewModelForTesting.Property1); _sessionState.Expect(c => c[RequestDataProvider.REQUESTDATA_PREFIX_KEY + "Property2"]).Return( _flashViewModelForTesting.Property2); _sessionState.Expect(c => c[RequestDataProvider.REQUESTDATA_PREFIX_KEY + "Property3"]).Return( _flashViewModelForTesting.Property3); var testing = new RequestDataProvider(_httpContext).Load<FlashViewModelForTesting>(); _httpContext.VerifyAllExpectations(); _sessionState.VerifyAllExpectations(); testing.Property1.ShouldBe(_flashViewModelForTesting.Property1); testing.Property2.ShouldBe(_flashViewModelForTesting.Property2); testing.Property3.ShouldBe(_flashViewModelForTesting.Property3); }
public void Should_do_nothing_when_trying_to_set_the_SessionState_when_the_current_session_is_null() { _httpContext.Stub(x => x.Session).Return(null); _requestDataProvider = new RequestDataProvider(_httpContext); _requestDataProvider.Store(_flashViewModelForTesting); _requestDataProvider.Load<FlashViewModelForTesting>().ShouldBeNull(); _httpContext.VerifyAllExpectations(); }