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); }