コード例 #1
0
ファイル: Extensions.cs プロジェクト: likeshan168/graphite
        public static HttpResponseMessage SetStatus(
            this HttpResponseMessage responseMessage,
            IEnumerable <IResponseStatus> responseStatus,
            ActionDescriptor actionDescriptor,
            ResponseState responseState,
            string errorMessage)
        {
            var context = new ResponseStatusContext(responseMessage, responseState, errorMessage);

            actionDescriptor.ResponseStatus.ThatAppliesToOrDefault(
                responseStatus, context)?.SetStatus(context);
            return(responseMessage);
        }
コード例 #2
0
        public virtual void SetStatus(ResponseStatusContext context)
        {
            switch (context.ResponseState)
            {
            case ResponseState.NoReader:
                SetStatus <NoReaderStatusAttribute>(context.ResponseMessage,
                                                    _configuration.DefaultNoReaderStatusCode,
                                                    _configuration.DefaultNoReaderReasonPhrase);
                break;

            case ResponseState.BindingFailure:
                SetStatus <BindingFailureStatusAttribute>(context.ResponseMessage,
                                                          _configuration.DefaultBindingFailureStatusCode,
                                                          _configuration.DefaultBindingFailureReasonPhrase?
                                                          .Invoke(context.ErrorMessage));
                break;

            case ResponseState.HasResponse:
                SetStatus <HasResponseStatusAttribute>(context.ResponseMessage,
                                                       _configuration.DefaultHasResponseStatusCode,
                                                       _configuration.DefaultHasResponseReasonPhrase);
                break;

            case ResponseState.NoResponse:
                SetStatus <NoResponseStatusAttribute>(context.ResponseMessage,
                                                      _configuration.DefaultNoResponseStatusCode,
                                                      _configuration.DefaultNoResponseReasonPhrase);
                break;

            case ResponseState.NoWriter:
                SetStatus <NoWriterStatusAttribute>(context.ResponseMessage,
                                                    _configuration.DefaultNoWriterStatusCode,
                                                    _configuration.DefaultNoWriterReasonPhrase);
                break;
            }
        }
コード例 #3
0
 public virtual bool AppliesTo(ResponseStatusContext context)
 {
     return(true);
 }