fix nullable warnings

This commit is contained in:
Фролов 2022-07-04 17:33:32 +05:00
parent 12ff470d5f
commit e634094738
8 changed files with 28 additions and 19 deletions

View File

@ -33,8 +33,11 @@ namespace AsbCloudDb
s => System.Text.Json.JsonSerializer.Deserialize<TProperty>(s, jsonSerializerOptions)!);
ValueComparer<TProperty> valueComparer = new (
(a,b) => a.GetHashCode() == b.GetHashCode(),
i => i.GetHashCode(),
(a,b) =>
(a!=null) && (b != null)
? a.GetHashCode() == b.GetHashCode()
: (a == null) && (b == null),
i => (i == null) ?-1 : i.GetHashCode(),
i => i);
builder.Metadata.SetValueComparer(valueComparer);

View File

@ -345,14 +345,15 @@ namespace AsbCloudDb.Model
FillData(modelBuilder);
}
public Task<int> RefreshMaterializedViewAsync<TEntity>(CancellationToken token = default)
public Task<int> RefreshMaterializedViewAsync<TEntity>(CancellationToken token)
where TEntity : class
{
var materializedViewName = Set<TEntity>().EntityType.GetViewName();
return RefreshMaterializedViewAsync(materializedViewName!, token);
var materializedViewName = Set<TEntity>().EntityType.GetViewName()
?? throw new System.Exception($"RefreshMaterializedViewAsync<{typeof(TEntity).Name}>(..) db table for this type does not found.");
return RefreshMaterializedViewAsync(materializedViewName, token);
}
public Task<int> RefreshMaterializedViewAsync(string materializedViewName, CancellationToken token = default)
public Task<int> RefreshMaterializedViewAsync(string materializedViewName, CancellationToken token)
{
var sql = $"REFRESH MATERIALIZED VIEW {materializedViewName};";
return Database.ExecuteSqlRawAsync(sql, token);

View File

@ -56,8 +56,8 @@ namespace AsbCloudDb.Model
DatabaseFacade Database { get; }
Task<int> RefreshMaterializedViewAsync(string? mwName = null, CancellationToken token = default);
Task<int> RefreshMaterializedViewAsync<TEntity>(CancellationToken token = default) where TEntity : class;
Task<int> RefreshMaterializedViewAsync(string mwName, CancellationToken token);
Task<int> RefreshMaterializedViewAsync<TEntity>(CancellationToken token) where TEntity : class;
int SaveChanges();
int SaveChanges(bool acceptAllChangesOnSuccess);
Task<int> SaveChangesAsync(CancellationToken cancellationToken);

View File

@ -9,6 +9,7 @@ using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Repository
{
#nullable enable
/// <summary>
/// CRUD ñåðâèñ ñ êåøåì â îïåðàòèâêå
/// </summary>

View File

@ -10,7 +10,7 @@ using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Repository
{
#nullable enable
/// <summary>
/// CRUD сервис для работы с БД
/// </summary>

View File

@ -126,7 +126,7 @@ namespace AsbCloudInfrastructure.Services.DailyReport
var dto = new DailyReportDto()
{
ReportDate = date,
WellName = well.Caption,
WellName = well!.Caption,
ClusterName = well.Cluster,
};
DailyReportDto result = dto;

View File

@ -12,6 +12,7 @@ using AsbCloudInfrastructure.Services.DetectOperations.Detectors;
namespace AsbCloudInfrastructure.Services.DetectOperations
{
#nullable enable
public class OperationDetectionBackgroundService : BackgroundService
{
private readonly string connectionString;
@ -116,12 +117,12 @@ namespace AsbCloudInfrastructure.Services.DetectOperations
{
DateTime = d.DateTime,
IdUser = d.IdUser,
WellDepth = (float)d.WellDepth,
Pressure = (float)d.Pressure,
HookWeight = (float)d.HookWeight,
BlockPosition = (float)d.BlockPosition,
BitDepth = (float)d.BitDepth,
RotorSpeed = (float)d.RotorSpeed,
WellDepth = d.WellDepth ?? float.NaN,
Pressure = d.Pressure ?? float.NaN,
HookWeight = d.HookWeight ?? float.NaN,
BlockPosition = d.BlockPosition ?? float.NaN,
BitDepth = d.BitDepth ?? float.NaN,
RotorSpeed = d.RotorSpeed ?? float.NaN,
})
.OrderBy(d => d.DateTime);
@ -150,9 +151,9 @@ namespace AsbCloudInfrastructure.Services.DetectOperations
{
for (int i = 0; i < detectors.Length; i++)
{
if (detectors[i].TryDetect(idTelemetry, data, positionBegin, positionEnd, lastDetectedOperation, out OperationDetectorResult result))
if (detectors[i].TryDetect(idTelemetry, data, positionBegin, positionEnd, lastDetectedOperation, out OperationDetectorResult? result))
{
detectedOperations.Add(result.Operation);
detectedOperations.Add(result!.Operation);
lastDetectedOperation = result.Operation;
isDetected = true;
positionBegin = result.TelemetryEnd;
@ -163,7 +164,7 @@ namespace AsbCloudInfrastructure.Services.DetectOperations
}
if (isDetected)
startDate = lastDetectedOperation.DateEnd;
startDate = lastDetectedOperation!.DateEnd;
else
startDate = data[positionEnd].DateTime;
}
@ -171,4 +172,5 @@ namespace AsbCloudInfrastructure.Services.DetectOperations
return detectedOperations;
}
}
#nullable disable
}

View File

@ -12,6 +12,7 @@ using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Services.WellOperationService
{
#nullable enable
public class WellOperationService : IWellOperationService
{
private readonly IAsbCloudDbContext db;
@ -219,4 +220,5 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
.ConfigureAwait(false);
}
}
#nullable disable
}