コード例 #1
0
 public static IActionResult Parse(object json, HttpStatusCode httpStatusCode)
 {
     return(new JsonResult(json)
     {
         StatusCode = httpStatusCode.GetHashCode()
     });
 }
コード例 #2
0
 protected IActionResult ResponseStatusCode(HttpStatusCode statusCode)
 {
     return(StatusCode(statusCode.GetHashCode(), new
     {
         data = null as object,
         errors = _notifications.GetNotifications().Select(x => x.Value)
     }));
 }
コード例 #3
0
        public static void ResponseJson(this HttpListenerResponse response, HttpStatusCode statusCode, string contenType, string encoding, string responseString)
        {
            var buffer = System.Text.Encoding.UTF8.GetBytes(responseString);

            response.StatusCode      = statusCode.GetHashCode();
            response.ContentEncoding = string.IsNullOrWhiteSpace(encoding) ? Encoding.UTF8 : Encoding.GetEncoding(encoding);
            response.ContentType     = string.IsNullOrWhiteSpace(contenType) ? "text/json" : contenType;
            response.ContentLength64 = buffer.Length;
            using (var output = response.OutputStream)
            {
                output.Write(buffer, 0, buffer.Length);
            }
        }
コード例 #4
0
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="c">错误类型</param>
        /// <param name="message">消息</param>
        /// <param name="stackTrace">堆栈信息</param>
        /// <returns></returns>
        public static ExceptionLog create(HttpStatusCode c, string message, string stackTrace)
        {
            Db_ExceptionLog log = new Db_ExceptionLog()
            {
                code       = c.GetHashCode().ToString(),
                codeString = c.ToString(),
                createdOn  = DateTime.Now,
                message    = message,
                logType    = (byte)BaseLogType.异常日志.GetHashCode(),
                stackTrace = stackTrace
            };

            using (var db = new DefaultContainer())
            {
                db.Db_BaseLogSet.Add(log);
                db.SaveChanges();
                return(new ExceptionLog(log));
            }
        }
コード例 #5
0
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         // Suitable nullity checks etc, of course :)
         if (Category != null)
         {
             hashCode = hashCode * 59 + Category.GetHashCode();
         }
         if (Code != null)
         {
             hashCode = hashCode * 59 + Code.GetHashCode();
         }
         if (HttpStatusCode != null)
         {
             hashCode = hashCode * 59 + HttpStatusCode.GetHashCode();
         }
         if (Id != null)
         {
             hashCode = hashCode * 59 + Id.GetHashCode();
         }
         if (Message != null)
         {
             hashCode = hashCode * 59 + Message.GetHashCode();
         }
         if (PropertyName != null)
         {
             hashCode = hashCode * 59 + PropertyName.GetHashCode();
         }
         if (RequestId != null)
         {
             hashCode = hashCode * 59 + RequestId.GetHashCode();
         }
         return(hashCode);
     }
 }
コード例 #6
0
        /// <summary>
        /// Metoto encarrgado de ajustar una
        /// Respuesta para el servicio a partir del
        /// del ccodigo de estado del protocolo http
        /// </summary>
        /// <param name="statusCode"></param>
        /// <returns></returns>
        private static Response AjustResponseFromStatusCode(HttpStatusCode?statusCode)
        {
            String messageError = "";
            int?   codError     = statusCode?.GetHashCode() ?? 1000;

            switch (statusCode)
            {
            //Errores del cliente
            case HttpStatusCode.BadRequest:
            case HttpStatusCode.MethodNotAllowed:
            case HttpStatusCode.LengthRequired:
            case HttpStatusCode.RequestEntityTooLarge:
            case HttpStatusCode.RequestUriTooLong:
            case HttpStatusCode.UnsupportedMediaType:
            case HttpStatusCode.RequestedRangeNotSatisfiable:
            case HttpStatusCode.ExpectationFailed:
                messageError = Message.RequestError;
                break;

            case HttpStatusCode.Unauthorized:
            case HttpStatusCode.Forbidden:
            case HttpStatusCode.ProxyAuthenticationRequired:
                messageError = Message.Unauthorized;
                break;

            case HttpStatusCode.PaymentRequired:
            case HttpStatusCode.NotAcceptable:
            case HttpStatusCode.Conflict:
                messageError = Message.ComunicationError;
                break;

            case HttpStatusCode.NotFound:
            case HttpStatusCode.Gone:
                messageError = Message.NotFound;
                break;

            case HttpStatusCode.RequestTimeout:
                messageError = Message.RequestTimeout;
                break;

            case HttpStatusCode.PreconditionFailed:
                messageError = Message.ServiceError;
                break;

            //Errroes del servidor
            case HttpStatusCode.InternalServerError:
            case HttpStatusCode.NotImplemented:
            case HttpStatusCode.BadGateway:
            case HttpStatusCode.GatewayTimeout:
            case HttpStatusCode.HttpVersionNotSupported:
                messageError = Message.ServerInternalError;
                break;

            case HttpStatusCode.ServiceUnavailable:
                messageError = Message.ServiceUnavailable;
                break;

            default:
                messageError = Message.ServerInternalError;
                break;
            }

            return(new Response()
            {
                CodError = codError ?? 1000,
                MessageErrorFromUser = messageError
            });
        }
コード例 #7
0
 /// <summary>
 /// 尝试读取响应状态 如果响应的状态码不正确会抛出自定义的异常
 /// </summary>
 /// <param name="statusCode"></param>
 /// <param name="message"></param>
 public static void TryReadResponseStatus(HttpStatusCode statusCode, string message)
 {
     if (statusCode != HttpStatusCode.OK)
     {
         if (statusCode == HttpStatusCode.Forbidden)
         {
             throw new NoRightException(message);
         }
         else if (statusCode == HttpStatusCode.BadRequest)
         {
             throw new InputParameterException(message);
         }
         else if (statusCode == HttpStatusCode.InternalServerError)
         {
             throw new ServerRuntimeException(message);
         }
         else
         {
             throw new UnknownException(string.Format("未知错误,错误代码:{0},错误信息:{1}", statusCode.GetHashCode(), message));
         }
     }
 }
コード例 #8
0
ファイル: Exceptions.cs プロジェクト: garydouble/Siesta.NET
 public Exception(HttpStatusCode status)
     : this(status, HttpWorkerRequest.GetStatusDescription(status.GetHashCode())) {}
コード例 #9
0
 public static ContentResult Response(string content, HttpStatusCode statusCode, string contentType = "application/json; charset=utf-8")
 {
     return(Response(content, statusCode.GetHashCode(), contentType));
 }
コード例 #10
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (TraceId.Length != 0)
            {
                hash ^= TraceId.GetHashCode();
            }
            if (SpanId.Length != 0)
            {
                hash ^= SpanId.GetHashCode();
            }
            if (ParentSpanId.Length != 0)
            {
                hash ^= ParentSpanId.GetHashCode();
            }
            if (SpanName.Length != 0)
            {
                hash ^= SpanName.GetHashCode();
            }
            if (startTime_ != null)
            {
                hash ^= StartTime.GetHashCode();
            }
            if (endTime_ != null)
            {
                hash ^= EndTime.GetHashCode();
            }
            hash ^= SpanTags.GetHashCode();
            if (HttpStatusCode != 0L)
            {
                hash ^= HttpStatusCode.GetHashCode();
            }
            if (ClientSpan != false)
            {
                hash ^= ClientSpan.GetHashCode();
            }
            if (RewriteClientSpanId != false)
            {
                hash ^= RewriteClientSpanId.GetHashCode();
            }
            if (SourceName.Length != 0)
            {
                hash ^= SourceName.GetHashCode();
            }
            if (sourceIp_ != null)
            {
                hash ^= SourceIp.GetHashCode();
            }
            if (DestinationName.Length != 0)
            {
                hash ^= DestinationName.GetHashCode();
            }
            if (destinationIp_ != null)
            {
                hash ^= DestinationIp.GetHashCode();
            }
            if (RequestSize != 0L)
            {
                hash ^= RequestSize.GetHashCode();
            }
            if (RequestTotalSize != 0L)
            {
                hash ^= RequestTotalSize.GetHashCode();
            }
            if (ResponseSize != 0L)
            {
                hash ^= ResponseSize.GetHashCode();
            }
            if (ResponseTotalSize != 0L)
            {
                hash ^= ResponseTotalSize.GetHashCode();
            }
            if (ApiProtocol.Length != 0)
            {
                hash ^= ApiProtocol.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
コード例 #11
0
 static bool IsValid(HttpStatusCode statusCode)
 {
     return(statusCode.GetHashCode() < 400);
 }
コード例 #12
0
 protected virtual IActionResult CreateResponse(HttpStatusCode httpStatusCode)
 {
     return(StatusCode(httpStatusCode.GetHashCode()));
 }
コード例 #13
0
 public AppDomainException(string message, HttpStatusCode statusCode, string sourceName)
     : base(message)
 {
     StatusCode = statusCode.GetHashCode();
     SourceName = sourceName ?? string.Empty;
 }