diff --git a/AsbCloudApp/Services/IDataService.cs b/AsbCloudApp/Services/IDataService.cs deleted file mode 100644 index c62f4678..00000000 --- a/AsbCloudApp/Services/IDataService.cs +++ /dev/null @@ -1,22 +0,0 @@ -using AsbCloudApp.Data; -using System; -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; - -namespace AsbCloudApp.Services -{ - - [Obsolete] - public interface IDataService - { - Task> GetAsync(int idWell, DateTime dateBegin = default, - double intervalSec = 600d, int approxPointsCount = 1024, - CancellationToken token = default); - - Task UpdateDataAsync(string uid, IEnumerable dtos, - CancellationToken token); - Task GetDataDatesRangeAsync(int idWell, - CancellationToken token); - } -} \ No newline at end of file diff --git a/AsbCloudDb/Readme.md b/AsbCloudDb/Readme.md index 1ec8eea1..161abdee 100644 --- a/AsbCloudDb/Readme.md +++ b/AsbCloudDb/Readme.md @@ -1,14 +1,13 @@ # Миграции -## создать миграцию +## Создать миграцию ``` dotnet ef migrations add --project AsbCloudDb ``` -## откатить миграцию +## Откатить миграцию ``` dotnet ef migrations remvoe --project AsbCloudDb ``` - - - Name of migration class +\ - Name of migration class. После создания миграции обязательно прочитать сгенерированый код. ## Применить миграции @@ -17,14 +16,15 @@ dotnet ef migrations remvoe --project AsbCloudDb dotnet ef database update --project .\AsbCloudDb ``` -# Backup +# Backup and restore +## Backup Terminal: ``` sudo -u postgres pg_dump -Fc -U postgres postgres -W > dump_2021-11-26.bak ``` -# Restore backup -## Step 1. (Re)Create DB and schema IF needeed. +## Restore backup +### Step 1. (Re)Create DB and schema IF needed. psql: ``` --drop schema public cascade; @@ -33,12 +33,13 @@ CREATE DATABASE postgres; create schema public; ``` -## Step 2. Innit timescaledb and prepare DB to restore +### Step 2. Innit timescaledb and prepare DB to restore ``` CREATE EXTENSION IF NOT EXISTS timescaledb; SELECT timescaledb_pre_restore(); ``` -## Step 3. Restore DB, then 'exit resore mode'. [Longest operation] + +### Step 3. Restore DB, then [Longest operation] Terminal: ``` sudo -u postgres psql -p 5499 -U postgres postgres -W < dump_2021-11-26.bak @@ -47,7 +48,7 @@ OR psql: ``` \! pg_restore -Fc -d postgres dump_2021-11-26.bak ``` -Then psql: +Then 'exit resore mode' psql: ``` SELECT timescaledb_post_restore(); ``` \ No newline at end of file diff --git a/AsbCloudInfrastructure/Services/Analysis/TelemetryAnalyticsService.cs b/AsbCloudInfrastructure/Services/Analysis/TelemetryAnalyticsService.cs index c2c6381a..e8ee381d 100644 --- a/AsbCloudInfrastructure/Services/Analysis/TelemetryAnalyticsService.cs +++ b/AsbCloudInfrastructure/Services/Analysis/TelemetryAnalyticsService.cs @@ -254,7 +254,7 @@ namespace AsbCloudInfrastructure.Services.Analysis if (dataSaubPart is null) break; - var count = dataSaubPart.Count(); + var count = dataSaubPart.Count; var skip = 0; if (step > count) @@ -434,31 +434,31 @@ namespace AsbCloudInfrastructure.Services.Analysis var intervalEndDate = operations.First().IntervalStart + intervalSeconds; - foreach (var op in operations) + foreach (var (IntervalStart, OperationName, OperationDuration) in operations) { - if (op.IntervalStart < intervalEndDate) + if (IntervalStart < intervalEndDate) { groupedOperationsObj.Operations.Add(new TelemetryOperationDetailsDto { - OperationName = op.OperationName, - DurationSec = op.OperationDuration + OperationName = OperationName, + DurationSec = OperationDuration }); } else { groupedOperationsList.Add(groupedOperationsObj); - intervalEndDate = op.IntervalStart + intervalSeconds; + intervalEndDate = IntervalStart + intervalSeconds; groupedOperationsObj = new TelemetryOperationInfoDto { - IntervalBegin = DateTimeOffset.FromUnixTimeSeconds(op.IntervalStart), + IntervalBegin = DateTimeOffset.FromUnixTimeSeconds(IntervalStart), Operations = new List() }; groupedOperationsObj.Operations.Add(new TelemetryOperationDetailsDto { - OperationName = op.OperationName, - DurationSec = op.OperationDuration + OperationName = OperationName, + DurationSec = OperationDuration }); } } diff --git a/AsbCloudInfrastructure/Services/AuthService.cs b/AsbCloudInfrastructure/Services/AuthService.cs index 470ef9a0..a8f3611d 100644 --- a/AsbCloudInfrastructure/Services/AuthService.cs +++ b/AsbCloudInfrastructure/Services/AuthService.cs @@ -195,7 +195,7 @@ namespace AsbCloudInfrastructure.Services return userPermissionsInfo.Select(p => new { PermissionName = cachePermissions.FirstOrDefault(c => c.Id == p.IdPermission)?.Name, - PermissionValue = p.PermissionValue + p.PermissionValue }).ToDictionary(k => k.PermissionName, v => v.PermissionValue); } diff --git a/AsbCloudInfrastructure/Services/ClusterService.cs b/AsbCloudInfrastructure/Services/ClusterService.cs index e4944329..fc2d11ee 100644 --- a/AsbCloudInfrastructure/Services/ClusterService.cs +++ b/AsbCloudInfrastructure/Services/ClusterService.cs @@ -33,7 +33,7 @@ namespace AsbCloudInfrastructure.Services select well).ToListAsync(token) .ConfigureAwait(false); - var gDepositEntities = groupWells(wellEntities); + var gDepositEntities = GroupWells(wellEntities); var dtos = CreateDepositDto(gDepositEntities); @@ -54,7 +54,7 @@ namespace AsbCloudInfrastructure.Services select well).ToListAsync(token) .ConfigureAwait(false); - var gDepositEntities = groupWells(wellEntities); + var gDepositEntities = GroupWells(wellEntities); var dtos = CreateDepositDto(gDepositEntities); @@ -114,7 +114,7 @@ namespace AsbCloudInfrastructure.Services return dtos; } - private IEnumerable>> groupWells(IEnumerable wellEntities) + private static IEnumerable>> GroupWells(IEnumerable wellEntities) { return wellEntities .GroupBy(w => w.Cluster) diff --git a/AsbCloudInfrastructure/Services/CrudServiceBase.cs b/AsbCloudInfrastructure/Services/CrudServiceBase.cs index 1dc6d100..10d4141a 100644 --- a/AsbCloudInfrastructure/Services/CrudServiceBase.cs +++ b/AsbCloudInfrastructure/Services/CrudServiceBase.cs @@ -104,7 +104,7 @@ namespace AsbCloudInfrastructure.Services public virtual async Task UpdateAsync(int id, TDto item, CancellationToken token = default) { - var existingEntity = await dbSet.AsNoTracking().FirstOrDefaultAsync(e => e.Id == id).ConfigureAwait(false); + var existingEntity = await dbSet.AsNoTracking().FirstOrDefaultAsync(e => e.Id == id, token).ConfigureAwait(false); if (existingEntity is null) return 0; var entity = Convert(item); diff --git a/AsbCloudInfrastructure/Services/MessageService.cs b/AsbCloudInfrastructure/Services/MessageService.cs index 56fd30e6..11fd706a 100644 --- a/AsbCloudInfrastructure/Services/MessageService.cs +++ b/AsbCloudInfrastructure/Services/MessageService.cs @@ -16,7 +16,6 @@ namespace AsbCloudInfrastructure.Services { private readonly IAsbCloudDbContext db; private readonly ITelemetryService telemetryService; - private readonly CacheTable cacheTelemetry; private readonly CacheTable cacheEvents; private readonly CacheTable cacheTUsers; @@ -24,7 +23,6 @@ namespace AsbCloudInfrastructure.Services { this.db = db; this.telemetryService = telemetryService; - cacheTelemetry = cacheDb.GetCachedTable((AsbCloudDbContext)db); cacheEvents = cacheDb.GetCachedTable((AsbCloudDbContext)db); cacheTUsers = cacheDb.GetCachedTable((AsbCloudDbContext)db); } diff --git a/AsbCloudInfrastructure/Services/RequerstTrackerService.cs b/AsbCloudInfrastructure/Services/RequerstTrackerService.cs index fda74784..695d0dd6 100644 --- a/AsbCloudInfrastructure/Services/RequerstTrackerService.cs +++ b/AsbCloudInfrastructure/Services/RequerstTrackerService.cs @@ -18,13 +18,12 @@ namespace AsbCloudInfrastructure.Services const int fastLimitMs = 500; static readonly char[] stackTraceSeparators = "\r\n".ToCharArray(); + private readonly ConcurrentQueue fastRequests = new ConcurrentQueue(); + private readonly ConcurrentQueue slowRequests = new ConcurrentQueue(); + private readonly ConcurrentQueue errorRequests = new ConcurrentQueue(); + private readonly ConcurrentDictionary users = new ConcurrentDictionary(); - ConcurrentQueue fastRequests = new ConcurrentQueue(); - ConcurrentQueue slowRequests = new ConcurrentQueue(); - ConcurrentQueue errorRequests = new ConcurrentQueue(); - ConcurrentDictionary users = new ConcurrentDictionary(); - - private IEnumerable Get(IEnumerable list, int take = -1) + private static IEnumerable Get(IEnumerable list, int take = -1) { IEnumerable orderedlist = list.OrderByDescending(r => r.Date); if (take > 0) diff --git a/AsbCloudInfrastructure/Services/WellOperationService/WellOperationImportService.cs b/AsbCloudInfrastructure/Services/WellOperationService/WellOperationImportService.cs index 3355ff89..b616f8b5 100644 --- a/AsbCloudInfrastructure/Services/WellOperationService/WellOperationImportService.cs +++ b/AsbCloudInfrastructure/Services/WellOperationService/WellOperationImportService.cs @@ -109,7 +109,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService return memoryStream; } - private void AddOperationsToWorkbook(XLWorkbook workbook, IEnumerable operations) + private static void AddOperationsToWorkbook(XLWorkbook workbook, IEnumerable operations) { var planOperations = operations.Where(o => o.IdType == 0); if (planOperations.Any()) @@ -126,17 +126,17 @@ namespace AsbCloudInfrastructure.Services.WellOperationService } } - private void AddOperationsToSheet(IXLWorksheet sheet, IEnumerable operations) + private static void AddOperationsToSheet(IXLWorksheet sheet, IEnumerable operations) { var operationsList = operations.ToList(); - for (int i = 0; i < operationsList.Count(); i++) + for (int i = 0; i < operationsList.Count; i++) { var row = sheet.Row(1 + i + headerRowsCount); AddOperationToRow(row, operationsList[i]); } } - private void AddOperationToRow(IXLRow row, WellOperation operation) + private static void AddOperationToRow(IXLRow row, WellOperation operation) { row.Cell(columnSection).Value = operation.WellSectionType?.Caption; row.Cell(columnCategory).Value = operation.OperationCategory?.Name; diff --git a/AsbCloudInfrastructure/Services/WellService.cs b/AsbCloudInfrastructure/Services/WellService.cs index 39c52770..0289915f 100644 --- a/AsbCloudInfrastructure/Services/WellService.cs +++ b/AsbCloudInfrastructure/Services/WellService.cs @@ -141,13 +141,13 @@ namespace AsbCloudInfrastructure.Services public async Task> GetClusterWellsIdsAsync(int idWell, CancellationToken token) { - var well = await cacheWells.FirstOrDefaultAsync(w => w.Id == idWell) + var well = await cacheWells.FirstOrDefaultAsync(w => w.Id == idWell, token) .ConfigureAwait(false); if (well is null) return null; - var clusterWells = await cacheWells.WhereAsync(w => w.IdCluster == well.IdCluster) + var clusterWells = await cacheWells.WhereAsync(w => w.IdCluster == well.IdCluster, token) .ConfigureAwait(false); return clusterWells.Select(w => w.Id); diff --git a/AsbCloudWebApi/Controllers/AdminTelemetryController.cs b/AsbCloudWebApi/Controllers/AdminTelemetryController.cs index 17daa825..eba4b213 100644 --- a/AsbCloudWebApi/Controllers/AdminTelemetryController.cs +++ b/AsbCloudWebApi/Controllers/AdminTelemetryController.cs @@ -27,7 +27,7 @@ namespace AsbCloudWebApi.Controllers [Route("/reduntentUids")] public IActionResult GetRedundentRemoteUids() { - var result = telemetryService.GetRedundentRemoteUids().Select(i => new { i.Key, ids = i.Item2 }); + var result = telemetryService.GetRedundentRemoteUids().Select(i => new { i.Key, ids = i.Ids }); return Ok(result); }