diff --git a/AsbCloudDb/Model/AsbCloudDbContext.cs b/AsbCloudDb/Model/AsbCloudDbContext.cs index 9fdbdc1d..c7651ff6 100644 --- a/AsbCloudDb/Model/AsbCloudDbContext.cs +++ b/AsbCloudDb/Model/AsbCloudDbContext.cs @@ -154,7 +154,7 @@ namespace AsbCloudDb.Model FillData(modelBuilder); } - private void FillData(ModelBuilder modelBuilder) + private static void FillData(ModelBuilder modelBuilder) { modelBuilder.Entity(entity => { @@ -210,9 +210,9 @@ namespace AsbCloudDb.Model }).FirstOrDefault(); if (datesRange is null) - return (From: DateTime.MinValue, To: DateTime.MaxValue); + return (DateTime.MinValue, DateTime.MaxValue); - return (From: datesRange.From, To: datesRange.To); + return (datesRange.From, datesRange.To); } public async Task CreatePartitionAsync(string propertyName, int id, CancellationToken token = default) diff --git a/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj b/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj index a934217c..4924a523 100644 --- a/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj +++ b/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj @@ -4,6 +4,10 @@ net5.0 + + 1701;1702;IDE0090;IDE0063 + + diff --git a/AsbCloudInfrastructure/Services/AuthService.cs b/AsbCloudInfrastructure/Services/AuthService.cs index da136f92..531355d8 100644 --- a/AsbCloudInfrastructure/Services/AuthService.cs +++ b/AsbCloudInfrastructure/Services/AuthService.cs @@ -128,7 +128,7 @@ namespace AsbCloudInfrastructure.Services return 0; } - private string MakeToken(IEnumerable claims) + private static string MakeToken(IEnumerable claims) { var now = DateTime.Now; diff --git a/AsbCloudInfrastructure/Services/BackgroundQueue.cs b/AsbCloudInfrastructure/Services/BackgroundQueue.cs index a182bdcd..f44de1a6 100644 --- a/AsbCloudInfrastructure/Services/BackgroundQueue.cs +++ b/AsbCloudInfrastructure/Services/BackgroundQueue.cs @@ -6,7 +6,7 @@ namespace AsbCloudInfrastructure.Services { class BackgroundQueue : IBackgroundQueue { - private ConcurrentQueue<(Action action, int id)> tasks = + private readonly ConcurrentQueue<(Action action, int id)> tasks = new ConcurrentQueue<(Action action, int id)>(); private int id = 0; diff --git a/AsbCloudInfrastructure/Services/BackgroundWorkerService.cs b/AsbCloudInfrastructure/Services/BackgroundWorkerService.cs index 7510cbb8..4c40f398 100644 --- a/AsbCloudInfrastructure/Services/BackgroundWorkerService.cs +++ b/AsbCloudInfrastructure/Services/BackgroundWorkerService.cs @@ -21,7 +21,7 @@ namespace AsbCloudInfrastructure.Services while (!token.IsCancellationRequested) { if (tasksQueue.TryDequeue(out var item)) - await Task.Run(item.action); + await Task.Run(item.action, token); else await Task.Delay(100, token); } diff --git a/AsbCloudInfrastructure/Services/DataService.cs b/AsbCloudInfrastructure/Services/DataService.cs index 7a757025..5dc58c56 100644 --- a/AsbCloudInfrastructure/Services/DataService.cs +++ b/AsbCloudInfrastructure/Services/DataService.cs @@ -68,7 +68,7 @@ namespace AsbCloudInfrastructure.Services public void UpdateData(string uid, IEnumerable dtos) { - if (dtos == default || dtos.Count() <= 0) + if (dtos == default || dtos.Any()) return; var telemetryId = telemetryService.GetOrCreateTemetryIdByUid(uid); @@ -102,9 +102,9 @@ namespace AsbCloudInfrastructure.Services if (telemetry is null) return null; - var result = db.GetDatesRange(telemetry.Id); + var (From, To) = db.GetDatesRange(telemetry.Id); - return new DatesRangeDto { From = result.From, To = result.To}; + return new DatesRangeDto { From = From, To = To}; } } } diff --git a/AsbCloudInfrastructure/Services/MessageService.cs b/AsbCloudInfrastructure/Services/MessageService.cs index 477e59b3..cf643b9b 100644 --- a/AsbCloudInfrastructure/Services/MessageService.cs +++ b/AsbCloudInfrastructure/Services/MessageService.cs @@ -17,8 +17,6 @@ namespace AsbCloudInfrastructure.Services private readonly IMapper mapper; private readonly ICacheTable cacheEvents; private readonly ICacheTable cacheTUsers; - private readonly ICacheTable cacheTelemetry; - private readonly ICacheTable cacheWells; public MessageService(IAsbCloudDbContext db, CacheDb cacheDb, ITelemetryService telemetryService, MapperConfiguration mapperConfiguration) { @@ -27,8 +25,6 @@ namespace AsbCloudInfrastructure.Services mapper = mapperConfiguration.CreateMapper(); cacheEvents = cacheDb.GetCachedTable((AsbCloudDbContext)db); cacheTUsers = cacheDb.GetCachedTable((AsbCloudDbContext)db); - cacheTelemetry = cacheDb.GetCachedTable((AsbCloudDbContext)db); - cacheWells = cacheDb.GetCachedTable((AsbCloudDbContext)db); } public PaginationContainer GetMessages(int wellId, IEnumerable categoryids = default, DateTime begin = default, DateTime end = default, int skip = 0, int take = 32) @@ -39,20 +35,20 @@ namespace AsbCloudInfrastructure.Services var events = cacheEvents.Select(e => e.IdTelemetry == telemetry.Id); - if (events.Count() == 0) + if (events.Any()) return null; var messages = from m in db.Messages where m.IdTelemetry == telemetry.Id select m; - if ((categoryids != default) && (categoryids.Count() > 0)) + if ((categoryids != default) && (categoryids.Any())) { var eventIds = from e in events where categoryids.ToList().Contains(e.IdCategory) select e.IdEvent; - if (eventIds.Count() == 0) + if (!eventIds.Any()) return null; messages = messages.Where(m => eventIds.Contains(m.IdEvent)); @@ -108,14 +104,14 @@ namespace AsbCloudInfrastructure.Services if (telemetry is null) return null; - var result = db.GetDatesRange(telemetry.Id); + var (From, To) = db.GetDatesRange(telemetry.Id); - return new DatesRangeDto { From = result.From, To = result.To }; + return new DatesRangeDto { From = From, To = To }; } public void Insert(string uid, IEnumerable dtos) { - if (dtos.Count() == 0) + if (dtos.Any()) return; var telemetryId = telemetryService.GetOrCreateTemetryIdByUid(uid); diff --git a/AsbCloudInfrastructure/Services/ReportService.cs b/AsbCloudInfrastructure/Services/ReportService.cs index bd4cc08c..0c36611b 100644 --- a/AsbCloudInfrastructure/Services/ReportService.cs +++ b/AsbCloudInfrastructure/Services/ReportService.cs @@ -14,16 +14,14 @@ namespace AsbCloudInfrastructure.Services private readonly IAsbCloudDbContext db; private readonly IConfiguration configuration; private readonly ITelemetryService telemetryService; - private readonly IServiceProvider serviceProvider; private readonly IBackgroundQueue queue; - public ReportService(IAsbCloudDbContext db, IConfiguration configuration, ITelemetryService telemetryService, IServiceProvider serviceProvider, IBackgroundQueue queue) + public ReportService(IAsbCloudDbContext db, IConfiguration configuration, ITelemetryService telemetryService, IBackgroundQueue queue) { this.db = db; this.configuration = configuration; this.telemetryService = telemetryService; this.queue = queue; - this.serviceProvider = serviceProvider; RootPath = "reports"; } @@ -59,9 +57,9 @@ namespace AsbCloudInfrastructure.Services if (telemetry is null) return null; - var result = db.GetDatesRange(telemetry.Id); + var (From, To) = db.GetDatesRange(telemetry.Id); - return new DatesRangeDto { From = result.From, To = result.To }; + return new DatesRangeDto { From = From, To = To }; } private IReportGenerator GetReportGenerator(int wellId, DateTime begin, DateTime end, int stepSeconds, int format, AsbCloudDbContext context) diff --git a/AsbCloudWebApi/Controllers/ReportController.cs b/AsbCloudWebApi/Controllers/ReportController.cs index 118f136e..dcffe590 100644 --- a/AsbCloudWebApi/Controllers/ReportController.cs +++ b/AsbCloudWebApi/Controllers/ReportController.cs @@ -15,17 +15,13 @@ namespace AsbCloudWebApi.Controllers [ApiController] public class ReportController : ControllerBase { - private readonly IAsbCloudDbContext db; private readonly IReportService reportService; private readonly IWellService wellService; - private readonly IWebHostEnvironment appEnvironment; - public ReportController(IAsbCloudDbContext db, IReportService reportService, IWellService wellService, IWebHostEnvironment appEnvironment) + public ReportController(IReportService reportService, IWellService wellService) { - this.db = db; this.reportService = reportService; this.wellService = wellService; - this.appEnvironment = appEnvironment; } /// diff --git a/AsbCloudWebApi/Controllers/TelemetryController.cs b/AsbCloudWebApi/Controllers/TelemetryController.cs index 128d7751..e5bc24d0 100644 --- a/AsbCloudWebApi/Controllers/TelemetryController.cs +++ b/AsbCloudWebApi/Controllers/TelemetryController.cs @@ -136,9 +136,9 @@ namespace AsbCloudWebApi.Controllers /// cli.ApiTelemetryDbAsync("1", new List<FileParameter> { file }).Wait(); /// /// - /// - /// - /// + // + // + // //[HttpPost] //[Route("{uid}/db")] //public IActionResult PostDb(string uid, IFormFileCollection files)