/// <summary> /// レスポンスからリクエストを作成します。 /// </summary> /// <param name="response">リクエストを作成するもととなる<see cref="PipeResponse"/></param> /// <returns><see cref="PipeRequest"/></returns> public PipeRequest CreateRequestFromResponse(PipeResponse response) { Contract.NotNull(response, "response"); PipeRequest request = new PipeRequest(response.Context, response.Data); return(request); }
/// <summary> /// 応答を作成する。 /// </summary> /// <param name="statusCode"></param> /// <param name="data"></param> /// <returns></returns> public PipeResponse CreateResponse(HttpStatusCode statusCode, object data = null) { PipeResponse response = new PipeResponse(this.Context, statusCode); response.Data = data; return(response); }
/// <summary> /// 指定されたアクション(メソッド)をパイプライン処理として実行します。 /// </summary> /// <param name="request"></param> /// <returns></returns> public PipeResponse Execute(PipeRequest request) { PipeResponse response = request.CreateResponse(HttpStatusCode.OK); response.Data = request.Data; var result = rules.Validate(request.Data as T); if (!result.IsValid) { response = request.CreateResponse(HttpStatusCode.BadRequest); response.Data = result; } return(response); }
/// <summary> /// パイプライン処理として登録されたアクション(メソッド)を実行します。 /// </summary> /// <param name="request"><see cref="PipeRequest"/></param> /// <returns>アクション実行結果を含んだ <see cref="PipeResponse"/></returns> public PipeResponse Execute(PipeRequest request) { Contract.NotNull(request, "request"); if (actions.Count == 0) { throw new InvalidOperationException(Resources.NoActionRegister); } PipeRequest nextRequest = request; PipeResponse response = null; foreach (var action in actions) { if (action.OnStart != null) { action.OnStart(); } response = action.Execute(nextRequest); if (response.StatusCode != HttpStatusCode.OK && !action.IsResumePipe) { if (action.OnError != null) { action.OnError(); } return(response); } else { if (action.OnEnd != null) { action.OnEnd(); } } nextRequest = CreateRequestFromResponse(response); } return(response); }