MES-ETL/ConsoleApp2/Services/ProcessContext.cs

64 lines
1.9 KiB
C#
Raw Normal View History

2024-01-19 13:47:35 +08:00
using System.Collections.Concurrent;
namespace ConsoleApp2.Services;
2023-12-29 16:16:05 +08:00
2024-01-04 09:00:44 +08:00
/// <summary>
/// 处理上下文类,标识处理进度
/// </summary>
2023-12-29 16:16:05 +08:00
public class ProcessContext
{
private int _inputCount;
private int _transformCount;
private int _outputCount;
2024-01-19 13:47:35 +08:00
private int _finishedTaskCount;
private ConcurrentBag<Exception> _exceptionList = new ConcurrentBag<Exception>();
2023-12-29 16:16:05 +08:00
public bool IsInputCompleted { get; private set; }
public bool IsTransformCompleted { get; private set; }
public bool IsOutputCompleted { get; private set; }
public int InputCount
{
get => _inputCount;
private set => _inputCount = value;
}
public int TransformCount
{
get => _transformCount;
private set => _transformCount = value;
}
public int OutputCount
{
get => _outputCount;
private set => _outputCount = value;
}
2024-01-12 16:50:37 +08:00
public void AddException(Exception ex)
{
_exceptionList.Add(ex);
}
2024-01-19 13:47:35 +08:00
public void AddFinishTask() => Interlocked.Increment(ref _finishedTaskCount);
public int FinishTaskCount
{
get => _finishedTaskCount;
}
public ConcurrentBag<Exception> GetExceptions()
2024-01-12 16:50:37 +08:00
{
return _exceptionList;
}
2023-12-29 16:16:05 +08:00
public void CompleteInput() => IsInputCompleted = true;
public void CompleteTransform() => IsTransformCompleted = true;
public void CompleteOutput() => IsOutputCompleted = true;
public void AddInput() => Interlocked.Increment(ref _inputCount);
public void AddInput(int count) => Interlocked.Add(ref _inputCount, count);
public void AddTransform() => Interlocked.Increment(ref _transformCount);
public void AddTransform(int count) => Interlocked.Add(ref _transformCount, count);
public void AddOutput() => Interlocked.Increment(ref _outputCount);
public void AddOutput(int count) => Interlocked.Add(ref _outputCount, count);
}