/// <summary> /// Requireses the permission. /// </summary> /// <param name="permission">The permission.</param> /// <param name="hint">The hint.</param> /// <param name="memberName">Name of the member.</param> /// <exception cref="UnauthorizedOperationException">MissingPermission</exception> public static void RequiresPermission(string permission, FriendlyHint hint = null, [CallerMemberName] string memberName = null) { if (!HasPermission(permission)) { throw new UnauthorizedOperationException("MissingPermission", data: new { requires = permission }, hint: hint, operationName: memberName); } }
/// <summary> /// Renders as panel view. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="viewPath">The view path.</param> /// <param name="defaultFriendlyHint">The default friendly hint.</param> /// <returns></returns> public virtual ActionResult RenderAsPanelView <T>(string viewPath = null, FriendlyHint defaultFriendlyHint = null) { string actualViewName = null; try { actualViewName = viewPath.SafeToString(GetDefaultPanelViewPath(typeof(T).Name)); return(View(actualViewName)); } catch (Exception ex) { return(HandleExceptionToRedirection(ex, new { actualViewName }, defaultFriendlyHint)); } }
/// <summary> /// Handles the exception. /// </summary> /// <param name="exception">The exception.</param> /// <param name="scene">The scene.</param> /// <param name="data">The data.</param> /// <param name="hint">The hint.</param> /// <param name="minorCode">The minor code.</param> /// <returns> /// BaseServiceException. /// </returns> internal static BaseException Handle(this Exception exception, ExceptionScene scene, object data = null, FriendlyHint hint = null, string minorCode = null) { TargetInvocationException targetInvocationException = exception as TargetInvocationException; if (targetInvocationException != null) { return(targetInvocationException.InnerException.Handle(scene, data, hint, minorCode)); } else { var baseException = exception as BaseException; var operationName = scene?.MethodName; if (baseException != null) { if (string.IsNullOrWhiteSpace(operationName)) { return(baseException); } else { switch (baseException.Code.Major) { case ExceptionCode.MajorCode.UnauthorizedOperation: return(new UnauthorizedOperationException(baseException, minorCode.SafeToString(baseException.Code.Minor), data, scene: scene) as BaseException); case ExceptionCode.MajorCode.OperationForbidden: return(new OperationForbiddenException(operationName, minorCode.SafeToString(baseException.Code?.Minor), baseException, data, scene: scene) as BaseException); case ExceptionCode.MajorCode.NullOrInvalidValue: case ExceptionCode.MajorCode.DataConflict: case ExceptionCode.MajorCode.NotImplemented: case ExceptionCode.MajorCode.ResourceNotFound: case ExceptionCode.MajorCode.CreditNotAfford: case ExceptionCode.MajorCode.ServiceUnavailable: return(baseException); default: break; } } } else { var sqlException = exception as SqlException; if (sqlException != null) { return(new OperationFailureException(exception, data, hint: hint, scene: scene, minor: minorCode) as BaseException); } else { var notImplementException = exception as NotImplementedException; if (notImplementException != null) { return(new UnimplementedException(operationName, notImplementException)); } } } return(new OperationFailureException(exception, data, scene: scene, minor: minorCode) as BaseException); } }
/// <summary> /// Renders as list partial view. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="entities">The entities.</param> /// <param name="viewPath">The view path.</param> /// <param name="defaultFriendlyHint">The default friendly hint.</param> /// <returns>PartialViewResult.</returns> public virtual PartialViewResult RenderAsListPartialView <T>(ICollection <T> entities, string viewPath = null, FriendlyHint defaultFriendlyHint = null) { string actualViewName = null; try { actualViewName = viewPath.SafeToString(string.Format(PortalViewNames.DefaultNamingPartialViewPath, this.ModuleName, typeof(T).Name)); return(PartialView(actualViewName, entities)); } catch (Exception ex) { return(HandleExceptionToPartialView(ex, new { entities, actualViewName }, defaultFriendlyHint)); } }
/// <summary> /// Initializes a new instance of the <see cref="UnauthorizedTokenException" /> class. /// </summary> /// <param name="data">The data.</param> /// <param name="hint">The hint.</param> /// <param name="scene">The scene.</param> public UnauthorizedTokenException(object data = null, FriendlyHint hint = null, ExceptionScene scene = null) : base("Unauthorized token or token expired.", new ExceptionCode { Major = ExceptionCode.MajorCode.UnauthorizedOperation, Minor = "Token" }, null, data, hint, scene) { }
/// <summary> /// Checks the empty crypto key. /// </summary> /// <param name="cryptoKey">The crypto key.</param> /// <param name="objectIdentity">The object identity.</param> /// <param name="friendlyHint">The friendly hint.</param> /// <param name="memberName">Name of the member.</param> /// <param name="sourceFilePath">The source file path.</param> /// <param name="sourceLineNumber">The source line number.</param> /// <exception cref="NullObjectException"></exception> /// <exception cref="ExceptionScene"></exception> public static void CheckEmptyCryptoKey(this CryptoKey cryptoKey, string objectIdentity, FriendlyHint friendlyHint = null, [CallerMemberName] string memberName = null, [CallerFilePath] string sourceFilePath = null, [CallerLineNumber] int sourceLineNumber = 0) { if (cryptoKey.ByteValue == null) { throw new NullObjectException(objectIdentity, friendlyHint, new ExceptionScene { FilePath = sourceFilePath, LineNumber = sourceLineNumber, MethodName = memberName }); } }
/// <summary> /// Checks the empty string as invalid exception. /// </summary> /// <param name="anyString">Any string.</param> /// <param name="objectIdentity">The object identity.</param> /// <param name="friendlyHint">The friendly hint.</param> /// <param name="memberName">Name of the member.</param> /// <param name="sourceFilePath">The source file path.</param> /// <param name="sourceLineNumber">The source line number.</param> /// <exception cref="InvalidObjectException"></exception> /// <exception cref="ExceptionScene"></exception> public static void CheckEmptyStringAsInvalidException(this string anyString, string objectIdentity, FriendlyHint friendlyHint = null, [CallerMemberName] string memberName = null, [CallerFilePath] string sourceFilePath = null, [CallerLineNumber] int sourceLineNumber = 0) { if (string.IsNullOrWhiteSpace(anyString)) { throw new InvalidObjectException(objectIdentity, hint: friendlyHint, scene: new ExceptionScene { FilePath = sourceFilePath, LineNumber = sourceLineNumber, MethodName = memberName }); } }
/// <summary> /// Creates the operation forbidden exception. /// </summary> /// <param name="reason">The reason.</param> /// <param name="innerException">The inner exception.</param> /// <param name="data">The data.</param> /// <param name="hint">The hint.</param> /// <param name="actionName">Name of the action.</param> /// <param name="memberName">Name of the member.</param> /// <param name="sourceFilePath">The source file path.</param> /// <param name="sourceLineNumber">The source line number.</param> /// <returns>OperationForbiddenException.</returns> public static OperationForbiddenException CreateOperationForbiddenException(string reason, Exception innerException = null, object data = null, FriendlyHint hint = null, [CallerMemberName] string actionName = null, [CallerMemberName] string memberName = null, [CallerFilePath] string sourceFilePath = null, [CallerLineNumber] int sourceLineNumber = 0) { return(new OperationForbiddenException(actionName, reason, innerException, data, hint, new ExceptionScene { FilePath = sourceFilePath, LineNumber = sourceLineNumber, MethodName = memberName })); }
/// <summary> /// Checks the empty cellphone number. /// </summary> /// <param name="cellphoneNumber">The cellphone number.</param> /// <param name="objectIdentity">The object identity.</param> /// <param name="friendlyHint">The friendly hint.</param> /// <param name="memberName">Name of the member.</param> /// <param name="sourceFilePath">The source file path.</param> /// <param name="sourceLineNumber">The source line number.</param> /// <exception cref="NullObjectException"></exception> /// <exception cref="ExceptionScene"></exception> public static void CheckEmptyCellphoneNumber(this CellphoneNumber cellphoneNumber, string objectIdentity = null, FriendlyHint friendlyHint = null, [CallerMemberName] string memberName = null, [CallerFilePath] string sourceFilePath = null, [CallerLineNumber] int sourceLineNumber = 0) { if (cellphoneNumber == null || string.IsNullOrWhiteSpace(cellphoneNumber.Number)) { throw new NullObjectException(objectIdentity.SafeToString(nameof(cellphoneNumber)), friendlyHint, new ExceptionScene { FilePath = sourceFilePath, LineNumber = sourceLineNumber, MethodName = memberName }); } }
/// <summary> /// Initializes a new instance of the <see cref="NullObjectException" /> class. /// </summary> /// <param name="objectIdentity">The object identity.</param> /// <param name="friendlyHint">The friendly hint.</param> /// <param name="scene">The scene.</param> public NullObjectException(string objectIdentity, FriendlyHint friendlyHint = null, ExceptionScene scene = null) : base(string.Format("[{0}] is null.", objectIdentity), new ExceptionCode { Major = ExceptionCode.MajorCode.NullOrInvalidValue, Minor = "NullObject" }, null, null, hint: friendlyHint, scene: scene) { }
/// <summary> /// Returns as json. /// </summary> /// <param name="ex">The ex.</param> /// <param name="exceptionObject">The exception object.</param> /// <param name="returnObject">The return object.</param> /// <param name="hint">The hint.</param> /// <param name="operationName">Name of the operation.</param> /// <param name="sourceFilePath">The source file path.</param> /// <param name="sourceLineNumber">The source line number.</param> /// <returns>JsonResult.</returns> public virtual JsonResult ReturnAsJson(Exception ex, object exceptionObject, object returnObject, FriendlyHint hint = null, [CallerMemberName] string operationName = null, [CallerFilePath] string sourceFilePath = null, [CallerLineNumber] int sourceLineNumber = 0) { var baseExceptionInfo = ex == null ? null : GetException(ex, exceptionObject, hint, operationName, sourceFilePath, sourceLineNumber); return(Json(baseExceptionInfo == null ? returnObject ?? string.Empty : baseExceptionInfo)); }
/// <summary> /// Gets the exception. /// </summary> /// <param name="ex">The ex.</param> /// <param name="exceptionObject">The exception object.</param> /// <param name="hint">The hint.</param> /// <param name="operationName">Name of the operation.</param> /// <param name="sourceFilePath">The source file path.</param> /// <param name="sourceLineNumber">The source line number.</param> /// <returns>Beyova.ExceptionSystem.BaseException.</returns> protected ExceptionInfo GetException(Exception ex, object exceptionObject = null, FriendlyHint hint = null, string operationName = null, string sourceFilePath = null, int sourceLineNumber = 0) { var baseExceptionInfo = ex.Handle(new ExceptionScene { MethodName = operationName, FilePath = sourceFilePath, LineNumber = sourceLineNumber }, new { exceptionObject, HttpMethod = Request?.HttpMethod, RawUrl = Request?.RawUrl }, hint).ToExceptionInfo(); if (baseExceptionInfo != null && this.apiTracking != null) { if (RestApiContextConsistenceAttribute.ApiEvent != null && baseExceptionInfo != null) { RestApiContextConsistenceAttribute.ApiEvent.ExceptionKey = baseExceptionInfo.Key; } this.apiTracking.LogException(baseExceptionInfo); } if (this.returnExceptionAsFriendly) { hint = hint ?? ((ex as BaseException)?.Hint); baseExceptionInfo = new ExceptionInfo { Message = string.Format("Error occurred when {0}: {1}", Request.HttpMethod, Request.RawUrl), Code = hint == null ? baseExceptionInfo.Code : new ExceptionCode { Minor = hint.HintCode, Major = baseExceptionInfo.Code.Major }, Data = baseExceptionInfo.Data }; } return(baseExceptionInfo); }
/// <summary> /// Handles the exception to redirection. /// </summary> /// <param name="ex">The ex.</param> /// <param name="exceptionObject">The exception object.</param> /// <param name="hint">The hint.</param> /// <param name="operationName">Name of the operation.</param> /// <param name="sourceFilePath">The source file path.</param> /// <param name="sourceLineNumber">The source line number.</param> /// <returns>RedirectToRouteResult.</returns> public virtual RedirectToRouteResult HandleExceptionToRedirection(Exception ex, object exceptionObject = null, FriendlyHint hint = null, [CallerMemberName] string operationName = null, [CallerFilePath] string sourceFilePath = null, [CallerLineNumber] int sourceLineNumber = 0) { var baseExceptionInfo = GetException(ex, exceptionObject, hint, operationName, sourceFilePath, sourceLineNumber); return(RedirectToAction("Index", "Error", new { code = (int)(baseExceptionInfo.Code.Major) })); }
/// <summary> /// Handles the exception to partial view. /// </summary> /// <param name="ex">The ex.</param> /// <param name="exceptionObject">The exception object.</param> /// <param name="hint">The hint.</param> /// <param name="operationName">Name of the operation.</param> /// <param name="sourceFilePath">The source file path.</param> /// <param name="sourceLineNumber">The source line number.</param> /// <returns>PartialViewResult.</returns> public virtual PartialViewResult HandleExceptionToPartialView(Exception ex, object exceptionObject, FriendlyHint hint = null, [CallerMemberName] string operationName = null, [CallerFilePath] string sourceFilePath = null, [CallerLineNumber] int sourceLineNumber = 0) { var baseExceptionInfo = GetException(ex, exceptionObject, hint, operationName, sourceFilePath, sourceLineNumber); return(PartialView(ErrorPartialView, baseExceptionInfo)); }
/// <summary> /// Initializes a new instance of the <see cref="UnauthorizedOperationException" /> class. /// </summary> /// <param name="reason">The reason.</param> /// <param name="data">The data.</param> /// <param name="hint">The hint.</param> /// <param name="scene">The scene.</param> public UnauthorizedAccountException(string reason, object data = null, FriendlyHint hint = null, ExceptionScene scene = null) : base(string.Format("Failed to authenticate account caused by [{0}].", reason), new ExceptionCode { Major = ExceptionCode.MajorCode.UnauthorizedOperation, Minor = reason.SafeToString("Account") }, data: data, hint: hint, scene: scene) { }
/// <summary> /// Checks the null or empty collection. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="collection">The collection.</param> /// <param name="objectIdentity">The object identity.</param> /// <param name="friendlyHint">The friendly hint.</param> /// <param name="memberName">Name of the member.</param> /// <param name="sourceFilePath">The source file path.</param> /// <param name="sourceLineNumber">The source line number.</param> /// <exception cref="InvalidObjectException">Null or empty collection</exception> /// <exception cref="ExceptionScene"></exception> public static void CheckNullOrEmptyCollection <T>(this IEnumerable <T> collection, string objectIdentity, FriendlyHint friendlyHint = null, [CallerMemberName] string memberName = null, [CallerFilePath] string sourceFilePath = null, [CallerLineNumber] int sourceLineNumber = 0) { if (!collection.HasItem()) { throw new InvalidObjectException(objectIdentity, reason: "EmptyCollection", hint: friendlyHint, scene: new ExceptionScene { FilePath = sourceFilePath, LineNumber = sourceLineNumber, MethodName = memberName }); } }
/// <summary> /// Creates the operation exception. /// </summary> /// <param name="data">The data.</param> /// <param name="reason">The reason.</param> /// <param name="hint">The hint.</param> /// <param name="memberName">Name of the member.</param> /// <param name="sourceFilePath">The source file path.</param> /// <param name="sourceLineNumber">The source line number.</param> /// <returns> /// OperationFailureException. /// </returns> /// <exception cref="Beyova.Diagnostic.OperationFailureException"></exception> /// <exception cref="ExceptionScene"></exception> public static OperationFailureException CreateOperationException(object data = null, string reason = null, FriendlyHint hint = null, [CallerMemberName] string memberName = null, [CallerFilePath] string sourceFilePath = null, [CallerLineNumber] int sourceLineNumber = 0) { return(new OperationFailureException(data: data, minor: reason, hint: hint, scene: new ExceptionScene { FilePath = sourceFilePath, LineNumber = sourceLineNumber, MethodName = memberName })); }
/// <summary> /// Checks the empty name of the null or. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="anyObject">Any object.</param> /// <param name="objectIdentity">The object identity.</param> /// <param name="friendlyHint">The friendly hint.</param> /// <param name="memberName">Name of the member.</param> /// <param name="sourceFilePath">The source file path.</param> /// <param name="sourceLineNumber">The source line number.</param> /// <exception cref="NullObjectException"></exception> /// <exception cref="ExceptionScene"></exception> public static void CheckNullOrEmptyName <T>(this T anyObject, string objectIdentity, FriendlyHint friendlyHint = null, [CallerMemberName] string memberName = null, [CallerFilePath] string sourceFilePath = null, [CallerLineNumber] int sourceLineNumber = 0) where T : INameObject { if (anyObject == null || string.IsNullOrWhiteSpace(anyObject.Name)) { throw new NullObjectException(objectIdentity, friendlyHint, new ExceptionScene { FilePath = sourceFilePath, LineNumber = sourceLineNumber, MethodName = memberName }); } }
/// <summary> /// Creates the unauthorized token exception. /// </summary> /// <param name="token">The token.</param> /// <param name="hint">The hint.</param> /// <param name="memberName">Name of the member.</param> /// <param name="sourceFilePath">The source file path.</param> /// <param name="sourceLineNumber">The source line number.</param> /// <returns></returns> public static UnauthorizedTokenException CreateUnauthorizedTokenException(string token, FriendlyHint hint = null, [CallerMemberName] string memberName = null, [CallerFilePath] string sourceFilePath = null, [CallerLineNumber] int sourceLineNumber = 0) { return(new UnauthorizedTokenException(data: token, hint: hint, scene: new ExceptionScene { FilePath = sourceFilePath, LineNumber = sourceLineNumber, MethodName = memberName })); }
/// <summary> /// Checks the default value object. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="anyObject">Any object.</param> /// <param name="objectIdentity">The object identity.</param> /// <param name="friendlyHint">The friendly hint.</param> /// <param name="memberName">Name of the member.</param> /// <param name="sourceFilePath">The source file path.</param> /// <param name="sourceLineNumber">The source line number.</param> /// <exception cref="NullObjectException"></exception> /// <exception cref="ExceptionScene"></exception> public static void CheckDefaultValueObject <T>(this T anyObject, string objectIdentity, FriendlyHint friendlyHint = null, [CallerMemberName] string memberName = null, [CallerFilePath] string sourceFilePath = null, [CallerLineNumber] int sourceLineNumber = 0) where T : struct, IConvertible { if ((anyObject as IConvertible).ToInt32(null) == 0) { throw new NullObjectException(objectIdentity, friendlyHint, new ExceptionScene { FilePath = sourceFilePath, LineNumber = sourceLineNumber, MethodName = memberName }); } }
/// <summary> /// Creates the unsupported exception. /// </summary> /// <param name="objectIdentifier">The object identifier.</param> /// <param name="data">The data.</param> /// <param name="reason">The reason.</param> /// <param name="innerException">The inner exception.</param> /// <param name="hint">The hint.</param> /// <param name="memberName">Name of the member.</param> /// <param name="sourceFilePath">The source file path.</param> /// <param name="sourceLineNumber">The source line number.</param> /// <returns>UnsupportedException.</returns> public static UnsupportedException CreateUnsupportedException(string objectIdentifier, object data = null, string reason = null, Exception innerException = null, FriendlyHint hint = null, [CallerMemberName] string memberName = null, [CallerFilePath] string sourceFilePath = null, [CallerLineNumber] int sourceLineNumber = 0) { return(new UnsupportedException(objectIdentifier, data: data, innerException: innerException, reason: reason, hint: hint, scene: new ExceptionScene { FilePath = sourceFilePath, LineNumber = sourceLineNumber, MethodName = memberName })); }
/// <summary> /// Validates the object. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="targetObject">The target object.</param> /// <param name="validator">The validator. Return true if passed validation.</param> /// <param name="objectIdentity">The object identity.</param> /// <param name="reason">The reason.</param> /// <param name="externalDataReference">The external data reference.</param> /// <param name="friendlyHint">The friendly hint.</param> /// <param name="memberName">Name of the member.</param> /// <param name="sourceFilePath">The source file path.</param> /// <param name="sourceLineNumber">The source line number.</param> /// <exception cref="InvalidObjectException"></exception> /// <exception cref="ExceptionScene"></exception> public static void ValidateObject <T>(this T targetObject, Func <T, bool> validator, string objectIdentity, string reason, object externalDataReference = null, FriendlyHint friendlyHint = null, [CallerMemberName] string memberName = null, [CallerFilePath] string sourceFilePath = null, [CallerLineNumber] int sourceLineNumber = 0) { targetObject.CheckNullObject(objectIdentity); if (!validator(targetObject)) { throw new InvalidObjectException(objectIdentity, data: new { targetObject, externalDataReference }, reason: reason, hint: friendlyHint, scene: new ExceptionScene { FilePath = sourceFilePath, LineNumber = sourceLineNumber, MethodName = memberName }); } }
/// <summary> /// Checks the null object as invalid. /// </summary> /// <param name="targetObject">The target object.</param> /// <param name="objectIdentity">The object identity.</param> /// <param name="reason">The reason.</param> /// <param name="data">The external data reference.</param> /// <param name="friendlyHint">The friendly hint.</param> /// <param name="memberName">Name of the member.</param> /// <param name="sourceFilePath">The source file path.</param> /// <param name="sourceLineNumber">The source line number.</param> /// <exception cref="InvalidObjectException"></exception> /// <exception cref="ExceptionScene"></exception> public static void CheckNullObjectAsInvalid(this object targetObject, string objectIdentity, string reason = null, object data = null, FriendlyHint friendlyHint = null, [CallerMemberName] string memberName = null, [CallerFilePath] string sourceFilePath = null, [CallerLineNumber] int sourceLineNumber = 0) { if (targetObject == null) { throw new InvalidObjectException(objectIdentity, data: new { data }, reason: reason, hint: friendlyHint, scene: new ExceptionScene { FilePath = sourceFilePath, LineNumber = sourceLineNumber, MethodName = memberName }); } }
/// <summary> /// Checks the null object as resource not found. /// </summary> /// <param name="targetObject">The target object.</param> /// <param name="objectIdentity">The object identity.</param> /// <param name="objectIdentifier">The object identifier.</param> /// <param name="friendlyHint">The friendly hint.</param> /// <param name="memberName">Name of the member.</param> /// <param name="sourceFilePath">The source file path.</param> /// <param name="sourceLineNumber">The source line number.</param> /// <exception cref="ResourceNotFoundException"></exception> /// <exception cref="ExceptionScene"></exception> public static void CheckNullObjectAsResourceNotFound(this object targetObject, string objectIdentity, string objectIdentifier = null, FriendlyHint friendlyHint = null, [CallerMemberName] string memberName = null, [CallerFilePath] string sourceFilePath = null, [CallerLineNumber] int sourceLineNumber = 0) { if (targetObject == null) { throw new ResourceNotFoundException(objectIdentity, objectIdentifier, friendlyHint: friendlyHint, scene: new ExceptionScene { FilePath = sourceFilePath, LineNumber = sourceLineNumber, MethodName = memberName }); } }
/// <summary> /// Checks the null resource. /// </summary> /// <param name="anyObject">Any object.</param> /// <param name="resourceName">Name of the resource.</param> /// <param name="resourceIdentity">The resource identity.</param> /// <param name="friendlyHint">The friendly hint.</param> /// <param name="memberName">Name of the member.</param> /// <param name="sourceFilePath">The source file path.</param> /// <param name="sourceLineNumber">The source line number.</param> /// <exception cref="Beyova.Diagnostic.ResourceNotFoundException"></exception> /// <exception cref="ExceptionScene"></exception> public static void CheckNullResource(this object anyObject, string resourceName, string resourceIdentity, FriendlyHint friendlyHint = null, [CallerMemberName] string memberName = null, [CallerFilePath] string sourceFilePath = null, [CallerLineNumber] int sourceLineNumber = 0) { if (anyObject == null) { throw new ResourceNotFoundException(resourceName, resourceIdentity, friendlyHint, new ExceptionScene { FilePath = sourceFilePath, LineNumber = sourceLineNumber, MethodName = memberName }); } }
/// <summary> /// Handles the specified exception. /// </summary> /// <param name="exception">The exception.</param> /// <param name="data">The data.</param> /// <param name="hint">The hint.</param> /// <param name="minorCode">The minor code.</param> /// <param name="operationName">Name of the operation.</param> /// <param name="sourceFilePath">The source file path.</param> /// <param name="sourceLineNumber">The source line number.</param> /// <returns> /// Beyova.Diagnostic.BaseException. /// </returns> public static BaseException Handle(this Exception exception, object data = null, FriendlyHint hint = null, string minorCode = null, [CallerMemberName] string operationName = null, [CallerFilePath] string sourceFilePath = null, [CallerLineNumber] int sourceLineNumber = 0) { return(Handle(exception, new ExceptionScene { MethodName = operationName, FilePath = sourceFilePath, LineNumber = sourceLineNumber }, data, hint, minorCode)); }
/// <summary> /// Checks the zero enum. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="enumObject">The enum object.</param> /// <param name="resourceName">Name of the resource.</param> /// <param name="friendlyHint">The friendly hint.</param> /// <param name="memberName">Name of the member.</param> /// <param name="sourceFilePath">The source file path.</param> /// <param name="sourceLineNumber">The source line number.</param> /// <exception cref="InvalidObjectException"></exception> /// <exception cref="ExceptionScene"></exception> public static void CheckZeroEnum <T>(this T enumObject, string resourceName = null, FriendlyHint friendlyHint = null, [CallerMemberName] string memberName = null, [CallerFilePath] string sourceFilePath = null, [CallerLineNumber] int sourceLineNumber = 0) where T : struct, IConvertible { if (enumObject.EnumToInt32() == 0) { throw new InvalidObjectException(resourceName.SafeToString(typeof(T).FullName), data: new { type = typeof(T).FullName }, reason: "ZeroEnumValue", hint: friendlyHint, scene: new ExceptionScene { FilePath = sourceFilePath, LineNumber = sourceLineNumber, MethodName = memberName }); } }
/// <summary> /// Converts the exception to base exception. /// </summary> /// <param name="exception">The exception.</param> /// <param name="data">The data.</param> /// <param name="friendlyHint">The friendly hint.</param> /// <param name="memberName">Name of the member.</param> /// <param name="sourceFilePath">The source file path.</param> /// <param name="sourceLineNumber">The source line number.</param> /// <returns> /// BaseException. /// </returns> public static BaseException ConvertExceptionToBaseException(this Exception exception, object data = null, FriendlyHint friendlyHint = null, [CallerMemberName] string memberName = null, [CallerFilePath] string sourceFilePath = null, [CallerLineNumber] int sourceLineNumber = 0) { return(exception == null ? null : ((exception as BaseException) ?? exception.Handle(new ExceptionScene { FilePath = sourceFilePath, LineNumber = sourceLineNumber, MethodName = memberName }, data, hint: friendlyHint))); }