/// <summary> /// Initialize a new instance with a specified <see cref="PostHandlingAction"/>. /// </summary> /// <param name="name">The configured name.</param> /// <param name="type">The full type name of any <see cref="System.Exception"/>.</param> /// <param name="postHandlingAction">One of the <see cref="PostHandlingAction"/> values.</param> public ExceptionTypeData(string name, string type, PostHandlingAction postHandlingAction) { this.name = name; this.type = type; this.postHandlingAction = postHandlingAction; this.exceptionHandlers = new ExceptionHandlerDataCollection(); }
/// <summary> /// Instantiates a new instance of the /// <see cref="ExceptionPolicyEntry"/> class. /// </summary> public ExceptionPolicyEntry(PostHandlingAction postHandlingAction, ICollection<IExceptionHandler> handlers) { if (handlers == null) throw new ArgumentNullException("handlers"); this.postHandlingAction = postHandlingAction; this.handlers = handlers; }
public ExceptionHandlingPolicy(Type exceptionType, PostHandlingAction handlingAction = PostHandlingAction.ThrowNewException) { ExceptionType = exceptionType; PostHandlingAction = handlingAction; _handlerData = new List<BaseHandlerData>(); }
/// <summary> /// Instantiates a new instance of the /// <see cref="ExceptionPolicyEntry"/> class. /// </summary> internal ExceptionPolicyEntry(string policyName, ExceptionTypeData typeData, ConfigurationContext context) { this.policyName = policyName; this.postHandlingAction = typeData.PostHandlingAction; this.typeDataName = typeData.Name; this.factory = new ExceptionHandlerFactory(context); }
GetExceptionPolicyEntry <TException>( PostHandlingAction action = PostHandlingAction.None) where TException : Exception { return(Entry.For <TException>() .Then(action) .WithExceptionHandler(GetExceptionHandlerData()) .GetExceptionPolicyEntry()); }
/// <summary> /// Instantiates a new <see cref="ExceptionManager"/> /// </summary> /// <param name="postHandlingAction"></param> /// <param name="handlers"></param> public ExceptionManager(PostHandlingAction postHandlingAction, IEnumerable <IExceptionHandler> handlers) { if (handlers == null) { throw new ArgumentNullException("handlers"); } this.handlers = handlers; this.postHandlingAction = postHandlingAction; }
/// <summary> /// Initializes a new instance of the /// <see cref="ExceptionPolicyEntry"/> class. /// </summary> /// <param name="exceptionType">Type of exception this policy refers to.</param> /// <param name="postHandlingAction">What to do after the exception is handled.</param> /// <param name="handlers">Handlers to execute on the exception.</param> public ExceptionPolicyEntry(Type exceptionType, PostHandlingAction postHandlingAction, IEnumerable<IExceptionHandler> handlers) { if (exceptionType == null) throw new ArgumentNullException("exceptionType"); if (handlers == null) throw new ArgumentNullException("handlers"); ExceptionType = exceptionType; this.postHandlingAction = postHandlingAction; this.handlers = handlers.ToArray(); }
public ExceptionPolicyEntry(PostHandlingAction postHandlingAction, ICollection <IExceptionHandler> handlers) { if (handlers == null) { throw new ArgumentNullException("handlers"); } this.postHandlingAction = postHandlingAction; this.handlers = handlers; }
private static ExceptionPolicyEntry CreateSubjectUnderTest <TException>( PostHandlingAction action = PostHandlingAction.None, params IExceptionHandler[] handlers) where TException : Exception { return(new ExceptionPolicyEntry( typeof(TException), action, handlers)); }
public ExceptionTypeNode(ExceptionTypeData exceptionTypeData) : base(nodeNameFormatter.CreateName(exceptionTypeData)) { if (exceptionTypeData == null) { throw new ArgumentNullException("exceptionTypeData"); } this.typeName = exceptionTypeData.TypeName; this.postHandlingAction = exceptionTypeData.PostHandlingAction; }
/// <summary> /// Initialize a new instance of the <see cref="ExceptionTypeNode"/> class with a <see cref="ExceptionTypeData"/> instance. /// </summary> /// <param name="exceptionTypeData">A <see cref="ExceptionTypeData"/> instance.</param> public ExceptionTypeNode(ExceptionTypeData exceptionTypeData) : base((exceptionTypeData == null) ? string.Empty : exceptionTypeData.Type.Name) { if (exceptionTypeData == null) { throw new ArgumentNullException("exceptionTypeData"); } this.type = exceptionTypeData.Type; this.postHandlingAction = exceptionTypeData.PostHandlingAction; }
/// <summary> /// Constructor /// </summary> /// <param name="exceptionType">Type of exception this policy refers to</param> /// <param name="action">What to do after the exception is handled</param> /// <param name="handlers">Handlers to execute on the exception</param> public ExceptionPolicyEntry( Type exceptionType, PostHandlingAction action, IEnumerable<IExceptionHandler> handlers) { exceptionType.NotNull(nameof(exceptionType)); handlers.NotNullOrEmpty(nameof(handlers)); ExceptionType = exceptionType; Action = action; _handlers = handlers.ToArray(); }
/// <summary> /// Constructor /// </summary> /// <param name="exceptionType">Type of exception this policy refers to</param> /// <param name="action">What to do after the exception is handled</param> /// <param name="handlers">Handlers to execute on the exception</param> public ExceptionPolicyEntry( Type exceptionType, PostHandlingAction action, IEnumerable <IExceptionHandler> handlers) { exceptionType.NotNull(nameof(exceptionType)); handlers.NotNullOrEmpty(nameof(handlers)); ExceptionType = exceptionType; Action = action; _handlers = handlers.ToArray(); }
public void AddHandlers(Type exceptionType, PostHandlingAction postHandlingAction, Action <IExceptionHandlerBuilder> configure) { Guard.ArgumentNotNull(exceptionType, nameof(exceptionType)); Guard.ArgumentNotNull(configure, nameof(configure)); if (_policyEntries.Any(it => it.ExceptionType == exceptionType)) { throw new ArgumentException(Resources.ExceptionDuplicateExceptionType.Fill(exceptionType.FullName), nameof(exceptionType)); } ExceptionHandlerBuilder builder = new ExceptionHandlerBuilder(this.ServiceProvider); configure(builder); _policyEntries.Add(new ExceptionPolicyEntry(exceptionType, postHandlingAction, builder.Build())); }
public void ExceptionTypeDataTest() { Type exceptionType = typeof(AppDomainUnloadedException); PostHandlingAction action = PostHandlingAction.None; ExceptionTypeData data = new ExceptionTypeData(); data.Type = exceptionType; data.PostHandlingAction = action; ExceptionTypeNode node = new ExceptionTypeNode(data); Assert.AreEqual(exceptionType.Name, node.Name); Assert.AreEqual(action, node.PostHandlingAction); }
public void PropertiesTest() { string typeName = "testType"; PostHandlingAction postHandlingAction = PostHandlingAction.ThrowNewException; ExceptionTypeNode node = new ExceptionTypeNode(); node.TypeName = typeName; node.PostHandlingAction = postHandlingAction; Assert.AreEqual(typeName, node.TypeName); Assert.AreEqual(postHandlingAction, node.PostHandlingAction); }
ExceptionPolicyEntry CreatePolicyEntry(IExceptionHandler exceptionHandler, PostHandlingAction postHandlingAction) { List <IExceptionHandler> handlerList = new List <IExceptionHandler>(); handlerList.Add(exceptionHandler); ExceptionPolicyEntry policyEntry = new ExceptionPolicyEntry(postHandlingAction, handlerList); instrumentationProvider = new ExceptionHandlingInstrumentationProvider(); instrumentationProvider.exceptionHandlingErrorOccurred += new EventHandler <ExceptionHandlingErrorEventArgs>(ErrorCallback); policyEntry.SetInstrumentationProvider(instrumentationProvider); return(policyEntry); }
private ExceptionPolicyEntry CreatePolicyEntry(IExceptionHandler exceptionHandler, PostHandlingAction postHandlingAction) { List<IExceptionHandler> handlerList = new List<IExceptionHandler>(); handlerList.Add(exceptionHandler); ExceptionPolicyEntry policyEntry = new ExceptionPolicyEntry(postHandlingAction, handlerList); instrumentationProvider = new ExceptionHandlingInstrumentationProvider(); instrumentationProvider.exceptionHandlingErrorOccurred += new EventHandler<ExceptionHandlingErrorEventArgs>(ErrorCallback); policyEntry.SetInstrumentationProvider(instrumentationProvider); return policyEntry; }
/// <summary> /// Initializes a new instance of the <see cref="ExceptionPolicyEntry"/> class. /// </summary> /// <param name="exceptionType">Type of exception this policy refers to.</param> /// <param name="postHandlingAction">What to do after the exception is handled.</param> /// <param name="handlers">Handlers to execute on the exception.</param> /// <param name="instrumentationProvider">Instrumentation provider</param> public ExceptionPolicyEntry( Type exceptionType, PostHandlingAction postHandlingAction, IEnumerable<IExceptionHandler> handlers, IExceptionHandlingInstrumentationProvider instrumentationProvider) { if (exceptionType == null) throw new ArgumentNullException("exceptionType"); if (handlers == null) throw new ArgumentNullException("handlers"); if(instrumentationProvider == null) throw new ArgumentNullException("instrumentationProvider"); ExceptionType = exceptionType; this.postHandlingAction = postHandlingAction; this.handlers = handlers; this.instrumentationProvider = instrumentationProvider; }
/// <summary> /// Create an exception handler based on specified exception to handle. /// </summary> /// <param name="exception">The exception to handle.</param> /// <param name="postHandlingAction">A <see cref="PostHandlingAction"/> determining what action should occur after an exception is handled by the configured exception handling chain. </param> /// <returns>A <see cref="Func{TExceptionContext, Task}"/> representing the exception handler.</returns> public Func <ExceptionContext, Task> CreateHandler(Exception exception, out PostHandlingAction postHandlingAction) { Guard.ArgumentNotNull(exception, nameof(exception)); ExceptionPolicyEntry policyEntry = this.GetPolicyEntry(exception.GetType()); postHandlingAction = policyEntry.PostHandlingAction; return(async context => { await this.PreHandler(context); await policyEntry.Handler(context); await this.PostHandler(context); }); }
ExceptionPolicyEntry CreatePolicyEntry(IExceptionHandler exceptionHandler, PostHandlingAction postHandlingAction) { List<IExceptionHandler> handlerList = new List<IExceptionHandler>(); handlerList.Add(exceptionHandler); ExceptionPolicyEntry policyEntry = new ExceptionPolicyEntry( typeof(Exception), postHandlingAction, handlerList, new TestInstrumentationProvider(this)); return policyEntry; }
ExceptionPolicyEntry CreatePolicyEntry(IExceptionHandler exceptionHandler, PostHandlingAction postHandlingAction) { List <IExceptionHandler> handlerList = new List <IExceptionHandler>(); handlerList.Add(exceptionHandler); ExceptionPolicyEntry policyEntry = new ExceptionPolicyEntry( typeof(Exception), postHandlingAction, handlerList, new TestInstrumentationProvider(this)); return(policyEntry); }
private IEnumerable <PolicyEntryConfiguration> BuildPolicyEntries(JObject policy) { List <PolicyEntryConfiguration> list = new List <PolicyEntryConfiguration>(); foreach (var it in policy) { if (it.Key != "pre" && it.Key != "post") { string exceptionTypeName = _alias.TryGetValue(it.Key, out string realTypename) ? realTypename : it.Key; JObject policyEntry = (JObject)it.Value; PostHandlingAction postHandlingAction = (PostHandlingAction)(Enum.Parse(typeof(PostHandlingAction), policyEntry["postHandlingAction"].ToString())); PolicyEntryConfiguration policyEntryElement = new PolicyEntryConfiguration(Type.GetType(exceptionTypeName, true), postHandlingAction); policyEntryElement.Handlers.AddRange(this.BuildExceptionHandlers((JArray)policyEntry["handlers"])); list.Add(policyEntryElement); } } return(list); }
/// <summary> /// Initializes a new instance of the <see cref="ExceptionPolicyEntry"/> class. /// </summary> /// <param name="exceptionType">Type of exception this policy refers to.</param> /// <param name="postHandlingAction">What to do after the exception is handled.</param> /// <param name="handlers">Handlers to execute on the exception.</param> /// <param name="instrumentationProvider">Instrumentation provider</param> public ExceptionPolicyEntry( Type exceptionType, PostHandlingAction postHandlingAction, IEnumerable <IExceptionHandler> handlers, IExceptionHandlingInstrumentationProvider instrumentationProvider) { if (exceptionType == null) { throw new ArgumentNullException("exceptionType"); } if (handlers == null) { throw new ArgumentNullException("handlers"); } if (instrumentationProvider == null) { throw new ArgumentNullException("instrumentationProvider"); } ExceptionType = exceptionType; this.postHandlingAction = postHandlingAction; this.handlers = handlers; this.instrumentationProvider = instrumentationProvider; }
/// <summary> /// Initializes a new instance of the /// <see cref="ExceptionPolicyEntry"/> class. /// </summary> /// <param name="exceptionType">Type of exception this policy refers to.</param> /// <param name="postHandlingAction">What to do after the exception is handled.</param> /// <param name="handlers">Handlers to execute on the exception.</param> public ExceptionPolicyEntry(Type exceptionType, PostHandlingAction postHandlingAction, IEnumerable <IExceptionHandler> handlers) : this(exceptionType, postHandlingAction, handlers, new NullExceptionHandlingInstrumentationProvider()) { }
GetExceptionPolicyEntry(PostHandlingAction action) { return(GetExceptionPolicyEntry <Exception>(action)); }
/// <summary> /// Initializes a new instance of the <see cref="ExceptionTypeData"/> class with a name, the <see cref="Exception"/> type and a <see cref="PostHandlingAction"/>. /// </summary> /// <param name="name">The name of the configured exception.</param> /// <param name="type">The <see cref="Exception"/> type.</param> /// <param name="postHandlingAction">One of the <see cref="PostHandlingAction"/> values.</param> public ExceptionTypeData(string name, Type type, PostHandlingAction postHandlingAction) : this(name, typeConverter.ConvertToString(type), postHandlingAction) { }
/// <summary> /// Initializes a new instance of the /// <see cref="ExceptionPolicyEntry"/> class. /// </summary> /// <param name="exceptionType">Type of exception this policy refers to.</param> /// <param name="postHandlingAction">What to do after the exception is handled.</param> /// <param name="handlers">Handlers to execute on the exception.</param> public ExceptionPolicyEntry(Type exceptionType, PostHandlingAction postHandlingAction, IEnumerable<IExceptionHandler> handlers) : this(exceptionType, postHandlingAction, handlers, new NullExceptionHandlingInstrumentationProvider()) { }
/// <summary> /// Initializes a new instance of the <see cref="ExceptionTypeData"/> class with a name, the fully qualified type name of the <see cref="Exception"/> and a <see cref="PostHandlingAction"/>. /// </summary> /// <param name="name">The name of the configured exception.</param> /// <param name="typeName">The fully qualified type name of the <see cref="Exception"/> type.</param> /// <param name="postHandlingAction">One of the <see cref="PostHandlingAction"/> values that specifies the action that should occur after the exception is handled.</param> public ExceptionTypeData(string name, string typeName, PostHandlingAction postHandlingAction) : base(name) { TypeName = typeName; PostHandlingAction = postHandlingAction; }
/// <summary> /// Sets the action to be performed once the exception has been handled /// </summary> /// <param name="then">The action</param> /// <returns>This entry</returns> public Entry Then(PostHandlingAction then) { Action = then; return(this); }
/// <summary> /// Create a new <see cref="ExceptionPolicyEntry"/>. /// </summary> /// <param name="exceptionType">The type of exception to handle.</param> /// <param name="postHandlingAction">Determining what action should occur after an exception is handled by the configured exception handling chain.</param> /// <param name="exceptionHandler">A <see cref="Func{ExceptionContext, Task}"/> representing the exception handler chain.</param> /// <exception cref="ArgumentNullException">The <paramref name="exceptionType"/> is null.</exception> /// <exception cref="ArgumentNullException">The <paramref name="postHandlingAction"/> is null.</exception> /// <exception cref="ArgumentNullException">The <paramref name="exceptionHandler"/> is null.</exception> public ExceptionPolicyEntry(Type exceptionType, PostHandlingAction postHandlingAction, Func <ExceptionContext, Task> exceptionHandler) { this.ExceptionType = Guard.ArgumentAssignableTo <Exception>(exceptionType, nameof(exceptionType)); this.ExceptionHandler = Guard.ArgumentNotNull(exceptionHandler, nameof(exceptionHandler)); this.PostHandlingAction = postHandlingAction; }
public ExceptionPolicy(Type exceptionType, PostHandlingAction handlingAction = PostHandlingAction.ThrowNewException) { _exceptionHandlingPolicy = new ExceptionHandlingPolicy(exceptionType, handlingAction); }
/// <summary> /// Initializes a new instance of the <see cref="ExceptionTypeData"/> class with a name, the <see cref="Exception"/> type and a <see cref="PostHandlingAction"/>. /// </summary> /// <param name="name">The name of the configured exception.</param> /// <param name="type">The <see cref="Exception"/> type.</param> /// <param name="postHandlingAction">One of the <see cref="PostHandlingAction"/> values.</param> public ExceptionTypeData(string name, Type type, PostHandlingAction postHandlingAction) : base(name) { this.Type = type; this.PostHandlingAction = postHandlingAction; }
public PolicyEntryConfiguration(Type exceptionType, PostHandlingAction postHandlingAction) { this.ExceptionType = exceptionType; this.Handlers = new List <HandlerConfiguration>(); this.PostHandlingAction = postHandlingAction; }
/// <summary> /// Register exception handler chain for specified exception type. /// </summary> /// <param name="builder">The <see cref="IExceptionPolicyBuilder"/> to which the type specific hanlder chain is registered.</param> /// <typeparam name="TException">The type of exception to handle.</typeparam> /// <param name="postHandlingAction">Determining what action should occur after an exception is handled by the configured exception handling chain.</param> /// <param name="configure">An <see cref="Action{IExceptionHandlerBuilder}"/> to build the exception handler chain.</param> /// <returns>The current <see cref="IExceptionPolicyBuilder"/>.</returns> public static IExceptionPolicyBuilder For <TException>(this IExceptionPolicyBuilder builder, PostHandlingAction postHandlingAction, Action <IExceptionHandlerBuilder> configure) where TException : Exception { Guard.ArgumentNotNull(builder, nameof(builder)); return(builder.For(typeof(TException), postHandlingAction, configure)); }
private static ExceptionPolicyEntry CreateSubjectUnderTest( PostHandlingAction action = PostHandlingAction.None, params IExceptionHandler[] handlers) { return(CreateSubjectUnderTest <Exception>(action, handlers)); }