ExceptionBehavior
Namespace:
Automatonymous
We found 10 examples in language CSharp for this search.
You will see 26 fragments of code.
Other methods
Other methods
Project:LionFire.Behaviors
File:TimerPollingProvider.cs
Examples:1
#if NO_COROUTINES
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace LionFire.Behaviors
{
public class TimerPollingProvider : IPollingProvider
{
//ConcurrentDictionary<long, Timer> timersByDuration = new ConcurrentDictionary<long, Timer>(); // TOAOT -
ConcurrentDictionary<IPoller, Timer> pollers = new ConcurrentDictionary<IPoller, Timer>();
#region Configuration
#region ExceptionBehavior
public PollingExceptionBehavior ExceptionBehavior
{
get { return exceptionBehavior; }
set { exceptionBehavior = value; }
} private PollingExceptionBehavior exceptionBehavior = PollingExceptionBehavior.Disable | PollingExceptionBehavior.WrapAndRethrow;
#endregion
#endregion
#region Construction
public TimerPollingProvider()
{
#if AOT
throw new NotSupportedException("TODO: Dictionary IComparer in ctor");
#endif
}
#endregion
#region IPollingProvider Implementation
public void Register(IPoller poller)
{
var rp = poller.RecurranceParameters;
if (rp == null) { throw new ArgumentNullException("IPoller instance does not have RecurranceParameters set"); }
int milliseconds = (int)rp.Interval.TotalMilliseconds; // DOUBLECAST
Timer timer = new Timer(OnTimerElapsed, poller, milliseconds, milliseconds);
if (!pollers.TryAdd(poller, timer)) throw new DuplicateNotAllowedException();
//poller.RecurranceParameters.Interval
}
public void Unregister(IPoller poller)
{
Timer timer;
if (pollers.TryRemove(poller, out timer))
{
timer.Dispose();
}
}
#endregion
#region (Private) Event handling
private void OnTimerElapsed(object state)
{
IPoller poller = (IPoller)state;
bool result;
try
{
#if POLLER_COROUTINES
result = poller.MoveNext();
#else // Poller Method, slightly more efficient
result = poller.Poll();
#endif
}
catch(Exception ex)
{
if(((ExceptionBehavior & PollingExceptionBehavior.WrapAndRethrow) != PollingExceptionBehavior.None))
{
throw new Exception("Poller threw exception", ex);
}
if (((ExceptionBehavior & PollingExceptionBehavior.Disable) != PollingExceptionBehavior.None))
{
result = false;
}
else
{
result = true;
}
}
if (!result)
{
Unregister(poller);
}
}
#endregion
}
}
#endif
Project:Fruberry-CSharp
File:List.cs
Examples:5
int IList.Add(object item) {
if (!item.GetType().IsAssignableFrom(typeof(T))) {
switch (ExceptionBehavior) {
case ExceptionBehavior.Throw: throw new ArgumentOutOfRangeException(nameof(item), item, $"Item must be of type {typeof(T)}");
default: return -1;
}
}
Add((T)item);
return Count - 1;
}
public T Find(Predicate<T> match) {
if (match == null) {
switch (ExceptionBehavior) {
case ExceptionBehavior.Throw: throw new ArgumentNullException("Match must be nonnull");
default: return default;
}
}
for (var i = 0; i < Length; i++) {
if (match(_items[i])) return _items[i];
}
return default;
}
public void ForEach(Action<T> action) {
if (action == null) {
switch (ExceptionBehavior) {
case ExceptionBehavior.Throw: throw new ArgumentNullException("Match must be nonnull");
default: return;
}
}
for (var i = 0; i < Length; i++) {
action(_items[i]);
}
}
public bool TrueForAll(Predicate<T> match) {
if (match == null) {
switch (ExceptionBehavior) {
case ExceptionBehavior.Throw: throw new ArgumentNullException("Match must be nonnull");
default: return false;
}
}
for (var i = 0; i < Length; i++) {
if (!match(_items[i])) return false;
}
return true;
}
public T Peek() {
if (Length == 0) {
switch(ExceptionBehavior) {
case ExceptionBehavior.Throw: throw new InvalidOperationException("Peek must be called on a nonempty structure");
default: return default;
}
}
return this[Length - 1];
}
Project:andres
File:BaseBusinessRules.cs
Examples:6
/// <summary>
/// ExceptionBehavior
/// </summary>
/// <typeparam name="TReturn">TReturn</typeparam>
/// <param name="fnAccion"></param>
/// <returns>Is Action</returns>
protected static TReturn ExceptionBehavior<TReturn>(Func<TReturn> fnAccion)
{
TReturn returnBehavior;
try
{
returnBehavior = fnAccion();
}
catch (Exception)
{
returnBehavior = default;
}
return returnBehavior;
}
/// <summary>
/// Count
/// </summary>
/// <param name="expression">expression</param>
/// <returns>Count entity</returns>
public int Count(Expression<Func<T, bool>> expression)
{
return ExceptionBehavior(() => DaoNegocio.Count(expression));
}
/// <summary>
/// Create
/// </summary>
/// <param name="objCreate">Id Entity</param>
/// <returns>Id Entity</returns>
public int? Create(T objCreate)
{
int? objReturn = null;
if (objCreate.IsNotNull())
{
objReturn = ExceptionBehavior(() =>
{
ValidationsToCreate(objCreate);
using var tran = new TransactionScope();
int? objReturn = DaoNegocio.Create(objCreate);
tran.Complete();
return objReturn;
});
}
return objReturn;
}
/// <summary>
/// Validations To Create
/// </summary>
/// <param name="entity">Entity</param>
protected virtual void ValidationsToCreate(T entity) { entity.TrimAll(); }
public int? Create(IEnumerable<T> objCreate)
{
return ExceptionBehavior(() => DaoNegocio.Create(objCreate));
}
/// <summary>
/// CreateAsync
/// </summary>
/// <param name="objCreate">Entity</param>
/// <returns>Id Create</returns>
public async Task<int?> CreateAsync(T objCreate)
{
int? objReturn = null;
if (objCreate.IsNotNull())
{
objReturn = await ExceptionBehaviorAsync(async () =>
{
ValidationsToCreate(objCreate);
using var tran = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled);
var objReturn = await DaoNegocio.CreateAsync(objCreate).ConfigureAwait(false);
tran.Complete();
return objReturn;
}).ConfigureAwait(false);
}
return objReturn;
}
Project:dot42
File:ExceptionBehaviorMap.cs
Examples:4
/// <summary>
/// Set to default values to the initial state.
/// </summary>
public void ResetDefaults()
{
DefaultStopOnThrow = false;
DefaultStopUncaught = true;
}
/// <summary>
/// Set to defaults.
/// </summary>
public void ResetAll()
{
lock (mapLock)
{
ResetDefaults();
map.Clear();
}
}
private ExceptionBehaviorMap Clone()
{
lock (mapLock)
{
return new ExceptionBehaviorMap(this);
}
}
/// <summary>
/// Copy the state of the given object to me.
///
/// Returns all behaviors that have changed, with their new values.
/// If the default behavior was changed, the first returned behavior
/// will be null.
/// </summary>
public IList<ExceptionBehavior> CopyFrom(ExceptionBehaviorMap source)
{
source = source.Clone();
lock (mapLock)
{
List<string> changed = new List<string>();
// find changed values
foreach (var entry in source.map)
{
if (!Equals(this[entry.Key], entry.Value))
changed.Add(entry.Key);
}
// add all values that have been removed.
changed.AddRange(map.Keys.ToList()
.Where(key => !source.map.ContainsKey(key)));
map.Clear();
foreach (var entry in source.map)
{
map[entry.Key] = entry.Value;
}
List<ExceptionBehavior> ret = new List<ExceptionBehavior>();
if(DefaultStopUncaught != source.DefaultStopUncaught || DefaultStopOnThrow != source.DefaultStopOnThrow)
ret.Insert(0, null);
ret.AddRange(changed.Select(x => this[x]));
DefaultStopOnThrow = source.DefaultStopOnThrow;
DefaultStopUncaught = source.DefaultStopUncaught;
return ret;
}
}
Project:Archive
File:ExceptionBehavior.cs
Examples:1
public async Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate<TResponse> next)
{
try
{
return await next();
}
catch (Exception e)
{
throw;
}
}
Project:kwetter
File:ExceptionBehavior.cs
Examples:1
/// <inheritdoc cref="IPipelineBehavior{TRequest,TResponse}.Handle(TRequest, CancellationToken, RequestHandlerDelegate{TResponse})"/>
public async Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate<TResponse> next)
{
try
{
return await next();
}
catch (ValidationException validationException)
{
TResponse response = new();
response.Errors.AddRange(
validationException.Errors.Select(validationFailure => validationFailure.ErrorMessage));
return response;
}
catch (Exception ex)
{
string requestName = typeof(TRequest).Name;
_logger.LogError(ex, "Unhandled Exception during Request {Name} {@Request}", requestName, request);
throw;
}
}
Project:NCStudio.Utility
File:ExceptionBehavior.cs
Examples:1
public async Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate<TResponse> next)
{
try
{
return await next();
}
catch (ValidationException ve)
{
return new BadRequestObjectResult(ve.ToString()) as TResponse;
}
}
Project:dot42
File:ExceptionBehavior.cs
Examples:3
#region Equality
private bool Equals(ExceptionBehavior other)
{
return string.Equals(ExceptionName, other.ExceptionName) && StopOnThrow == other.StopOnThrow && StopUncaught == other.StopUncaught;
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
return obj is ExceptionBehavior && Equals((ExceptionBehavior) obj);
}
public override int GetHashCode()
{
unchecked
{
var hashCode = (ExceptionName != null ? ExceptionName.GetHashCode() : 0);
hashCode = (hashCode*397) ^ StopOnThrow.GetHashCode();
hashCode = (hashCode*397) ^ StopUncaught.GetHashCode();
return hashCode;
}
}
Project:CommonFoundation
File:ApiPermissionAttribute.cs
Examples:1
using System;
using Beyova.Diagnostic;
namespace Beyova.Api
{
/// <summary>
/// Class ApiPermissionAttribute.
/// </summary>
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = true, Inherited = true)]
public class ApiPermissionAttribute : Attribute
{
/// <summary>
/// Gets or sets the permission identifier.
/// </summary>
/// <value>The permission identifier.</value>
public string PermissionIdentifier { get; protected set; }
/// <summary>
/// Gets or sets the permission.
/// </summary>
/// <value>The permission.</value>
public ApiPermission Permission { get; protected set; }
/// <summary>
/// Gets or sets the exception behavior.
/// </summary>
/// <value>
/// The exception behavior.
/// </value>
public ExceptionCode ExceptionBehavior { get; protected set; }
/// <summary>
/// Initializes a new instance of the <see cref="ApiPermissionAttribute" /> class.
/// </summary>
/// <param name="permissionIdentifier">The permission identifier.</param>
/// <param name="permission">The permission.</param>
public ApiPermissionAttribute(string permissionIdentifier, ApiPermission permission = ApiPermission.Required)
{
PermissionIdentifier = permissionIdentifier;
Permission = permission;
}
/// <summary>
/// Initializes a new instance of the <see cref="ApiPermissionAttribute"/> class.
/// </summary>
/// <param name="permissionIdentifier">The permission identifier.</param>
/// <param name="exceptionBehavior">The exception behavior.</param>
/// <param name="permission">The permission.</param>
public ApiPermissionAttribute(string permissionIdentifier, ExceptionCode exceptionBehavior, ApiPermission permission = ApiPermission.Required)
: this(permissionIdentifier, permission)
{
ExceptionBehavior = exceptionBehavior;
}
}
}
Project:realmmud
File:ExceptionExtensions.cs
Examples:3
/// <summary>
/// Handles exceptions based upon the indicated behavior and throws a new exception of the given
/// type, assigning the original exception as the InnerException
/// </summary>
public static void Handle<T>(this Exception exception, ExceptionHandlingOptions exceptionBehavior, ILogWrapper log = null,
string msg = "", params object[] parameters) where T : Exception
{
var caller = GetCaller();
if (exceptionBehavior == ExceptionHandlingOptions.RecordOnly || exceptionBehavior == ExceptionHandlingOptions.RecordAndThrow)
{
ILogWrapper logger = log ?? new LogWrapper(LogManager.GetLogger(caller), LogLevel.Error);
if (string.IsNullOrEmpty(msg))
logger.Error(exception);
else
logger.Error(String.Format(msg, parameters), exception);
}
if (exceptionBehavior == ExceptionHandlingOptions.RecordAndThrow || exceptionBehavior == ExceptionHandlingOptions.ThrowOnly)
throw (T)Activator.CreateInstance(typeof(T), string.Format(Resources.MSG_EXCEPTION_LOCATION, caller), exception);
}
/// <summary>
/// Handles exceptions based upon the indicated behavior and rethrows the Exception
/// </summary>
/// <param name="exception"></param>
/// <param name="exceptionBehavior"></param>
/// <param name="log"></param>
/// <param name="msg"></param>
/// <param name="parameters"></param>
public static void Handle(this Exception exception, ExceptionHandlingOptions exceptionBehavior, ILogWrapper log = null,
string msg = "", params object[] parameters)
{
var caller = GetCaller();
if (exceptionBehavior == ExceptionHandlingOptions.RecordOnly || exceptionBehavior == ExceptionHandlingOptions.RecordAndThrow)
{
ILogWrapper logger = log ?? new LogWrapper(LogManager.GetLogger(caller), LogLevel.Error);
if (string.IsNullOrEmpty(msg))
logger.Error(exception);
else
logger.Error(String.Format(msg, parameters), exception);
}
if (exceptionBehavior == ExceptionHandlingOptions.RecordAndThrow ||
exceptionBehavior == ExceptionHandlingOptions.ThrowOnly)
throw exception;
}
/// <summary>
/// Gets the calling class and method for the current stack
/// </summary>
/// <returns>Returns the full name of the class (with namespace) and the calling method</returns>
private static string GetCaller(int level = 2)
{
var method = new StackTrace().GetFrame(level).GetMethod();
if (method == null || method.DeclaringType == null)
return string.Empty;
return string.Format("{0}:{1}", method.DeclaringType.FullName, method.Name);
}
Automatonymous.Behaviors.ExceptionBehavior<TInstance> : Behavior
Constructors :
public ExceptionBehavior()Methods :
public Void Probe(ProbeContext context = )public Type GetType()
public String ToString()
public Boolean Equals(Object obj = )
public Int32 GetHashCode()
Other methods
Other methods
ExceptionBehavior
Namespace:
Automatonymous
We found 10 examples in language CSharp for this search.
You will see 26 fragments of code.
Other methods
Other methods
Project:LionFire.Behaviors
File:TimerPollingProvider.cs
Examples:1
#if NO_COROUTINES
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace LionFire.Behaviors
{
public class TimerPollingProvider : IPollingProvider
{
//ConcurrentDictionary<long, Timer> timersByDuration = new ConcurrentDictionary<long, Timer>(); // TOAOT -
ConcurrentDictionary<IPoller, Timer> pollers = new ConcurrentDictionary<IPoller, Timer>();
#region Configuration
#region ExceptionBehavior
public PollingExceptionBehavior ExceptionBehavior
{
get { return exceptionBehavior; }
set { exceptionBehavior = value; }
} private PollingExceptionBehavior exceptionBehavior = PollingExceptionBehavior.Disable | PollingExceptionBehavior.WrapAndRethrow;
#endregion
#endregion
#region Construction
public TimerPollingProvider()
{
#if AOT
throw new NotSupportedException("TODO: Dictionary IComparer in ctor");
#endif
}
#endregion
#region IPollingProvider Implementation
public void Register(IPoller poller)
{
var rp = poller.RecurranceParameters;
if (rp == null) { throw new ArgumentNullException("IPoller instance does not have RecurranceParameters set"); }
int milliseconds = (int)rp.Interval.TotalMilliseconds; // DOUBLECAST
Timer timer = new Timer(OnTimerElapsed, poller, milliseconds, milliseconds);
if (!pollers.TryAdd(poller, timer)) throw new DuplicateNotAllowedException();
//poller.RecurranceParameters.Interval
}
public void Unregister(IPoller poller)
{
Timer timer;
if (pollers.TryRemove(poller, out timer))
{
timer.Dispose();
}
}
#endregion
#region (Private) Event handling
private void OnTimerElapsed(object state)
{
IPoller poller = (IPoller)state;
bool result;
try
{
#if POLLER_COROUTINES
result = poller.MoveNext();
#else // Poller Method, slightly more efficient
result = poller.Poll();
#endif
}
catch(Exception ex)
{
if(((ExceptionBehavior & PollingExceptionBehavior.WrapAndRethrow) != PollingExceptionBehavior.None))
{
throw new Exception("Poller threw exception", ex);
}
if (((ExceptionBehavior & PollingExceptionBehavior.Disable) != PollingExceptionBehavior.None))
{
result = false;
}
else
{
result = true;
}
}
if (!result)
{
Unregister(poller);
}
}
#endregion
}
}
#endif
Project:Fruberry-CSharp
File:List.cs
Examples:5
int IList.Add(object item) {
if (!item.GetType().IsAssignableFrom(typeof(T))) {
switch (ExceptionBehavior) {
case ExceptionBehavior.Throw: throw new ArgumentOutOfRangeException(nameof(item), item, $"Item must be of type {typeof(T)}");
default: return -1;
}
}
Add((T)item);
return Count - 1;
}
public T Find(Predicate<T> match) {
if (match == null) {
switch (ExceptionBehavior) {
case ExceptionBehavior.Throw: throw new ArgumentNullException("Match must be nonnull");
default: return default;
}
}
for (var i = 0; i < Length; i++) {
if (match(_items[i])) return _items[i];
}
return default;
}
public void ForEach(Action<T> action) {
if (action == null) {
switch (ExceptionBehavior) {
case ExceptionBehavior.Throw: throw new ArgumentNullException("Match must be nonnull");
default: return;
}
}
for (var i = 0; i < Length; i++) {
action(_items[i]);
}
}
public bool TrueForAll(Predicate<T> match) {
if (match == null) {
switch (ExceptionBehavior) {
case ExceptionBehavior.Throw: throw new ArgumentNullException("Match must be nonnull");
default: return false;
}
}
for (var i = 0; i < Length; i++) {
if (!match(_items[i])) return false;
}
return true;
}
public T Peek() {
if (Length == 0) {
switch(ExceptionBehavior) {
case ExceptionBehavior.Throw: throw new InvalidOperationException("Peek must be called on a nonempty structure");
default: return default;
}
}
return this[Length - 1];
}
Project:andres
File:BaseBusinessRules.cs
Examples:6
/// <summary>
/// ExceptionBehavior
/// </summary>
/// <typeparam name="TReturn">TReturn</typeparam>
/// <param name="fnAccion"></param>
/// <returns>Is Action</returns>
protected static TReturn ExceptionBehavior<TReturn>(Func<TReturn> fnAccion)
{
TReturn returnBehavior;
try
{
returnBehavior = fnAccion();
}
catch (Exception)
{
returnBehavior = default;
}
return returnBehavior;
}
/// <summary>
/// Count
/// </summary>
/// <param name="expression">expression</param>
/// <returns>Count entity</returns>
public int Count(Expression<Func<T, bool>> expression)
{
return ExceptionBehavior(() => DaoNegocio.Count(expression));
}
/// <summary>
/// Create
/// </summary>
/// <param name="objCreate">Id Entity</param>
/// <returns>Id Entity</returns>
public int? Create(T objCreate)
{
int? objReturn = null;
if (objCreate.IsNotNull())
{
objReturn = ExceptionBehavior(() =>
{
ValidationsToCreate(objCreate);
using var tran = new TransactionScope();
int? objReturn = DaoNegocio.Create(objCreate);
tran.Complete();
return objReturn;
});
}
return objReturn;
}
/// <summary>
/// Validations To Create
/// </summary>
/// <param name="entity">Entity</param>
protected virtual void ValidationsToCreate(T entity) { entity.TrimAll(); }
public int? Create(IEnumerable<T> objCreate)
{
return ExceptionBehavior(() => DaoNegocio.Create(objCreate));
}
/// <summary>
/// CreateAsync
/// </summary>
/// <param name="objCreate">Entity</param>
/// <returns>Id Create</returns>
public async Task<int?> CreateAsync(T objCreate)
{
int? objReturn = null;
if (objCreate.IsNotNull())
{
objReturn = await ExceptionBehaviorAsync(async () =>
{
ValidationsToCreate(objCreate);
using var tran = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled);
var objReturn = await DaoNegocio.CreateAsync(objCreate).ConfigureAwait(false);
tran.Complete();
return objReturn;
}).ConfigureAwait(false);
}
return objReturn;
}
Project:dot42
File:ExceptionBehaviorMap.cs
Examples:4
/// <summary>
/// Set to default values to the initial state.
/// </summary>
public void ResetDefaults()
{
DefaultStopOnThrow = false;
DefaultStopUncaught = true;
}
/// <summary>
/// Set to defaults.
/// </summary>
public void ResetAll()
{
lock (mapLock)
{
ResetDefaults();
map.Clear();
}
}
private ExceptionBehaviorMap Clone()
{
lock (mapLock)
{
return new ExceptionBehaviorMap(this);
}
}
/// <summary>
/// Copy the state of the given object to me.
///
/// Returns all behaviors that have changed, with their new values.
/// If the default behavior was changed, the first returned behavior
/// will be null.
/// </summary>
public IList<ExceptionBehavior> CopyFrom(ExceptionBehaviorMap source)
{
source = source.Clone();
lock (mapLock)
{
List<string> changed = new List<string>();
// find changed values
foreach (var entry in source.map)
{
if (!Equals(this[entry.Key], entry.Value))
changed.Add(entry.Key);
}
// add all values that have been removed.
changed.AddRange(map.Keys.ToList()
.Where(key => !source.map.ContainsKey(key)));
map.Clear();
foreach (var entry in source.map)
{
map[entry.Key] = entry.Value;
}
List<ExceptionBehavior> ret = new List<ExceptionBehavior>();
if(DefaultStopUncaught != source.DefaultStopUncaught || DefaultStopOnThrow != source.DefaultStopOnThrow)
ret.Insert(0, null);
ret.AddRange(changed.Select(x => this[x]));
DefaultStopOnThrow = source.DefaultStopOnThrow;
DefaultStopUncaught = source.DefaultStopUncaught;
return ret;
}
}
Project:Archive
File:ExceptionBehavior.cs
Examples:1
public async Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate<TResponse> next)
{
try
{
return await next();
}
catch (Exception e)
{
throw;
}
}
Project:kwetter
File:ExceptionBehavior.cs
Examples:1
/// <inheritdoc cref="IPipelineBehavior{TRequest,TResponse}.Handle(TRequest, CancellationToken, RequestHandlerDelegate{TResponse})"/>
public async Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate<TResponse> next)
{
try
{
return await next();
}
catch (ValidationException validationException)
{
TResponse response = new();
response.Errors.AddRange(
validationException.Errors.Select(validationFailure => validationFailure.ErrorMessage));
return response;
}
catch (Exception ex)
{
string requestName = typeof(TRequest).Name;
_logger.LogError(ex, "Unhandled Exception during Request {Name} {@Request}", requestName, request);
throw;
}
}
Project:NCStudio.Utility
File:ExceptionBehavior.cs
Examples:1
public async Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate<TResponse> next)
{
try
{
return await next();
}
catch (ValidationException ve)
{
return new BadRequestObjectResult(ve.ToString()) as TResponse;
}
}
Project:dot42
File:ExceptionBehavior.cs
Examples:3
#region Equality
private bool Equals(ExceptionBehavior other)
{
return string.Equals(ExceptionName, other.ExceptionName) && StopOnThrow == other.StopOnThrow && StopUncaught == other.StopUncaught;
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
return obj is ExceptionBehavior && Equals((ExceptionBehavior) obj);
}
public override int GetHashCode()
{
unchecked
{
var hashCode = (ExceptionName != null ? ExceptionName.GetHashCode() : 0);
hashCode = (hashCode*397) ^ StopOnThrow.GetHashCode();
hashCode = (hashCode*397) ^ StopUncaught.GetHashCode();
return hashCode;
}
}
Project:CommonFoundation
File:ApiPermissionAttribute.cs
Examples:1
using System;
using Beyova.Diagnostic;
namespace Beyova.Api
{
/// <summary>
/// Class ApiPermissionAttribute.
/// </summary>
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = true, Inherited = true)]
public class ApiPermissionAttribute : Attribute
{
/// <summary>
/// Gets or sets the permission identifier.
/// </summary>
/// <value>The permission identifier.</value>
public string PermissionIdentifier { get; protected set; }
/// <summary>
/// Gets or sets the permission.
/// </summary>
/// <value>The permission.</value>
public ApiPermission Permission { get; protected set; }
/// <summary>
/// Gets or sets the exception behavior.
/// </summary>
/// <value>
/// The exception behavior.
/// </value>
public ExceptionCode ExceptionBehavior { get; protected set; }
/// <summary>
/// Initializes a new instance of the <see cref="ApiPermissionAttribute" /> class.
/// </summary>
/// <param name="permissionIdentifier">The permission identifier.</param>
/// <param name="permission">The permission.</param>
public ApiPermissionAttribute(string permissionIdentifier, ApiPermission permission = ApiPermission.Required)
{
PermissionIdentifier = permissionIdentifier;
Permission = permission;
}
/// <summary>
/// Initializes a new instance of the <see cref="ApiPermissionAttribute"/> class.
/// </summary>
/// <param name="permissionIdentifier">The permission identifier.</param>
/// <param name="exceptionBehavior">The exception behavior.</param>
/// <param name="permission">The permission.</param>
public ApiPermissionAttribute(string permissionIdentifier, ExceptionCode exceptionBehavior, ApiPermission permission = ApiPermission.Required)
: this(permissionIdentifier, permission)
{
ExceptionBehavior = exceptionBehavior;
}
}
}
Project:realmmud
File:ExceptionExtensions.cs
Examples:3
/// <summary>
/// Handles exceptions based upon the indicated behavior and throws a new exception of the given
/// type, assigning the original exception as the InnerException
/// </summary>
public static void Handle<T>(this Exception exception, ExceptionHandlingOptions exceptionBehavior, ILogWrapper log = null,
string msg = "", params object[] parameters) where T : Exception
{
var caller = GetCaller();
if (exceptionBehavior == ExceptionHandlingOptions.RecordOnly || exceptionBehavior == ExceptionHandlingOptions.RecordAndThrow)
{
ILogWrapper logger = log ?? new LogWrapper(LogManager.GetLogger(caller), LogLevel.Error);
if (string.IsNullOrEmpty(msg))
logger.Error(exception);
else
logger.Error(String.Format(msg, parameters), exception);
}
if (exceptionBehavior == ExceptionHandlingOptions.RecordAndThrow || exceptionBehavior == ExceptionHandlingOptions.ThrowOnly)
throw (T)Activator.CreateInstance(typeof(T), string.Format(Resources.MSG_EXCEPTION_LOCATION, caller), exception);
}
/// <summary>
/// Handles exceptions based upon the indicated behavior and rethrows the Exception
/// </summary>
/// <param name="exception"></param>
/// <param name="exceptionBehavior"></param>
/// <param name="log"></param>
/// <param name="msg"></param>
/// <param name="parameters"></param>
public static void Handle(this Exception exception, ExceptionHandlingOptions exceptionBehavior, ILogWrapper log = null,
string msg = "", params object[] parameters)
{
var caller = GetCaller();
if (exceptionBehavior == ExceptionHandlingOptions.RecordOnly || exceptionBehavior == ExceptionHandlingOptions.RecordAndThrow)
{
ILogWrapper logger = log ?? new LogWrapper(LogManager.GetLogger(caller), LogLevel.Error);
if (string.IsNullOrEmpty(msg))
logger.Error(exception);
else
logger.Error(String.Format(msg, parameters), exception);
}
if (exceptionBehavior == ExceptionHandlingOptions.RecordAndThrow ||
exceptionBehavior == ExceptionHandlingOptions.ThrowOnly)
throw exception;
}
/// <summary>
/// Gets the calling class and method for the current stack
/// </summary>
/// <returns>Returns the full name of the class (with namespace) and the calling method</returns>
private static string GetCaller(int level = 2)
{
var method = new StackTrace().GetFrame(level).GetMethod();
if (method == null || method.DeclaringType == null)
return string.Empty;
return string.Format("{0}:{1}", method.DeclaringType.FullName, method.Name);
}
Automatonymous.Behaviors.ExceptionBehavior<TInstance, TData> : Behavior
Constructors :
public ExceptionBehavior()Methods :
public Void Probe(ProbeContext context = )public Type GetType()
public String ToString()
public Boolean Equals(Object obj = )
public Int32 GetHashCode()
Other methods
Other methods
ExceptionBehavior
Namespace:
Automatonymous
We found 10 examples in language CSharp for this search.
You will see 25 fragments of code.
Other methods
Other methods
Project:LionFire.Behaviors
File:TimerPollingProvider.cs
Examples:1
#if NO_COROUTINES
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace LionFire.Behaviors
{
public class TimerPollingProvider : IPollingProvider
{
//ConcurrentDictionary<long, Timer> timersByDuration = new ConcurrentDictionary<long, Timer>(); // TOAOT -
ConcurrentDictionary<IPoller, Timer> pollers = new ConcurrentDictionary<IPoller, Timer>();
#region Configuration
#region ExceptionBehavior
public PollingExceptionBehavior ExceptionBehavior
{
get { return exceptionBehavior; }
set { exceptionBehavior = value; }
} private PollingExceptionBehavior exceptionBehavior = PollingExceptionBehavior.Disable | PollingExceptionBehavior.WrapAndRethrow;
#endregion
#endregion
#region Construction
public TimerPollingProvider()
{
#if AOT
throw new NotSupportedException("TODO: Dictionary IComparer in ctor");
#endif
}
#endregion
#region IPollingProvider Implementation
public void Register(IPoller poller)
{
var rp = poller.RecurranceParameters;
if (rp == null) { throw new ArgumentNullException("IPoller instance does not have RecurranceParameters set"); }
int milliseconds = (int)rp.Interval.TotalMilliseconds; // DOUBLECAST
Timer timer = new Timer(OnTimerElapsed, poller, milliseconds, milliseconds);
if (!pollers.TryAdd(poller, timer)) throw new DuplicateNotAllowedException();
//poller.RecurranceParameters.Interval
}
public void Unregister(IPoller poller)
{
Timer timer;
if (pollers.TryRemove(poller, out timer))
{
timer.Dispose();
}
}
#endregion
#region (Private) Event handling
private void OnTimerElapsed(object state)
{
IPoller poller = (IPoller)state;
bool result;
try
{
#if POLLER_COROUTINES
result = poller.MoveNext();
#else // Poller Method, slightly more efficient
result = poller.Poll();
#endif
}
catch(Exception ex)
{
if(((ExceptionBehavior & PollingExceptionBehavior.WrapAndRethrow) != PollingExceptionBehavior.None))
{
throw new Exception("Poller threw exception", ex);
}
if (((ExceptionBehavior & PollingExceptionBehavior.Disable) != PollingExceptionBehavior.None))
{
result = false;
}
else
{
result = true;
}
}
if (!result)
{
Unregister(poller);
}
}
#endregion
}
}
#endif
Project:Fruberry-CSharp
File:List.cs
Examples:5
int IList.Add(object item) {
if (!item.GetType().IsAssignableFrom(typeof(T))) {
switch (ExceptionBehavior) {
case ExceptionBehavior.Throw: throw new ArgumentOutOfRangeException(nameof(item), item, $"Item must be of type {typeof(T)}");
default: return -1;
}
}
Add((T)item);
return Count - 1;
}
public T Find(Predicate<T> match) {
if (match == null) {
switch (ExceptionBehavior) {
case ExceptionBehavior.Throw: throw new ArgumentNullException("Match must be nonnull");
default: return default;
}
}
for (var i = 0; i < Length; i++) {
if (match(_items[i])) return _items[i];
}
return default;
}
public void ForEach(Action<T> action) {
if (action == null) {
switch (ExceptionBehavior) {
case ExceptionBehavior.Throw: throw new ArgumentNullException("Match must be nonnull");
default: return;
}
}
for (var i = 0; i < Length; i++) {
action(_items[i]);
}
}
public bool TrueForAll(Predicate<T> match) {
if (match == null) {
switch (ExceptionBehavior) {
case ExceptionBehavior.Throw: throw new ArgumentNullException("Match must be nonnull");
default: return false;
}
}
for (var i = 0; i < Length; i++) {
if (!match(_items[i])) return false;
}
return true;
}
public T Peek() {
if (Length == 0) {
switch(ExceptionBehavior) {
case ExceptionBehavior.Throw: throw new InvalidOperationException("Peek must be called on a nonempty structure");
default: return default;
}
}
return this[Length - 1];
}
Project:andres
File:BaseBusinessRules.cs
Examples:5
/// <summary>
/// Count
/// </summary>
/// <param name="expression">expression</param>
/// <returns>Count entity</returns>
public int Count(Expression<Func<T, bool>> expression)
{
return ExceptionBehavior(() => DaoNegocio.Count(expression));
}
public int? Create(IEnumerable<T> objCreate)
{
return ExceptionBehavior(() => DaoNegocio.Create(objCreate));
}
/// <summary>
/// Edit
/// </summary>
/// <param name="objEdit">obj to edit</param>
/// <returns>Is Edit</returns>
public bool? Edit(ICollection<T> objEdit)
{
return ExceptionBehavior(() => DaoNegocio.Edit(objEdit));
}
/// <summary>
/// Search
/// </summary>
/// <param name="expression">expression</param>
/// <returns>Entity</returns>
public T Search(Expression<Func<T, bool>> expression)
{
return ExceptionBehavior(() => DaoNegocio.Search(expression));
}
/// <summary>
/// Search
/// </summary>
/// <param name="expression">expression</param>
/// <param name="includes">includes</param>
/// <returns>Entity</returns>
public T Search(Expression<Func<T, bool>> expression, params Expression<Func<T, object>>[] includes)
{
return ExceptionBehavior(() => DaoNegocio.Search(expression, includes));
}
Project:dot42
File:ExceptionBehaviorMap.cs
Examples:4
/// <summary>
/// Set to default values to the initial state.
/// </summary>
public void ResetDefaults()
{
DefaultStopOnThrow = false;
DefaultStopUncaught = true;
}
/// <summary>
/// Set to defaults.
/// </summary>
public void ResetAll()
{
lock (mapLock)
{
ResetDefaults();
map.Clear();
}
}
private ExceptionBehaviorMap Clone()
{
lock (mapLock)
{
return new ExceptionBehaviorMap(this);
}
}
/// <summary>
/// Copy the state of the given object to me.
///
/// Returns all behaviors that have changed, with their new values.
/// If the default behavior was changed, the first returned behavior
/// will be null.
/// </summary>
public IList<ExceptionBehavior> CopyFrom(ExceptionBehaviorMap source)
{
source = source.Clone();
lock (mapLock)
{
List<string> changed = new List<string>();
// find changed values
foreach (var entry in source.map)
{
if (!Equals(this[entry.Key], entry.Value))
changed.Add(entry.Key);
}
// add all values that have been removed.
changed.AddRange(map.Keys.ToList()
.Where(key => !source.map.ContainsKey(key)));
map.Clear();
foreach (var entry in source.map)
{
map[entry.Key] = entry.Value;
}
List<ExceptionBehavior> ret = new List<ExceptionBehavior>();
if(DefaultStopUncaught != source.DefaultStopUncaught || DefaultStopOnThrow != source.DefaultStopOnThrow)
ret.Insert(0, null);
ret.AddRange(changed.Select(x => this[x]));
DefaultStopOnThrow = source.DefaultStopOnThrow;
DefaultStopUncaught = source.DefaultStopUncaught;
return ret;
}
}
Project:Archive
File:ExceptionBehavior.cs
Examples:1
public async Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate<TResponse> next)
{
try
{
return await next();
}
catch (Exception e)
{
throw;
}
}
Project:kwetter
File:ExceptionBehavior.cs
Examples:1
/// <inheritdoc cref="IPipelineBehavior{TRequest,TResponse}.Handle(TRequest, CancellationToken, RequestHandlerDelegate{TResponse})"/>
public async Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate<TResponse> next)
{
try
{
return await next();
}
catch (ValidationException validationException)
{
TResponse response = new();
response.Errors.AddRange(
validationException.Errors.Select(validationFailure => validationFailure.ErrorMessage));
return response;
}
catch (Exception ex)
{
string requestName = typeof(TRequest).Name;
_logger.LogError(ex, "Unhandled Exception during Request {Name} {@Request}", requestName, request);
throw;
}
}
Project:NCStudio.Utility
File:ExceptionBehavior.cs
Examples:1
public async Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate<TResponse> next)
{
try
{
return await next();
}
catch (ValidationException ve)
{
return new BadRequestObjectResult(ve.ToString()) as TResponse;
}
}
Project:dot42
File:ExceptionBehavior.cs
Examples:3
#region Equality
private bool Equals(ExceptionBehavior other)
{
return string.Equals(ExceptionName, other.ExceptionName) && StopOnThrow == other.StopOnThrow && StopUncaught == other.StopUncaught;
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
return obj is ExceptionBehavior && Equals((ExceptionBehavior) obj);
}
public override int GetHashCode()
{
unchecked
{
var hashCode = (ExceptionName != null ? ExceptionName.GetHashCode() : 0);
hashCode = (hashCode*397) ^ StopOnThrow.GetHashCode();
hashCode = (hashCode*397) ^ StopUncaught.GetHashCode();
return hashCode;
}
}
Project:CommonFoundation
File:ApiPermissionAttribute.cs
Examples:1
using System;
using Beyova.Diagnostic;
namespace Beyova.Api
{
/// <summary>
/// Class ApiPermissionAttribute.
/// </summary>
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = true, Inherited = true)]
public class ApiPermissionAttribute : Attribute
{
/// <summary>
/// Gets or sets the permission identifier.
/// </summary>
/// <value>The permission identifier.</value>
public string PermissionIdentifier { get; protected set; }
/// <summary>
/// Gets or sets the permission.
/// </summary>
/// <value>The permission.</value>
public ApiPermission Permission { get; protected set; }
/// <summary>
/// Gets or sets the exception behavior.
/// </summary>
/// <value>
/// The exception behavior.
/// </value>
public ExceptionCode ExceptionBehavior { get; protected set; }
/// <summary>
/// Initializes a new instance of the <see cref="ApiPermissionAttribute" /> class.
/// </summary>
/// <param name="permissionIdentifier">The permission identifier.</param>
/// <param name="permission">The permission.</param>
public ApiPermissionAttribute(string permissionIdentifier, ApiPermission permission = ApiPermission.Required)
{
PermissionIdentifier = permissionIdentifier;
Permission = permission;
}
/// <summary>
/// Initializes a new instance of the <see cref="ApiPermissionAttribute"/> class.
/// </summary>
/// <param name="permissionIdentifier">The permission identifier.</param>
/// <param name="exceptionBehavior">The exception behavior.</param>
/// <param name="permission">The permission.</param>
public ApiPermissionAttribute(string permissionIdentifier, ExceptionCode exceptionBehavior, ApiPermission permission = ApiPermission.Required)
: this(permissionIdentifier, permission)
{
ExceptionBehavior = exceptionBehavior;
}
}
}
Project:realmmud
File:ExceptionExtensions.cs
Examples:3
/// <summary>
/// Handles exceptions based upon the indicated behavior and throws a new exception of the given
/// type, assigning the original exception as the InnerException
/// </summary>
public static void Handle<T>(this Exception exception, ExceptionHandlingOptions exceptionBehavior, ILogWrapper log = null,
string msg = "", params object[] parameters) where T : Exception
{
var caller = GetCaller();
if (exceptionBehavior == ExceptionHandlingOptions.RecordOnly || exceptionBehavior == ExceptionHandlingOptions.RecordAndThrow)
{
ILogWrapper logger = log ?? new LogWrapper(LogManager.GetLogger(caller), LogLevel.Error);
if (string.IsNullOrEmpty(msg))
logger.Error(exception);
else
logger.Error(String.Format(msg, parameters), exception);
}
if (exceptionBehavior == ExceptionHandlingOptions.RecordAndThrow || exceptionBehavior == ExceptionHandlingOptions.ThrowOnly)
throw (T)Activator.CreateInstance(typeof(T), string.Format(Resources.MSG_EXCEPTION_LOCATION, caller), exception);
}
/// <summary>
/// Handles exceptions based upon the indicated behavior and rethrows the Exception
/// </summary>
/// <param name="exception"></param>
/// <param name="exceptionBehavior"></param>
/// <param name="log"></param>
/// <param name="msg"></param>
/// <param name="parameters"></param>
public static void Handle(this Exception exception, ExceptionHandlingOptions exceptionBehavior, ILogWrapper log = null,
string msg = "", params object[] parameters)
{
var caller = GetCaller();
if (exceptionBehavior == ExceptionHandlingOptions.RecordOnly || exceptionBehavior == ExceptionHandlingOptions.RecordAndThrow)
{
ILogWrapper logger = log ?? new LogWrapper(LogManager.GetLogger(caller), LogLevel.Error);
if (string.IsNullOrEmpty(msg))
logger.Error(exception);
else
logger.Error(String.Format(msg, parameters), exception);
}
if (exceptionBehavior == ExceptionHandlingOptions.RecordAndThrow ||
exceptionBehavior == ExceptionHandlingOptions.ThrowOnly)
throw exception;
}
/// <summary>
/// Gets the calling class and method for the current stack
/// </summary>
/// <returns>Returns the full name of the class (with namespace) and the calling method</returns>
private static string GetCaller(int level = 2)
{
var method = new StackTrace().GetFrame(level).GetMethod();
if (method == null || method.DeclaringType == null)
return string.Empty;
return string.Format("{0}:{1}", method.DeclaringType.FullName, method.Name);
}
Automatonymous.Activities.ExceptionBehavior<TInstance, TException> : Behavior
Constructors :
public ExceptionBehavior(Behavior<TInstance> next = , BehaviorExceptionContext<TInstance, TException> context = )Methods :
public Void Probe(ProbeContext context = )public Type GetType()
public String ToString()
public Boolean Equals(Object obj = )
public Int32 GetHashCode()
Other methods
Other methods
ExceptionBehavior
Namespace:
Automatonymous
We found 10 examples in language CSharp for this search.
You will see 24 fragments of code.
Other methods
Other methods
Project:LionFire.Behaviors
File:TimerPollingProvider.cs
Examples:1
#if NO_COROUTINES
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace LionFire.Behaviors
{
public class TimerPollingProvider : IPollingProvider
{
//ConcurrentDictionary<long, Timer> timersByDuration = new ConcurrentDictionary<long, Timer>(); // TOAOT -
ConcurrentDictionary<IPoller, Timer> pollers = new ConcurrentDictionary<IPoller, Timer>();
#region Configuration
#region ExceptionBehavior
public PollingExceptionBehavior ExceptionBehavior
{
get { return exceptionBehavior; }
set { exceptionBehavior = value; }
} private PollingExceptionBehavior exceptionBehavior = PollingExceptionBehavior.Disable | PollingExceptionBehavior.WrapAndRethrow;
#endregion
#endregion
#region Construction
public TimerPollingProvider()
{
#if AOT
throw new NotSupportedException("TODO: Dictionary IComparer in ctor");
#endif
}
#endregion
#region IPollingProvider Implementation
public void Register(IPoller poller)
{
var rp = poller.RecurranceParameters;
if (rp == null) { throw new ArgumentNullException("IPoller instance does not have RecurranceParameters set"); }
int milliseconds = (int)rp.Interval.TotalMilliseconds; // DOUBLECAST
Timer timer = new Timer(OnTimerElapsed, poller, milliseconds, milliseconds);
if (!pollers.TryAdd(poller, timer)) throw new DuplicateNotAllowedException();
//poller.RecurranceParameters.Interval
}
public void Unregister(IPoller poller)
{
Timer timer;
if (pollers.TryRemove(poller, out timer))
{
timer.Dispose();
}
}
#endregion
#region (Private) Event handling
private void OnTimerElapsed(object state)
{
IPoller poller = (IPoller)state;
bool result;
try
{
#if POLLER_COROUTINES
result = poller.MoveNext();
#else // Poller Method, slightly more efficient
result = poller.Poll();
#endif
}
catch(Exception ex)
{
if(((ExceptionBehavior & PollingExceptionBehavior.WrapAndRethrow) != PollingExceptionBehavior.None))
{
throw new Exception("Poller threw exception", ex);
}
if (((ExceptionBehavior & PollingExceptionBehavior.Disable) != PollingExceptionBehavior.None))
{
result = false;
}
else
{
result = true;
}
}
if (!result)
{
Unregister(poller);
}
}
#endregion
}
}
#endif
Project:Fruberry-CSharp
File:List.cs
Examples:5
int IList.Add(object item) {
if (!item.GetType().IsAssignableFrom(typeof(T))) {
switch (ExceptionBehavior) {
case ExceptionBehavior.Throw: throw new ArgumentOutOfRangeException(nameof(item), item, $"Item must be of type {typeof(T)}");
default: return -1;
}
}
Add((T)item);
return Count - 1;
}
public T Find(Predicate<T> match) {
if (match == null) {
switch (ExceptionBehavior) {
case ExceptionBehavior.Throw: throw new ArgumentNullException("Match must be nonnull");
default: return default;
}
}
for (var i = 0; i < Length; i++) {
if (match(_items[i])) return _items[i];
}
return default;
}
public void ForEach(Action<T> action) {
if (action == null) {
switch (ExceptionBehavior) {
case ExceptionBehavior.Throw: throw new ArgumentNullException("Match must be nonnull");
default: return;
}
}
for (var i = 0; i < Length; i++) {
action(_items[i]);
}
}
public bool TrueForAll(Predicate<T> match) {
if (match == null) {
switch (ExceptionBehavior) {
case ExceptionBehavior.Throw: throw new ArgumentNullException("Match must be nonnull");
default: return false;
}
}
for (var i = 0; i < Length; i++) {
if (!match(_items[i])) return false;
}
return true;
}
public T Peek() {
if (Length == 0) {
switch(ExceptionBehavior) {
case ExceptionBehavior.Throw: throw new InvalidOperationException("Peek must be called on a nonempty structure");
default: return default;
}
}
return this[Length - 1];
}
Project:andres
File:BaseBusinessRules.cs
Examples:5
/// <summary>
/// Count
/// </summary>
/// <param name="expression">expression</param>
/// <returns>Count entity</returns>
public int Count(Expression<Func<T, bool>> expression)
{
return ExceptionBehavior(() => DaoNegocio.Count(expression));
}
public int? Create(IEnumerable<T> objCreate)
{
return ExceptionBehavior(() => DaoNegocio.Create(objCreate));
}
/// <summary>
/// Edit
/// </summary>
/// <param name="objEdit">obj to edit</param>
/// <returns>Is Edit</returns>
public bool? Edit(ICollection<T> objEdit)
{
return ExceptionBehavior(() => DaoNegocio.Edit(objEdit));
}
/// <summary>
/// Search
/// </summary>
/// <param name="expression">expression</param>
/// <returns>Entity</returns>
public T Search(Expression<Func<T, bool>> expression)
{
return ExceptionBehavior(() => DaoNegocio.Search(expression));
}
/// <summary>
/// Search
/// </summary>
/// <param name="expression">expression</param>
/// <param name="includes">includes</param>
/// <returns>Entity</returns>
public T Search(Expression<Func<T, bool>> expression, params Expression<Func<T, object>>[] includes)
{
return ExceptionBehavior(() => DaoNegocio.Search(expression, includes));
}
Project:Archive
File:ExceptionBehavior.cs
Examples:1
public async Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate<TResponse> next)
{
try
{
return await next();
}
catch (Exception e)
{
throw;
}
}
Project:kwetter
File:ExceptionBehavior.cs
Examples:1
/// <inheritdoc cref="IPipelineBehavior{TRequest,TResponse}.Handle(TRequest, CancellationToken, RequestHandlerDelegate{TResponse})"/>
public async Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate<TResponse> next)
{
try
{
return await next();
}
catch (ValidationException validationException)
{
TResponse response = new();
response.Errors.AddRange(
validationException.Errors.Select(validationFailure => validationFailure.ErrorMessage));
return response;
}
catch (Exception ex)
{
string requestName = typeof(TRequest).Name;
_logger.LogError(ex, "Unhandled Exception during Request {Name} {@Request}", requestName, request);
throw;
}
}
Project:NCStudio.Utility
File:ExceptionBehavior.cs
Examples:1
public async Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate<TResponse> next)
{
try
{
return await next();
}
catch (ValidationException ve)
{
return new BadRequestObjectResult(ve.ToString()) as TResponse;
}
}
Project:dot42
File:ExceptionBehavior.cs
Examples:3
#region Equality
private bool Equals(ExceptionBehavior other)
{
return string.Equals(ExceptionName, other.ExceptionName) && StopOnThrow == other.StopOnThrow && StopUncaught == other.StopUncaught;
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
return obj is ExceptionBehavior && Equals((ExceptionBehavior) obj);
}
public override int GetHashCode()
{
unchecked
{
var hashCode = (ExceptionName != null ? ExceptionName.GetHashCode() : 0);
hashCode = (hashCode*397) ^ StopOnThrow.GetHashCode();
hashCode = (hashCode*397) ^ StopUncaught.GetHashCode();
return hashCode;
}
}
Project:CommonFoundation
File:ApiPermissionAttribute.cs
Examples:1
using System;
using Beyova.Diagnostic;
namespace Beyova.Api
{
/// <summary>
/// Class ApiPermissionAttribute.
/// </summary>
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = true, Inherited = true)]
public class ApiPermissionAttribute : Attribute
{
/// <summary>
/// Gets or sets the permission identifier.
/// </summary>
/// <value>The permission identifier.</value>
public string PermissionIdentifier { get; protected set; }
/// <summary>
/// Gets or sets the permission.
/// </summary>
/// <value>The permission.</value>
public ApiPermission Permission { get; protected set; }
/// <summary>
/// Gets or sets the exception behavior.
/// </summary>
/// <value>
/// The exception behavior.
/// </value>
public ExceptionCode ExceptionBehavior { get; protected set; }
/// <summary>
/// Initializes a new instance of the <see cref="ApiPermissionAttribute" /> class.
/// </summary>
/// <param name="permissionIdentifier">The permission identifier.</param>
/// <param name="permission">The permission.</param>
public ApiPermissionAttribute(string permissionIdentifier, ApiPermission permission = ApiPermission.Required)
{
PermissionIdentifier = permissionIdentifier;
Permission = permission;
}
/// <summary>
/// Initializes a new instance of the <see cref="ApiPermissionAttribute"/> class.
/// </summary>
/// <param name="permissionIdentifier">The permission identifier.</param>
/// <param name="exceptionBehavior">The exception behavior.</param>
/// <param name="permission">The permission.</param>
public ApiPermissionAttribute(string permissionIdentifier, ExceptionCode exceptionBehavior, ApiPermission permission = ApiPermission.Required)
: this(permissionIdentifier, permission)
{
ExceptionBehavior = exceptionBehavior;
}
}
}
Project:realmmud
File:ExceptionExtensions.cs
Examples:3
/// <summary>
/// Handles exceptions based upon the indicated behavior and throws a new exception of the given
/// type, assigning the original exception as the InnerException
/// </summary>
public static void Handle<T>(this Exception exception, ExceptionHandlingOptions exceptionBehavior, ILogWrapper log = null,
string msg = "", params object[] parameters) where T : Exception
{
var caller = GetCaller();
if (exceptionBehavior == ExceptionHandlingOptions.RecordOnly || exceptionBehavior == ExceptionHandlingOptions.RecordAndThrow)
{
ILogWrapper logger = log ?? new LogWrapper(LogManager.GetLogger(caller), LogLevel.Error);
if (string.IsNullOrEmpty(msg))
logger.Error(exception);
else
logger.Error(String.Format(msg, parameters), exception);
}
if (exceptionBehavior == ExceptionHandlingOptions.RecordAndThrow || exceptionBehavior == ExceptionHandlingOptions.ThrowOnly)
throw (T)Activator.CreateInstance(typeof(T), string.Format(Resources.MSG_EXCEPTION_LOCATION, caller), exception);
}
/// <summary>
/// Handles exceptions based upon the indicated behavior and rethrows the Exception
/// </summary>
/// <param name="exception"></param>
/// <param name="exceptionBehavior"></param>
/// <param name="log"></param>
/// <param name="msg"></param>
/// <param name="parameters"></param>
public static void Handle(this Exception exception, ExceptionHandlingOptions exceptionBehavior, ILogWrapper log = null,
string msg = "", params object[] parameters)
{
var caller = GetCaller();
if (exceptionBehavior == ExceptionHandlingOptions.RecordOnly || exceptionBehavior == ExceptionHandlingOptions.RecordAndThrow)
{
ILogWrapper logger = log ?? new LogWrapper(LogManager.GetLogger(caller), LogLevel.Error);
if (string.IsNullOrEmpty(msg))
logger.Error(exception);
else
logger.Error(String.Format(msg, parameters), exception);
}
if (exceptionBehavior == ExceptionHandlingOptions.RecordAndThrow ||
exceptionBehavior == ExceptionHandlingOptions.ThrowOnly)
throw exception;
}
/// <summary>
/// Gets the calling class and method for the current stack
/// </summary>
/// <returns>Returns the full name of the class (with namespace) and the calling method</returns>
private static string GetCaller(int level = 2)
{
var method = new StackTrace().GetFrame(level).GetMethod();
if (method == null || method.DeclaringType == null)
return string.Empty;
return string.Format("{0}:{1}", method.DeclaringType.FullName, method.Name);
}
Project:realmmud
File:ExceptionExtensions.cs
Examples:3
/// <summary>
/// Handles exceptions based upon the indicated behavior and throws a new exception of the given
/// type, assigning the original exception as the InnerException
/// </summary>
public static void Handle<T>(this Exception exception, ExceptionHandlingOptions exceptionBehavior, ILogWrapper log = null,
string msg = "", params object[] parameters) where T : Exception
{
var caller = GetCaller();
if (exceptionBehavior == ExceptionHandlingOptions.RecordOnly || exceptionBehavior == ExceptionHandlingOptions.RecordAndThrow)
{
ILogWrapper logger = log ?? new LogWrapper(LogManager.GetLogger(caller), LogLevel.Error);
if (string.IsNullOrEmpty(msg))
logger.Error(exception);
else
logger.Error(string.Format(msg, parameters), exception);
}
if (exceptionBehavior == ExceptionHandlingOptions.RecordAndThrow || exceptionBehavior == ExceptionHandlingOptions.ThrowOnly)
throw (T)Activator.CreateInstance(typeof(T), string.Format(Resources.MSG_EXCEPTION_LOCATION, caller), exception);
}
/// <summary>
/// Handles exceptions based upon the indicated behavior and rethrows the Exception
/// </summary>
/// <param name="exception"></param>
/// <param name="exceptionBehavior"></param>
/// <param name="log"></param>
/// <param name="msg"></param>
/// <param name="parameters"></param>
public static void Handle(this Exception exception, ExceptionHandlingOptions exceptionBehavior, ILogWrapper log = null,
string msg = "", params object[] parameters)
{
var caller = GetCaller();
if (exceptionBehavior == ExceptionHandlingOptions.RecordOnly || exceptionBehavior == ExceptionHandlingOptions.RecordAndThrow)
{
ILogWrapper logger = log ?? new LogWrapper(LogManager.GetLogger(caller), LogLevel.Error);
if (string.IsNullOrEmpty(msg))
logger.Error(exception);
else
logger.Error(string.Format(msg, parameters), exception);
}
if (exceptionBehavior == ExceptionHandlingOptions.RecordAndThrow ||
exceptionBehavior == ExceptionHandlingOptions.ThrowOnly)
throw exception;
}
/// <summary>
/// Gets the calling class and method for the current stack
/// </summary>
/// <returns>Returns the full name of the class (with namespace) and the calling method</returns>
private static string GetCaller(int level = 2)
{
var method = new StackTrace().GetFrame(level).GetMethod();
return method?.DeclaringType == null ? string.Empty : $"{method.DeclaringType.FullName}:{method.Name}";
}
Automatonymous.Activities.ExceptionBehavior<TInstance, TData, TException> : Behavior
Constructors :
public ExceptionBehavior(Behavior<TInstance, TData> next = , BehaviorExceptionContext<TInstance, TData, TException> context = )Methods :
public Void Probe(ProbeContext context = )public Type GetType()
public String ToString()
public Boolean Equals(Object obj = )
public Int32 GetHashCode()