-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #142 from kolan72/dev
Update main before release.
- Loading branch information
Showing
32 changed files
with
2,236 additions
and
77 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace PoliNorError | ||
{ | ||
public class DefaultErrorProcessor<TParam> : IErrorProcessor | ||
{ | ||
private readonly DefaultErrorProcessorT _errorProcessor; | ||
public DefaultErrorProcessor(Action<Exception, ProcessingErrorInfo<TParam>> actionProcessor) | ||
{ | ||
_errorProcessor = DefaultErrorProcessorT.Create(actionProcessor); | ||
} | ||
|
||
public DefaultErrorProcessor(Action<Exception, ProcessingErrorInfo<TParam>, CancellationToken> actionProcessor) | ||
{ | ||
_errorProcessor = DefaultErrorProcessorT.Create(actionProcessor); | ||
} | ||
|
||
public DefaultErrorProcessor(Action<Exception, ProcessingErrorInfo<TParam>> actionProcessor, CancellationType cancellationType) | ||
{ | ||
_errorProcessor = DefaultErrorProcessorT.Create(actionProcessor, cancellationType); | ||
} | ||
|
||
public DefaultErrorProcessor(Func<Exception, ProcessingErrorInfo<TParam>, Task> funcProcessor) | ||
{ | ||
_errorProcessor = DefaultErrorProcessorT.Create(funcProcessor); | ||
} | ||
|
||
public DefaultErrorProcessor(Func<Exception, ProcessingErrorInfo<TParam>, CancellationToken, Task> funcProcessor) | ||
{ | ||
_errorProcessor = DefaultErrorProcessorT.Create(funcProcessor); | ||
} | ||
|
||
public DefaultErrorProcessor(Func<Exception, ProcessingErrorInfo<TParam>, Task> funcProcessor, CancellationType cancellationType) | ||
{ | ||
_errorProcessor = DefaultErrorProcessorT.Create(funcProcessor, cancellationType); | ||
} | ||
|
||
public Exception Process(Exception error, ProcessingErrorInfo catchBlockProcessErrorInfo = null, CancellationToken cancellationToken = default) | ||
{ | ||
return _errorProcessor.Process(error, catchBlockProcessErrorInfo, cancellationToken); | ||
} | ||
|
||
public async Task<Exception> ProcessAsync(Exception error, ProcessingErrorInfo catchBlockProcessErrorInfo = null, bool configAwait = false, CancellationToken cancellationToken = default) | ||
{ | ||
return await _errorProcessor.ProcessAsync(error, catchBlockProcessErrorInfo, configAwait, cancellationToken).ConfigureAwait(configAwait); | ||
} | ||
} | ||
|
||
internal class DefaultErrorProcessorT : ErrorProcessorBase<ProcessingErrorInfo> | ||
{ | ||
public static DefaultErrorProcessorT Create<TParam>(Action<Exception, ProcessingErrorInfo<TParam>> actionProcessor) | ||
{ | ||
var action = ConvertToNonGenericAction(actionProcessor); | ||
var res = new DefaultErrorProcessorT(); | ||
res.SetSyncRunner(action); | ||
return res; | ||
} | ||
|
||
public static DefaultErrorProcessorT Create<TParam>(Action<Exception, ProcessingErrorInfo<TParam>, CancellationToken> actionProcessor) | ||
{ | ||
void action(Exception ex, ProcessingErrorInfo pi, CancellationToken token) | ||
{ | ||
if (pi is ProcessingErrorInfo<TParam> gpi) | ||
actionProcessor(ex, gpi, token); | ||
} | ||
var res = new DefaultErrorProcessorT(); | ||
res.SetSyncRunner(action); | ||
return res; | ||
} | ||
|
||
public static DefaultErrorProcessorT Create<TParam>(Action<Exception, ProcessingErrorInfo<TParam>> actionProcessor, CancellationType cancellationType) | ||
{ | ||
var action = ConvertToNonGenericAction(actionProcessor); | ||
var res = new DefaultErrorProcessorT(); | ||
res.SetSyncRunner(action, cancellationType); | ||
return res; | ||
} | ||
|
||
public static DefaultErrorProcessorT Create<TParam>(Func<Exception, ProcessingErrorInfo<TParam>, Task> funcProcessor) | ||
{ | ||
var func = ConvertToNonGenericFunc(funcProcessor); | ||
var res = new DefaultErrorProcessorT(); | ||
res.SetAsyncRunner(func); | ||
return res; | ||
} | ||
|
||
public static DefaultErrorProcessorT Create<TParam>(Func<Exception, ProcessingErrorInfo<TParam>, CancellationToken, Task> funcProcessor) | ||
{ | ||
Task fn(Exception ex, ProcessingErrorInfo pi, CancellationToken token) | ||
{ | ||
if (pi is ProcessingErrorInfo<TParam> gpi) | ||
return funcProcessor(ex, gpi, token); | ||
else | ||
return Task.CompletedTask; | ||
} | ||
var res = new DefaultErrorProcessorT(); | ||
res.SetAsyncRunner(fn); | ||
return res; | ||
} | ||
|
||
public static DefaultErrorProcessorT Create<TParam>(Func<Exception, ProcessingErrorInfo<TParam>, Task> funcProcessor, CancellationType cancellationType) | ||
{ | ||
var func = ConvertToNonGenericFunc(funcProcessor); | ||
var res = new DefaultErrorProcessorT(); | ||
res.SetAsyncRunner(func, cancellationType); | ||
return res; | ||
} | ||
|
||
private static Action<Exception, ProcessingErrorInfo> ConvertToNonGenericAction<TParam>(Action<Exception, ProcessingErrorInfo<TParam>> actionProcessor) | ||
{ | ||
return (Exception ex, ProcessingErrorInfo pi) => | ||
{ | ||
if (pi is ProcessingErrorInfo<TParam> gpi) | ||
actionProcessor(ex, gpi); | ||
}; | ||
} | ||
|
||
private static Func<Exception, ProcessingErrorInfo, Task> ConvertToNonGenericFunc<TParam>(Func<Exception, ProcessingErrorInfo<TParam>, Task> funcProcessor) | ||
{ | ||
return (Exception ex, ProcessingErrorInfo pi) => | ||
{ | ||
if (pi is ProcessingErrorInfo<TParam> gpi) | ||
return funcProcessor(ex, gpi); | ||
else | ||
return Task.CompletedTask; | ||
}; | ||
} | ||
|
||
protected override Func<ProcessingErrorInfo, ProcessingErrorInfo> ParameterConverter => (_) => _; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace PoliNorError | ||
{ | ||
public class ProcessingErrorContext<TParam> : ProcessingErrorContext | ||
{ | ||
public ProcessingErrorContext(PolicyAlias policyKind, TParam param) : base(policyKind) | ||
{ | ||
Param = param; | ||
} | ||
public TParam Param { get; set; } | ||
|
||
internal override ProcessingErrorInfo ToProcessingErrorInfo() | ||
{ | ||
return new ProcessingErrorInfo<TParam>(this); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace PoliNorError | ||
{ | ||
public class ProcessingErrorInfo<TParam> : ProcessingErrorInfo | ||
{ | ||
internal ProcessingErrorInfo(ProcessingErrorContext<TParam> currentContext) : this(currentContext.PolicyKind, currentContext) { } | ||
|
||
public ProcessingErrorInfo(PolicyAlias policyKind, ProcessingErrorContext<TParam> currentContext = null) : base(policyKind, currentContext) | ||
{ | ||
if (currentContext != null) | ||
{ | ||
Param = currentContext.Param; | ||
} | ||
} | ||
public TParam Param { get; private set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.