Treat common and private registries separately
This commit is contained in:
@ -0,0 +1,59 @@
|
||||
using Hcs.WebApp.Data.Hcs;
|
||||
using Hcs.WebApp.Services;
|
||||
|
||||
namespace Hcs.WebApp.BackgroundServices.CampaignManagers
|
||||
{
|
||||
public class ExportCommonRegistryElementsManager_15_7_0_1(IServiceScope scope, OperationExecutionState operationExecutionState, Campaign campaign) : ManagerBase(scope, operationExecutionState, campaign)
|
||||
{
|
||||
public override async Task StartAsync()
|
||||
{
|
||||
if (campaign.Step > 0) return;
|
||||
|
||||
var headquartersService = scope.ServiceProvider.GetRequiredService<HeadquartersService>();
|
||||
var registryService = scope.ServiceProvider.GetRequiredService<RegistryService>();
|
||||
using var context = headquartersService.GetNewContext();
|
||||
using var transaction = await context.Database.BeginTransactionAsync();
|
||||
IEnumerable<Operation> operations = null;
|
||||
try
|
||||
{
|
||||
await headquartersService.SetCampaignStartedAsync(context, campaign.Id);
|
||||
await headquartersService.SetCampaignStepAsync(context, campaign.Id, 1);
|
||||
var registryCount = await registryService.GetRegistryCountAsync(context, true);
|
||||
operations = await headquartersService.InitiateOperationsAsync(context, registryCount, campaign.Id, Operation.OperationType.NsiCommon_ExportNsiItem_15_7_0_1);
|
||||
await registryService.SetOperationsToRegistriesAsync(context, true, operations);
|
||||
await transaction.CommitAsync();
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction?.Rollback();
|
||||
|
||||
throw;
|
||||
}
|
||||
|
||||
if (operations != null)
|
||||
{
|
||||
foreach (var operation in operations)
|
||||
{
|
||||
operationExecutionState.EnqueueOperation(operation);
|
||||
}
|
||||
}
|
||||
|
||||
State = IManager.ManagerState.Started;
|
||||
}
|
||||
|
||||
public override async Task CheckStateAsync()
|
||||
{
|
||||
if (State == IManager.ManagerState.Started)
|
||||
{
|
||||
var headquartersService = scope.ServiceProvider.GetRequiredService<HeadquartersService>();
|
||||
var hasActiveOperations = await headquartersService.HasActiveOperationsAsync(campaign.Id);
|
||||
if (!hasActiveOperations)
|
||||
{
|
||||
State = IManager.ManagerState.Ended;
|
||||
|
||||
await headquartersService.SetCampaignEndedAsync(campaign.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user