Add progress to campaign entity
This commit is contained in:
@ -20,8 +20,10 @@ namespace Hcs.WebApp.BackgroundServices.CampaignManagers
|
||||
|
||||
private RegistryService? registryService;
|
||||
|
||||
protected RegistryService RegistryService => registryService ??= scope.ServiceProvider.GetRequiredService<RegistryService>();
|
||||
protected override int StepCount => Enum.GetValues(typeof(Step)).Length;
|
||||
|
||||
protected RegistryService RegistryService => registryService ??= scope.ServiceProvider.GetRequiredService<RegistryService>();
|
||||
|
||||
public override async Task ProcessAsync()
|
||||
{
|
||||
switch ((Step)campaign.Step)
|
||||
@ -53,8 +55,7 @@ namespace Hcs.WebApp.BackgroundServices.CampaignManagers
|
||||
{
|
||||
await HeadquartersService.SetCampaignStartedAsync(context, campaign.Id);
|
||||
|
||||
campaign.Step = (int)Step.ExecutionWait;
|
||||
await HeadquartersService.UpdateCampaignStepAsync(context, campaign);
|
||||
await ProgressStepAsync(context, (int)Step.ExecutionWait);
|
||||
|
||||
var registryCount = await RegistryService.GetRegistryCountAsync(context, true);
|
||||
operations = await HeadquartersService.InitiateOperationsAsync(context, registryCount, campaign.Id, Operation.OperationType.NsiCommon_ExportNsiItem_15_7_0_1);
|
||||
@ -85,8 +86,7 @@ namespace Hcs.WebApp.BackgroundServices.CampaignManagers
|
||||
{
|
||||
if (operationExecutionState.HasCampaignOperation(campaign.Id)) return;
|
||||
|
||||
campaign.Step = (int)Step.ResultWait;
|
||||
await HeadquartersService.UpdateCampaignStepAsync(campaign);
|
||||
await ProgressStepAsync((int)Step.ResultWait);
|
||||
|
||||
var operations = await HeadquartersService.GetOperationsAsync(campaign.Id);
|
||||
foreach (var operation in operations)
|
||||
@ -109,8 +109,7 @@ namespace Hcs.WebApp.BackgroundServices.CampaignManagers
|
||||
using var transaction = await context.Database.BeginTransactionAsync();
|
||||
try
|
||||
{
|
||||
campaign.Step = (int)Step.End;
|
||||
await HeadquartersService.UpdateCampaignStepAsync(context, campaign);
|
||||
await ProgressStepAsync(context, (int)Step.End);
|
||||
|
||||
await HeadquartersService.SetCampaignEndedAsync(context, campaign.Id);
|
||||
|
||||
|
||||
@ -20,6 +20,8 @@ namespace Hcs.WebApp.BackgroundServices.CampaignManagers
|
||||
|
||||
private RegistryService? registryService;
|
||||
|
||||
protected override int StepCount => Enum.GetValues(typeof(Step)).Length;
|
||||
|
||||
protected RegistryService RegistryService => registryService ??= scope.ServiceProvider.GetRequiredService<RegistryService>();
|
||||
|
||||
public override async Task ProcessAsync()
|
||||
@ -53,8 +55,7 @@ namespace Hcs.WebApp.BackgroundServices.CampaignManagers
|
||||
{
|
||||
await HeadquartersService.SetCampaignStartedAsync(context, campaign.Id);
|
||||
|
||||
campaign.Step = (int)Step.ExecutionWait;
|
||||
await HeadquartersService.UpdateCampaignStepAsync(context, campaign);
|
||||
await ProgressStepAsync(context, (int)Step.ExecutionWait);
|
||||
|
||||
var registryCount = await RegistryService.GetRegistryCountAsync(context, false);
|
||||
operations = await HeadquartersService.InitiateOperationsAsync(context, registryCount, campaign.Id, Operation.OperationType.Nsi_ExportNsiItem_15_7_0_1);
|
||||
@ -85,8 +86,7 @@ namespace Hcs.WebApp.BackgroundServices.CampaignManagers
|
||||
{
|
||||
if (operationExecutionState.HasCampaignOperation(campaign.Id)) return;
|
||||
|
||||
campaign.Step = (int)Step.ResultWait;
|
||||
await HeadquartersService.UpdateCampaignStepAsync(campaign);
|
||||
await ProgressStepAsync((int)Step.ResultWait);
|
||||
|
||||
var operations = await HeadquartersService.GetOperationsAsync(campaign.Id);
|
||||
foreach (var operation in operations)
|
||||
@ -109,8 +109,7 @@ namespace Hcs.WebApp.BackgroundServices.CampaignManagers
|
||||
using var transaction = await context.Database.BeginTransactionAsync();
|
||||
try
|
||||
{
|
||||
campaign.Step = (int)Step.End;
|
||||
await HeadquartersService.UpdateCampaignStepAsync(context, campaign);
|
||||
await ProgressStepAsync(context, (int)Step.End);
|
||||
|
||||
await HeadquartersService.SetCampaignEndedAsync(context, campaign.Id);
|
||||
|
||||
|
||||
@ -19,6 +19,8 @@ namespace Hcs.WebApp.BackgroundServices.CampaignManagers
|
||||
|
||||
protected HeadquartersService HeadquartersService => headquartersService ??= scope.ServiceProvider.GetRequiredService<HeadquartersService>();
|
||||
|
||||
protected abstract int StepCount { get; }
|
||||
|
||||
public Campaign Campaign => campaign;
|
||||
|
||||
public IManager.ManagerState State { get; protected set; } = IManager.ManagerState.Created;
|
||||
@ -31,5 +33,18 @@ namespace Hcs.WebApp.BackgroundServices.CampaignManagers
|
||||
|
||||
State = IManager.ManagerState.Ended;
|
||||
}
|
||||
|
||||
protected async Task ProgressStepAsync(int step)
|
||||
{
|
||||
using var context = HeadquartersService.GetNewContext();
|
||||
await ProgressStepAsync(context, step);
|
||||
}
|
||||
|
||||
protected async Task ProgressStepAsync(HcsDbContext context, int step)
|
||||
{
|
||||
campaign.Step = step;
|
||||
campaign.Progress = (step + 1) / StepCount;
|
||||
await HeadquartersService.UpdateCampaignStepAndProgressAsync(context, campaign);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user