diff --git a/AsbCloudApp/Services/IFileService.cs b/AsbCloudApp/Services/IFileService.cs index 63d61fdc..91d6681e 100644 --- a/AsbCloudApp/Services/IFileService.cs +++ b/AsbCloudApp/Services/IFileService.cs @@ -17,6 +17,7 @@ namespace AsbCloudApp.Services int idCategory, DateTime begin, DateTime end, int skip, int take, CancellationToken token = default); - (int Id, string Name, int IdCategory)? GetFileInfo(int fileId); + Task<(int Id, string Name, int IdCategory)?> GetFileInfoAsync(int fileId, + CancellationToken token); } } diff --git a/AsbCloudInfrastructure/Services/AnalyticsService.cs b/AsbCloudInfrastructure/Services/AnalyticsService.cs index a2243be3..f802e8c5 100644 --- a/AsbCloudInfrastructure/Services/AnalyticsService.cs +++ b/AsbCloudInfrastructure/Services/AnalyticsService.cs @@ -59,7 +59,7 @@ namespace AsbCloudInfrastructure.Services WellDepth = d.WellDepth ?? 0.0, BitDepth = d.BitDepth ?? 0.0, Date = d.Date - }).AsNoTracking().ToListAsync(token); + }).AsNoTracking().ToListAsync(token).ConfigureAwait(false); } public async Task> GetWellDepthToIntervalAsync(int idWell, @@ -75,7 +75,7 @@ namespace AsbCloudInfrastructure.Services var timezoneOffset = telemetryService.GetTimezoneOffsetByTelemetryId((int)telemetryId); var drillingPeriodsInfo = await db.GetDepthToIntervalAsync((int)telemetryId, intervalSeconds, - workBeginSeconds, timezoneOffset, token); + workBeginSeconds, timezoneOffset, token).ConfigureAwait(false); var wellDepthToIntervalData = drillingPeriodsInfo.Select(d => new WellDepthToIntervalDto { @@ -122,14 +122,15 @@ namespace AsbCloudInfrastructure.Services operations = operations.Where(m => (m.UnixDate + m.DurationSec) <= unixEnd); } - result.Count = await operations.CountAsync(token); + result.Count = await operations.CountAsync(token).ConfigureAwait(false); if (skip > 0) operations = operations.Skip(skip); var operationsList = await operations.Take(take) .AsNoTracking() - .ToListAsync(token); + .ToListAsync(token) + .ConfigureAwait(false); if (operationsList.Count == 0) return result; @@ -173,7 +174,8 @@ namespace AsbCloudInfrastructure.Services OperationName = g.Key.Name, Duration = g.Where(g => g.DurationSec > 0) .Sum(a => a.DurationSec) - }).AsNoTracking().ToListAsync(token); + }).AsNoTracking().ToListAsync(token) + .ConfigureAwait(false); } public async Task> GetOperationsToIntervalAsync(int idWell, @@ -202,7 +204,8 @@ namespace AsbCloudInfrastructure.Services IntervalStart = g.Min(d => d.UnixDate), OperationName = g.Key.Name, OperationsDuration = g.Sum(an => an.DurationSec) - }).AsNoTracking().ToListAsync(token); + }).AsNoTracking().ToListAsync(token) + .ConfigureAwait(false); var operationsGroupedByInterval = operations.GroupBy(op => op.IntervalStart) .Select(o => new TelemetryOperationInfoDto diff --git a/AsbCloudInfrastructure/Services/AuthService.cs b/AsbCloudInfrastructure/Services/AuthService.cs index 1dad61bf..a8bf9448 100644 --- a/AsbCloudInfrastructure/Services/AuthService.cs +++ b/AsbCloudInfrastructure/Services/AuthService.cs @@ -41,7 +41,9 @@ namespace AsbCloudInfrastructure.Services public async Task LoginAsync(string login, string password, CancellationToken token = default) { - var identity = await GetClaimsUserAsync(login, password, token); + var identity = await GetClaimsUserAsync(login, password, token) + .ConfigureAwait(false); + if (identity == default) return null; @@ -144,7 +146,8 @@ namespace AsbCloudInfrastructure.Services var user = await db .GetUsersByLogin(login) .AsNoTracking() - .FirstOrDefaultAsync(token); + .FirstOrDefaultAsync(token) + .ConfigureAwait(false); if (user is null) return default; diff --git a/AsbCloudInfrastructure/Services/BackgroundWorkerService.cs b/AsbCloudInfrastructure/Services/BackgroundWorkerService.cs index 2917fa26..8e3a4bab 100644 --- a/AsbCloudInfrastructure/Services/BackgroundWorkerService.cs +++ b/AsbCloudInfrastructure/Services/BackgroundWorkerService.cs @@ -21,9 +21,9 @@ namespace AsbCloudInfrastructure.Services try { if (tasksQueue.TryDequeue(out var item)) - await Task.Run(() => item.action(item.id), token); + await Task.Run(() => item.action(item.id), token).ConfigureAwait(false); else - await Task.Delay(100, token); + await Task.Delay(100, token).ConfigureAwait(false); } catch { @@ -34,7 +34,7 @@ namespace AsbCloudInfrastructure.Services public override async Task StopAsync(CancellationToken token) { - await base.StopAsync(token); + await base.StopAsync(token).ConfigureAwait(false); } } } diff --git a/AsbCloudInfrastructure/Services/ClusterService.cs b/AsbCloudInfrastructure/Services/ClusterService.cs index 52e4046e..9421c9eb 100644 --- a/AsbCloudInfrastructure/Services/ClusterService.cs +++ b/AsbCloudInfrastructure/Services/ClusterService.cs @@ -27,7 +27,8 @@ namespace AsbCloudInfrastructure.Services .Include(w => w.Cluster) .ThenInclude(c => c.Deposit) where well.RelationCompaniesWells.Any(r => r.IdCompany == idCompany) - select well).AsNoTracking().ToListAsync(token); + select well).ToListAsync(token) + .ConfigureAwait(false); var gDepositEntities = wellEntities .GroupBy(w => w.Cluster) @@ -70,7 +71,8 @@ namespace AsbCloudInfrastructure.Services .Select(e => e.Cluster) .Distinct() .AsNoTracking() - .ToListAsync(token); + .ToListAsync(token) + .ConfigureAwait(false); var dtos = entities.Select(e => new ClusterDto { @@ -91,7 +93,8 @@ namespace AsbCloudInfrastructure.Services .Where(e => e.IdDeposit == depositId) .Distinct() .AsNoTracking() - .ToListAsync(token); + .ToListAsync(token) + .ConfigureAwait(false); var dtos = entities.Select(e => new ClusterDto { @@ -110,7 +113,8 @@ namespace AsbCloudInfrastructure.Services var entities = await db.GetWellsForCompany(idCompany) .Where(e => e.IdCluster == idCluster) .AsNoTracking() - .ToListAsync(token); + .ToListAsync(token) + .ConfigureAwait(false); var dtos = entities.Select(e => new WellDto { @@ -174,12 +178,15 @@ namespace AsbCloudInfrastructure.Services CompanyType = c.Company.CompanyType.Caption, }), WellType = e.WellType.Caption, - }).AsNoTracking().ToListAsync(token); + }).AsNoTracking().ToListAsync(token) + .ConfigureAwait(false); if (!wellStatDtos.Any()) return null; - var clusterById = await db.Clusters.AsNoTracking().FirstOrDefaultAsync(c => c.Id == idCluster, token); + var clusterById = await db.Clusters.AsNoTracking() + .FirstOrDefaultAsync(c => c.Id == idCluster, token) + .ConfigureAwait(false); return new ClusterStatDto { diff --git a/AsbCloudInfrastructure/Services/DataService.cs b/AsbCloudInfrastructure/Services/DataService.cs index 4437ab53..084418eb 100644 --- a/AsbCloudInfrastructure/Services/DataService.cs +++ b/AsbCloudInfrastructure/Services/DataService.cs @@ -52,7 +52,8 @@ namespace AsbCloudInfrastructure.Services && data.Date >= dateBegin && data.Date < datEnd select data; - var fullDataCount = await query.CountAsync(token); + var fullDataCount = await query.CountAsync(token) + .ConfigureAwait(false); if (fullDataCount == 0) return default; @@ -64,7 +65,8 @@ namespace AsbCloudInfrastructure.Services query = query.Where(d => d.Id % m == 0); } - var entities = await query.AsNoTracking().ToListAsync(token); + var entities = await query.AsNoTracking() + .ToListAsync(token).ConfigureAwait(false); var dtos = entities.Adapt(); @@ -85,7 +87,9 @@ namespace AsbCloudInfrastructure.Services where d.IdTelemetry == telemetryId && d.Date > dtoMinDate && d.Date < dtoMaxDate - select d).AsNoTracking().ToListAsync(token); + select d).AsNoTracking() + .ToListAsync(token) + .ConfigureAwait(false); if (oldDataSaubBase.Any()) db.DataSaubBases.RemoveRange(oldDataSaubBase); @@ -111,7 +115,8 @@ namespace AsbCloudInfrastructure.Services if (telemetryId is null) return null; - var (From, To) = await db.GetDatesRangeAsync((int)telemetryId, token); + var (From, To) = await db.GetDatesRangeAsync((int)telemetryId, token) + .ConfigureAwait(false); return new DatesRangeDto { From = From, To = To }; } diff --git a/AsbCloudInfrastructure/Services/EventService.cs b/AsbCloudInfrastructure/Services/EventService.cs index ec6a7db1..d1d2f86e 100644 --- a/AsbCloudInfrastructure/Services/EventService.cs +++ b/AsbCloudInfrastructure/Services/EventService.cs @@ -35,7 +35,8 @@ namespace AsbCloudInfrastructure.Services IdCategory = dto.IdCategory, MessageTemplate = dto.Message }); - await cacheEvents.UpsertAsync(entities, token); + await cacheEvents.UpsertAsync(entities, token) + .ConfigureAwait(false); } } } diff --git a/AsbCloudInfrastructure/Services/FileService.cs b/AsbCloudInfrastructure/Services/FileService.cs index c3ac5c7b..73ee07c8 100644 --- a/AsbCloudInfrastructure/Services/FileService.cs +++ b/AsbCloudInfrastructure/Services/FileService.cs @@ -64,12 +64,15 @@ namespace AsbCloudInfrastructure.Services if (end != default) filesInfoQuery = filesInfoQuery.Where(m => m.Date <= end).AsNoTracking(); - result.Count = await filesInfoQuery.CountAsync(token); + result.Count = await filesInfoQuery.CountAsync(token) + .ConfigureAwait(false); if (skip > 0) filesInfoQuery = filesInfoQuery.Skip(skip).AsNoTracking(); - var filesInfoList = await filesInfoQuery.OrderBy(f => f.Date).Take(take).ToListAsync(token); + var filesInfoList = await filesInfoQuery.OrderBy(f => f.Date) + .Take(take).ToListAsync(token) + .ConfigureAwait(false); if (filesInfoList.Count == 0) return result; @@ -91,9 +94,12 @@ namespace AsbCloudInfrastructure.Services return result; } - public (int Id, string Name, int IdCategory)? GetFileInfo(int fileId) + public async Task<(int Id, string Name, int IdCategory)?> GetFileInfoAsync(int fileId, + CancellationToken token = default) { - var fileInfo = db.Files.AsNoTracking().FirstOrDefault(f => f.Id == fileId); + var fileInfo = await db.Files.AsNoTracking() + .FirstOrDefaultAsync(f => f.Id == fileId, token) + .ConfigureAwait(false); if (fileInfo is null) return null; diff --git a/AsbCloudInfrastructure/Services/LastDataService.cs b/AsbCloudInfrastructure/Services/LastDataService.cs index 8042a32d..3891f3d3 100644 --- a/AsbCloudInfrastructure/Services/LastDataService.cs +++ b/AsbCloudInfrastructure/Services/LastDataService.cs @@ -21,7 +21,8 @@ namespace AsbCloudInfrastructure.Services CancellationToken token = default) { var entity = await db.LastData.AsNoTracking().FirstOrDefaultAsync(e => - e.IdWell == idWell && e.IdCategory == idCategory, token); + e.IdWell == idWell && e.IdCategory == idCategory, token) + .ConfigureAwait(false); if (entity is null) return new Tdto(); @@ -37,7 +38,8 @@ namespace AsbCloudInfrastructure.Services var entity = await db.LastData.AsNoTracking() .FirstOrDefaultAsync(ld => ld.IdWell == idWell && - ld.IdCategory == idCategory, token); + ld.IdCategory == idCategory, token) + .ConfigureAwait(false); if (entity is not null) { diff --git a/AsbCloudInfrastructure/Services/MessageService.cs b/AsbCloudInfrastructure/Services/MessageService.cs index 209be08e..f85d0003 100644 --- a/AsbCloudInfrastructure/Services/MessageService.cs +++ b/AsbCloudInfrastructure/Services/MessageService.cs @@ -84,7 +84,7 @@ namespace AsbCloudInfrastructure.Services query = query.Skip(skip); var messagesList = await query.Take(take).AsNoTracking() - .ToListAsync(token); + .ToListAsync(token).ConfigureAwait(false); if (messagesList.Count == 0) return result; @@ -120,7 +120,8 @@ namespace AsbCloudInfrastructure.Services if (telemetryId is null) return null; - var (From, To) = await db.GetDatesRangeAsync((int)telemetryId, token); + var (From, To) = await db.GetDatesRangeAsync((int)telemetryId, token) + .ConfigureAwait(false); return new DatesRangeDto { From = From, To = To }; } diff --git a/AsbCloudInfrastructure/Services/ReportService.cs b/AsbCloudInfrastructure/Services/ReportService.cs index b1980407..7a9ba05a 100644 --- a/AsbCloudInfrastructure/Services/ReportService.cs +++ b/AsbCloudInfrastructure/Services/ReportService.cs @@ -95,7 +95,8 @@ namespace AsbCloudInfrastructure.Services public async Task> GetSuitableReportsAsync(int idWell, DateTime begin, DateTime end, int stepSeconds, int format, CancellationToken token = default) { - var suitableReportsFromDb = await GetSuitableReportsFromDbAsync(idWell, begin, end, stepSeconds, format); + var suitableReportsFromDb = await GetSuitableReportsFromDbAsync(idWell, + begin, end, stepSeconds, format, token).ConfigureAwait(false); var suitableReportsProperties = suitableReportsFromDb.Select(r => new ReportPropertiesDto { @@ -134,7 +135,8 @@ namespace AsbCloudInfrastructure.Services From = g.Min(), To = g.Max() }).OrderBy(gr => gr.From) - .FirstOrDefaultAsync(token); + .FirstOrDefaultAsync(token) + .ConfigureAwait(false); return new DatesRangeDto { @@ -155,7 +157,8 @@ namespace AsbCloudInfrastructure.Services && r.Format == format select r).OrderBy(o => o.File.Date) .AsNoTracking() - .Take(512).ToListAsync(token); + .Take(512).ToListAsync(token) + .ConfigureAwait(false); return suitableReportsNames; } diff --git a/AsbCloudInfrastructure/Services/WellSectionService.cs b/AsbCloudInfrastructure/Services/WellSectionService.cs index b78447fb..16f2bf25 100644 --- a/AsbCloudInfrastructure/Services/WellSectionService.cs +++ b/AsbCloudInfrastructure/Services/WellSectionService.cs @@ -76,7 +76,7 @@ namespace AsbCloudInfrastructure.Services public async Task InsertAsync(WellSectionDto item, int idWell, CancellationToken token = default) { - var sectionType = await GetWellSectionTypeFromCacheAndAssert(item.SectionType); + var sectionType = await GetWellSectionTypeFromCacheAndAssertAsync(item.SectionType); var entity = item.Adapt(); entity.Id = default; @@ -96,7 +96,7 @@ namespace AsbCloudInfrastructure.Services for (int i = 0; i < dbEntities.Length; i++) { - var sectionType = await GetWellSectionTypeFromCacheAndAssert(items.ElementAt(i).SectionType); + var sectionType = await GetWellSectionTypeFromCacheAndAssertAsync(items.ElementAt(i).SectionType, token); var item = items.ElementAt(i).Adapt(); item.IdWell = idWell; item.IdWellSectionType = sectionType.Id; @@ -117,7 +117,8 @@ namespace AsbCloudInfrastructure.Services public async Task UpdateAsync(WellSectionDto item, int idSection, int idWell, CancellationToken token = default) { - var sectionType = await GetWellSectionTypeFromCacheAndAssert(item.SectionType); + var sectionType = await GetWellSectionTypeFromCacheAndAssertAsync(item.SectionType, token) + .ConfigureAwait(false); var entity = item.Adapt(); entity.Id = idSection; @@ -138,7 +139,7 @@ namespace AsbCloudInfrastructure.Services return context.SaveChangesAsync(token); } - private async Task GetWellSectionTypeFromCacheAndAssert(string wellSectionType, CancellationToken token = default) + private async Task GetWellSectionTypeFromCacheAndAssertAsync(string wellSectionType, CancellationToken token = default) { if (string.IsNullOrEmpty(wellSectionType)) throw new ArgumentException("Тип секции должен быть указан", nameof(WellSectionDto.SectionType)); diff --git a/AsbCloudInfrastructure/Services/WellService.cs b/AsbCloudInfrastructure/Services/WellService.cs index 50f05eee..de706f14 100644 --- a/AsbCloudInfrastructure/Services/WellService.cs +++ b/AsbCloudInfrastructure/Services/WellService.cs @@ -34,7 +34,8 @@ namespace AsbCloudInfrastructure.Services wells = await db.GetWellsForCompany(idCompany) .Where(w => activeTelemetriesUids.Contains(w.Telemetry.RemoteUid)) .AsNoTracking() - .ToListAsync(token); + .ToListAsync(token) + .ConfigureAwait(false); } return wells.Select(w => From(w)); } @@ -47,13 +48,14 @@ namespace AsbCloudInfrastructure.Services public async Task IsCompanyInvolvedInWellAsync(int idCompany, int idWell, CancellationToken token) => await cacheRelationCompaniesWells.ContainsAsync(r => r.IdWell == idWell && - r.IdCompany == idCompany, token); + r.IdCompany == idCompany, token).ConfigureAwait(false); public async Task> GetOperationsAsync(int idWell, CancellationToken token) { var entities = await db.WellOperations.Where(o => o.IdWell == idWell) .AsNoTracking() - .ToListAsync(token); + .ToListAsync(token) + .ConfigureAwait(false); var dtos = entities.Adapt(); diff --git a/AsbCloudWebApi/Controllers/AnalyticsController.cs b/AsbCloudWebApi/Controllers/AnalyticsController.cs index 5006fcc7..8d0fa0e0 100644 --- a/AsbCloudWebApi/Controllers/AnalyticsController.cs +++ b/AsbCloudWebApi/Controllers/AnalyticsController.cs @@ -44,10 +44,12 @@ namespace AsbCloudWebApi.Controllers { int? idCompany = User.GetCompanyId(); - if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell, token)) - return Forbid(); + if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, + idWell, token).ConfigureAwait(false)) + return Forbid(); - var analytics = await analyticsService.GetOperationsByWellAsync(idWell, categoryIds, begin, end, skip, take, token); + var analytics = await analyticsService.GetOperationsByWellAsync(idWell, categoryIds, begin, end, skip, take, token) + .ConfigureAwait(false); if (analytics is null || analytics.Count == 0) return NoContent(); @@ -69,10 +71,12 @@ namespace AsbCloudWebApi.Controllers { int? idCompany = User.GetCompanyId(); - if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell, token)) - return Forbid(); + if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, + idWell, token).ConfigureAwait(false)) + return Forbid(); - var wellDepthToDayData = await analyticsService.GetWellDepthToDayAsync(idWell, token); + var wellDepthToDayData = await analyticsService.GetWellDepthToDayAsync(idWell, token) + .ConfigureAwait(false); if (wellDepthToDayData is null || !wellDepthToDayData.Any()) return NoContent(); @@ -97,11 +101,11 @@ namespace AsbCloudWebApi.Controllers int? idCompany = User.GetCompanyId(); if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, - idWell, token)) - return Forbid(); + idWell, token).ConfigureAwait(false)) + return Forbid(); var wellDepthToIntervalData = await analyticsService.GetWellDepthToIntervalAsync(idWell, - intervalSeconds, workBeginSeconds, token); + intervalSeconds, workBeginSeconds, token).ConfigureAwait(false); if (wellDepthToIntervalData is null || !wellDepthToIntervalData.Any()) return NoContent(); @@ -125,10 +129,12 @@ namespace AsbCloudWebApi.Controllers { int? idCompany = User.GetCompanyId(); - if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell, token)) - return Forbid(); + if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, + idWell, token).ConfigureAwait(false)) + return Forbid(); - var analytics = await analyticsService .GetOperationsSummaryAsync(idWell, begin, end, token); + var analytics = await analyticsService .GetOperationsSummaryAsync(idWell, + begin, end, token).ConfigureAwait(false); if (analytics is null || !analytics.Any()) return NoContent(); @@ -152,11 +158,12 @@ namespace AsbCloudWebApi.Controllers { int? idCompany = User.GetCompanyId(); - if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync ((int)idCompany, idWell, token)) - return Forbid(); + if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync ((int)idCompany, + idWell, token).ConfigureAwait(false)) + return Forbid(); var analytics = await analyticsService.GetOperationsToIntervalAsync(idWell, - intervalSeconds, workBeginSeconds, token); + intervalSeconds, workBeginSeconds, token).ConfigureAwait(false); if (analytics is null || !analytics.Any()) return NoContent(); diff --git a/AsbCloudWebApi/Controllers/AuthController.cs b/AsbCloudWebApi/Controllers/AuthController.cs index 1192ddba..6c3b48d7 100644 --- a/AsbCloudWebApi/Controllers/AuthController.cs +++ b/AsbCloudWebApi/Controllers/AuthController.cs @@ -32,7 +32,9 @@ namespace AsbCloudWebApi.Controllers [ProducesResponseType(typeof(UserTokenDto), (int)System.Net.HttpStatusCode.OK)] public async Task LoginAsync([FromBody] AuthDto auth, CancellationToken token = default) { - var userToken = await authService.LoginAsync(auth.Login, auth.Password, token); + var userToken = await authService.LoginAsync(auth.Login, + auth.Password, token).ConfigureAwait(false); + if (userToken is null) BadRequest();//"wrong login or password" diff --git a/AsbCloudWebApi/Controllers/ClusterController.cs b/AsbCloudWebApi/Controllers/ClusterController.cs index c8a17740..000df459 100644 --- a/AsbCloudWebApi/Controllers/ClusterController.cs +++ b/AsbCloudWebApi/Controllers/ClusterController.cs @@ -37,7 +37,8 @@ namespace AsbCloudWebApi.Controllers if (idCompany is null) return Forbid(); - var result = await clusterService.GetClustersAsync((int)idCompany, token); + var result = await clusterService.GetClustersAsync((int)idCompany, + token).ConfigureAwait(false); return Ok(result); } @@ -56,7 +57,8 @@ namespace AsbCloudWebApi.Controllers if (idCompany is null) return Forbid(); - var result = await clusterService.GetWellsAsync((int)idCompany, idCluster, token); + var result = await clusterService.GetWellsAsync((int)idCompany, + idCluster, token).ConfigureAwait(false); return Ok(result); } @@ -75,7 +77,8 @@ namespace AsbCloudWebApi.Controllers if (idCompany is null) return Forbid(); - var result = await clusterService.GetStatAsync((int)idCompany, idCluster, token); + var result = await clusterService.GetStatAsync((int)idCompany, + idCluster, token).ConfigureAwait(false); return Ok(result); } } diff --git a/AsbCloudWebApi/Controllers/DataController.cs b/AsbCloudWebApi/Controllers/DataController.cs index b335f2de..1b86617b 100644 --- a/AsbCloudWebApi/Controllers/DataController.cs +++ b/AsbCloudWebApi/Controllers/DataController.cs @@ -46,7 +46,7 @@ namespace AsbCloudWebApi.Controllers if (begin == default) begin = DateTime.Now.AddSeconds(-intervalSec); var content = await telemetryDataService.GetAsync(idWell, begin, - intervalSec, approxPointsCount, token); + intervalSec, approxPointsCount, token).ConfigureAwait(false); if (content is null || !content.Any()) return NoContent(); @@ -72,13 +72,13 @@ namespace AsbCloudWebApi.Controllers return Forbid(); bool isCompanyOwnsWell = await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, - idWell, token); + idWell, token).ConfigureAwait(false); if (!isCompanyOwnsWell) return Forbid(); DatesRangeDto dataDatesRange = await telemetryDataService.GetDataDatesRangeAsync(idWell, - token); + token).ConfigureAwait(false); return Ok(dataDatesRange); } diff --git a/AsbCloudWebApi/Controllers/DepositController.cs b/AsbCloudWebApi/Controllers/DepositController.cs index 28e8192c..617357dd 100644 --- a/AsbCloudWebApi/Controllers/DepositController.cs +++ b/AsbCloudWebApi/Controllers/DepositController.cs @@ -37,7 +37,8 @@ namespace AsbCloudWebApi.Controllers if (idCompany is null) return Forbid(); - var result = await clusterService.GetDepositsAsync((int)idCompany, token); + var result = await clusterService.GetDepositsAsync((int)idCompany, + token).ConfigureAwait(false); return Ok(result); } @@ -57,7 +58,8 @@ namespace AsbCloudWebApi.Controllers if (idCompany is null) return Forbid(); - var result = await clusterService.GetClustersAsync((int)idCompany, depositId, token); + var result = await clusterService.GetClustersAsync((int)idCompany, + depositId, token).ConfigureAwait(false); return Ok(result); } diff --git a/AsbCloudWebApi/Controllers/FileController.cs b/AsbCloudWebApi/Controllers/FileController.cs index 674055c7..336041f6 100644 --- a/AsbCloudWebApi/Controllers/FileController.cs +++ b/AsbCloudWebApi/Controllers/FileController.cs @@ -45,8 +45,9 @@ namespace AsbCloudWebApi.Controllers if (idCompany is null) return Forbid(); - if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell, token)) - return Forbid(); + if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, + idWell, token).ConfigureAwait(false)) + return Forbid(); var fileInfoCollection = files.Select(f => (f.FileName, idWell, idCategory, DateTime.Now, idUser)); @@ -92,11 +93,11 @@ namespace AsbCloudWebApi.Controllers int? idCompany = User.GetCompanyId(); if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, - idWell, token)) - return Forbid(); + idWell, token).ConfigureAwait(false)) + return Forbid(); var filesInfo = await fileService.GetFilesInfoAsync(idWell, idCategory, - begin, end, skip, take, token); + begin, end, skip, take, token).ConfigureAwait(false); if (filesInfo is null || !filesInfo.Items.Any()) return NoContent(); @@ -124,10 +125,11 @@ namespace AsbCloudWebApi.Controllers if (idCompany is null) return Forbid(); - if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell, token)) - return Forbid(); + if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, + idWell, token).ConfigureAwait(false)) + return Forbid(); - var fileInfo = fileService.GetFileInfo(fileId); + var fileInfo = await fileService.GetFileInfoAsync(fileId, token); if (fileInfo is null) throw new FileNotFoundException(); diff --git a/AsbCloudWebApi/Controllers/LastDataController.cs b/AsbCloudWebApi/Controllers/LastDataController.cs index f3d17abe..0dcdfc16 100644 --- a/AsbCloudWebApi/Controllers/LastDataController.cs +++ b/AsbCloudWebApi/Controllers/LastDataController.cs @@ -25,10 +25,12 @@ namespace AsbCloudWebApi.Controllers { int? idCompany = User.GetCompanyId(); - if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell, token)) - return Forbid(); + if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, + idWell, token).ConfigureAwait(false)) + return Forbid(); - var result = await lastDataService.GetAsync(idWell, idCategory, token); + var result = await lastDataService.GetAsync(idWell, + idCategory, token).ConfigureAwait(false); return Ok(result); } @@ -38,10 +40,12 @@ namespace AsbCloudWebApi.Controllers { int? idCompany = User.GetCompanyId(); - if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell, token)) - return Forbid(); + if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, + idWell, token).ConfigureAwait(false)) + return Forbid(); - await lastDataService.UpsertAsync(idWell, idCategory, data, token); + await lastDataService.UpsertAsync(idWell, + idCategory, data, token).ConfigureAwait(false); return Ok(); } } diff --git a/AsbCloudWebApi/Controllers/MessageController.cs b/AsbCloudWebApi/Controllers/MessageController.cs index f479761b..fb44ae61 100644 --- a/AsbCloudWebApi/Controllers/MessageController.cs +++ b/AsbCloudWebApi/Controllers/MessageController.cs @@ -50,7 +50,7 @@ namespace AsbCloudWebApi.Controllers var result = await messageService.GetMessagesAsync(idWell, categoryids, begin, end, searchString, - skip, take, token); + skip, take, token).ConfigureAwait(false); if (result is null || result.Count == 0) return NoContent(); @@ -76,7 +76,7 @@ namespace AsbCloudWebApi.Controllers return Forbid(); bool isCompanyOwnsWell = await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, - idWell, token); + idWell, token).ConfigureAwait(false); if (!isCompanyOwnsWell) return Forbid(); diff --git a/AsbCloudWebApi/Controllers/ReportController.cs b/AsbCloudWebApi/Controllers/ReportController.cs index 766a6f3a..cf1c91d8 100644 --- a/AsbCloudWebApi/Controllers/ReportController.cs +++ b/AsbCloudWebApi/Controllers/ReportController.cs @@ -39,7 +39,7 @@ namespace AsbCloudWebApi.Controllers reportsHubContext.Clients.Group($"Report_{id}").SendAsync( nameof(IReportHubClient.GetReportProgress), new { Progress = progress, Operation = operation, ReportName = "" } - ); + ).ConfigureAwait(false); }); private void HandleReportNameAsync(string reportName, int groupId) => @@ -48,7 +48,7 @@ namespace AsbCloudWebApi.Controllers reportsHubContext.Clients.All.SendAsync( nameof(IReportHubClient.GetReportProgress), new { Progress = 100, Operation = "Отчет успешно создан", ReportName = reportName } - ); + ).ConfigureAwait(false); }); @@ -75,8 +75,9 @@ namespace AsbCloudWebApi.Controllers if (idCompany is null) return Forbid(); - if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell, token)) - return Forbid(); + if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, + idWell, token).ConfigureAwait(false)) + return Forbid(); var id = reportService.CreateReport(idWell, idUser, stepSeconds, format, begin, end, HandleReportProgressAsync, HandleReportNameAsync); @@ -104,8 +105,10 @@ namespace AsbCloudWebApi.Controllers if (idCompany is null) return Forbid(); - if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell, token)) - return Forbid(); + if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, + idWell, token).ConfigureAwait(false)) + return Forbid(); + // TODO: словарь content typoв var relativePath = Path.Combine(fileService.RootPath, $"{idWell}", $"{reportService.ReportCategoryId}", reportName); @@ -136,7 +139,7 @@ namespace AsbCloudWebApi.Controllers CancellationToken token = default) { var suitableReportsNames = await reportService.GetSuitableReportsAsync(idWell, - begin, end, stepSeconds, format, token); + begin, end, stepSeconds, format, token).ConfigureAwait(false); if (suitableReportsNames is null || !suitableReportsNames.Any()) return NoContent(); @@ -166,8 +169,9 @@ namespace AsbCloudWebApi.Controllers if (idCompany is null) return Forbid(); - if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell, token)) - return Forbid(); + if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, + idWell, token).ConfigureAwait(false)) + return Forbid(); int reportSize = reportService.GetReportPagesCount(idWell, begin, end, stepSeconds, format); @@ -192,11 +196,12 @@ namespace AsbCloudWebApi.Controllers if (idCompany is null) return Forbid(); - if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell, token)) - return Forbid(); + if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, + idWell, token).ConfigureAwait(false)) + return Forbid(); DatesRangeDto wellReportsDatesRange = await reportService.GetReportsDatesRangeAsync(idWell, - token); + token).ConfigureAwait(false); return Ok(wellReportsDatesRange); } diff --git a/AsbCloudWebApi/Controllers/TelemetryController.cs b/AsbCloudWebApi/Controllers/TelemetryController.cs index d1889333..0430abea 100644 --- a/AsbCloudWebApi/Controllers/TelemetryController.cs +++ b/AsbCloudWebApi/Controllers/TelemetryController.cs @@ -71,10 +71,11 @@ namespace AsbCloudWebApi.Controllers CancellationToken token = default) { var idWell = telemetryService.GetidWellByTelemetryUid(uid); - await DataService.UpdateDataAsync(uid, dtos, token); + await DataService.UpdateDataAsync(uid, dtos, token).ConfigureAwait(false); if (idWell != null && dtos.Any()) - await Task.Run(() => telemetryHubContext.Clients.Group($"well_{idWell}").SendAsync(nameof(ITelemetryHubClient.ReceiveDataSaub), dtos), token); + await Task.Run(() => telemetryHubContext.Clients.Group($"well_{idWell}") + .SendAsync(nameof(ITelemetryHubClient.ReceiveDataSaub), dtos), token).ConfigureAwait(false); telemetryTracker.SaveRequestDate(uid); return Ok(); @@ -93,10 +94,11 @@ namespace AsbCloudWebApi.Controllers CancellationToken token = default) { var idWell = telemetryService.GetidWellByTelemetryUid(uid); - await messageService.InsertAsync(uid, dtos, token); + await messageService.InsertAsync(uid, dtos, token).ConfigureAwait(false); if (dtos.Any()) - await Task.Run(() => telemetryHubContext.Clients.Group($"well_{idWell}").SendAsync(nameof(ITelemetryHubClient.ReceiveMessages), dtos), token); + await Task.Run(() => telemetryHubContext.Clients.Group($"well_{idWell}") + .SendAsync(nameof(ITelemetryHubClient.ReceiveMessages), dtos), token).ConfigureAwait(false); telemetryTracker.SaveRequestDate(uid); return Ok(); @@ -114,7 +116,8 @@ namespace AsbCloudWebApi.Controllers public async Task PostEventsAsync(string uid, [FromBody] List events, CancellationToken token = default) { - await eventService.UpsertAsync(uid, events, token); + await eventService.UpsertAsync(uid, events, token) + .ConfigureAwait(false); telemetryTracker.SaveRequestDate(uid); return Ok(); } diff --git a/AsbCloudWebApi/Controllers/WellController.cs b/AsbCloudWebApi/Controllers/WellController.cs index fdc95633..af7c2e21 100644 --- a/AsbCloudWebApi/Controllers/WellController.cs +++ b/AsbCloudWebApi/Controllers/WellController.cs @@ -32,7 +32,8 @@ namespace AsbCloudWebApi.Controllers return NoContent(); } - var wells = await wellService.GetWellsByCompanyAsync((int)idCompany, token); + var wells = await wellService.GetWellsByCompanyAsync((int)idCompany, + token).ConfigureAwait(false); if (wells is null || !wells.Any()) return NoContent(); @@ -49,10 +50,12 @@ namespace AsbCloudWebApi.Controllers if (idCompany is null) return NoContent(); - if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell, token)) - return Forbid(); + if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, + idWell, token).ConfigureAwait(false)) + return Forbid(); - var dto = await wellService.GetOperationsAsync(idWell, token); + var dto = await wellService.GetOperationsAsync(idWell, + token).ConfigureAwait(false); return Ok(dto); } @@ -66,7 +69,8 @@ namespace AsbCloudWebApi.Controllers if (idCompany is null) return NoContent(); - var transmittingWells = await wellService.GetTransmittingWellsAsync((int)idCompany, token); + var transmittingWells = await wellService.GetTransmittingWellsAsync((int)idCompany, + token).ConfigureAwait(false); if (transmittingWells is null || !transmittingWells.Any()) return NoContent(); diff --git a/AsbCloudWebApi/Controllers/WellSectionController.cs b/AsbCloudWebApi/Controllers/WellSectionController.cs index bb13d194..8c4a354f 100644 --- a/AsbCloudWebApi/Controllers/WellSectionController.cs +++ b/AsbCloudWebApi/Controllers/WellSectionController.cs @@ -26,7 +26,7 @@ namespace AsbCloudWebApi.Controllers public async Task GetAllAsync(int idWell, int skip = 0, int take = 32, CancellationToken token = default) { - if(!await CanUserAccessToWellAsync(idWell, token)) + if(!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false)) return Forbid(); var result = await sectionsService.GetAllByWellIdAsync(idWell, skip, take, token).ConfigureAwait(false); @@ -38,7 +38,7 @@ namespace AsbCloudWebApi.Controllers public async Task GetAsync(int idSection, int idWell, CancellationToken token = default) { - if (!await CanUserAccessToWellAsync(idWell, token)) + if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false)) return Forbid(); var result = await sectionsService.GetAsync(idSection, token).ConfigureAwait(false); @@ -49,7 +49,7 @@ namespace AsbCloudWebApi.Controllers public async Task InsertAsync(int idWell, [FromBody] IEnumerable values, CancellationToken token = default) { - if (!await CanUserAccessToWellAsync(idWell, token)) + if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false)) return Forbid(); var result = await sectionsService.InsertRangeAsync(values, idWell, token).ConfigureAwait(false); @@ -59,7 +59,7 @@ namespace AsbCloudWebApi.Controllers [HttpPut("{id}")] public async Task PutAsync(int id, int idWell, [FromBody] WellSectionDto value, CancellationToken token = default) { - if (!await CanUserAccessToWellAsync(idWell, token)) + if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false)) return Forbid(); var result = await sectionsService.UpdateAsync(value, id, idWell, token).ConfigureAwait(false); @@ -69,8 +69,9 @@ namespace AsbCloudWebApi.Controllers [HttpDelete("{id}")] public async Task DeleteAsync(int id, int idWell, CancellationToken token = default) { - if (!await CanUserAccessToWellAsync(idWell, token)) - return Forbid(); + if (!await CanUserAccessToWellAsync(idWell, + token).ConfigureAwait(false)) + return Forbid(); var result = await sectionsService.DeleteAsync(new int[] { id }, token).ConfigureAwait(false); return Ok(result); @@ -79,7 +80,8 @@ namespace AsbCloudWebApi.Controllers private async Task CanUserAccessToWellAsync(int idWell, CancellationToken token = default) { int? idCompany = User.GetCompanyId(); - return idCompany is not null && await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell, token); + return idCompany is not null && await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, + idWell, token).ConfigureAwait(false); } } }