コード例 #1
0
        static string GetResponseString(HttpContext context)
        {
            MornRequestData requestData = MornRequestData.Create(context);

            if (ProtocolDataVerifier != null)
            {
                try
                {
                    ProtocolDataVerifier.Validate(requestData);
                }
                catch (MornException ex)
                {
                    return(MornErrorUtil.GenError(
                               ex.ErrorType,
                               ex.Message));
                }
            }

            var handler = GetProtocolHandler(requestData.Method);

            if (handler == null)
            {
                return(MornErrorUtil.GenError(MornErrorType.UnknownMethod));
            }

            return(handler.Process(requestData));
        }
コード例 #2
0
ファイル: MornError.cs プロジェクト: morningf/MornCore
 /// <summary>
 /// 生成错误回应字符串
 /// </summary>
 /// <param name="type">错误类型</param>
 /// <returns>错误回应字符串</returns>
 public static string GenError(MornErrorType type)
 {
     return(JsonConvert.SerializeObject(new Dictionary <string, object>()
     {
         { MornConstants.ERROR_CODE, MornErrorUtil.GetErrorCode(type) },
         { MornConstants.ERROR_MESSAGE, MornErrorUtil.GetDescription(type) },
     }));
 }
コード例 #3
0
 public string Process(MornRequestData data)
 {
     try
     {
         return(_client.DoPost(_url, data.Context));
     }
     catch (Exception ex)
     {
         return(MornErrorUtil.GenError(MornErrorType.SystemError, ex.Message));
     }
 }
コード例 #4
0
ファイル: MornClient.cs プロジェクト: morningf/MornCore
        private T CreateErrorResponse <T>(MornErrorType type, string addition) where T : MornResponse
        {
            var rsp = Activator.CreateInstance <T>();

            rsp.ErrorCode = MornErrorUtil.GetErrorCode(type);
            if (string.IsNullOrEmpty(addition))
            {
                rsp.ErrorMessage = MornErrorUtil.GetDescription(type);
            }
            else
            {
                rsp.ErrorMessage = string.Format("{0} : {1}", MornErrorUtil.GetDescription(type), addition);
            }
            return(rsp);
        }
コード例 #5
0
        public static async Task ProcessHttpContextAsync(HttpContext context)
        {
            string responseString = string.Empty;

            try
            {
                responseString = GetResponseString(context);
            }
            catch (Exception ex)
            {
                responseString = MornErrorUtil.GenError(
                    MornErrorType.SystemError,
                    ex.Message);
            }

            context.Response.ContentType = "application/json;charset=UTF-8";
            await context.Response.WriteAsync(responseString);
        }