Add events aggregator
This commit is contained in:
8
Hcs.WebApp/BackgroundServices/Delegates.cs
Normal file
8
Hcs.WebApp/BackgroundServices/Delegates.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace Hcs.WebApp.BackgroundServices
|
||||
{
|
||||
public delegate void OperationStarted(int operationId, int campaignId, DateTime startedAt);
|
||||
|
||||
public delegate void OperationExecuted(int operationId, int campaignId, string messageGuid);
|
||||
|
||||
public delegate void OperationEnded(int operationId, int campaignId, DateTime endedAt, string failureReason);
|
||||
}
|
||||
22
Hcs.WebApp/BackgroundServices/EventsAggregator.cs
Normal file
22
Hcs.WebApp/BackgroundServices/EventsAggregator.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using Hcs.WebApp.Data.Hcs;
|
||||
|
||||
namespace Hcs.WebApp.BackgroundServices
|
||||
{
|
||||
public class EventsAggregator
|
||||
{
|
||||
public event Action<Operation> OnOperationCreated;
|
||||
public event OperationStarted OnOperationStarted;
|
||||
public event OperationExecuted OnOperationExecuted;
|
||||
public event OperationEnded OnOperationEnded;
|
||||
|
||||
public EventsAggregator(OperationExecutionState operationExecutionState, ResultGetState resultGetState)
|
||||
{
|
||||
operationExecutionState.OnOperationCreated += (a) => OnOperationCreated?.Invoke(a);
|
||||
operationExecutionState.OnOperationStarted += (a, b, c) => OnOperationStarted?.Invoke(a, b, c);
|
||||
operationExecutionState.OnOperationExecuted += (a, b, c) => OnOperationExecuted?.Invoke(a, b, c);
|
||||
operationExecutionState.OnOperationEnded += (a, b, c, d) => OnOperationEnded?.Invoke(a, b, c, d);
|
||||
|
||||
resultGetState.OnOperationEnded += (a, b, c, d) => OnOperationEnded?.Invoke(a, b, c, d);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -5,10 +5,6 @@ namespace Hcs.WebApp.BackgroundServices
|
||||
{
|
||||
public class OperationExecutionState
|
||||
{
|
||||
public delegate void OperationStarted(int operationId, int campaignId, DateTime startedAt);
|
||||
public delegate void OperationExecuted(int operationId, int campaignId, string messageGuid);
|
||||
public delegate void OperationEnded(int operationId, int campaignId, DateTime endedAt, string failureReason);
|
||||
|
||||
private readonly ConcurrentQueue<Operation> operationsInQueue = new();
|
||||
private readonly HashSet<Operation> operationsInProcess = [];
|
||||
|
||||
|
||||
@ -5,8 +5,6 @@ namespace Hcs.WebApp.BackgroundServices
|
||||
{
|
||||
public class ResultGetState
|
||||
{
|
||||
public delegate void OperationEnded(int operationId, int campaignId, DateTime endedAt, string failureReason);
|
||||
|
||||
private readonly ConcurrentQueue<Operation> operationsInQueue = new();
|
||||
private readonly HashSet<Operation> operationsInProcess = [];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user