CS2-50: Added .ConfigureAwait(false) to all async methods.

This commit is contained in:
KharchenkoVV 2021-08-11 17:26:02 +05:00
parent f13b757a84
commit ab63bc4aa1
25 changed files with 179 additions and 110 deletions

View File

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

View File

@ -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<IEnumerable<WellDepthToIntervalDto>> 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<IEnumerable<TelemetryOperationInfoDto>> 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

View File

@ -41,7 +41,9 @@ namespace AsbCloudInfrastructure.Services
public async Task<UserTokenDto> 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;

View File

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

View File

@ -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
{

View File

@ -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<DataSaubBaseDto>();
@ -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<DataSaubBase>((int)telemetryId, token);
var (From, To) = await db.GetDatesRangeAsync<DataSaubBase>((int)telemetryId, token)
.ConfigureAwait(false);
return new DatesRangeDto { From = From, To = To };
}

View File

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

View File

@ -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;

View File

@ -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)
{

View File

@ -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<TelemetryMessage>((int)telemetryId, token);
var (From, To) = await db.GetDatesRangeAsync<TelemetryMessage>((int)telemetryId, token)
.ConfigureAwait(false);
return new DatesRangeDto { From = From, To = To };
}

View File

@ -95,7 +95,8 @@ namespace AsbCloudInfrastructure.Services
public async Task<IEnumerable<ReportPropertiesDto>> 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;
}

View File

@ -76,7 +76,7 @@ namespace AsbCloudInfrastructure.Services
public async Task<WellSectionDto> InsertAsync(WellSectionDto item, int idWell, CancellationToken token = default)
{
var sectionType = await GetWellSectionTypeFromCacheAndAssert(item.SectionType);
var sectionType = await GetWellSectionTypeFromCacheAndAssertAsync(item.SectionType);
var entity = item.Adapt<WellSection>();
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<WellSection>();
item.IdWell = idWell;
item.IdWellSectionType = sectionType.Id;
@ -117,7 +117,8 @@ namespace AsbCloudInfrastructure.Services
public async Task<WellSectionDto> 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<WellSection>();
entity.Id = idSection;
@ -138,7 +139,7 @@ namespace AsbCloudInfrastructure.Services
return context.SaveChangesAsync(token);
}
private async Task<WellSectionType> GetWellSectionTypeFromCacheAndAssert(string wellSectionType, CancellationToken token = default)
private async Task<WellSectionType> GetWellSectionTypeFromCacheAndAssertAsync(string wellSectionType, CancellationToken token = default)
{
if (string.IsNullOrEmpty(wellSectionType))
throw new ArgumentException("Тип секции должен быть указан", nameof(WellSectionDto.SectionType));

View File

@ -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<bool> 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<IEnumerable<WellOperationDto>> 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<WellOperationDto>();

View File

@ -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();

View File

@ -32,7 +32,9 @@ namespace AsbCloudWebApi.Controllers
[ProducesResponseType(typeof(UserTokenDto), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> 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"

View File

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

View File

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

View File

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

View File

@ -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();

View File

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

View File

@ -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();

View File

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

View File

@ -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<IActionResult> PostEventsAsync(string uid, [FromBody] List<EventDto> events,
CancellationToken token = default)
{
await eventService.UpsertAsync(uid, events, token);
await eventService.UpsertAsync(uid, events, token)
.ConfigureAwait(false);
telemetryTracker.SaveRequestDate(uid);
return Ok();
}

View File

@ -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();

View File

@ -26,7 +26,7 @@ namespace AsbCloudWebApi.Controllers
public async Task<IActionResult> 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<IActionResult> 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<IActionResult> InsertAsync(int idWell, [FromBody] IEnumerable<WellSectionDto> 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<IActionResult> 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<IActionResult> 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<bool> 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);
}
}
}