41 lines
1.5 KiB
C#
41 lines
1.5 KiB
C#
using Hcs.WebApp.Data.Hcs;
|
|
using Hcs.WebApp.Services;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Hcs.WebApp.BackgroundServices.DataParsers
|
|
{
|
|
public class HousesDataParser_15_7_0_1(IServiceScope scope, Operation operation) : DataParserBase(scope, operation)
|
|
{
|
|
public override async Task ParseAsync()
|
|
{
|
|
var headquartersService = scope.ServiceProvider.GetRequiredService<HeadquartersService>();
|
|
var fileToParseService = scope.ServiceProvider.GetRequiredService<FileToParseService>();
|
|
|
|
using var context = headquartersService.GetNewContext();
|
|
var executionStrategy = context.Database.CreateExecutionStrategy();
|
|
await executionStrategy.ExecuteAsync(async () =>
|
|
{
|
|
using var transaction = await context.Database.BeginTransactionAsync();
|
|
try
|
|
{
|
|
var now = DateTime.UtcNow;
|
|
|
|
var fileToParse = await fileToParseService.GetFileToParseByOperationIdAsync(context, operation.Id);
|
|
fileToParse.ParsedAt = now;
|
|
await context.SaveChangesAsync();
|
|
|
|
await headquartersService.SetOperationEndedAsync(context, operation.Id, now);
|
|
|
|
await transaction.CommitAsync();
|
|
}
|
|
catch
|
|
{
|
|
await transaction.RollbackAsync();
|
|
|
|
throw;
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}
|