From b8e5a8bf4cc6af307fa9aa498f13b150eab32f07 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Thu, 13 Apr 2023 11:15:45 +0500 Subject: [PATCH 1/8] #nullable enable --- .../Repository/QueryContainer.cs | 2 ++ .../Repository/SetpointsRequestRepository.cs | 2 ++ .../Repository/WitsRecordRepository.cs | 18 ++++++++++-------- .../Services/DailyReport/BlockAbstract.cs | 2 ++ .../DailyReport/DailyReportBlocks/BhaBlock.cs | 4 +++- .../DailyReportBlocks/DimensionlessBlock.cs | 8 ++++---- .../DailyReport/DailyReportBlocks/HeadBlock.cs | 3 ++- .../DailyReport/DailyReportBlocks/SaubBlock.cs | 2 ++ .../DailyReport/DailyReportBlocks/SignBlock.cs | 4 ++-- .../DailyReport/DailyReportMakerExcel.cs | 4 +++- .../Services/DailyReport/XLExtentions.cs | 2 ++ .../DetectOperations/DetectableTelemetry.cs | 2 ++ .../DetectedOperationExportService.cs | 5 ++++- .../Detectors/OperationDetectorResult.cs | 4 +++- .../DetectOperations/InterpolationLine.cs | 2 ++ .../DrillingProgram/DrillingProgramMaker.cs | 6 +++++- .../Services/DrillingProgram/ImageInfo.cs | 6 ++++-- 17 files changed, 54 insertions(+), 22 deletions(-) diff --git a/AsbCloudInfrastructure/Repository/QueryContainer.cs b/AsbCloudInfrastructure/Repository/QueryContainer.cs index a1586220..80838c31 100644 --- a/AsbCloudInfrastructure/Repository/QueryContainer.cs +++ b/AsbCloudInfrastructure/Repository/QueryContainer.cs @@ -5,6 +5,7 @@ using System.Linq; namespace AsbCloudInfrastructure.Repository { +#nullable enable public class QueryContainer where TEntity : class, IId { protected readonly IAsbCloudDbContext dbContext; @@ -25,4 +26,5 @@ namespace AsbCloudInfrastructure.Repository GetQuery = () => makeQuery(dbSet); } } +#nullable disable } \ No newline at end of file diff --git a/AsbCloudInfrastructure/Repository/SetpointsRequestRepository.cs b/AsbCloudInfrastructure/Repository/SetpointsRequestRepository.cs index 844ebcfe..38c00559 100644 --- a/AsbCloudInfrastructure/Repository/SetpointsRequestRepository.cs +++ b/AsbCloudInfrastructure/Repository/SetpointsRequestRepository.cs @@ -11,6 +11,7 @@ using System.Linq; namespace AsbCloudInfrastructure.Repository { +#nullable enable public class SetpointsRequestRepository : CrudWellRelatedCacheRepositoryBase { private readonly IWellService wellService; @@ -61,4 +62,5 @@ namespace AsbCloudInfrastructure.Repository return result; } } +#nullable disable } diff --git a/AsbCloudInfrastructure/Repository/WitsRecordRepository.cs b/AsbCloudInfrastructure/Repository/WitsRecordRepository.cs index 35c2fabb..eeac93d9 100644 --- a/AsbCloudInfrastructure/Repository/WitsRecordRepository.cs +++ b/AsbCloudInfrastructure/Repository/WitsRecordRepository.cs @@ -11,6 +11,7 @@ using System.Threading.Tasks; namespace AsbCloudInfrastructure.Repository { +#nullable enable public class WitsRecordRepository : IWitsRecordRepository where TEntity : AsbCloudDb.Model.WITS.RecordBase, ITelemetryData where TDto : AsbCloudApp.Data.ITelemetryData @@ -53,7 +54,9 @@ namespace AsbCloudInfrastructure.Repository .Where(d => d.DateTime <= end) .AsNoTracking(); var data = await query.ToListAsync(token); - return data.Select(d => Convert(d, timezoneHours)); + return data + .Where(d => d is not null) + .Select(d => Convert(d, timezoneHours)); } public async Task> GetLastAsync(int idTelemetry, CancellationToken token) @@ -64,7 +67,10 @@ namespace AsbCloudInfrastructure.Repository .OrderBy(d => d.DateTime) .AsNoTracking(); var data = await query.LastOrDefaultAsync(token); - return new TDto[] { Convert(data, timezoneHours) }; + if(data is not null) + return new TDto[] { Convert(data, timezoneHours) }; + + return new TDto[] { }; } public async Task SaveDataAsync(int idTelemetry, IEnumerable dtos, CancellationToken token) @@ -75,6 +81,7 @@ namespace AsbCloudInfrastructure.Repository var timezoneHours = telemetryService.GetTimezone(idTelemetry).Hours; var entities = dtos .DistinctBy(d => d.DateTime) + .Where(dto => dto is not null) .Select(dto => Convert(dto, idTelemetry, timezoneHours)); var dateMin = entities.Min(e => e.DateTime); @@ -128,9 +135,6 @@ namespace AsbCloudInfrastructure.Repository private static TEntity Convert(TDto dto, int idTelemetry, double timezoneHours) { - if (dto is null) - return null; - var entity = dto.Adapt(); entity.Recid = GetRecId(dto); entity.IdTelemetry = idTelemetry; @@ -140,13 +144,11 @@ namespace AsbCloudInfrastructure.Repository private static TDto Convert(TEntity entity, double timezoneHours) { - if (entity is null) - return default; - var data = entity.Adapt(); data.DateTime = entity.DateTime.ToRemoteDateTime(timezoneHours); return data; } } +#nullable disable } diff --git a/AsbCloudInfrastructure/Services/DailyReport/BlockAbstract.cs b/AsbCloudInfrastructure/Services/DailyReport/BlockAbstract.cs index cebcb11f..5814914f 100644 --- a/AsbCloudInfrastructure/Services/DailyReport/BlockAbstract.cs +++ b/AsbCloudInfrastructure/Services/DailyReport/BlockAbstract.cs @@ -2,10 +2,12 @@ namespace AsbCloudInfrastructure.Services.DailyReport { +#nullable enable abstract class BlockAbstract { public abstract CellAddress AddressBlockBegin { get; } public abstract CellAddress AddressBlockEnd { get; } public abstract void Draw(IXLWorksheet sheet); } +#nullable disable } diff --git a/AsbCloudInfrastructure/Services/DailyReport/DailyReportBlocks/BhaBlock.cs b/AsbCloudInfrastructure/Services/DailyReport/DailyReportBlocks/BhaBlock.cs index cd859b00..f38e498e 100644 --- a/AsbCloudInfrastructure/Services/DailyReport/DailyReportBlocks/BhaBlock.cs +++ b/AsbCloudInfrastructure/Services/DailyReport/DailyReportBlocks/BhaBlock.cs @@ -3,6 +3,7 @@ using ClosedXML.Excel; namespace AsbCloudInfrastructure.Services.DailyReport.DailyReportBlocks { +#nullable enable class BhaBlock : BlockAbstract { private readonly BhaDto blockDto; @@ -110,7 +111,8 @@ namespace AsbCloudInfrastructure.Services.DailyReport.DailyReportBlocks .SetFormulaA1($"{FormulaBhaBlock(AddressDurationDataStart[4], AddressDurationDataFinish[4])}").Style.SetAllBorders(); } } +#nullable disable } - + diff --git a/AsbCloudInfrastructure/Services/DailyReport/DailyReportBlocks/DimensionlessBlock.cs b/AsbCloudInfrastructure/Services/DailyReport/DailyReportBlocks/DimensionlessBlock.cs index f10c046e..28318820 100644 --- a/AsbCloudInfrastructure/Services/DailyReport/DailyReportBlocks/DimensionlessBlock.cs +++ b/AsbCloudInfrastructure/Services/DailyReport/DailyReportBlocks/DimensionlessBlock.cs @@ -3,12 +3,12 @@ using ClosedXML.Excel; namespace AsbCloudInfrastructure.Services.DailyReport.DailyReportBlocks { - +#nullable enable internal class DimensionlessBlock : BlockAbstract { private readonly NoDrillingDto blockDto; - public SaubBlock SaubBlock { get; set; } + public SaubBlock SaubBlock { get; set; } = null!; public CellAddress AddressDimensionTitle { get; } public CellAddress AddressPreparationTitle { get; } @@ -19,7 +19,7 @@ namespace AsbCloudInfrastructure.Services.DailyReport.DailyReportBlocks public CellAddress[] AddressPreparationValue { get; } public CellAddress[] AddressExtensionHead { get; } public CellAddress[] AddressExtensionValue { get; } - public CellAddress AddressBlockFormula { get; } + public CellAddress AddressBlockFormula { get; } = null!; public override CellAddress AddressBlockBegin { get; } public override CellAddress AddressBlockEnd { get; } public DimensionlessBlock(CellAddress addressBlockBegin, NoDrillingDto blockDto) @@ -114,6 +114,6 @@ namespace AsbCloudInfrastructure.Services.DailyReport.DailyReportBlocks ._SetValue("Наращивание"); } } - +#nullable disable } diff --git a/AsbCloudInfrastructure/Services/DailyReport/DailyReportBlocks/HeadBlock.cs b/AsbCloudInfrastructure/Services/DailyReport/DailyReportBlocks/HeadBlock.cs index 2acc1160..a306413f 100644 --- a/AsbCloudInfrastructure/Services/DailyReport/DailyReportBlocks/HeadBlock.cs +++ b/AsbCloudInfrastructure/Services/DailyReport/DailyReportBlocks/HeadBlock.cs @@ -3,7 +3,7 @@ using ClosedXML.Excel; namespace AsbCloudInfrastructure.Services.DailyReport.DailyReportBlocks { - +#nullable enable class HeadBlock : BlockAbstract { private readonly HeadDto blockDto; @@ -175,6 +175,7 @@ namespace AsbCloudInfrastructure.Services.DailyReport.DailyReportBlocks ._SetValue($"{blockDto.CountLaunchesMSE}"); } } +#nullable disable } diff --git a/AsbCloudInfrastructure/Services/DailyReport/DailyReportBlocks/SaubBlock.cs b/AsbCloudInfrastructure/Services/DailyReport/DailyReportBlocks/SaubBlock.cs index 84ad001a..2f3b0588 100644 --- a/AsbCloudInfrastructure/Services/DailyReport/DailyReportBlocks/SaubBlock.cs +++ b/AsbCloudInfrastructure/Services/DailyReport/DailyReportBlocks/SaubBlock.cs @@ -3,6 +3,7 @@ using ClosedXML.Excel; namespace AsbCloudInfrastructure.Services.DailyReport.DailyReportBlocks { +#nullable enable internal class SaubBlock : BlockAbstract { private readonly SaubDto blockDto; @@ -224,5 +225,6 @@ namespace AsbCloudInfrastructure.Services.DailyReport.DailyReportBlocks ._SetValue($"Примечание: {blockDto.DeclinesReasonsROP}"); } } +#nullable disable } diff --git a/AsbCloudInfrastructure/Services/DailyReport/DailyReportBlocks/SignBlock.cs b/AsbCloudInfrastructure/Services/DailyReport/DailyReportBlocks/SignBlock.cs index b4fd4e8f..4461b9d4 100644 --- a/AsbCloudInfrastructure/Services/DailyReport/DailyReportBlocks/SignBlock.cs +++ b/AsbCloudInfrastructure/Services/DailyReport/DailyReportBlocks/SignBlock.cs @@ -3,6 +3,7 @@ using ClosedXML.Excel; namespace AsbCloudInfrastructure.Services.DailyReport.DailyReportBlocks { +#nullable enable internal class SignBlock : BlockAbstract { private readonly SignDto blockDto; @@ -10,7 +11,6 @@ namespace AsbCloudInfrastructure.Services.DailyReport.DailyReportBlocks public CellAddress AddressDrillMaster { get; } public CellAddress AddressSupervisorHead { get; } public CellAddress AddressSupervisor { get; } - public CellAddress[] AddressPeriodTableDataArray { get; } public override CellAddress AddressBlockBegin { get; } public override CellAddress AddressBlockEnd { get; } @@ -45,7 +45,7 @@ namespace AsbCloudInfrastructure.Services.DailyReport.DailyReportBlocks .SetValue($"{blockDto.Supervisor}"); } } - +#nullable disable } diff --git a/AsbCloudInfrastructure/Services/DailyReport/DailyReportMakerExcel.cs b/AsbCloudInfrastructure/Services/DailyReport/DailyReportMakerExcel.cs index 201b1341..500c260a 100644 --- a/AsbCloudInfrastructure/Services/DailyReport/DailyReportMakerExcel.cs +++ b/AsbCloudInfrastructure/Services/DailyReport/DailyReportMakerExcel.cs @@ -6,9 +6,10 @@ using System.Collections.Generic; using System.IO; namespace AsbCloudInfrastructure.Services.DailyReport { +#nullable enable public class DailyReportMakerExcel { - private IEnumerable OperationCategories; + private IEnumerable OperationCategories = null!; public Stream MakeReportFromBlocks(DailyReportDto dto, IEnumerable operationCategories) { @@ -55,5 +56,6 @@ namespace AsbCloudInfrastructure.Services.DailyReport sheet.Rows().AdjustToContents(); } } +#nullable disable } diff --git a/AsbCloudInfrastructure/Services/DailyReport/XLExtentions.cs b/AsbCloudInfrastructure/Services/DailyReport/XLExtentions.cs index 5297b0e1..23f902a7 100644 --- a/AsbCloudInfrastructure/Services/DailyReport/XLExtentions.cs +++ b/AsbCloudInfrastructure/Services/DailyReport/XLExtentions.cs @@ -3,6 +3,7 @@ using System; namespace AsbCloudInfrastructure.Services.DailyReport { +#nullable enable internal static class XLExtentions { public static IXLRange _SetValue(this IXLRange range, object value) @@ -156,4 +157,5 @@ namespace AsbCloudInfrastructure.Services.DailyReport => sheet.Range(begin.RowNumber, begin.ColumnNumber, end.RowNumber, end.ColumnNumber); } +#nullable disable } diff --git a/AsbCloudInfrastructure/Services/DetectOperations/DetectableTelemetry.cs b/AsbCloudInfrastructure/Services/DetectOperations/DetectableTelemetry.cs index 1ed08c7a..87f3defe 100644 --- a/AsbCloudInfrastructure/Services/DetectOperations/DetectableTelemetry.cs +++ b/AsbCloudInfrastructure/Services/DetectOperations/DetectableTelemetry.cs @@ -2,6 +2,7 @@ namespace AsbCloudInfrastructure.Services.DetectOperations { +#nullable enable public class DetectableTelemetry { public DateTimeOffset DateTime { get; set; } @@ -13,4 +14,5 @@ namespace AsbCloudInfrastructure.Services.DetectOperations public float BitDepth { get; set; } public float RotorSpeed { get; set; } } +#nullable disable } diff --git a/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationExportService.cs b/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationExportService.cs index ffca6b9f..c261e87d 100644 --- a/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationExportService.cs +++ b/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationExportService.cs @@ -12,6 +12,7 @@ using System.Threading.Tasks; namespace AsbCloudInfrastructure.Services.DetectOperations { +#nullable enable internal class DetectedOperationExportService { private readonly IAsbCloudDbContext db; @@ -41,7 +42,8 @@ namespace AsbCloudInfrastructure.Services.DetectOperations return; var wells = idsWells.Select(i => wellService.GetOrDefault(i)) - .Where(w => w is not null && w.IdTelemetry is not null); + .Where(w => w is not null && w.IdTelemetry is not null) + .Select(w => w!); if (!wells.Any()) return; @@ -114,4 +116,5 @@ namespace AsbCloudInfrastructure.Services.DetectOperations sheet.Cell(rowNumber, 6).Value = operation.Value; } } +#nullable enable } diff --git a/AsbCloudInfrastructure/Services/DetectOperations/Detectors/OperationDetectorResult.cs b/AsbCloudInfrastructure/Services/DetectOperations/Detectors/OperationDetectorResult.cs index f0391b4f..94ee7fc7 100644 --- a/AsbCloudInfrastructure/Services/DetectOperations/Detectors/OperationDetectorResult.cs +++ b/AsbCloudInfrastructure/Services/DetectOperations/Detectors/OperationDetectorResult.cs @@ -2,10 +2,12 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors { +#nullable enable class OperationDetectorResult { public int TelemetryBegin { get; set; } public int TelemetryEnd { get; set; } - public DetectedOperation Operation { get; set; } + public DetectedOperation Operation { get; set; } = null!; } +#nullable enable } diff --git a/AsbCloudInfrastructure/Services/DetectOperations/InterpolationLine.cs b/AsbCloudInfrastructure/Services/DetectOperations/InterpolationLine.cs index 1dc99547..cc49c079 100644 --- a/AsbCloudInfrastructure/Services/DetectOperations/InterpolationLine.cs +++ b/AsbCloudInfrastructure/Services/DetectOperations/InterpolationLine.cs @@ -2,6 +2,7 @@ namespace AsbCloudInfrastructure.Services.DetectOperations { +#nullable enable public class InterpolationLine { private readonly double xSum; @@ -52,4 +53,5 @@ namespace AsbCloudInfrastructure.Services.DetectOperations public bool IsAverageYGreaterThan(double bound) => (ySum / count) >= bound; } +#nullable disable } diff --git a/AsbCloudInfrastructure/Services/DrillingProgram/DrillingProgramMaker.cs b/AsbCloudInfrastructure/Services/DrillingProgram/DrillingProgramMaker.cs index dae5ff4f..032895c9 100644 --- a/AsbCloudInfrastructure/Services/DrillingProgram/DrillingProgramMaker.cs +++ b/AsbCloudInfrastructure/Services/DrillingProgram/DrillingProgramMaker.cs @@ -6,6 +6,7 @@ using System.Linq; namespace AsbCloudInfrastructure.Services.DrillingProgram { +#nullable enable internal class DrillingProgramMaker { private const int maxAllowedColumns = 256; @@ -15,7 +16,9 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram var resultExcelFile = new XLWorkbook(XLEventTracking.Disabled); var titleSheet = resultExcelFile.AddWorksheet("Титульный лист"); - var marks = parts.SelectMany(p => p.File.FileMarks); + var marks = parts + .Where(p => p.File is not null) + .SelectMany(p => p.File!.FileMarks); var titleSheetMaker = new TitleListSheet(marks, well); titleSheetMaker.Draw(titleSheet); @@ -128,4 +131,5 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram return rngData; } } +#nullable disable } diff --git a/AsbCloudInfrastructure/Services/DrillingProgram/ImageInfo.cs b/AsbCloudInfrastructure/Services/DrillingProgram/ImageInfo.cs index 8f9265f9..aeedd213 100644 --- a/AsbCloudInfrastructure/Services/DrillingProgram/ImageInfo.cs +++ b/AsbCloudInfrastructure/Services/DrillingProgram/ImageInfo.cs @@ -2,14 +2,16 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram { +#nullable enable class ImageInfo { public int Id { get; set; } - public byte[] Data { get; set; } + public byte[] Data { get; set; } = null!; public int Height { get; set; } public int Width { get; set; } - public IXLAddress TopLeftCellAddress { get; set; } + public IXLAddress TopLeftCellAddress { get; set; } = null!; public int Left { get; set; } public int Top { get; set; } } +#nullable disable } \ No newline at end of file From 2431557539bbe72918b5c58eec3ad816ad57bd82 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Thu, 13 Apr 2023 15:34:16 +0500 Subject: [PATCH 2/8] #nullable enable (part 2) --- AsbCloudApp/Services/IFileCategoryService.cs | 2 +- AsbCloudApp/Services/IMeasureService.cs | 2 +- AsbCloudInfrastructure/DateTimeExtentions.cs | 2 ++ .../IInfrastructureMarker.cs | 8 -------- .../Repository/WitsRecordRepository.cs | 1 - .../DrillingProgram/DrillingProgramMaker.cs | 4 +--- .../Services/Email/BaseFactory.cs | 10 ++++++---- .../Services/Email/DrillingMailBodyFactory.cs | 4 +++- .../WellFinalDocumentMailBodyFactory .cs | 4 +++- .../Services/FileCategoryService.cs | 2 ++ AsbCloudInfrastructure/Services/IConverter.cs | 8 -------- .../ProcessMap/ProcessMapReportService.cs | 1 - .../Services/ProcessMap/XLExtentions.cs | 2 ++ .../Services/SAUB/CsvSerializer.cs | 3 +-- .../Services/SAUB/EventService.cs | 2 ++ .../Services/SAUB/SetpointsService.cs | 1 + .../Services/SAUB/TelemetryDataSpinService.cs | 2 ++ .../Services/SAUB/TelemetryTracker.cs | 16 +++++++++++----- .../TrajectoryVisualizationService.cs | 1 + .../ScheduleReportService.cs | 19 +++++++++++-------- .../Controllers/MeasureController.cs | 2 +- 21 files changed, 51 insertions(+), 45 deletions(-) delete mode 100644 AsbCloudInfrastructure/IInfrastructureMarker.cs delete mode 100644 AsbCloudInfrastructure/Services/IConverter.cs diff --git a/AsbCloudApp/Services/IFileCategoryService.cs b/AsbCloudApp/Services/IFileCategoryService.cs index 91ca05a7..f660d0fa 100644 --- a/AsbCloudApp/Services/IFileCategoryService.cs +++ b/AsbCloudApp/Services/IFileCategoryService.cs @@ -16,7 +16,7 @@ namespace AsbCloudApp.Services /// /// /// - Task GetOrDefaultAsync(int id, CancellationToken token); + Task GetOrDefaultAsync(int id, CancellationToken token); /// /// Получение справочника категорий файлов diff --git a/AsbCloudApp/Services/IMeasureService.cs b/AsbCloudApp/Services/IMeasureService.cs index f7fff368..ceb99ce1 100644 --- a/AsbCloudApp/Services/IMeasureService.cs +++ b/AsbCloudApp/Services/IMeasureService.cs @@ -24,7 +24,7 @@ namespace AsbCloudApp.Services /// /// /// - Task GetLastAsync(int idWell, int idCategory, CancellationToken token); + Task GetLastOrDefaultAsync(int idWell, int idCategory, CancellationToken token); /// /// История измерений по категории diff --git a/AsbCloudInfrastructure/DateTimeExtentions.cs b/AsbCloudInfrastructure/DateTimeExtentions.cs index 01a994b9..9686e948 100644 --- a/AsbCloudInfrastructure/DateTimeExtentions.cs +++ b/AsbCloudInfrastructure/DateTimeExtentions.cs @@ -2,6 +2,7 @@ namespace AsbCloudInfrastructure { +#nullable enable public static class DateTimeExtentions { /// @@ -77,4 +78,5 @@ namespace AsbCloudInfrastructure return indexOfMiddle; } } +#nullable disable } diff --git a/AsbCloudInfrastructure/IInfrastructureMarker.cs b/AsbCloudInfrastructure/IInfrastructureMarker.cs deleted file mode 100644 index 207081d6..00000000 --- a/AsbCloudInfrastructure/IInfrastructureMarker.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace AsbCloudInfrastructure -{ - /// - /// Тип для поиска этой сборки - /// - public interface IInfrastructureMarker - { } -} diff --git a/AsbCloudInfrastructure/Repository/WitsRecordRepository.cs b/AsbCloudInfrastructure/Repository/WitsRecordRepository.cs index eeac93d9..743b4e29 100644 --- a/AsbCloudInfrastructure/Repository/WitsRecordRepository.cs +++ b/AsbCloudInfrastructure/Repository/WitsRecordRepository.cs @@ -81,7 +81,6 @@ namespace AsbCloudInfrastructure.Repository var timezoneHours = telemetryService.GetTimezone(idTelemetry).Hours; var entities = dtos .DistinctBy(d => d.DateTime) - .Where(dto => dto is not null) .Select(dto => Convert(dto, idTelemetry, timezoneHours)); var dateMin = entities.Min(e => e.DateTime); diff --git a/AsbCloudInfrastructure/Services/DrillingProgram/DrillingProgramMaker.cs b/AsbCloudInfrastructure/Services/DrillingProgram/DrillingProgramMaker.cs index 032895c9..d159ac56 100644 --- a/AsbCloudInfrastructure/Services/DrillingProgram/DrillingProgramMaker.cs +++ b/AsbCloudInfrastructure/Services/DrillingProgram/DrillingProgramMaker.cs @@ -16,9 +16,7 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram var resultExcelFile = new XLWorkbook(XLEventTracking.Disabled); var titleSheet = resultExcelFile.AddWorksheet("Титульный лист"); - var marks = parts - .Where(p => p.File is not null) - .SelectMany(p => p.File!.FileMarks); + var marks = parts.SelectMany(p => p.File!.FileMarks); var titleSheetMaker = new TitleListSheet(marks, well); titleSheetMaker.Draw(titleSheet); diff --git a/AsbCloudInfrastructure/Services/Email/BaseFactory.cs b/AsbCloudInfrastructure/Services/Email/BaseFactory.cs index 81a319cd..4e6d3084 100644 --- a/AsbCloudInfrastructure/Services/Email/BaseFactory.cs +++ b/AsbCloudInfrastructure/Services/Email/BaseFactory.cs @@ -1,10 +1,12 @@ using AsbCloudApp.Data; +using AsbCloudApp.Exceptions; using Microsoft.Extensions.Configuration; using System; using System.IO; namespace AsbCloudInfrastructure.Services.Email { +#nullable enable public class BaseFactory { private readonly string platformName; @@ -23,14 +25,13 @@ namespace AsbCloudInfrastructure.Services.Email public static string GetImageBase64(string resourceFileName) { if (string.IsNullOrEmpty(resourceFileName)) - return null; + throw new ArgumentInvalidException("ResourceFileName doesn`t exist", nameof(resourceFileName)); - var baseDir = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); + var baseDir = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + ?? string.Empty; var resoursesDir = "Res"; var logoFilePath = Path.Combine(baseDir, resoursesDir, resourceFileName); - if(!File.Exists(logoFilePath)) - return string.Empty; var imageBytes = File.ReadAllBytes(logoFilePath); var format = Path.GetExtension(resourceFileName).Trim('.'); return "data:image/" + format + ";base64," + Convert.ToBase64String(imageBytes); @@ -53,4 +54,5 @@ namespace AsbCloudInfrastructure.Services.Email public virtual string MakeSubject(WellDto well, string action) => $"{well.Deposit}, {well.Cluster}, {well.Caption}. {action}"; } +#nullable disable } diff --git a/AsbCloudInfrastructure/Services/Email/DrillingMailBodyFactory.cs b/AsbCloudInfrastructure/Services/Email/DrillingMailBodyFactory.cs index 664fee99..eb0bef1a 100644 --- a/AsbCloudInfrastructure/Services/Email/DrillingMailBodyFactory.cs +++ b/AsbCloudInfrastructure/Services/Email/DrillingMailBodyFactory.cs @@ -6,7 +6,8 @@ using System.IO; namespace AsbCloudInfrastructure { - class DrillingMailBodyFactory : BaseFactory +#nullable enable + class DrillingMailBodyFactory : BaseFactory { private readonly string platformName; private readonly string platformUrl; @@ -84,4 +85,5 @@ namespace AsbCloudInfrastructure return drillingProgramHref; } } +#nullable disable } diff --git a/AsbCloudInfrastructure/Services/Email/WellFinalDocumentMailBodyFactory .cs b/AsbCloudInfrastructure/Services/Email/WellFinalDocumentMailBodyFactory .cs index e83fa55a..9d409c0c 100644 --- a/AsbCloudInfrastructure/Services/Email/WellFinalDocumentMailBodyFactory .cs +++ b/AsbCloudInfrastructure/Services/Email/WellFinalDocumentMailBodyFactory .cs @@ -6,7 +6,8 @@ using System.IO; namespace AsbCloudInfrastructure { - class WellFinalDocumentMailBodyFactory : BaseFactory +#nullable enable + class WellFinalDocumentMailBodyFactory : BaseFactory { private readonly string platformName; @@ -29,4 +30,5 @@ namespace AsbCloudInfrastructure return body; } } +#nullable disable } diff --git a/AsbCloudInfrastructure/Services/FileCategoryService.cs b/AsbCloudInfrastructure/Services/FileCategoryService.cs index b50c9418..4f07a34c 100644 --- a/AsbCloudInfrastructure/Services/FileCategoryService.cs +++ b/AsbCloudInfrastructure/Services/FileCategoryService.cs @@ -10,6 +10,7 @@ using System.Threading.Tasks; namespace AsbCloudInfrastructure.Services { +#nullable enable public class FileCategoryService : CrudCacheRepositoryBase, IFileCategoryService { public FileCategoryService(IAsbCloudDbContext context, IMemoryCache memoryCache) @@ -28,4 +29,5 @@ namespace AsbCloudInfrastructure.Services return dtos; } } +#nullable disable } diff --git a/AsbCloudInfrastructure/Services/IConverter.cs b/AsbCloudInfrastructure/Services/IConverter.cs deleted file mode 100644 index a1c6fd54..00000000 --- a/AsbCloudInfrastructure/Services/IConverter.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace AsbCloudInfrastructure.Services -{ - public interface IConverter - { - TModel Convert(TDto src); - TDto Convert(TModel src); - } -} \ No newline at end of file diff --git a/AsbCloudInfrastructure/Services/ProcessMap/ProcessMapReportService.cs b/AsbCloudInfrastructure/Services/ProcessMap/ProcessMapReportService.cs index f0c69468..15b1455b 100644 --- a/AsbCloudInfrastructure/Services/ProcessMap/ProcessMapReportService.cs +++ b/AsbCloudInfrastructure/Services/ProcessMap/ProcessMapReportService.cs @@ -6,7 +6,6 @@ using AsbCloudApp.Services; using System; using System.Collections.Generic; using System.Linq; -using System.Numerics; using System.Threading; using System.Threading.Tasks; diff --git a/AsbCloudInfrastructure/Services/ProcessMap/XLExtentions.cs b/AsbCloudInfrastructure/Services/ProcessMap/XLExtentions.cs index b5443037..6e0a56e3 100644 --- a/AsbCloudInfrastructure/Services/ProcessMap/XLExtentions.cs +++ b/AsbCloudInfrastructure/Services/ProcessMap/XLExtentions.cs @@ -5,6 +5,7 @@ namespace AsbCloudInfrastructure.Services.ProcessMap; internal static class XLExtentions { +#nullable enable public static IXLCell SetVal(this IXLCell cell, string value, bool adaptRowHeight = false) { cell.Value = value; @@ -47,4 +48,5 @@ internal static class XLExtentions cell.Style.NumberFormat.Format = format; return cell; } +#nullable disable } diff --git a/AsbCloudInfrastructure/Services/SAUB/CsvSerializer.cs b/AsbCloudInfrastructure/Services/SAUB/CsvSerializer.cs index a7b5a80f..7b089dbb 100644 --- a/AsbCloudInfrastructure/Services/SAUB/CsvSerializer.cs +++ b/AsbCloudInfrastructure/Services/SAUB/CsvSerializer.cs @@ -1,5 +1,4 @@ -using DocumentFormat.OpenXml.Drawing.Diagrams; -using System.Collections.Generic; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; diff --git a/AsbCloudInfrastructure/Services/SAUB/EventService.cs b/AsbCloudInfrastructure/Services/SAUB/EventService.cs index 56fe1737..71760736 100644 --- a/AsbCloudInfrastructure/Services/SAUB/EventService.cs +++ b/AsbCloudInfrastructure/Services/SAUB/EventService.cs @@ -10,6 +10,7 @@ using System.Threading.Tasks; namespace AsbCloudInfrastructure.Services.SAUB { +#nullable enable public class EventService : IEventService { private readonly IAsbCloudDbContext db; @@ -42,4 +43,5 @@ namespace AsbCloudInfrastructure.Services.SAUB memoryCache.DropBasic(); } } +#nullable disable } diff --git a/AsbCloudInfrastructure/Services/SAUB/SetpointsService.cs b/AsbCloudInfrastructure/Services/SAUB/SetpointsService.cs index f5ebdb05..bd86b5fb 100644 --- a/AsbCloudInfrastructure/Services/SAUB/SetpointsService.cs +++ b/AsbCloudInfrastructure/Services/SAUB/SetpointsService.cs @@ -113,4 +113,5 @@ namespace AsbCloudInfrastructure.Services.SAUB public IEnumerable GetSetpointsNames() => SetpointInfos.Values; } +#nullable disable } diff --git a/AsbCloudInfrastructure/Services/SAUB/TelemetryDataSpinService.cs b/AsbCloudInfrastructure/Services/SAUB/TelemetryDataSpinService.cs index 64862dcc..1773c0a2 100644 --- a/AsbCloudInfrastructure/Services/SAUB/TelemetryDataSpinService.cs +++ b/AsbCloudInfrastructure/Services/SAUB/TelemetryDataSpinService.cs @@ -5,6 +5,7 @@ using Mapster; namespace AsbCloudInfrastructure.Services.SAUB { +#nullable enable public class TelemetryDataSpinService : TelemetryDataBaseService { public TelemetryDataSpinService( @@ -28,4 +29,5 @@ namespace AsbCloudInfrastructure.Services.SAUB return dto; } } +#nullable disable } diff --git a/AsbCloudInfrastructure/Services/SAUB/TelemetryTracker.cs b/AsbCloudInfrastructure/Services/SAUB/TelemetryTracker.cs index ff5ca394..3cdf0776 100644 --- a/AsbCloudInfrastructure/Services/SAUB/TelemetryTracker.cs +++ b/AsbCloudInfrastructure/Services/SAUB/TelemetryTracker.cs @@ -12,13 +12,14 @@ using System.Threading.Tasks; namespace AsbCloudInfrastructure.Services.SAUB { +#nullable enable public class TelemetryTracker : ITelemetryTracker { class TrackerStat { //public int Id { get; set; } - public string RemoteUid { get; set; } + public string RemoteUid { get; set; } = null!; /// /// Время последнего запроса (по времени сервера) @@ -88,10 +89,14 @@ namespace AsbCloudInfrastructure.Services.SAUB foreach (var oldReq in oldRequests) { - var telemetryStat = telemetriesStats.GetOrAdd(oldReq.Uid, (uid) => new TrackerStat { RemoteUid = uid }); - telemetryStat.TelemetryDateUtcMin = oldReq.DateMin; - telemetryStat.TelemetryDateUtcMax = oldReq.DateMax; - telemetryStat.LastTimeServer = oldReq.DateMax; + if (oldReq.Uid is not null) + { + var telemetryStat = telemetriesStats.GetOrAdd(oldReq.Uid, (uid) => new TrackerStat { RemoteUid = uid }); + telemetryStat.TelemetryDateUtcMin = oldReq.DateMin; + telemetryStat.TelemetryDateUtcMax = oldReq.DateMax; + telemetryStat.LastTimeServer = oldReq.DateMax; + } + } }).ContinueWith((t) => { @@ -147,4 +152,5 @@ namespace AsbCloudInfrastructure.Services.SAUB public IEnumerable GetTransmittingTelemetriesUids() => telemetriesStats.Keys; } +#nullable disable } diff --git a/AsbCloudInfrastructure/Services/Trajectory/TrajectoryVisualizationService.cs b/AsbCloudInfrastructure/Services/Trajectory/TrajectoryVisualizationService.cs index d8a30c7d..04b76630 100644 --- a/AsbCloudInfrastructure/Services/Trajectory/TrajectoryVisualizationService.cs +++ b/AsbCloudInfrastructure/Services/Trajectory/TrajectoryVisualizationService.cs @@ -54,4 +54,5 @@ namespace AsbCloudInfrastructure.Services.Trajectory return cartesianCoordinates; } } +#nullable disable } diff --git a/AsbCloudInfrastructure/Services/WellOperationService/ScheduleReportService.cs b/AsbCloudInfrastructure/Services/WellOperationService/ScheduleReportService.cs index 7d2763b8..703d815f 100644 --- a/AsbCloudInfrastructure/Services/WellOperationService/ScheduleReportService.cs +++ b/AsbCloudInfrastructure/Services/WellOperationService/ScheduleReportService.cs @@ -1,4 +1,5 @@ using AsbCloudApp.Data; +using AsbCloudApp.Exceptions; using AsbCloudApp.Services; using AsbCloudDb.Model; using ClosedXML.Excel; @@ -11,6 +12,7 @@ using System.Threading.Tasks; namespace AsbCloudInfrastructure.Services.WellOperationService { +#nullable enable public class ScheduleReportService : IScheduleReportService { private readonly IOperationsStatService operationsStatService; @@ -29,11 +31,11 @@ namespace AsbCloudInfrastructure.Services.WellOperationService { var tvd = await operationsStatService.GetTvdAsync(idWell, token); - if (!tvd.Any()) - return null; - var well = await wellService.GetOrDefaultAsync(idWell, token); + if(well is null) + throw new ArgumentInvalidException("idWell doesn`t exist", nameof(idWell)); + var ecxelTemplateStream = GetExcelTemplateStream(); using var workbook = new XLWorkbook(ecxelTemplateStream, XLEventTracking.Disabled); FillScheduleSheetToWorkbook(workbook, tvd, well); @@ -236,9 +238,9 @@ namespace AsbCloudInfrastructure.Services.WellOperationService ? operation.DateStart.AddHours(operation.DurationHours) : default; - var endDatePlan = GetEndDate(planLast); - var endDateFact = GetEndDate(factLast); - var endDatePredict = GetEndDate(predictLast); + var endDatePlan = planLast is not null ? GetEndDate(planLast) : default; + var endDateFact = factLast is not null ? GetEndDate(factLast) : default; + var endDatePredict = predictLast is not null ? GetEndDate(predictLast) : default; var endDate = endDatePredict > endDateFact ? endDatePredict @@ -301,7 +303,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService return cell; } - private static IXLCell SetCell(IXLRow row, int colunm, object value) + private static IXLCell SetCell(IXLRow row, int colunm, object? value) { var cell = row.Cell(colunm); cell.Value = value; @@ -330,8 +332,9 @@ namespace AsbCloudInfrastructure.Services.WellOperationService private static Stream GetExcelTemplateStream() { var stream = System.Reflection.Assembly.GetExecutingAssembly() - .GetManifestResourceStream("AsbCloudInfrastructure.Services.WellOperationService.ScheduleReportTemplate.xlsx"); + .GetManifestResourceStream("AsbCloudInfrastructure.Services.WellOperationService.ScheduleReportTemplate.xlsx")!; return stream; } } +#nullable disable } diff --git a/AsbCloudWebApi/Controllers/MeasureController.cs b/AsbCloudWebApi/Controllers/MeasureController.cs index bbfebcf6..dac77733 100644 --- a/AsbCloudWebApi/Controllers/MeasureController.cs +++ b/AsbCloudWebApi/Controllers/MeasureController.cs @@ -44,7 +44,7 @@ namespace AsbCloudWebApi.Controllers if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false)) return Forbid(); - var result = await measureService.GetLastAsync(idWell, idCategory, token).ConfigureAwait(false); + var result = await measureService.GetLastOrDefaultAsync(idWell, idCategory, token).ConfigureAwait(false); return Ok(result); } From 5100a221e0d12472e00e0bdb382c55074539d4dd Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Thu, 13 Apr 2023 15:37:11 +0500 Subject: [PATCH 3/8] =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B0=20new?= =?UTF-8?q?=20TDto[]=20{=20}=20=D0=BD=D0=B0=20Enumerable.Empty()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudInfrastructure/Repository/WitsRecordRepository.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AsbCloudInfrastructure/Repository/WitsRecordRepository.cs b/AsbCloudInfrastructure/Repository/WitsRecordRepository.cs index 743b4e29..bf98daa5 100644 --- a/AsbCloudInfrastructure/Repository/WitsRecordRepository.cs +++ b/AsbCloudInfrastructure/Repository/WitsRecordRepository.cs @@ -70,7 +70,7 @@ namespace AsbCloudInfrastructure.Repository if(data is not null) return new TDto[] { Convert(data, timezoneHours) }; - return new TDto[] { }; + return Enumerable.Empty(); } public async Task SaveDataAsync(int idTelemetry, IEnumerable dtos, CancellationToken token) From cb9e8dd6728988e3aa9666d82b608f5d94dc7a5e Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Fri, 14 Apr 2023 10:02:38 +0500 Subject: [PATCH 4/8] =?UTF-8?q?nullable=20enable=20(=D1=87=D0=B0=D1=81?= =?UTF-8?q?=D1=82=D1=8C=203)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudInfrastructure/DependencyInjection.cs | 26 +++++++++++-------- .../Services/MeasureService.cs | 17 ++++++++---- .../WellOperationImportService.cs | 21 +++++++++------ 3 files changed, 40 insertions(+), 24 deletions(-) diff --git a/AsbCloudInfrastructure/DependencyInjection.cs b/AsbCloudInfrastructure/DependencyInjection.cs index 62fa5d3f..496e4729 100644 --- a/AsbCloudInfrastructure/DependencyInjection.cs +++ b/AsbCloudInfrastructure/DependencyInjection.cs @@ -26,6 +26,7 @@ using System; namespace AsbCloudInfrastructure { +#nullable enable public static class DependencyInjection { public static IAsbCloudDbContext MakeContext(string connectionString) @@ -49,7 +50,7 @@ namespace AsbCloudInfrastructure TypeAdapterConfig.GlobalSettings.Default.Config .ForType() - .MapWith((source) => source == default ? default : source.MakeTimeOnly()); + .MapWith((source) => source.MakeTimeOnly()); TypeAdapterConfig.GlobalSettings.Default.Config .ForType() @@ -59,6 +60,7 @@ namespace AsbCloudInfrastructure .ForType() .MapWith((source) => new(source)); +#pragma warning disable CS8603 // Possible null reference return. TypeAdapterConfig.GlobalSettings.Default.Config .ForType() .Ignore(dst => dst.Cluster, @@ -68,6 +70,7 @@ namespace AsbCloudInfrastructure dst => dst.WellCompositeSrcs, dst => dst.WellOperations, dst => dst.WellType); +#pragma warning restore CS8603 // Possible null reference return. TypeAdapterConfig.GlobalSettings.Default.Config .ForType() @@ -93,7 +96,7 @@ namespace AsbCloudInfrastructure services.AddMemoryCache(); - services.AddScoped(provider => provider.GetService()); + services.AddScoped(provider => provider.GetRequiredService()); services.AddScoped(); services.AddSingleton(new WitsInfoService()); @@ -140,25 +143,25 @@ namespace AsbCloudInfrastructure // admin crud services: services.AddTransient, CrudCacheRepositoryBase>(s => new CrudCacheRepositoryBase( - s.GetService(), - s.GetService(), + s.GetRequiredService(), + s.GetRequiredService(), dbSet => dbSet.Include(t => t.Well))); // может быть включен в сервис TelemetryService services.AddTransient, CrudCacheRepositoryBase>(s => new CrudCacheRepositoryBase( - s.GetService(), - s.GetService(), + s.GetRequiredService(), + s.GetRequiredService(), dbSet => dbSet.Include(d => d.Clusters))); services.AddTransient, CrudCacheRepositoryBase>(s => new CrudCacheRepositoryBase( - s.GetService(), - s.GetService(), + s.GetRequiredService(), + s.GetRequiredService(), dbSet => dbSet.Include(c => c.CompanyType))); services.AddTransient, CrudCacheRepositoryBase>(); services.AddTransient, CrudCacheRepositoryBase>(s => new CrudCacheRepositoryBase( - s.GetService(), - s.GetService(), + s.GetRequiredService(), + s.GetRequiredService(), dbSet => dbSet .Include(c => c.Wells) .Include(c => c.Deposit))); // может быть включен в сервис ClusterService @@ -200,7 +203,7 @@ namespace AsbCloudInfrastructure where TService : class where TImplementation : class, TService => services.AddTransient() - .AddTransient(provider => new Lazy(provider.GetService)); + .AddTransient(provider => new Lazy(provider.GetRequiredService)); public static IServiceCollection AddTransientLazy(this IServiceCollection services, Func implementationFactory) where TService : class @@ -209,4 +212,5 @@ namespace AsbCloudInfrastructure .AddTransient(provider => new Lazy(() => implementationFactory(provider))); } +#nullable disable } diff --git a/AsbCloudInfrastructure/Services/MeasureService.cs b/AsbCloudInfrastructure/Services/MeasureService.cs index 56157786..d32a7882 100644 --- a/AsbCloudInfrastructure/Services/MeasureService.cs +++ b/AsbCloudInfrastructure/Services/MeasureService.cs @@ -13,6 +13,7 @@ using System.Threading.Tasks; namespace AsbCloudInfrastructure.Services { +#nullable enable public class MeasureService : IMeasureService { private readonly IAsbCloudDbContext db; @@ -40,7 +41,7 @@ namespace AsbCloudInfrastructure.Services return cache; } - public async Task GetLastAsync(int idWell, int idCategory, CancellationToken token) + public async Task GetLastOrDefaultAsync(int idWell, int idCategory, CancellationToken token) { var query = db.Measures .Include(m => m.Category) @@ -54,8 +55,11 @@ namespace AsbCloudInfrastructure.Services .ConfigureAwait(false); var timezone = wellService.GetTimezone(idWell); - var dto = Convert(entity, timezone.Hours); - return dto; + + if (entity is null) + return null; + + return Convert(entity, timezone.Hours); } public async Task> GetHisoryAsync(int idWell, int? idCategory = null, CancellationToken token = default) @@ -124,6 +128,9 @@ namespace AsbCloudInfrastructure.Services .FirstOrDefaultAsync(token) .ConfigureAwait(false); + if (entity is null) + throw new ArgumentInvalidException($"Measure doesn't exist", nameof(idWell)); + entity.IsDeleted = true; return await db.SaveChangesAsync(token).ConfigureAwait(false); @@ -140,16 +147,16 @@ namespace AsbCloudInfrastructure.Services private MeasureDto Convert(Measure entity, double hours) { var dto = entity.Adapt(); - dto.CategoryName = entity.Category?.Name; + dto.CategoryName = entity.Category?.Name ?? String.Empty; dto.Timestamp = entity.Timestamp.ToRemoteDateTime(hours); return dto; } private Measure Convert(MeasureDto dto, double hours) { var entity = dto.Adapt(); - entity.Category = null; entity.Timestamp = dto.Timestamp.ToUtcDateTimeOffset(hours); return entity; } } +#nullable disable } diff --git a/AsbCloudInfrastructure/Services/WellOperationService/WellOperationImportService.cs b/AsbCloudInfrastructure/Services/WellOperationService/WellOperationImportService.cs index e9ed3d11..fe8c77d1 100644 --- a/AsbCloudInfrastructure/Services/WellOperationService/WellOperationImportService.cs +++ b/AsbCloudInfrastructure/Services/WellOperationService/WellOperationImportService.cs @@ -11,6 +11,7 @@ using System.Linq; namespace AsbCloudInfrastructure.Services.WellOperationService { +#nullable enable /* * password for WellOperationImportTemplate.xlsx is ASB2020! */ @@ -36,7 +37,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService private readonly IAsbCloudDbContext db; private readonly IWellService wellService; - private List categories = null; + private List categories = null!; public List Categories { get @@ -52,7 +53,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService } } - private List sections = null; + private List sections = null!; public List Sections { get @@ -92,9 +93,6 @@ namespace AsbCloudInfrastructure.Services.WellOperationService .AsNoTracking() .ToList(); - if (!operations.Any()) - return null; - var timezone = wellService.GetTimezone(idWell); return MakeExelFileStream(operations, timezone.Hours); @@ -102,8 +100,12 @@ namespace AsbCloudInfrastructure.Services.WellOperationService public Stream GetExcelTemplateStream() { + var resourceName = System.Reflection.Assembly.GetExecutingAssembly() + .GetManifestResourceNames() + .FirstOrDefault(n => n.EndsWith("WellOperationImportTemplate.xlsx"))!; + var stream = System.Reflection.Assembly.GetExecutingAssembly() - .GetManifestResourceStream("AsbCloudInfrastructure.Services.WellOperationService.WellOperationImportTemplate.xlsx"); + .GetManifestResourceStream(resourceName)!; return stream; } @@ -126,14 +128,16 @@ namespace AsbCloudInfrastructure.Services.WellOperationService if (planOperations.Any()) { var sheetPlan = workbook.Worksheets.FirstOrDefault(ws => ws.Name == sheetNamePlan); - AddOperationsToSheet(sheetPlan, planOperations, timezoneOffset); + if (sheetPlan is not null) + AddOperationsToSheet(sheetPlan, planOperations, timezoneOffset); } var factOperations = operations.Where(o => o.IdType == 1); if (factOperations.Any()) { var sheetFact = workbook.Worksheets.FirstOrDefault(ws => ws.Name == sheetNameFact); - AddOperationsToSheet(sheetFact, factOperations, timezoneOffset); + if (sheetFact is not null) + AddOperationsToSheet(sheetFact, factOperations, timezoneOffset); } } @@ -328,4 +332,5 @@ namespace AsbCloudInfrastructure.Services.WellOperationService return operation; } } +#nullable disable } From b61808e0627828ef2efff4c6e11aaa07ffadb037 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Fri, 14 Apr 2023 10:11:15 +0500 Subject: [PATCH 5/8] =?UTF-8?q?nullable=20enable=20(=D1=87=D0=B0=D1=81?= =?UTF-8?q?=D1=82=D1=8C=204)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudInfrastructure/ReportDataSourcePgCloud.cs | 7 ++++++- AsbCloudInfrastructure/Startup.cs | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/AsbCloudInfrastructure/ReportDataSourcePgCloud.cs b/AsbCloudInfrastructure/ReportDataSourcePgCloud.cs index f85a3108..c32f426d 100644 --- a/AsbCloudInfrastructure/ReportDataSourcePgCloud.cs +++ b/AsbCloudInfrastructure/ReportDataSourcePgCloud.cs @@ -8,6 +8,7 @@ using System.Linq; namespace AsbCloudInfrastructure { +#nullable enable public class ReportDataSourcePgCloud : IReportDataSource { private readonly IAsbCloudDbContext context; @@ -37,6 +38,9 @@ namespace AsbCloudInfrastructure .Include(w => w.Telemetry) .FirstOrDefault(w => w.Id == idWell); + if(well is null) + throw new ArgumentInvalidException("idWell doesn`t exist", nameof(idWell)); + idTelemetry = well?.IdTelemetry; if (idTelemetry is null) throw new ArgumentInvalidException($"Well {idWell} doesn't contain telemetry", nameof(idWell)); @@ -49,7 +53,7 @@ namespace AsbCloudInfrastructure .Where(u => u.IdTelemetry == idTelemetry) .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 { @@ -155,4 +159,5 @@ namespace AsbCloudInfrastructure public WellInfoReport GetWellInfo() => info; } +#nullable disable } diff --git a/AsbCloudInfrastructure/Startup.cs b/AsbCloudInfrastructure/Startup.cs index e93dc5e5..4ffdcf2f 100644 --- a/AsbCloudInfrastructure/Startup.cs +++ b/AsbCloudInfrastructure/Startup.cs @@ -13,6 +13,7 @@ using AsbCloudInfrastructure.Background; namespace AsbCloudInfrastructure { +#nullable enable public class Startup { public static void BeforeRunHandler(IHost host) @@ -20,7 +21,7 @@ namespace AsbCloudInfrastructure using var scope = host.Services.CreateScope(); var provider = scope.ServiceProvider; - var context = provider.GetService(); + var context = provider.GetRequiredService(); context.Database.SetCommandTimeout(TimeSpan.FromSeconds(2 * 60)); context.Database.Migrate(); @@ -70,4 +71,5 @@ namespace AsbCloudInfrastructure return bytes.ToString("### ### ###"); } } +#nullable disable } From e77f542207d7e72a3f5928544055bf23976e9959 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Fri, 14 Apr 2023 10:14:37 +0500 Subject: [PATCH 6/8] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudInfrastructure/ReportDataSourcePgCloud.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AsbCloudInfrastructure/ReportDataSourcePgCloud.cs b/AsbCloudInfrastructure/ReportDataSourcePgCloud.cs index c32f426d..1fdc7d21 100644 --- a/AsbCloudInfrastructure/ReportDataSourcePgCloud.cs +++ b/AsbCloudInfrastructure/ReportDataSourcePgCloud.cs @@ -53,7 +53,7 @@ namespace AsbCloudInfrastructure .Where(u => u.IdTelemetry == idTelemetry) .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 { From 4ac3afdabf1410d06b43f0fa30583910cee9577e Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Fri, 14 Apr 2023 15:23:43 +0500 Subject: [PATCH 7/8] =?UTF-8?q?#nullable=20enable=20(=D1=83=D1=81=D1=82?= =?UTF-8?q?=D1=80=D0=B0=D0=BD=D0=B5=D0=BD=D0=B8=D0=B5=20warnings)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repository/WitsRecordRepository.cs | 5 +---- .../DrillingProgram/DrillingProgramService.cs | 20 +++++++++++++++---- .../Services/WellFinalDocumentsService.cs | 20 +++++++++++++++---- .../ScheduleReportService.cs | 2 +- 4 files changed, 34 insertions(+), 13 deletions(-) diff --git a/AsbCloudInfrastructure/Repository/WitsRecordRepository.cs b/AsbCloudInfrastructure/Repository/WitsRecordRepository.cs index bf98daa5..8eaddbe1 100644 --- a/AsbCloudInfrastructure/Repository/WitsRecordRepository.cs +++ b/AsbCloudInfrastructure/Repository/WitsRecordRepository.cs @@ -1,5 +1,4 @@ using AsbCloudApp.Services; -using AsbCloudDb; using AsbCloudDb.Model; using Mapster; using Microsoft.EntityFrameworkCore; @@ -54,9 +53,7 @@ namespace AsbCloudInfrastructure.Repository .Where(d => d.DateTime <= end) .AsNoTracking(); var data = await query.ToListAsync(token); - return data - .Where(d => d is not null) - .Select(d => Convert(d, timezoneHours)); + return data.Select(d => Convert(d, timezoneHours)); } public async Task> GetLastAsync(int idTelemetry, CancellationToken token) diff --git a/AsbCloudInfrastructure/Services/DrillingProgram/DrillingProgramService.cs b/AsbCloudInfrastructure/Services/DrillingProgram/DrillingProgramService.cs index 816cd836..78f15615 100644 --- a/AsbCloudInfrastructure/Services/DrillingProgram/DrillingProgramService.cs +++ b/AsbCloudInfrastructure/Services/DrillingProgram/DrillingProgramService.cs @@ -369,10 +369,13 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram { var file = await fileService.GetOrDefaultAsync(fileMark.IdFile, token); var well = await wellService.GetOrDefaultAsync(file!.IdWell, token); + if (well is null) + throw new ArgumentInvalidException("idWell doesn`t exist", nameof(file.IdWell)); + var user = file.Author!; var factory = new DrillingMailBodyFactory(configuration); var subject = factory.MakeSubject(well, "Загруженный вами документ полностью согласован"); - var body = factory.MakeMailBodyForPublisherOnFullAccept(well, user.Name, file.Id, file.Name); + var body = factory.MakeMailBodyForPublisherOnFullAccept(well, user.Name ?? string.Empty, file.Id, file.Name); emailService.EnqueueSend(user.Email, subject, body); } @@ -381,10 +384,13 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram { var file = await fileService.GetOrDefaultAsync(fileMark.IdFile, token); var well = await wellService.GetOrDefaultAsync(file!.IdWell, token); + if (well is null) + throw new ArgumentInvalidException("idWell doesn`t exist", nameof(file.IdWell)); + var user = file.Author!; var factory = new DrillingMailBodyFactory(configuration); var subject = factory.MakeSubject(well, "Загруженный вами документ отклонен"); - var body = factory.MakeMailBodyForPublisherOnReject(well, user.Name, file.Id, file.Name, fileMark); + var body = factory.MakeMailBodyForPublisherOnReject(well, user.Name ?? string.Empty, file.Id, file.Name, fileMark); emailService.EnqueueSend(user.Email, subject, body); } @@ -392,6 +398,9 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram private async Task NotifyApproversAsync(DrillingProgramPart part, int idFile, string fileName, CancellationToken token) { var well = await wellService.GetOrDefaultAsync(part.IdWell, token); + if (well is null) + throw new ArgumentInvalidException("idWell doesn`t exist", nameof(part.IdWell)); + var factory = new DrillingMailBodyFactory(configuration); var subject = factory.MakeSubject(well, "Загружен новый документ для согласования."); var users = part.RelatedUsers @@ -400,7 +409,7 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram foreach (var user in users) { - var body = factory.MakeMailBodyForApproverNewFile(well, user.Name, idFile, fileName); + var body = factory.MakeMailBodyForApproverNewFile(well, user.Name ?? string.Empty, idFile, fileName); emailService.EnqueueSend(user.Email, subject, body); } } @@ -408,9 +417,12 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram private async Task NotifyNewPublisherAsync(int idWell, UserDto user, string documentCategory, CancellationToken token) { var well = await wellService.GetOrDefaultAsync(idWell, token); + if (well is null) + throw new ArgumentInvalidException("idWell doesn`t exist", nameof(idWell)); + var factory = new DrillingMailBodyFactory(configuration); var subject = factory.MakeSubject(well, $"От вас ожидается загрузка на портал документа «{documentCategory}»"); - var body = factory.MakeMailBodyForNewPublisher(well, user.Name, documentCategory); + var body = factory.MakeMailBodyForNewPublisher(well, user.Name ?? string.Empty, documentCategory); emailService.EnqueueSend(user.Email, subject, body); } diff --git a/AsbCloudInfrastructure/Services/WellFinalDocumentsService.cs b/AsbCloudInfrastructure/Services/WellFinalDocumentsService.cs index 91121ef6..e683532a 100644 --- a/AsbCloudInfrastructure/Services/WellFinalDocumentsService.cs +++ b/AsbCloudInfrastructure/Services/WellFinalDocumentsService.cs @@ -125,18 +125,30 @@ namespace AsbCloudInfrastructure.Services { var category = await fileCategoryService.GetOrDefaultAsync(item.IdCategory, token); var well = await wellService.GetOrDefaultAsync(item.IdWell, token); + if(well is null) + throw new ArgumentInvalidException("idWell doesn`t exist", nameof(item.IdWell)); - SendMessage(well, user, category.Name, message); + SendMessage(well, user, category?.Name ?? string.Empty, message); } } } - private void SendMessage(WellDto? well, UserDto user, string documentCategory, string message) + private void SendMessage(WellDto well, UserDto user, string documentCategory, string message) { var factory = new WellFinalDocumentMailBodyFactory(configuration); var subject = factory.MakeSubject(well, documentCategory); - var body = factory.MakeMailBodyForWellFinalDocument(well, user.Name ?? user.Surname, string.Format(message, documentCategory)); - emailService.EnqueueSend(user.Email, subject, body); + + if(!string.IsNullOrEmpty(user.Email)) + { + var body = factory.MakeMailBodyForWellFinalDocument( + well, + (user.Name ?? user.Surname ?? string.Empty), + string.Format(message, documentCategory) + ); + + emailService.EnqueueSend(user.Email, subject, body); + } + } } #nullable disable diff --git a/AsbCloudInfrastructure/Services/WellOperationService/ScheduleReportService.cs b/AsbCloudInfrastructure/Services/WellOperationService/ScheduleReportService.cs index 703d815f..028b16e0 100644 --- a/AsbCloudInfrastructure/Services/WellOperationService/ScheduleReportService.cs +++ b/AsbCloudInfrastructure/Services/WellOperationService/ScheduleReportService.cs @@ -82,7 +82,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService var tvdList = tvd.ToList(); var facts = tvd .Where(t => t.Fact is not null) - .Select(t => t.Fact) + .Select(t => t.Fact!) .ToList(); DateTime lastFactDate = default; From fe29dae8f571d362922a23bd5cb62421c37ed919 Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Mon, 17 Apr 2023 18:04:38 +0500 Subject: [PATCH 8/8] =?UTF-8?q?Email.BaseFactory.GetImageBase64()=20=D0=92?= =?UTF-8?q?=D0=BE=D0=B7=D0=B2=D1=80=D0=B0=D1=89=D0=B0=D0=B5=D1=82=20=D0=BF?= =?UTF-8?q?=D1=83=D1=81=D1=82=D1=83=D1=8E=20=D1=81=D1=82=D1=80=D0=BE=D0=BA?= =?UTF-8?q?=D1=83=20=D0=B5=D1=81=D0=BB=D0=B8=20=D1=84=D0=B0=D0=B9=D0=BB=20?= =?UTF-8?q?=D0=BD=D0=B5=20=D0=BD=D0=B0=D0=B9=D0=B4=D0=B5=D0=BD.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/Email/BaseFactory.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/AsbCloudInfrastructure/Services/Email/BaseFactory.cs b/AsbCloudInfrastructure/Services/Email/BaseFactory.cs index 4e6d3084..8e44725f 100644 --- a/AsbCloudInfrastructure/Services/Email/BaseFactory.cs +++ b/AsbCloudInfrastructure/Services/Email/BaseFactory.cs @@ -22,16 +22,23 @@ namespace AsbCloudInfrastructure.Services.Email supportMail = configuration.GetValue("email:supportMail", "support@digitaldrilling.ru"); } - public static string GetImageBase64(string resourceFileName) + public static string GetOrEmptyImageBase64(string resourceFileName) { if (string.IsNullOrEmpty(resourceFileName)) throw new ArgumentInvalidException("ResourceFileName doesn`t exist", nameof(resourceFileName)); var baseDir = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) ?? string.Empty; - var resoursesDir = "Res"; + var resourcesDir = "Res"; + + var logoFilePath = Path.Combine(baseDir, resourcesDir, resourceFileName); + + if (!File.Exists(logoFilePath)) + { + System.Diagnostics.Trace.TraceWarning($"GetOrEmptyImageBase64(). File {logoFilePath} not found."); + return string.Empty; + } - var logoFilePath = Path.Combine(baseDir, resoursesDir, resourceFileName); var imageBytes = File.ReadAllBytes(logoFilePath); var format = Path.GetExtension(resourceFileName).Trim('.'); return "data:image/" + format + ";base64," + Convert.ToBase64String(imageBytes); @@ -42,7 +49,7 @@ namespace AsbCloudInfrastructure.Services.Email public string MakeSignatue() { - var logo = GetImageBase64("logo_32.png"); + var logo = GetOrEmptyImageBase64("logo_32.png"); var sign = $"

---

" + $"{companyName}
" + $"Это письмо сформировано автоматически.
" +