コード例 #1
0
ファイル: AMQPClient.cs プロジェクト: RobboVariwn/VarBot
 public static void SendRuntimeErrorMessage(LogicException logicException)
 {
     SendRuntimeErrorMessage(logicException.Logic.WorldLocationId,
                             logicException.Line,
                             logicException.Column,
                             logicException.Message);
 }
コード例 #2
0
        /// <summary>
        /// 测试日期(年、月、日)的有效性
        /// </summary>
        /// <param name="year">年</param>
        /// <param name="month">月</param>
        /// <param name="day">日</param>
        /// <returns>异常</returns>
        public static LogicException TestDateValid(int year, int month, int day)
        {
            var exception = new LogicException("数据无效");

            if (year < 0 || year > 9999)
            {
                exception.Key = "Year";
            }
            if (month > 0 && month <= 12)
            {
                int daysInMonth = DateTime.DaysInMonth(year, month);
                if (day > daysInMonth)
                {
                    exception.Key = "Day";
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                exception.Key = "Month";
            }
            return(exception);
        }
 /// <summary>
 /// Extension method that generates problem details for the exception.
 /// </summary>
 /// <param name="source">The exception to map to a <see cref="ProblemDetails"/></param>
 /// <param name="controller">The base controller the exception occured in. </param>
 /// <param name="type">Optional parameter that sets the URL for the human readable explanation for the status code. Default value is set to https://httpstatuses.com/500 </param>
 /// <param name="status">Optional parameter that sets the return status code for the problem. Default value is set to 500.</param>
 /// <param name="title">Optional parameter that sets the title for the problem. Default value is set to Internal Server Error.</param>
 /// <returns>Instance of the problem details.</returns>
 public static ProblemDetails GetProblemDetails(this LogicException source,
                                                ControllerBase controller, string type = "https://httpstatuses.com/500",
                                                int?status = 500, string title = "Internal Server Error")
 {
     return(new ProblemDetails {
         Type = type, Status = status, Title = title, Instance = controller?.HttpContext?.Request?.Path, Detail = source?.Message
     });
 }
        public static void AddLogicErrors(this ModelStateDictionary modelstate, LogicException ex)
        {
            if (ex.Errors == null || ex.Errors.Count == 0)
            {
                if (string.IsNullOrWhiteSpace(ex.Message))
                {
                    return;
                }

                modelstate.AddModelError("", ex.Message);
            }
            else
            {
                foreach (LogicError error in (Collection <LogicError>)ex.Errors)
                {
                    modelstate.AddModelError("", error.Message);
                }
            }
        }