diff --git a/AsbCloudApp/Services/IAnalyticsService.cs b/AsbCloudApp/Services/IAnalyticsService.cs index 16d22f1c..d0c83a59 100644 --- a/AsbCloudApp/Services/IAnalyticsService.cs +++ b/AsbCloudApp/Services/IAnalyticsService.cs @@ -1,20 +1,21 @@ using AsbCloudApp.Data; using System; using System.Collections.Generic; +using System.Threading.Tasks; namespace AsbCloudApp.Services { public interface IAnalyticsService { - PaginationContainer GetOperationsByWell(int idWell, + Task> GetOperationsByWellAsync(int idWell, IEnumerable categoryids = default, DateTime begin = default, DateTime end = default, int skip = 0, int take = 32); - IEnumerable GetWellDepthToDay(int idWell); - IEnumerable GetWellDepthToInterval(int idWell, + Task> GetWellDepthToDayAsync(int idWell); + Task> GetWellDepthToIntervalAsync(int idWell, int intervalHoursTimestamp, int workBeginTimestamp); - IEnumerable GetOperationsSummary(int idWell, + Task> GetOperationsSummaryAsync(int idWell, DateTime begin = default, DateTime end = default); - IEnumerable GetOperationsToInterval(int idWell, + Task> GetOperationsToIntervalAsync(int idWell, int intervalHoursTimestamp, int workBeginTimestamp); void SaveAnalytics(DataSaubBaseDto dataSaub); } diff --git a/AsbCloudApp/Services/IClusterService.cs b/AsbCloudApp/Services/IClusterService.cs index 7b121401..96a64386 100644 --- a/AsbCloudApp/Services/IClusterService.cs +++ b/AsbCloudApp/Services/IClusterService.cs @@ -1,14 +1,15 @@ using AsbCloudApp.Data; using System.Collections.Generic; +using System.Threading.Tasks; namespace AsbCloudApp.Services { public interface IClusterService { - IEnumerable GetDeposits(int idCompany); - IEnumerable GetClusters(int idCompany, int depositId); - IEnumerable GetClusters(int idCompany); - IEnumerable GetWells(int idCompany, int clusterId); - ClusterStatDto GetStat(int idCompany, int clusterId); + Task> GetDepositsAsync(int idCompany); + Task> GetClustersAsync(int idCompany, int depositId); + Task> GetClustersAsync(int idCompany); + Task> GetWellsAsync(int idCompany, int clusterId); + Task GetStatAsync(int idCompany, int clusterId); } } diff --git a/AsbCloudApp/Services/IWellService.cs b/AsbCloudApp/Services/IWellService.cs index b107cca3..503d0569 100644 --- a/AsbCloudApp/Services/IWellService.cs +++ b/AsbCloudApp/Services/IWellService.cs @@ -1,13 +1,14 @@ using AsbCloudApp.Data; using System.Collections.Generic; +using System.Threading.Tasks; namespace AsbCloudApp.Services { public interface IWellService { - IEnumerable GetWellsByCompany(int idCompany); - IEnumerable GetTransmittingWells(int idCompany); - bool IsCompanyInvolvedInWell(int idCompany, int idWell); - IEnumerable GetOperations(int idWell); + Task> GetWellsByCompanyAsync(int idCompany); + Task> GetTransmittingWellsAsync(int idCompany); + Task IsCompanyInvolvedInWellAsync(int idCompany, int idWell); + Task> GetOperationsAsync(int idWell); } } diff --git a/AsbCloudDb/Model/AsbCloudDbContext.cs b/AsbCloudDb/Model/AsbCloudDbContext.cs index 221363d0..d1632212 100644 --- a/AsbCloudDb/Model/AsbCloudDbContext.cs +++ b/AsbCloudDb/Model/AsbCloudDbContext.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; +using System.Data.Common; #nullable disable @@ -490,7 +491,7 @@ namespace AsbCloudDb.Model return (datesRange.From, datesRange.To); } - public IEnumerable<(double? MinDepth, double? MaxDepth, DateTime BeginPeriodDate)> GetDepthToInterval(int telemetryId, + public async Task> GetDepthToIntervalAsync(int telemetryId, int intervalHoursTimestamp, int workStartTimestamp, double timezoneOffset) { //TODO: Сменить на LINQ группирование @@ -502,19 +503,25 @@ namespace AsbCloudDb.Model GROUP BY floor((extract(epoch from t.date) - {workStartTimestamp} + {timezoneOffset}) / {intervalHoursTimestamp});"; Database.OpenConnection(); - using var reader = command.ExecuteReader(); - if (reader.HasRows) + using var reader = await command.ExecuteReaderAsync(); + + IEnumerable<(double? MinDepth, double? MaxDepth, DateTime BeginPeriodDate)> GetResult(DbDataReader rd) { - while (reader.Read()) + if (rd.HasRows) { - yield return - ( - (double?)reader.GetValue(0), - (double?)reader.GetValue(1), - (DateTime)reader.GetValue(2) - ); + while (reader.Read()) + { + yield return + ( + (double?)reader.GetValue(0), + (double?)reader.GetValue(1), + (DateTime)reader.GetValue(2) + ); + } } } + + return GetResult(reader); } public async Task CreatePartitionAsync(string propertyName, int id, CancellationToken token = default) diff --git a/AsbCloudDb/Model/IAsbCloudDbContext.cs b/AsbCloudDb/Model/IAsbCloudDbContext.cs index c9c0c966..7e218e93 100644 --- a/AsbCloudDb/Model/IAsbCloudDbContext.cs +++ b/AsbCloudDb/Model/IAsbCloudDbContext.cs @@ -41,7 +41,7 @@ namespace AsbCloudDb.Model IQueryable GetWellsForCompany(int idCompany); IQueryable GetUsersByLogin(string login); (DateTime From, DateTime To) GetDatesRange(int idTelemetry) where T : class, IIdTelemetryDate; - IEnumerable<(double? MinDepth, double? MaxDepth, DateTime BeginPeriodDate)> GetDepthToInterval(int telemetryId, + Task> GetDepthToIntervalAsync(int telemetryId, int intervalHoursTimestamp, int workStartTimestamp, double timezoneOffset); Task CreatePartitionAsync(string propertyName, int id, CancellationToken token = default) where TEntity : class; } diff --git a/AsbCloudInfrastructure/Services/AnalyticsService.cs b/AsbCloudInfrastructure/Services/AnalyticsService.cs index 24211480..af0b3ccf 100644 --- a/AsbCloudInfrastructure/Services/AnalyticsService.cs +++ b/AsbCloudInfrastructure/Services/AnalyticsService.cs @@ -7,6 +7,7 @@ using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; namespace AsbCloudInfrastructure.Services { @@ -30,7 +31,7 @@ namespace AsbCloudInfrastructure.Services operationDetectorService = new TelemetryOperationDetectorService(operations); } - public IEnumerable GetWellDepthToDay(int idWell) + public async Task> GetWellDepthToDayAsync(int idWell) { var telemetryId = telemetryService.GetIdTelemetryByIdWell(idWell); @@ -52,15 +53,15 @@ namespace AsbCloudInfrastructure.Services if (m > 1) depthToTimeData = depthToTimeData.Where(d => d.Id % m == 0); - return depthToTimeData.Select(d => new WellDepthToDayDto + return await depthToTimeData.Select(d => new WellDepthToDayDto { WellDepth = d.WellDepth ?? 0.0, BitDepth = d.BitDepth ?? 0.0, Date = d.Date - }).AsNoTracking().ToList(); + }).AsNoTracking().ToListAsync(); } - public IEnumerable GetWellDepthToInterval(int idWell, + public async Task> GetWellDepthToIntervalAsync(int idWell, int intervalSeconds, int workBeginSeconds) { intervalSeconds = intervalSeconds == 0 ? 86400 : intervalSeconds; @@ -72,7 +73,7 @@ namespace AsbCloudInfrastructure.Services var timezoneOffset = telemetryService.GetTimezoneOffsetByTelemetryId((int)telemetryId); - var drillingPeriodsInfo = db.GetDepthToInterval((int)telemetryId, intervalSeconds, + var drillingPeriodsInfo = await db.GetDepthToIntervalAsync((int)telemetryId, intervalSeconds, workBeginSeconds, timezoneOffset); var wellDepthToIntervalData = drillingPeriodsInfo.Select(d => new WellDepthToIntervalDto @@ -84,7 +85,7 @@ namespace AsbCloudInfrastructure.Services return wellDepthToIntervalData; } - public PaginationContainer GetOperationsByWell(int idWell, + public async Task> GetOperationsByWellAsync(int idWell, IEnumerable categoryIds = default, DateTime begin = default, DateTime end = default, int skip = 0, int take = 32) { @@ -125,7 +126,7 @@ namespace AsbCloudInfrastructure.Services if (skip > 0) operations = operations.Skip(skip); - var operationsList = operations.Take(take).AsNoTracking().ToList(); + var operationsList = await operations.Take(take).AsNoTracking().ToListAsync(); if (operationsList.Count == 0) return result; @@ -148,7 +149,7 @@ namespace AsbCloudInfrastructure.Services return result; } - public IEnumerable GetOperationsSummary(int idWell, + public async Task> GetOperationsSummaryAsync(int idWell, DateTime begin = default, DateTime end = default) { var telemetryId = telemetryService.GetIdTelemetryByIdWell(idWell); @@ -159,22 +160,22 @@ namespace AsbCloudInfrastructure.Services var unixBegin = (begin - new DateTime(1970, 1, 1)).TotalSeconds; var unixEnd = (end - new DateTime(1970, 1, 1)).TotalSeconds; - var operations = (from a in db.TelemetryAnalysis - where a.IdTelemetry == telemetryId && - a.UnixDate > unixBegin && a.UnixDate < unixEnd - join o in db.TelemetryOperations on a.IdOperation equals o.Id - group a by new { a.IdOperation, o.Name } into g - select new TelemetryOperationDurationDto - { - OperationName = g.Key.Name, - Duration = g.Where(g => g.DurationSec > 0) - .Sum(a => a.DurationSec) - }).AsNoTracking().ToList(); + var operations = await (from a in db.TelemetryAnalysis + where a.IdTelemetry == telemetryId && + a.UnixDate > unixBegin && a.UnixDate < unixEnd + join o in db.TelemetryOperations on a.IdOperation equals o.Id + group a by new { a.IdOperation, o.Name } into g + select new TelemetryOperationDurationDto + { + OperationName = g.Key.Name, + Duration = g.Where(g => g.DurationSec > 0) + .Sum(a => a.DurationSec) + }).AsNoTracking().ToListAsync(); return operations; } - public IEnumerable GetOperationsToInterval(int idWell, + public async Task> GetOperationsToIntervalAsync(int idWell, int intervalSeconds, int workBeginSeconds) { intervalSeconds = intervalSeconds == 0 ? 86400 : intervalSeconds; @@ -186,21 +187,21 @@ namespace AsbCloudInfrastructure.Services var timezoneOffset = telemetryService.GetTimezoneOffsetByTelemetryId((int)telemetryId); - var operations = (from a in db.TelemetryAnalysis - where a.IdTelemetry == telemetryId - join o in db.TelemetryOperations on a.IdOperation equals o.Id - group a by new - { - Interval = Math.Floor((a.UnixDate - workBeginSeconds + timezoneOffset) / intervalSeconds), - OperationId = a.IdOperation, - o.Name - } into g - select new - { - IntervalStart = g.Min(d => d.UnixDate), - OperationName = g.Key.Name, - OperationsDuration = g.Sum(an => an.DurationSec) - }).AsNoTracking().ToList(); + var operations = await (from a in db.TelemetryAnalysis + where a.IdTelemetry == telemetryId + join o in db.TelemetryOperations on a.IdOperation equals o.Id + group a by new + { + Interval = Math.Floor((a.UnixDate - workBeginSeconds + timezoneOffset) / intervalSeconds), + OperationId = a.IdOperation, + o.Name + } into g + select new + { + IntervalStart = g.Min(d => d.UnixDate), + OperationName = g.Key.Name, + OperationsDuration = g.Sum(an => an.DurationSec) + }).AsNoTracking().ToListAsync(); var operationsGroupedByInterval = operations.GroupBy(op => op.IntervalStart) .Select(o => new TelemetryOperationInfoDto diff --git a/AsbCloudInfrastructure/Services/ClusterService.cs b/AsbCloudInfrastructure/Services/ClusterService.cs index ef71692f..0539783e 100644 --- a/AsbCloudInfrastructure/Services/ClusterService.cs +++ b/AsbCloudInfrastructure/Services/ClusterService.cs @@ -4,6 +4,7 @@ using AsbCloudDb.Model; using Microsoft.EntityFrameworkCore; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; namespace AsbCloudInfrastructure.Services { @@ -16,15 +17,15 @@ namespace AsbCloudInfrastructure.Services this.db = db; } - public IEnumerable GetDeposits(int idCompany) + public async Task> GetDepositsAsync(int idCompany) { - var wellEntities = (from well in db.Wells + var wellEntities = await (from well in db.Wells .Include(w => w.RelationCompaniesWells) .Include(w => w.WellType) .Include(w => w.Cluster) .ThenInclude(c => c.Deposit) where well.RelationCompaniesWells.Any(r => r.IdCompany == idCompany) - select well).AsNoTracking().ToList(); + select well).AsNoTracking().ToListAsync(); var gDepositEntities = wellEntities .GroupBy(w => w.Cluster) @@ -60,13 +61,13 @@ namespace AsbCloudInfrastructure.Services return dtos; } - public IEnumerable GetClusters(int idCompany) + public async Task> GetClustersAsync(int idCompany) { - var entities = db.GetWellsForCompany(idCompany) + var entities = await db.GetWellsForCompany(idCompany) .Select(e => e.Cluster) .Distinct() .AsNoTracking() - .ToList(); + .ToListAsync(); var dtos = entities.Select(e => new ClusterDto { @@ -79,14 +80,14 @@ namespace AsbCloudInfrastructure.Services return dtos; } - public IEnumerable GetClusters(int idCompany, int depositId) + public async Task> GetClustersAsync(int idCompany, int depositId) { - var entities = db.GetWellsForCompany(idCompany) + var entities = await db.GetWellsForCompany(idCompany) .Select(e => e.Cluster) .Where(e => e.IdDeposit == depositId) .Distinct() .AsNoTracking() - .ToList(); + .ToListAsync(); var dtos = entities.Select(e => new ClusterDto { @@ -99,12 +100,12 @@ namespace AsbCloudInfrastructure.Services return dtos; } - public IEnumerable GetWells(int idCompany, int idCluster) + public async Task> GetWellsAsync(int idCompany, int idCluster) { - var entities = db.GetWellsForCompany(idCompany) + var entities = await db.GetWellsForCompany(idCompany) .Where(e => e.IdCluster == idCluster) .AsNoTracking() - .ToList(); + .ToListAsync(); var dtos = entities.Select(e => new WellDto { @@ -119,13 +120,13 @@ namespace AsbCloudInfrastructure.Services return dtos; } - public ClusterStatDto GetStat(int idCompany, int idCluster) + public async Task GetStatAsync(int idCompany, int idCluster) { var wellEntities = from w in db.Wells where w.IdCluster == idCluster && w.RelationCompaniesWells.Any(c => c.IdCompany == idCompany) select w; - var wellStatDtos = wellEntities.Select(e => new WellStatDto + var wellStatDtos = await wellEntities.Select(e => new WellStatDto { Id = e.Id, Caption = e.Caption, @@ -167,7 +168,7 @@ namespace AsbCloudInfrastructure.Services CompanyType = c.Company.CompanyType.Caption, }), WellType = e.WellType.Caption, - }).AsNoTracking().ToList(); + }).AsNoTracking().ToListAsync(); if (!wellStatDtos.Any()) return null; diff --git a/AsbCloudInfrastructure/Services/WellService.cs b/AsbCloudInfrastructure/Services/WellService.cs index e0e42a5f..1475e3e1 100644 --- a/AsbCloudInfrastructure/Services/WellService.cs +++ b/AsbCloudInfrastructure/Services/WellService.cs @@ -6,6 +6,8 @@ using Mapster; using System; using System.Collections.Generic; using System.Linq; +using System.Threading; +using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; namespace AsbCloudInfrastructure.Services @@ -23,36 +25,35 @@ namespace AsbCloudInfrastructure.Services cacheRelationCompaniesWells = cacheDb.GetCachedTable((AsbCloudDbContext)db); } - public IEnumerable GetTransmittingWells(int idCompany) + public async Task> GetTransmittingWellsAsync(int idCompany) { var wells = new List(); IEnumerable activeTelemetriesUids = telemetryTracker.GetTransmittingTelemetryUids(); if (activeTelemetriesUids.Any()) { - wells = db.GetWellsForCompany(idCompany) + wells = await db.GetWellsForCompany(idCompany) .Where(w => activeTelemetriesUids.Contains(w.Telemetry.RemoteUid)) .AsNoTracking() - .ToList(); + .ToListAsync(); } return wells.Select(w => From(w)); } - public IEnumerable GetWellsByCompany(int idCompany) + public async Task> GetWellsByCompanyAsync(int idCompany) { - var wells = db.GetWellsForCompany(idCompany).ToList(); + var wells = await db.GetWellsForCompany(idCompany).ToListAsync(); return wells.Select(w => From(w)); } - public bool IsCompanyInvolvedInWell(int idCompany, int idWell) - => cacheRelationCompaniesWells.Contains(r => r.IdWell == idWell && r.IdCompany == idCompany); + public async Task IsCompanyInvolvedInWellAsync(int idCompany, int idWell) + => await cacheRelationCompaniesWells.ContainsAsync(r => r.IdWell == idWell && + r.IdCompany == idCompany, new CancellationToken()); - public IEnumerable GetOperations(int idWell) + public async Task> GetOperationsAsync(int idWell) { - var entities = db - .WellOperations - .Where(o => o.IdWell == idWell) + var entities = await db.WellOperations.Where(o => o.IdWell == idWell) .AsNoTracking() - .ToList(); + .ToListAsync(); var dtos = entities.Adapt(); diff --git a/AsbCloudWebApi/Controllers/AnalyticsController.cs b/AsbCloudWebApi/Controllers/AnalyticsController.cs index 93c0d07c..ccf6d5ed 100644 --- a/AsbCloudWebApi/Controllers/AnalyticsController.cs +++ b/AsbCloudWebApi/Controllers/AnalyticsController.cs @@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; namespace AsbCloudWebApi.Controllers { @@ -35,15 +36,15 @@ namespace AsbCloudWebApi.Controllers [HttpGet] [Route("{idWell}/operationsByWell")] [ProducesResponseType(typeof(PaginationContainer), (int)System.Net.HttpStatusCode.OK)] - public IActionResult GetOperationsByWell(int idWell, int skip = 0, int take = 32, + public async Task GetOperationsByWellAsync(int idWell, int skip = 0, int take = 32, [FromQuery] IEnumerable categoryIds = default, DateTime begin = default, DateTime end = default) { int? idCompany = User.GetCompanyId(); - if (idCompany is null || !wellService.IsCompanyInvolvedInWell((int)idCompany, idWell)) + if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell)) return Forbid(); - var analytics = analyticsService.GetOperationsByWell(idWell, categoryIds, begin, end, skip, take); + var analytics = await analyticsService.GetOperationsByWellAsync(idWell, categoryIds, begin, end, skip, take); if (analytics is null || analytics.Count == 0) return NoContent(); @@ -59,14 +60,14 @@ namespace AsbCloudWebApi.Controllers [HttpGet] [Route("{idWell}/wellDepthToDay")] [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] - public IActionResult GetWellDepthToDay(int idWell) + public async Task GetWellDepthToDayAsync(int idWell) { int? idCompany = User.GetCompanyId(); - if (idCompany is null || !wellService.IsCompanyInvolvedInWell((int)idCompany, idWell)) + if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell)) return Forbid(); - var wellDepthToDayData = analyticsService.GetWellDepthToDay(idWell); + var wellDepthToDayData = await analyticsService.GetWellDepthToDayAsync(idWell); if (wellDepthToDayData is null || !wellDepthToDayData.Any()) return NoContent(); @@ -84,15 +85,15 @@ namespace AsbCloudWebApi.Controllers [HttpGet] [Route("{idWell}/wellDepthToInterval")] [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] - public IActionResult GetWellDepthToInterval(int idWell, + public async Task GetWellDepthToIntervalAsync(int idWell, int intervalSeconds, int workBeginSeconds) { int? idCompany = User.GetCompanyId(); - if (idCompany is null || !wellService.IsCompanyInvolvedInWell((int)idCompany, idWell)) + if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync ((int)idCompany, idWell)) return Forbid(); - var wellDepthToIntervalData = analyticsService.GetWellDepthToInterval(idWell, + var wellDepthToIntervalData = await analyticsService.GetWellDepthToIntervalAsync(idWell, intervalSeconds, workBeginSeconds); if (wellDepthToIntervalData is null || !wellDepthToIntervalData.Any()) @@ -111,14 +112,14 @@ namespace AsbCloudWebApi.Controllers [HttpGet] [Route("{idWell}/operationsSummary")] [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] - public IActionResult GetOperationsSummary(int idWell, DateTime begin = default, DateTime end = default) + public async Task GetOperationsSummaryAsync(int idWell, DateTime begin = default, DateTime end = default) { int? idCompany = User.GetCompanyId(); - if (idCompany is null || !wellService.IsCompanyInvolvedInWell((int)idCompany, idWell)) + if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync ((int)idCompany, idWell)) return Forbid(); - var analytics = analyticsService.GetOperationsSummary(idWell, begin, end); + var analytics = await analyticsService .GetOperationsSummaryAsync(idWell, begin, end); if (analytics is null || !analytics.Any()) return NoContent(); @@ -136,15 +137,15 @@ namespace AsbCloudWebApi.Controllers [HttpGet] [Route("{idWell}/operationsToInterval")] [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] - public IActionResult GetOperationsToInterval(int idWell, + public async Task GetOperationsToIntervalAsync(int idWell, int intervalSeconds, int workBeginSeconds) { int? idCompany = User.GetCompanyId(); - if (idCompany is null || !wellService.IsCompanyInvolvedInWell((int)idCompany, idWell)) + if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync ((int)idCompany, idWell)) return Forbid(); - var analytics = analyticsService.GetOperationsToInterval(idWell, intervalSeconds, workBeginSeconds); + var analytics = await analyticsService.GetOperationsToIntervalAsync(idWell, intervalSeconds, workBeginSeconds); if (analytics is null || !analytics.Any()) return NoContent(); diff --git a/AsbCloudWebApi/Controllers/ClusterController.cs b/AsbCloudWebApi/Controllers/ClusterController.cs index 528a55f2..e43ede33 100644 --- a/AsbCloudWebApi/Controllers/ClusterController.cs +++ b/AsbCloudWebApi/Controllers/ClusterController.cs @@ -3,6 +3,7 @@ using AsbCloudApp.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using System.Collections.Generic; +using System.Threading.Tasks; namespace AsbCloudWebApi.Controllers { @@ -27,14 +28,14 @@ namespace AsbCloudWebApi.Controllers /// [HttpGet()] [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] - public IActionResult GetClusters() + public async Task GetClustersAsync() { int? idCompany = User.GetCompanyId(); if (idCompany is null) return Forbid(); - var result = clusterService.GetClusters((int)idCompany); + var result = await clusterService.GetClustersAsync((int)idCompany); return Ok(result); } @@ -45,14 +46,14 @@ namespace AsbCloudWebApi.Controllers /// [HttpGet("{idCluster}")] [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] - public IActionResult GetWells(int idCluster) + public async Task GetWellsAsync(int idCluster) { int? idCompany = User.GetCompanyId(); if (idCompany is null) return Forbid(); - var result = clusterService.GetWells((int)idCompany, idCluster); + var result = await clusterService.GetWellsAsync((int)idCompany, idCluster); return Ok(result); } @@ -63,14 +64,14 @@ namespace AsbCloudWebApi.Controllers /// [HttpGet("{idCluster}/Stat")] [ProducesResponseType(typeof(ClusterStatDto), (int)System.Net.HttpStatusCode.OK)] - public IActionResult GetStat(int idCluster) + public async Task GetStatAsync(int idCluster) { int? idCompany = User.GetCompanyId(); if (idCompany is null) return Forbid(); - var result = clusterService.GetStat((int)idCompany, idCluster); + var result = await clusterService.GetStatAsync((int)idCompany, idCluster); return Ok(result); } } diff --git a/AsbCloudWebApi/Controllers/DataController.cs b/AsbCloudWebApi/Controllers/DataController.cs index 059f2674..e21007ff 100644 --- a/AsbCloudWebApi/Controllers/DataController.cs +++ b/AsbCloudWebApi/Controllers/DataController.cs @@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; namespace AsbCloudWebApi.Controllers { @@ -52,14 +53,14 @@ namespace AsbCloudWebApi.Controllers [HttpGet] [Route("{idWell}/dataDatesRange")] [ProducesResponseType(typeof(DatesRangeDto), (int)System.Net.HttpStatusCode.OK)] - public IActionResult GetDataDatesRange(int idWell) + public async Task GetDataDatesRangeAsync(int idWell) { int? idCompany = User.GetCompanyId(); if (idCompany is null) return Forbid(); - bool isCompanyOwnsWell = wellService.IsCompanyInvolvedInWell((int)idCompany, idWell); + bool isCompanyOwnsWell = await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell); if (!isCompanyOwnsWell) return Forbid(); diff --git a/AsbCloudWebApi/Controllers/DepositController.cs b/AsbCloudWebApi/Controllers/DepositController.cs index e38366e8..1bb43de3 100644 --- a/AsbCloudWebApi/Controllers/DepositController.cs +++ b/AsbCloudWebApi/Controllers/DepositController.cs @@ -3,6 +3,7 @@ using AsbCloudApp.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using System.Collections.Generic; +using System.Threading.Tasks; namespace AsbCloudWebApi.Controllers { @@ -27,14 +28,14 @@ namespace AsbCloudWebApi.Controllers /// [HttpGet] [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] - public IActionResult GetDeposits() + public async Task GetDepositsAsync() { int? idCompany = User.GetCompanyId(); if (idCompany is null) return Forbid(); - var result = clusterService.GetDeposits((int)idCompany); + var result = await clusterService.GetDepositsAsync((int)idCompany); return Ok(result); } @@ -45,14 +46,14 @@ namespace AsbCloudWebApi.Controllers /// [HttpGet("{depositId}")] [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] - public IActionResult GetClusters(int depositId) + public async Task GetClustersAsync(int depositId) { int? idCompany = User.GetCompanyId(); if (idCompany is null) return Forbid(); - var result = clusterService.GetClusters((int)idCompany, depositId); + var result = await clusterService.GetClustersAsync((int)idCompany, depositId); return Ok(result); } diff --git a/AsbCloudWebApi/Controllers/FileController.cs b/AsbCloudWebApi/Controllers/FileController.cs index ff0c3204..383272e5 100644 --- a/AsbCloudWebApi/Controllers/FileController.cs +++ b/AsbCloudWebApi/Controllers/FileController.cs @@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Mvc; using System; using System.IO; using System.Linq; +using System.Threading.Tasks; namespace AsbCloudWebApi.Controllers { @@ -34,7 +35,7 @@ namespace AsbCloudWebApi.Controllers [HttpPost] [Route("{idWell}/files")] [ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)] - public IActionResult SaveFiles(int idWell, int idCategory, int idUser, + public async Task SaveFilesAsync(int idWell, int idCategory, int idUser, [FromForm] IFormFileCollection files) { int? idCompany = User.GetCompanyId(); @@ -42,7 +43,7 @@ namespace AsbCloudWebApi.Controllers if (idCompany is null) return Forbid(); - if (!wellService.IsCompanyInvolvedInWell((int)idCompany, idWell)) + if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell)) return Forbid(); var fileInfoCollection = files.Select(f => @@ -81,13 +82,13 @@ namespace AsbCloudWebApi.Controllers [HttpGet] [Route("{idWell}")] [ProducesResponseType(typeof(PaginationContainer), (int)System.Net.HttpStatusCode.OK)] - public IActionResult GetFilesInfo([FromRoute] int idWell, + public async Task GetFilesInfoAsync([FromRoute] int idWell, int skip = 0, int take = 32, int idCategory = default, DateTime begin = default, DateTime end = default) { int? idCompany = User.GetCompanyId(); - if (idCompany is null || !wellService.IsCompanyInvolvedInWell((int)idCompany, idWell)) + if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell)) return Forbid(); var filesInfo = fileService.GetFilesInfo(idWell, idCategory, @@ -108,7 +109,7 @@ namespace AsbCloudWebApi.Controllers [HttpGet] [Route("{idWell}/{fileId}")] [ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK)] - public IActionResult GetFile([FromRoute] int idWell, int fileId) + public async Task GetFileAsync([FromRoute] int idWell, int fileId) { try { @@ -117,7 +118,7 @@ namespace AsbCloudWebApi.Controllers if (idCompany is null) return Forbid(); - if (!wellService.IsCompanyInvolvedInWell((int)idCompany, idWell)) + if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell)) return Forbid(); var fileInfo = fileService.GetFileInfo(fileId); diff --git a/AsbCloudWebApi/Controllers/LastDataController.cs b/AsbCloudWebApi/Controllers/LastDataController.cs index cabdc0ca..746af90e 100644 --- a/AsbCloudWebApi/Controllers/LastDataController.cs +++ b/AsbCloudWebApi/Controllers/LastDataController.cs @@ -1,6 +1,7 @@ using AsbCloudApp.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using System.Threading.Tasks; namespace AsbCloudWebApi.Controllers { @@ -18,11 +19,11 @@ namespace AsbCloudWebApi.Controllers } [HttpGet] - public IActionResult Get([FromRoute] int idWell, [FromQuery] int idCategory) + public async Task GetAsync([FromRoute] int idWell, [FromQuery] int idCategory) { int? idCompany = User.GetCompanyId(); - if (idCompany is null || !wellService.IsCompanyInvolvedInWell((int)idCompany, idWell)) + if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell)) return Forbid(); var result = lastDataService.Get(idWell, idCategory); @@ -30,11 +31,11 @@ namespace AsbCloudWebApi.Controllers } [HttpPost] - public IActionResult Put([FromRoute] int idWell, [FromQuery] int idCategory, T data) + public async Task PutAsync([FromRoute] int idWell, [FromQuery] int idCategory, T data) { int? idCompany = User.GetCompanyId(); - if (idCompany is null || !wellService.IsCompanyInvolvedInWell((int)idCompany, idWell)) + if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell)) return Forbid(); lastDataService.Upsert(idWell, idCategory, data); diff --git a/AsbCloudWebApi/Controllers/MessageController.cs b/AsbCloudWebApi/Controllers/MessageController.cs index 8580b805..6cffa45e 100644 --- a/AsbCloudWebApi/Controllers/MessageController.cs +++ b/AsbCloudWebApi/Controllers/MessageController.cs @@ -3,6 +3,7 @@ using AsbCloudApp.Services; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; +using System.Threading.Tasks; namespace AsbCloudWebApi.Controllers { @@ -51,14 +52,14 @@ namespace AsbCloudWebApi.Controllers [HttpGet] [Route("{idWell}/messagesDatesRange")] [ProducesResponseType(typeof(DatesRangeDto), (int)System.Net.HttpStatusCode.OK)] - public IActionResult GetMessagesDateRange(int idWell) + public async Task GetMessagesDateRangeAsync(int idWell) { int? idCompany = User.GetCompanyId(); if (idCompany is null) return Forbid(); - bool isCompanyOwnsWell = wellService.IsCompanyInvolvedInWell((int)idCompany, idWell); + bool isCompanyOwnsWell = await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell); if (!isCompanyOwnsWell) return Forbid(); diff --git a/AsbCloudWebApi/Controllers/ReportController.cs b/AsbCloudWebApi/Controllers/ReportController.cs index 2d6f76ab..9763e3af 100644 --- a/AsbCloudWebApi/Controllers/ReportController.cs +++ b/AsbCloudWebApi/Controllers/ReportController.cs @@ -64,7 +64,7 @@ namespace AsbCloudWebApi.Controllers [HttpPost] [Route("{idWell}/report")] [ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)] - public IActionResult CreateReport(int idWell, int idUser, int stepSeconds, int format, + public async Task CreateReportAsync(int idWell, int idUser, int stepSeconds, int format, DateTime begin = default, DateTime end = default) { int? idCompany = User.GetCompanyId(); @@ -72,7 +72,7 @@ namespace AsbCloudWebApi.Controllers if (idCompany is null) return Forbid(); - if (!wellService.IsCompanyInvolvedInWell((int)idCompany, idWell)) + if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell)) return Forbid(); var id = reportService.CreateReport(idWell, idUser, @@ -90,7 +90,7 @@ namespace AsbCloudWebApi.Controllers [HttpGet] [Route("{idWell}/{reportName}")] [ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK)] - public IActionResult GetReport([FromRoute] int idWell, string reportName) + public async Task GetReportAsync([FromRoute] int idWell, string reportName) { try { @@ -99,7 +99,7 @@ namespace AsbCloudWebApi.Controllers if (idCompany is null) return Forbid(); - if (!wellService.IsCompanyInvolvedInWell((int)idCompany, idWell)) + if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell)) return Forbid(); // TODO: словарь content typoв var relativePath = Path.Combine(fileService.RootPath, $"{idWell}", @@ -148,14 +148,14 @@ namespace AsbCloudWebApi.Controllers [HttpGet] [Route("{idWell}/reportSize")] [ProducesResponseType(typeof(string), (int)System.Net.HttpStatusCode.OK)] - public IActionResult GetReportSize(int idWell, int stepSeconds, int format, DateTime begin = default, DateTime end = default) + public async Task GetReportSizeAsync(int idWell, int stepSeconds, int format, DateTime begin = default, DateTime end = default) { int? idCompany = User.GetCompanyId(); if (idCompany is null) return Forbid(); - if (!wellService.IsCompanyInvolvedInWell((int)idCompany, idWell)) + if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell)) return Forbid(); int reportSize = reportService.GetReportPagesCount(idWell, begin, end, stepSeconds, format); @@ -171,14 +171,14 @@ namespace AsbCloudWebApi.Controllers [HttpGet] [Route("{idWell}/reportsDatesRange")] [ProducesResponseType(typeof(DatesRangeDto), (int)System.Net.HttpStatusCode.OK)] - public IActionResult GetReportsDateRange(int idWell) + public async Task GetReportsDateRangeAsync(int idWell) { int? idCompany = User.GetCompanyId(); if (idCompany is null) return Forbid(); - if (!wellService.IsCompanyInvolvedInWell((int)idCompany, idWell)) + if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell)) return Forbid(); DatesRangeDto wellReportsDatesRange = reportService.GetReportsDatesRange(idWell); diff --git a/AsbCloudWebApi/Controllers/WellController.cs b/AsbCloudWebApi/Controllers/WellController.cs index 8b918f97..eacbb87f 100644 --- a/AsbCloudWebApi/Controllers/WellController.cs +++ b/AsbCloudWebApi/Controllers/WellController.cs @@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; namespace AsbCloudWebApi.Controllers { @@ -21,7 +22,7 @@ namespace AsbCloudWebApi.Controllers [HttpGet] [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] - public IActionResult GetWells() + public async Task GetWellsAsync() { var idCompany = User.GetCompanyId(); @@ -30,7 +31,7 @@ namespace AsbCloudWebApi.Controllers return NoContent(); } - var wells = wellService.GetWellsByCompany((int)idCompany); + var wells = await wellService.GetWellsByCompanyAsync((int)idCompany); if (wells is null || !wells.Any()) return NoContent(); @@ -40,31 +41,31 @@ namespace AsbCloudWebApi.Controllers [HttpGet("{idWell}/operations")] [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] - public IActionResult GetOperations(int idWell) + public async Task GetOperationsAsync(int idWell) { var idCompany = User.GetCompanyId(); if (idCompany is null) return NoContent(); - if (!wellService.IsCompanyInvolvedInWell((int)idCompany, idWell)) + if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell)) return Forbid(); - var dto = wellService.GetOperations(idWell); + var dto = await wellService.GetOperationsAsync(idWell); return Ok(dto); } [HttpGet("transmittingWells")] [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] - public IActionResult GetTransmittingWells() + public async Task GetTransmittingWellsAsync() { var idCompany = User.GetCompanyId(); if (idCompany is null) return NoContent(); - var transmittingWells = wellService.GetTransmittingWells((int)idCompany); + var transmittingWells = await wellService.GetTransmittingWellsAsync((int)idCompany); if (transmittingWells is null || !transmittingWells.Any()) return NoContent(); diff --git a/AsbCloudWebApi/Controllers/WellSectionController.cs b/AsbCloudWebApi/Controllers/WellSectionController.cs index 26301fa6..5a02467e 100644 --- a/AsbCloudWebApi/Controllers/WellSectionController.cs +++ b/AsbCloudWebApi/Controllers/WellSectionController.cs @@ -25,7 +25,7 @@ namespace AsbCloudWebApi.Controllers [HttpGet] public async Task GetAllAsync(int idWell, int skip = 0, int take = 32, CancellationToken token = default) { - if(!CanUserAccessToWell(idWell)) + if(!await CanUserAccessToWellAsync(idWell)) return Forbid(); var result = await sectionsService.GetAllByWellIdAsync(idWell, skip, take, token).ConfigureAwait(false); @@ -36,7 +36,7 @@ namespace AsbCloudWebApi.Controllers [Route("{idSection}")] public async Task GetAsync(int idSection, int idWell, CancellationToken token = default) { - if (!CanUserAccessToWell(idWell)) + if (!await CanUserAccessToWellAsync(idWell)) return Forbid(); var result = await sectionsService.GetAsync(idSection, token).ConfigureAwait(false); @@ -44,9 +44,9 @@ namespace AsbCloudWebApi.Controllers } [HttpPost] - public async Task Insert(int idWell, [FromBody] IEnumerable values, CancellationToken token = default) + public async Task InsertAsync(int idWell, [FromBody] IEnumerable values, CancellationToken token = default) { - if (!CanUserAccessToWell(idWell)) + if (!await CanUserAccessToWellAsync(idWell)) return Forbid(); var result = await sectionsService.InsertRangeAsync(values, idWell, token).ConfigureAwait(false); @@ -54,9 +54,9 @@ namespace AsbCloudWebApi.Controllers } [HttpPut("{id}")] - public async Task Put(int id, int idWell, [FromBody] WellSectionDto value, CancellationToken token = default) + public async Task PutAsync(int id, int idWell, [FromBody] WellSectionDto value, CancellationToken token = default) { - if (!CanUserAccessToWell(idWell)) + if (!await CanUserAccessToWellAsync(idWell)) return Forbid(); var result = await sectionsService.UpdateAsync(value, id, idWell, token).ConfigureAwait(false); @@ -64,19 +64,19 @@ namespace AsbCloudWebApi.Controllers } [HttpDelete("{id}")] - public async Task Delete(int id, int idWell, CancellationToken token = default) + public async Task DeleteAsync(int id, int idWell, CancellationToken token = default) { - if (!CanUserAccessToWell(idWell)) + if (!await CanUserAccessToWellAsync(idWell)) return Forbid(); var result = await sectionsService.DeleteAsync(new int[] { id }, token).ConfigureAwait(false); return Ok(result); } - private bool CanUserAccessToWell(int idWell) + private async Task CanUserAccessToWellAsync(int idWell) { int? idCompany = User.GetCompanyId(); - return idCompany is not null && wellService.IsCompanyInvolvedInWell((int)idCompany, idWell); + return idCompany is not null && await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell); } } }