diff --git a/Hcs.WebApp/BackgroundServices/OperationExecutionService.cs b/Hcs.WebApp/BackgroundServices/OperationExecutionService.cs index aef4a44..3e603ee 100644 --- a/Hcs.WebApp/BackgroundServices/OperationExecutionService.cs +++ b/Hcs.WebApp/BackgroundServices/OperationExecutionService.cs @@ -42,16 +42,23 @@ namespace Hcs.WebApp.BackgroundServices { var executor = executorFactory.CreateExecutor(scope, client, operation); await headquartersService.SetOperationStartedAsync(operation.Id); + + state.InvokeOnOperationStarted(operation); + messageGuid = await executor.ExecuteAsync(stoppingToken); } catch (Exception e) { await headquartersService.SetOperationEndedWithFailAsync(operation.Id, e.CombineMessages()); + + state.InvokeOnOperationEnded(operation); } if (!string.IsNullOrEmpty(messageGuid)) { await headquartersService.SetOperationMessageGuidAsync(operation.Id, messageGuid); + + state.InvokeOnOperationExecuted(operation); } state.UnsetProcessingOperation(operation); diff --git a/Hcs.WebApp/BackgroundServices/OperationExecutionState.cs b/Hcs.WebApp/BackgroundServices/OperationExecutionState.cs index d5d25d4..d57c912 100644 --- a/Hcs.WebApp/BackgroundServices/OperationExecutionState.cs +++ b/Hcs.WebApp/BackgroundServices/OperationExecutionState.cs @@ -10,6 +10,10 @@ namespace Hcs.WebApp.BackgroundServices public bool Ready { get; set; } + public event Action OnOperationStarted; + public event Action OnOperationExecuted; + public event Action OnOperationEnded; + public void EnqueueOperation(Operation operation) { operationsInQueue.Enqueue(operation); @@ -34,5 +38,32 @@ namespace Hcs.WebApp.BackgroundServices { return operationsInQueue.Any(x => x.CampaignId == campaignId) || operationsInProcess.Any(x => x.CampaignId == campaignId); } + + public void InvokeOnOperationStarted(Operation operation) + { + try + { + OnOperationStarted?.Invoke(operation); + } + catch { } + } + + public void InvokeOnOperationExecuted(Operation operation) + { + try + { + OnOperationExecuted?.Invoke(operation); + } + catch { } + } + + public void InvokeOnOperationEnded(Operation operation) + { + try + { + OnOperationEnded?.Invoke(operation); + } + catch { } + } } } diff --git a/Hcs.WebApp/BackgroundServices/ResultWaitService.cs b/Hcs.WebApp/BackgroundServices/ResultWaitService.cs index 2bd1cc4..156f796 100644 --- a/Hcs.WebApp/BackgroundServices/ResultWaitService.cs +++ b/Hcs.WebApp/BackgroundServices/ResultWaitService.cs @@ -84,6 +84,8 @@ namespace Hcs.WebApp.BackgroundServices await headquartersService.SetOperationEndedWithFailAsync(entry.operation.Id, e.CombineMessages()); entry.state.done = true; + + state.InvokeOnOperationEnded(entry.operation); } entry.state.attempt++; @@ -93,6 +95,7 @@ namespace Hcs.WebApp.BackgroundServices if (entry.state.done) { state.UnsetProcessingOperation(entry.operation); + state.InvokeOnOperationEnded(entry.operation); } } diff --git a/Hcs.WebApp/BackgroundServices/ResultWaitState.cs b/Hcs.WebApp/BackgroundServices/ResultWaitState.cs index 3ed9594..0fd59f7 100644 --- a/Hcs.WebApp/BackgroundServices/ResultWaitState.cs +++ b/Hcs.WebApp/BackgroundServices/ResultWaitState.cs @@ -10,6 +10,8 @@ namespace Hcs.WebApp.BackgroundServices public bool Ready { get; set; } + public event Action OnOperationEnded; + public void EnqueueOperation(Operation operation) { operationsInQueue.Enqueue(operation); @@ -34,5 +36,14 @@ namespace Hcs.WebApp.BackgroundServices { return operationsInQueue.Any(x => x.CampaignId == campaignId) || operationsInProcess.Any(x => x.CampaignId == campaignId); } + + public void InvokeOnOperationEnded(Operation operation) + { + try + { + OnOperationEnded?.Invoke(operation); + } + catch { } + } } } diff --git a/Hcs.WebApp/Components/Pages/Campaigns.razor b/Hcs.WebApp/Components/Pages/Campaigns.razor index dacdf69..7e90432 100644 --- a/Hcs.WebApp/Components/Pages/Campaigns.razor +++ b/Hcs.WebApp/Components/Pages/Campaigns.razor @@ -11,6 +11,8 @@ @inject AuthenticationStateProvider AuthenticationStateProvider @inject HeadquartersService HeadquartersService @inject CampaignManagementState CampaignManagementState +@inject OperationExecutionState OperationExecutionState +@inject ResultWaitState ResultWaitState Кампании @@ -24,7 +26,7 @@ - +