progress
This commit is contained in:
parent
16e76d6b31
commit
484dbfc9d9
529 changed files with 113694 additions and 0 deletions
71
AspClassic.Scripting/ErrorCounter.cs
Normal file
71
AspClassic.Scripting/ErrorCounter.cs
Normal file
|
@ -0,0 +1,71 @@
|
|||
using System.Threading;
|
||||
using AspClassic.Scripting.Utils;
|
||||
|
||||
namespace AspClassic.Scripting;
|
||||
|
||||
public class ErrorCounter : ErrorSink
|
||||
{
|
||||
private readonly ErrorSink _sink;
|
||||
|
||||
private int _fatalErrorCount;
|
||||
|
||||
private int _errorCount;
|
||||
|
||||
private int _warningCount;
|
||||
|
||||
public int FatalErrorCount => _fatalErrorCount;
|
||||
|
||||
public int ErrorCount => _errorCount;
|
||||
|
||||
public int WarningCount => _warningCount;
|
||||
|
||||
public bool AnyError
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_errorCount <= 0)
|
||||
{
|
||||
return _fatalErrorCount > 0;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public ErrorCounter()
|
||||
: this(ErrorSink.Null)
|
||||
{
|
||||
}
|
||||
|
||||
public ErrorCounter(ErrorSink sink)
|
||||
{
|
||||
ContractUtils.RequiresNotNull(sink, "sink");
|
||||
_sink = sink;
|
||||
}
|
||||
|
||||
protected virtual void CountError(Severity severity)
|
||||
{
|
||||
switch (severity)
|
||||
{
|
||||
case Severity.FatalError:
|
||||
Interlocked.Increment(ref _fatalErrorCount);
|
||||
break;
|
||||
case Severity.Error:
|
||||
Interlocked.Increment(ref _errorCount);
|
||||
break;
|
||||
case Severity.Warning:
|
||||
Interlocked.Increment(ref _warningCount);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearCounters()
|
||||
{
|
||||
_warningCount = (_errorCount = (_fatalErrorCount = 0));
|
||||
}
|
||||
|
||||
public override void Add(SourceUnit source, string message, SourceSpan span, int errorCode, Severity severity)
|
||||
{
|
||||
CountError(severity);
|
||||
_sink.Add(source, message, span, errorCode, severity);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue