Treat common and private registries separately
This commit is contained in:
@ -3,7 +3,7 @@ using Hcs.WebApp.Services;
|
|||||||
|
|
||||||
namespace Hcs.WebApp.BackgroundServices.CampaignManagers
|
namespace Hcs.WebApp.BackgroundServices.CampaignManagers
|
||||||
{
|
{
|
||||||
public class ExportRequiredRegistryElementsManager_15_7_0_1(IServiceScope scope, OperationExecutionState operationExecutionState, Campaign campaign) : ManagerBase(scope, operationExecutionState, campaign)
|
public class ExportCommonRegistryElementsManager_15_7_0_1(IServiceScope scope, OperationExecutionState operationExecutionState, Campaign campaign) : ManagerBase(scope, operationExecutionState, campaign)
|
||||||
{
|
{
|
||||||
public override async Task StartAsync()
|
public override async Task StartAsync()
|
||||||
{
|
{
|
||||||
@ -18,9 +18,9 @@ namespace Hcs.WebApp.BackgroundServices.CampaignManagers
|
|||||||
{
|
{
|
||||||
await headquartersService.SetCampaignStartedAsync(context, campaign.Id);
|
await headquartersService.SetCampaignStartedAsync(context, campaign.Id);
|
||||||
await headquartersService.SetCampaignStepAsync(context, campaign.Id, 1);
|
await headquartersService.SetCampaignStepAsync(context, campaign.Id, 1);
|
||||||
var registryCount = await registryService.GetRegistryCountAsync(context);
|
var registryCount = await registryService.GetRegistryCountAsync(context, true);
|
||||||
operations = await headquartersService.InitiateOperationsAsync(context, registryCount, campaign.Id, Operation.OperationType.NsiCommon_ExportNsiItem_15_7_0_1);
|
operations = await headquartersService.InitiateOperationsAsync(context, registryCount, campaign.Id, Operation.OperationType.NsiCommon_ExportNsiItem_15_7_0_1);
|
||||||
await registryService.SetOperationsToRegistriesAsync(context, operations);
|
await registryService.SetOperationsToRegistriesAsync(context, true, operations);
|
||||||
await transaction.CommitAsync();
|
await transaction.CommitAsync();
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
@ -10,8 +10,8 @@ namespace Hcs.WebApp.BackgroundServices.CampaignManagers
|
|||||||
{
|
{
|
||||||
switch (campaign.Type)
|
switch (campaign.Type)
|
||||||
{
|
{
|
||||||
case Campaign.CampaignType.ExportRequiredRegistryElements_15_7_0_1:
|
case Campaign.CampaignType.ExportCommonRegistryElements_15_7_0_1:
|
||||||
return new ExportRequiredRegistryElementsManager_15_7_0_1(scope, state, campaign);
|
return new ExportCommonRegistryElementsManager_15_7_0_1(scope, state, campaign);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
|
|||||||
@ -83,7 +83,7 @@
|
|||||||
var state = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
var state = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
||||||
if (state.User.IsInRole(AppRole.ADMINISTRATOR_TYPE) || state.User.IsInRole(AppRole.OPERATOR_TYPE))
|
if (state.User.IsInRole(AppRole.ADMINISTRATOR_TYPE) || state.User.IsInRole(AppRole.OPERATOR_TYPE))
|
||||||
{
|
{
|
||||||
var operationInProgress = await HeadquartersService.HasActiveCampaignAsync(Campaign.CampaignType.ExportRequiredRegistryElements_15_7_0_1);
|
var operationInProgress = await HeadquartersService.HasActiveCampaignAsync(Campaign.CampaignType.ExportCommonRegistryElements_15_7_0_1);
|
||||||
if (operationInProgress)
|
if (operationInProgress)
|
||||||
{
|
{
|
||||||
finalState = CommonPageState.OperationWaiting;
|
finalState = CommonPageState.OperationWaiting;
|
||||||
@ -106,14 +106,14 @@
|
|||||||
|
|
||||||
ChangeState(CommonPageState.OperationWaiting);
|
ChangeState(CommonPageState.OperationWaiting);
|
||||||
|
|
||||||
if (await HeadquartersService.HasActiveCampaignAsync(Campaign.CampaignType.ExportRequiredRegistryElements_15_7_0_1))
|
if (await HeadquartersService.HasActiveCampaignAsync(Campaign.CampaignType.ExportCommonRegistryElements_15_7_0_1))
|
||||||
{
|
{
|
||||||
ChangeState(CommonPageState.Idle);
|
ChangeState(CommonPageState.Idle);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// TODO: Use user id
|
// TODO: Use user id
|
||||||
var campaign = await HeadquartersService.InitiateCampaignAsync(Campaign.CampaignType.ExportRequiredRegistryElements_15_7_0_1, "");
|
var campaign = await HeadquartersService.InitiateCampaignAsync(Campaign.CampaignType.ExportCommonRegistryElements_15_7_0_1, "");
|
||||||
CampaignManagementState.EnqueueCampaign(campaign);
|
CampaignManagementState.EnqueueCampaign(campaign);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -164,7 +164,7 @@
|
|||||||
|
|
||||||
void OnCampaignStarted(Campaign campaign)
|
void OnCampaignStarted(Campaign campaign)
|
||||||
{
|
{
|
||||||
if (campaign.Type == Campaign.CampaignType.ExportRequiredRegistryElements_15_7_0_1)
|
if (campaign.Type == Campaign.CampaignType.ExportCommonRegistryElements_15_7_0_1)
|
||||||
{
|
{
|
||||||
InvokeAsync(() => ChangeState(CommonPageState.OperationWaiting));
|
InvokeAsync(() => ChangeState(CommonPageState.OperationWaiting));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,8 @@ namespace Hcs.WebApp.Data.Hcs
|
|||||||
{
|
{
|
||||||
public enum CampaignType
|
public enum CampaignType
|
||||||
{
|
{
|
||||||
ExportRequiredRegistryElements_15_7_0_1
|
ExportCommonRegistryElements_15_7_0_1,
|
||||||
|
ExportPrivateRegistryElements_15_7_0_1
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|||||||
@ -6,7 +6,8 @@ namespace Hcs.WebApp.Data.Hcs
|
|||||||
{
|
{
|
||||||
public enum OperationType
|
public enum OperationType
|
||||||
{
|
{
|
||||||
NsiCommon_ExportNsiItem_15_7_0_1
|
NsiCommon_ExportNsiItem_15_7_0_1,
|
||||||
|
Nsi_ExportNsiItem_15_7_0_1
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|||||||
@ -5,9 +5,9 @@ namespace Hcs.WebApp.Services
|
|||||||
{
|
{
|
||||||
public class RegistryService(IDbContextFactory<HcsDbContext> factory) : HcsServiceBase(factory)
|
public class RegistryService(IDbContextFactory<HcsDbContext> factory) : HcsServiceBase(factory)
|
||||||
{
|
{
|
||||||
public async Task<int> GetRegistryCountAsync(HcsDbContext context)
|
public async Task<int> GetRegistryCountAsync(HcsDbContext context, bool isCommon)
|
||||||
{
|
{
|
||||||
return await context.Registries.CountAsync();
|
return await context.Registries.CountAsync(x => x.IsCommon == isCommon);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<Registry>> GetAllRegistriesAsync(bool isCommon)
|
public async Task<IEnumerable<Registry>> GetAllRegistriesAsync(bool isCommon)
|
||||||
@ -32,10 +32,16 @@ namespace Hcs.WebApp.Services
|
|||||||
select registry).ToListAsync();
|
select registry).ToListAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SetOperationsToRegistriesAsync(HcsDbContext context, IEnumerable<Operation> operations)
|
public async Task SetOperationsToRegistriesAsync(HcsDbContext context, bool isCommon, IEnumerable<Operation> operations)
|
||||||
{
|
{
|
||||||
var queue = new Queue<Operation>(operations);
|
var queue = new Queue<Operation>(operations);
|
||||||
await context.Registries.ForEachAsync(x => x.LastSyncOperationId = queue.Dequeue().Id);
|
await context.Registries.ForEachAsync(x =>
|
||||||
|
{
|
||||||
|
if (x.IsCommon == isCommon)
|
||||||
|
{
|
||||||
|
x.LastSyncOperationId = queue.Dequeue().Id;
|
||||||
|
}
|
||||||
|
});
|
||||||
await context.SaveChangesAsync();
|
await context.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user