nullable enable (часть 4)

This commit is contained in:
Olga Nemt 2023-04-14 10:11:15 +05:00
parent cb9e8dd672
commit b61808e062
2 changed files with 9 additions and 2 deletions

View File

@ -8,6 +8,7 @@ using System.Linq;
namespace AsbCloudInfrastructure namespace AsbCloudInfrastructure
{ {
#nullable enable
public class ReportDataSourcePgCloud : IReportDataSource public class ReportDataSourcePgCloud : IReportDataSource
{ {
private readonly IAsbCloudDbContext context; private readonly IAsbCloudDbContext context;
@ -37,6 +38,9 @@ namespace AsbCloudInfrastructure
.Include(w => w.Telemetry) .Include(w => w.Telemetry)
.FirstOrDefault(w => w.Id == idWell); .FirstOrDefault(w => w.Id == idWell);
if(well is null)
throw new ArgumentInvalidException("idWell doesn`t exist", nameof(idWell));
idTelemetry = well?.IdTelemetry; idTelemetry = well?.IdTelemetry;
if (idTelemetry is null) if (idTelemetry is null)
throw new ArgumentInvalidException($"Well {idWell} doesn't contain telemetry", nameof(idWell)); throw new ArgumentInvalidException($"Well {idWell} doesn't contain telemetry", nameof(idWell));
@ -49,7 +53,7 @@ namespace AsbCloudInfrastructure
.Where(u => u.IdTelemetry == idTelemetry) .Where(u => u.IdTelemetry == idTelemetry)
.ToDictionary(u => u.IdUser, u => u); .ToDictionary(u => u.IdUser, u => u);
timezoneOffset = well?.Telemetry?.Info?.TimeZoneOffsetTotalHours ?? well.Timezone?.Hours ?? 5.0; timezoneOffset = well?.Telemetry?.Info?.TimeZoneOffsetTotalHours ?? well!.Timezone?.Hours ?? 5.0;
info = new WellInfoReport info = new WellInfoReport
{ {
@ -155,4 +159,5 @@ namespace AsbCloudInfrastructure
public WellInfoReport GetWellInfo() public WellInfoReport GetWellInfo()
=> info; => info;
} }
#nullable disable
} }

View File

@ -13,6 +13,7 @@ using AsbCloudInfrastructure.Background;
namespace AsbCloudInfrastructure namespace AsbCloudInfrastructure
{ {
#nullable enable
public class Startup public class Startup
{ {
public static void BeforeRunHandler(IHost host) public static void BeforeRunHandler(IHost host)
@ -20,7 +21,7 @@ namespace AsbCloudInfrastructure
using var scope = host.Services.CreateScope(); using var scope = host.Services.CreateScope();
var provider = scope.ServiceProvider; var provider = scope.ServiceProvider;
var context = provider.GetService<IAsbCloudDbContext>(); var context = provider.GetRequiredService<IAsbCloudDbContext>();
context.Database.SetCommandTimeout(TimeSpan.FromSeconds(2 * 60)); context.Database.SetCommandTimeout(TimeSpan.FromSeconds(2 * 60));
context.Database.Migrate(); context.Database.Migrate();
@ -70,4 +71,5 @@ namespace AsbCloudInfrastructure
return bytes.ToString("### ### ###"); return bytes.ToString("### ### ###");
} }
} }
#nullable disable
} }