diff --git a/DD.Persistence.API/Controllers/ChangeLogController.cs b/DD.Persistence.API/Controllers/ChangeLogController.cs
index 21761e1..8b788c4 100644
--- a/DD.Persistence.API/Controllers/ChangeLogController.cs
+++ b/DD.Persistence.API/Controllers/ChangeLogController.cs
@@ -4,6 +4,7 @@ using DD.Persistence.Models;
using DD.Persistence.Models.Requests;
using DD.Persistence.Repositories;
using System.Net;
+using DD.Persistence.Models.Common;
namespace DD.Persistence.API.Controllers;
diff --git a/DD.Persistence.API/Controllers/DataSaubController.cs b/DD.Persistence.API/Controllers/DataSaubController.cs
deleted file mode 100644
index 832faec..0000000
--- a/DD.Persistence.API/Controllers/DataSaubController.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-using Microsoft.AspNetCore.Authorization;
-using Microsoft.AspNetCore.Mvc;
-using DD.Persistence.Models;
-using DD.Persistence.Repositories;
-
-namespace DD.Persistence.API.Controllers;
-
-///
-/// Работа с временными данными
-///
-[ApiController]
-[Authorize]
-[Route("api/[controller]")]
-public class DataSaubController : TimeSeriesController
-{
- public DataSaubController(ITimeSeriesDataRepository timeSeriesDataRepository) : base(timeSeriesDataRepository)
- {
-
- }
-}
diff --git a/DD.Persistence.API/Controllers/SetpointController.cs b/DD.Persistence.API/Controllers/SetpointController.cs
index e3b8b14..2f1c6fc 100644
--- a/DD.Persistence.API/Controllers/SetpointController.cs
+++ b/DD.Persistence.API/Controllers/SetpointController.cs
@@ -3,6 +3,8 @@ using Microsoft.AspNetCore.Mvc;
using DD.Persistence.Models;
using DD.Persistence.Repositories;
using System.Net;
+using System.Text.Json;
+using DD.Persistence.Models.Common;
namespace DD.Persistence.API.Controllers;
@@ -28,9 +30,9 @@ public class SetpointController : ControllerBase, ISetpointApi
///
///
[HttpGet("current")]
- public async Task>> GetCurrent([FromQuery] IEnumerable setpointKeys, CancellationToken token)
+ public async Task>> GetCurrent([FromQuery] IEnumerable setpointKeys, CancellationToken token)
{
- var result = await setpointRepository.GetCurrent(setpointKeys, token);
+ var result = await setpointRepository.GetCurrentDictionary(setpointKeys, token);
return Ok(result);
}
@@ -104,7 +106,7 @@ public class SetpointController : ControllerBase, ISetpointApi
public async Task Add(Guid setpointKey, object newValue, CancellationToken token)
{
var userId = User.GetUserId();
- await setpointRepository.Add(setpointKey, newValue, userId, token);
+ await setpointRepository.Add(setpointKey, (JsonElement)newValue, userId, token);
return CreatedAtAction(nameof(Add), true);
}
diff --git a/DD.Persistence.API/Controllers/TechMessagesController.cs b/DD.Persistence.API/Controllers/TechMessagesController.cs
index 81663e0..cd98e42 100644
--- a/DD.Persistence.API/Controllers/TechMessagesController.cs
+++ b/DD.Persistence.API/Controllers/TechMessagesController.cs
@@ -4,6 +4,7 @@ using DD.Persistence.Models;
using DD.Persistence.Models.Requests;
using DD.Persistence.Repositories;
using System.Net;
+using DD.Persistence.Models.Common;
namespace DD.Persistence.API.Controllers;
diff --git a/DD.Persistence.API/Controllers/TimeSeriesController.cs b/DD.Persistence.API/Controllers/TimeSeriesController.cs
deleted file mode 100644
index 5fded36..0000000
--- a/DD.Persistence.API/Controllers/TimeSeriesController.cs
+++ /dev/null
@@ -1,76 +0,0 @@
-using Microsoft.AspNetCore.Authorization;
-using Microsoft.AspNetCore.Mvc;
-using DD.Persistence.Models;
-using DD.Persistence.Repositories;
-
-namespace DD.Persistence.API.Controllers;
-
-[ApiController]
-[Authorize]
-[Route("api/[controller]")]
-public class TimeSeriesController : ControllerBase, ITimeSeriesDataApi
- where TDto : class, ITimeSeriesAbstractDto, new()
-{
- private readonly ITimeSeriesDataRepository timeSeriesDataRepository;
-
- public TimeSeriesController(ITimeSeriesDataRepository timeSeriesDataRepository)
- {
- this.timeSeriesDataRepository = timeSeriesDataRepository;
- }
-
- ///
- /// Получить список объектов, удовлетворяющий диапазону дат
- ///
- ///
- ///
- ///
- [HttpGet]
- [ProducesResponseType(StatusCodes.Status200OK)]
- public async Task Get(DateTimeOffset dateBegin, CancellationToken token)
- {
- var result = await timeSeriesDataRepository.GetGtDate(dateBegin, token);
- return Ok(result);
- }
-
- ///
- /// Получить диапазон дат, для которых есть данные в репозитории
- ///
- ///
- ///
- [HttpGet("datesRange")]
- public async Task GetDatesRange(CancellationToken token)
- {
- var result = await timeSeriesDataRepository.GetDatesRange(token);
- return Ok(result);
- }
-
- ///
- /// Получить список объектов с прореживанием, удовлетворяющий диапазону дат
- ///
- ///
- ///
- ///
- ///
- ///
- [HttpGet("resampled")]
- public async Task GetResampledData(DateTimeOffset dateBegin, double intervalSec = 600d, int approxPointsCount = 1024, CancellationToken token = default)
- {
- var result = await timeSeriesDataRepository.GetResampledData(dateBegin, intervalSec, approxPointsCount, token);
- return Ok(result);
- }
-
- ///
- /// Добавить записи
- ///
- ///
- ///
- ///
- [HttpPost]
- public async Task AddRange(IEnumerable dtos, CancellationToken token)
- {
- var result = await timeSeriesDataRepository.AddRange(dtos, token);
- return Ok(result);
- }
-
-
-}
diff --git a/DD.Persistence.API/Controllers/TimestampedSetController.cs b/DD.Persistence.API/Controllers/TimestampedSetController.cs
deleted file mode 100644
index 0c805ab..0000000
--- a/DD.Persistence.API/Controllers/TimestampedSetController.cs
+++ /dev/null
@@ -1,104 +0,0 @@
-using Microsoft.AspNetCore.Authorization;
-using Microsoft.AspNetCore.Mvc;
-using DD.Persistence.Models;
-using DD.Persistence.Repositories;
-using System.Net;
-
-namespace DD.Persistence.API.Controllers;
-
-///
-/// Хранение наборов данных с отметкой времени.
-/// Не оптимизировано под большие данные.
-///
-[ApiController]
-[Authorize]
-[Route("api/[controller]/{idDiscriminator}")]
-public class TimestampedSetController : ControllerBase
-{
- private readonly ITimestampedSetRepository repository;
-
- public TimestampedSetController(ITimestampedSetRepository repository)
- {
- this.repository = repository;
- }
-
- ///
- /// Записать новые данные
- /// Предполагается что данные с одним дискриминатором имеют одинаковую структуру
- ///
- /// Дискриминатор (идентификатор) набора
- ///
- ///
- /// кол-во затронутых записей
- [HttpPost]
- [ProducesResponseType(typeof(int), (int)HttpStatusCode.OK)]
- public async Task AddRange([FromRoute] Guid idDiscriminator, [FromBody] IEnumerable sets, CancellationToken token)
- {
- var result = await repository.AddRange(idDiscriminator, sets, token);
- return Ok(result);
- }
-
- ///
- /// Получение данных с фильтрацией. Значение фильтра null - отключен
- ///
- /// Дискриминатор (идентификатор) набора
- /// Фильтр позднее даты
- /// Фильтр свойств набора. Можно запросить только некоторые свойства из набора
- ///
- ///
- ///
- /// Фильтрованный набор данных с сортировкой по отметке времени
- [HttpGet]
- [ProducesResponseType(typeof(IEnumerable), (int)HttpStatusCode.OK)]
- public async Task Get(Guid idDiscriminator, DateTimeOffset? geTimestamp, [FromQuery] IEnumerable? columnNames, int skip, int take, CancellationToken token)
- {
- var result = await repository.Get(idDiscriminator, geTimestamp, columnNames, skip, take, token);
- return Ok(result);
- }
-
- ///
- /// Получить последние данные
- ///
- /// Дискриминатор (идентификатор) набора
- /// Фильтр свойств набора. Можно запросить только некоторые свойства из набора
- ///
- ///
- /// Фильтрованный набор данных с сортировкой по отметке времени
- [HttpGet("last")]
- [ProducesResponseType(typeof(IEnumerable), (int)HttpStatusCode.OK)]
- public async Task GetLast(Guid idDiscriminator, [FromQuery] IEnumerable? columnNames, int take, CancellationToken token)
- {
- var result = await repository.GetLast(idDiscriminator, columnNames, take, token);
- return Ok(result);
- }
-
- ///
- /// Диапазон дат за которые есть данные
- ///
- ///
- ///
- /// Дата первой и последней записи
- [HttpGet("datesRange")]
- [ProducesResponseType(typeof(DatesRangeDto), (int)HttpStatusCode.OK)]
- [ProducesResponseType((int)HttpStatusCode.NoContent)]
- public async Task GetDatesRange(Guid idDiscriminator, CancellationToken token)
- {
- var result = await repository.GetDatesRange(idDiscriminator, token);
- return Ok(result);
- }
-
- ///
- /// Количество записей по указанному набору в БД. Для пагинации.
- ///
- /// Дискриминатор (идентификатор) набора
- ///
- ///
- [HttpGet("count")]
- [ProducesResponseType(typeof(int), (int)HttpStatusCode.OK)]
- [ProducesResponseType((int)HttpStatusCode.NoContent)]
- public async Task Count(Guid idDiscriminator, CancellationToken token)
- {
- var result = await repository.Count(idDiscriminator, token);
- return Ok(result);
- }
-}
diff --git a/DD.Persistence.API/Controllers/TimestampedValuesController.cs b/DD.Persistence.API/Controllers/TimestampedValuesController.cs
new file mode 100644
index 0000000..abc1114
--- /dev/null
+++ b/DD.Persistence.API/Controllers/TimestampedValuesController.cs
@@ -0,0 +1,151 @@
+using DD.Persistence.Models;
+using DD.Persistence.Models.Common;
+using DD.Persistence.Services.Interfaces;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Mvc;
+using System.Net;
+
+namespace DD.Persistence.API.Controllers;
+
+///
+/// Хранение наборов данных с отметкой времени.
+///
+[ApiController]
+[Authorize]
+[Route("api/[controller]/{discriminatorId}")]
+public class TimestampedValuesController : ControllerBase
+{
+ private readonly ITimestampedValuesService timestampedValuesRepository;
+
+ public TimestampedValuesController(ITimestampedValuesService repository)
+ {
+ this.timestampedValuesRepository = repository;
+ }
+
+ ///
+ /// Записать новые данные.
+ /// Предполагается что данные с одним дискриминатором имеют одинаковую структуру
+ ///
+ /// Дискриминатор (идентификатор) набора
+ ///
+ ///
+ [HttpPost]
+ [ProducesResponseType(typeof(int), (int)HttpStatusCode.Created)]
+ public async Task AddRange([FromRoute] Guid discriminatorId, [FromBody] IEnumerable dtos, CancellationToken token)
+ {
+ var result = await timestampedValuesRepository.AddRange(discriminatorId, dtos, token);
+
+ return CreatedAtAction(nameof(AddRange), result);
+ }
+
+ ///
+ /// Получение данных с фильтрацией. Значение фильтра null - отключен
+ ///
+ /// Дискриминатор (идентификатор) набора
+ /// Фильтр позднее даты
+ /// Фильтр свойств набора
+ ///
+ ///
+ ///
+ [HttpGet]
+ [ProducesResponseType(typeof(IEnumerable), (int)HttpStatusCode.OK)]
+ [ProducesResponseType((int)HttpStatusCode.NoContent)]
+ public async Task>> Get([FromRoute] Guid discriminatorId, DateTimeOffset? timestampBegin, [FromQuery] string[]? columnNames, int skip, int take, CancellationToken token)
+ {
+ var result = await timestampedValuesRepository.Get(discriminatorId, timestampBegin, columnNames, skip, take, token);
+
+ return result.Any() ? Ok(result) : NoContent();
+ }
+
+ ///
+ /// Получить данные, начиная с заданной отметки времени
+ ///
+ /// Дискриминатор (идентификатор) набора
+ /// Фильтр позднее даты
+ ///
+ [HttpGet("gtdate")]
+ [ProducesResponseType(typeof(IEnumerable), (int)HttpStatusCode.OK)]
+ [ProducesResponseType((int)HttpStatusCode.NoContent)]
+ public async Task>> GetGtDate([FromRoute] Guid discriminatorId, DateTimeOffset timestampBegin, CancellationToken token)
+ {
+ var result = await timestampedValuesRepository.GetGtDate(discriminatorId, timestampBegin, token);
+
+ return result.Any() ? Ok(result) : NoContent();
+ }
+
+ ///
+ /// Получить данные c начала
+ ///
+ /// Дискриминатор (идентификатор) набора
+ ///
+ ///
+ [HttpGet("first")]
+ [ProducesResponseType(typeof(IEnumerable), (int)HttpStatusCode.OK)]
+ [ProducesResponseType((int)HttpStatusCode.NoContent)]
+ public async Task>> GetFirst([FromRoute] Guid discriminatorId, int take, CancellationToken token)
+ {
+ var result = await timestampedValuesRepository.GetFirst(discriminatorId, take, token);
+
+ return result.Any() ? Ok(result) : NoContent();
+ }
+
+ ///
+ /// Получить данные c конца
+ ///
+ /// Дискриминатор (идентификатор) набора
+ ///
+ ///
+ [HttpGet("last")]
+ [ProducesResponseType(typeof(IEnumerable), (int)HttpStatusCode.OK)]
+ [ProducesResponseType((int)HttpStatusCode.NoContent)]
+ public async Task>> GetLast([FromRoute] Guid discriminatorId, int take, CancellationToken token)
+ {
+ var result = await timestampedValuesRepository.GetLast(discriminatorId, take, token);
+
+ return result.Any() ? Ok(result) : NoContent();
+ }
+
+ ///
+ /// Получить список объектов с прореживанием, удовлетворяющий диапазону дат
+ ///
+ /// Дискриминатор (идентификатор) набора
+ /// Фильтр позднее даты
+ ///
+ ///
+ ///
+ [HttpGet("resampled")]
+ [ProducesResponseType(typeof(IEnumerable), (int)HttpStatusCode.OK)]
+ [ProducesResponseType((int)HttpStatusCode.NoContent)]
+ public async Task>> GetResampledData([FromRoute] Guid discriminatorId, DateTimeOffset timestampBegin, double intervalSec = 600d, int approxPointsCount = 1024, CancellationToken token = default)
+ {
+ var result = await timestampedValuesRepository.GetResampledData(discriminatorId, timestampBegin, intervalSec, approxPointsCount, token);
+
+ return result.Any() ? Ok(result) : NoContent();
+ }
+
+ ///
+ /// Получить количество записей по указанному набору в БД. Для пагинации
+ ///
+ /// Дискриминатор (идентификатор) набора
+ ///
+ [HttpGet("count")]
+ public async Task> Count([FromRoute] Guid discriminatorId, CancellationToken token)
+ {
+ var result = await timestampedValuesRepository.Count(discriminatorId, token);
+
+ return Ok(result);
+ }
+
+ ///
+ /// Получить диапазон дат, в пределах которых хранятся даные
+ ///
+ ///
+ ///
+ [HttpGet("datesRange")]
+ public async Task> GetDatesRange([FromRoute] Guid discriminatorId, CancellationToken token)
+ {
+ var result = await timestampedValuesRepository.GetDatesRange(discriminatorId, token);
+
+ return Ok(result);
+ }
+}
diff --git a/DD.Persistence.API/Controllers/WitsDataController.cs b/DD.Persistence.API/Controllers/WitsDataController.cs
index 5df6c3f..c87345e 100644
--- a/DD.Persistence.API/Controllers/WitsDataController.cs
+++ b/DD.Persistence.API/Controllers/WitsDataController.cs
@@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Mvc;
using DD.Persistence.Models;
using DD.Persistence.Services.Interfaces;
using System.Net;
+using DD.Persistence.Models.Common;
namespace DD.Persistence.API.Controllers;
diff --git a/DD.Persistence.API/DependencyInjection.cs b/DD.Persistence.API/DependencyInjection.cs
index b0a71d5..b543841 100644
--- a/DD.Persistence.API/DependencyInjection.cs
+++ b/DD.Persistence.API/DependencyInjection.cs
@@ -16,12 +16,6 @@ namespace DD.Persistence.API;
public static class DependencyInjection
{
- //public static void MapsterSetup()
- //{
- // TypeAdapterConfig.GlobalSettings.Default.Config
- // .ForType()
- // .Ignore(dest => dest.System, dest => dest.SystemId);
- //}
public static void AddSwagger(this IServiceCollection services, IConfiguration configuration)
{
services.AddSwaggerGen(c =>
@@ -59,6 +53,7 @@ public static class DependencyInjection
public static void AddServices(this IServiceCollection services)
{
services.AddTransient();
+ services.AddTransient();
}
#region Authentication
diff --git a/DD.Persistence.API/Readme.md b/DD.Persistence.API/Readme.md
new file mode 100644
index 0000000..43bbbf3
--- /dev/null
+++ b/DD.Persistence.API/Readme.md
@@ -0,0 +1,51 @@
+# Persistence Service Readme
+
+## Краткое описание
+Persistence сервис отвечает за работу с хранимыми данными
+в рамках совокупности различных систем.
+
+## Локальное развертывание
+1. Скачать репозиторий по SSH
+```
+ssh://git@git.ddrilling.ru:2221/on.nemtina/persistence.git
+```
+
+Для доступа к репозиториям редварительно необходимо сгенерировать SSH ключ и добавить его в Gitea
+
+2. Выбрать ветку dev
+
+## Использование Swagger-а
+1. Сконфигурировать appsettings.Development.json
+(при отсутствии) занести флаг:
+```json
+"NeedUseKeyCloak": true
+```
+2. Запустить решение в режиме Debug
+3. Выполнить авторизацию через KeyCloak - качестве client_id указать:
+```
+webapi
+```
+После этого должен произойти редирект на страницу авторизации в KeyCloak
+
+4. Заполнить поля и авторизоваться
+```
+Username or email: myuser
+```
+```
+Password: 12345
+```
+
+## Тестирование
+Запуск тестов рекомендуется осуществлять без использования KeyCloak
Для этого
+настройка appsettings.Tests.json должна содержать:
+```
+"NeedUseKeyCloak": false,
+"AuthUser": {
+ "username": "myuser",
+ "password": 12345,
+ "clientId": "webapi",
+ "grantType": "password"
+}
+```
+
+
diff --git a/DD.Persistence.API/Startup.cs b/DD.Persistence.API/Startup.cs
index c6c44a4..c5e8c5a 100644
--- a/DD.Persistence.API/Startup.cs
+++ b/DD.Persistence.API/Startup.cs
@@ -26,8 +26,6 @@ public class Startup
services.AddJWTAuthentication(Configuration);
services.AddMemoryCache();
services.AddServices();
-
- //DependencyInjection.MapsterSetup();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
diff --git a/DD.Persistence.App/appsettings.json b/DD.Persistence.App/appsettings.json
index 8002fc7..7ad8c67 100644
--- a/DD.Persistence.App/appsettings.json
+++ b/DD.Persistence.App/appsettings.json
@@ -19,6 +19,7 @@
"password": 12345,
"clientId": "webapi",
"grantType": "password",
- "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier": "7d9f3574-6574-4ca3-845a-0276eb4aa8f6"
- }
+ "http://schemas.xmlsoap.org/ws/2005/05/identity /claims/nameidentifier": "7d9f3574-6574-4ca3-845a-0276eb4aa8f6"
+ },
+ "ClientUrl": "http://localhost:5000/"
}
diff --git a/DD.Persistence.Client/Clients/ChangeLogClient.cs b/DD.Persistence.Client/Clients/ChangeLogClient.cs
index e10008e..e4f5904 100644
--- a/DD.Persistence.Client/Clients/ChangeLogClient.cs
+++ b/DD.Persistence.Client/Clients/ChangeLogClient.cs
@@ -3,16 +3,18 @@ using DD.Persistence.Client.Clients.Base;
using DD.Persistence.Client.Clients.Interfaces;
using DD.Persistence.Models;
using DD.Persistence.Models.Requests;
+using DD.Persistence.Client.Clients.Interfaces.Refit;
+using DD.Persistence.Models.Common;
namespace DD.Persistence.Client.Clients;
public class ChangeLogClient : BaseClient, IChangeLogClient
{
- private readonly Interfaces.Refit.IRefitChangeLogClient refitChangeLogClient;
+ private readonly IRefitChangeLogClient refitChangeLogClient;
- public ChangeLogClient(Interfaces.Refit.IRefitChangeLogClient refitChangeLogClient, ILogger logger) : base(logger)
+ public ChangeLogClient(IRefitClientFactory refitClientFactory, ILogger logger) : base(logger)
{
- this.refitChangeLogClient = refitChangeLogClient;
- }
+ this.refitChangeLogClient = refitClientFactory.Create();
+ }
public async Task ClearAndAddRange(Guid idDiscriminator, IEnumerable dtos, CancellationToken token)
{
diff --git a/DD.Persistence.Client/Clients/DataSourceSystemClient.cs b/DD.Persistence.Client/Clients/DataSourceSystemClient.cs
index 45e2d29..7e70255 100644
--- a/DD.Persistence.Client/Clients/DataSourceSystemClient.cs
+++ b/DD.Persistence.Client/Clients/DataSourceSystemClient.cs
@@ -9,9 +9,9 @@ public class DataSourceSystemClient : BaseClient, IDataSourceSystemClient
{
private readonly IRefitDataSourceSystemClient dataSourceSystemClient;
- public DataSourceSystemClient(IRefitDataSourceSystemClient dataSourceSystemClient, ILogger logger) : base(logger)
+ public DataSourceSystemClient(IRefitClientFactory dataSourceSystemClientFactory, ILogger logger) : base(logger)
{
- this.dataSourceSystemClient = dataSourceSystemClient;
+ this.dataSourceSystemClient = dataSourceSystemClientFactory.Create();
}
public async Task Add(DataSourceSystemDto dataSourceSystemDto, CancellationToken token)
diff --git a/DD.Persistence.Client/Clients/Interfaces/IChangeLogClient.cs b/DD.Persistence.Client/Clients/Interfaces/IChangeLogClient.cs
index 19edeab..f81ac8d 100644
--- a/DD.Persistence.Client/Clients/Interfaces/IChangeLogClient.cs
+++ b/DD.Persistence.Client/Clients/Interfaces/IChangeLogClient.cs
@@ -1,4 +1,5 @@
using DD.Persistence.Models;
+using DD.Persistence.Models.Common;
using DD.Persistence.Models.Requests;
namespace DD.Persistence.Client.Clients.Interfaces;
diff --git a/DD.Persistence.Client/Clients/Interfaces/ISetpointClient.cs b/DD.Persistence.Client/Clients/Interfaces/ISetpointClient.cs
index 86462ea..407eb1c 100644
--- a/DD.Persistence.Client/Clients/Interfaces/ISetpointClient.cs
+++ b/DD.Persistence.Client/Clients/Interfaces/ISetpointClient.cs
@@ -1,4 +1,5 @@
using DD.Persistence.Models;
+using DD.Persistence.Models.Common;
namespace DD.Persistence.Client.Clients.Interfaces;
@@ -24,12 +25,21 @@ public interface ISetpointClient : IDisposable
///
Task> GetCurrent(IEnumerable setpointKeys, CancellationToken token);
- ///
- /// Получить диапазон дат, для которых есть данные в репозитории
- ///
- ///
- ///
- Task GetDatesRangeAsync(CancellationToken token);
+ ///
+ /// Получить актуальные значения уставок
+ ///
+ ///
+ ///
+ /// s
+ Task> GetCurrentDictionary(IEnumerable setpointConfigs, CancellationToken token);
+
+
+ ///
+ /// Получить диапазон дат, для которых есть данные в репозитории
+ ///
+ ///
+ ///
+ Task GetDatesRangeAsync(CancellationToken token);
///
/// Получить значения уставок за определенный момент времени
diff --git a/DD.Persistence.Client/Clients/Interfaces/ITechMessagesClient.cs b/DD.Persistence.Client/Clients/Interfaces/ITechMessagesClient.cs
index a27e553..2af1af6 100644
--- a/DD.Persistence.Client/Clients/Interfaces/ITechMessagesClient.cs
+++ b/DD.Persistence.Client/Clients/Interfaces/ITechMessagesClient.cs
@@ -1,4 +1,5 @@
using DD.Persistence.Models;
+using DD.Persistence.Models.Common;
using DD.Persistence.Models.Requests;
namespace DD.Persistence.Client.Clients.Interfaces;
diff --git a/DD.Persistence.Client/Clients/Interfaces/ITimeSeriesClient.cs b/DD.Persistence.Client/Clients/Interfaces/ITimeSeriesClient.cs
deleted file mode 100644
index 26bbfa6..0000000
--- a/DD.Persistence.Client/Clients/Interfaces/ITimeSeriesClient.cs
+++ /dev/null
@@ -1,44 +0,0 @@
-using DD.Persistence.Models;
-
-namespace DD.Persistence.Client.Clients.Interfaces;
-
-///
-/// Клиент для работы с временными данными
-///
-///
-public interface ITimeSeriesClient : IDisposable where TDto : class, new()
-{
- ///
- /// Добавление записей
- ///
- ///
- ///
- ///
- Task AddRange(IEnumerable dtos, CancellationToken token);
-
- ///
- /// Получить список объектов, удовлетворяющий диапазону дат
- ///
- ///
- ///
- ///
- ///
- Task> Get(DateTimeOffset dateBegin, DateTimeOffset dateEnd, CancellationToken token);
-
- ///
- /// Получить диапазон дат, для которых есть данные в репозитории
- ///
- ///
- ///
- Task GetDatesRange(CancellationToken token);
-
- ///
- /// Получить список объектов с прореживанием, удовлетворяющий диапазону дат
- ///
- ///
- ///
- ///
- ///
- ///
- Task> GetResampledData(DateTimeOffset dateBegin, double intervalSec = 600, int approxPointsCount = 1024, CancellationToken token = default);
-}
\ No newline at end of file
diff --git a/DD.Persistence.Client/Clients/Interfaces/ITimestampedSetClient.cs b/DD.Persistence.Client/Clients/Interfaces/ITimestampedSetClient.cs
deleted file mode 100644
index be98a77..0000000
--- a/DD.Persistence.Client/Clients/Interfaces/ITimestampedSetClient.cs
+++ /dev/null
@@ -1,59 +0,0 @@
-using DD.Persistence.Models;
-
-namespace DD.Persistence.Client.Clients.Interfaces;
-
-///
-/// Клиент для работы с репозиторием для хранения разных наборов данных рядов.
-/// idDiscriminator - идентифицирует конкретный набор данных, прим.: циклы измерения АСИБР, или отчет о DrillTest.
-/// idDiscriminator формируют клиенты и только им известно что они обозначают.
-/// Так как данные приходят редко, то их прореживания для построения графиков не предусмотрено.
-///
-public interface ITimestampedSetClient : IDisposable
-{
- ///
- /// Записать новые данные
- ///
- ///
- ///
- ///
- ///
- Task AddRange(Guid idDiscriminator, IEnumerable sets, CancellationToken token);
-
- ///
- /// Количество записей по указанному набору в БД. Для пагинации
- ///
- ///
- ///
- ///
- Task Count(Guid idDiscriminator, CancellationToken token);
-
- ///
- /// Получение данных с фильтрацией. Значение фильтра null - отключен
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- Task> Get(Guid idDiscriminator, DateTimeOffset? geTimestamp, IEnumerable? columnNames, int skip, int take, CancellationToken token);
-
- ///
- /// Диапазон дат за которые есть данные
- ///
- ///
- ///
- ///
- Task GetDatesRange(Guid idDiscriminator, CancellationToken token);
-
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- Task> GetLast(Guid idDiscriminator, IEnumerable? columnNames, int take, CancellationToken token);
-}
\ No newline at end of file
diff --git a/DD.Persistence.Client/Clients/Interfaces/ITimestampedValuesClient.cs b/DD.Persistence.Client/Clients/Interfaces/ITimestampedValuesClient.cs
new file mode 100644
index 0000000..b0ea180
--- /dev/null
+++ b/DD.Persistence.Client/Clients/Interfaces/ITimestampedValuesClient.cs
@@ -0,0 +1,103 @@
+using DD.Persistence.Models;
+using DD.Persistence.Models.Common;
+
+namespace DD.Persistence.Client.Clients.Interfaces;
+
+///
+/// Клиент для работы с наборами данных, имеющими отметку времени.
+/// discriminatorId - идентифицирует конкретный набор данных, прим.: циклы измерения АСИБР, или отчет о DrillTest.
+/// discriminatorId формируют клиенты и только им известно что они обозначают.
+///
+public interface ITimestampedValuesClient : IDisposable
+{
+ ///
+ /// Записать новые данные
+ /// Предполагается что данные с одним дискриминатором имеют одинаковую структуру
+ ///
+ /// Дискриминатор (идентификатор) набора
+ ///
+ ///
+ Task AddRange(Guid discriminatorId, IEnumerable dtos, CancellationToken token);
+
+ ///
+ /// Получить данные с фильтрацией. Значение фильтра null - отключен
+ ///
+ /// Дискриминатор (идентификатор) набора
+ /// Фильтр позднее даты
+ /// Фильтр свойств набора
+ ///
+ ///
+ ///
+ Task> Get(Guid discriminatorId, DateTimeOffset? timestampBegin, IEnumerable? columnNames, int skip, int take, CancellationToken token);
+
+ ///
+ /// Получить данные, начиная с заданной отметки времени
+ ///
+ /// Дискриминатор (идентификатор) набора
+ /// Фильтр позднее даты
+ ///
+ Task> GetGtDate(Guid discriminatorId, DateTimeOffset timestampBegin, CancellationToken token);
+
+ ///
+ /// Получить данные с начала
+ ///
+ /// Дискриминатор (идентификатор) набора
+ ///
+ ///
+ Task> GetFirst(Guid discriminatorId, int take, CancellationToken token);
+
+ ///
+ /// Получить данные с конца
+ ///
+ /// Дискриминатор (идентификатор) набора
+ ///
+ ///
+ Task> GetLast(Guid discriminatorId, int take, CancellationToken token);
+
+ ///
+ /// Получить данные с прореживанием, удовлетворяющем диапазону дат
+ ///
+ /// Дискриминатор (идентификатор) набора
+ ///
+ ///
+ ///
+ ///
+ Task> GetResampledData(Guid discriminatorId, DateTimeOffset timestampBegin, double intervalSec = 600d, int approxPointsCount = 1024, CancellationToken token = default);
+
+ ///
+ /// Количество записей по указанному набору в БД. Для пагинации
+ ///
+ /// Дискриминатор (идентификатор) набора
+ ///
+ Task Count(Guid discriminatorId, CancellationToken token);
+
+ ///
+ /// Диапазон дат, в пределах которых осуществляется хранение данных
+ ///
+ /// Дискриминатор (идентификатор) набора
+ ///
+ Task GetDatesRange(Guid discriminatorId, CancellationToken token);
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task> Get(Guid idDiscriminator, DateTimeOffset? geTimestamp, IEnumerable? columnNames, int skip, int take, CancellationToken token);
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task> GetLast(Guid idDiscriminator, int take, CancellationToken token);
+}
\ No newline at end of file
diff --git a/DD.Persistence.Client/Clients/Interfaces/IWitsDataClient.cs b/DD.Persistence.Client/Clients/Interfaces/IWitsDataClient.cs
index e954484..0ac015d 100644
--- a/DD.Persistence.Client/Clients/Interfaces/IWitsDataClient.cs
+++ b/DD.Persistence.Client/Clients/Interfaces/IWitsDataClient.cs
@@ -1,4 +1,5 @@
using DD.Persistence.Models;
+using DD.Persistence.Models.Common;
using Refit;
namespace DD.Persistence.Client.Clients.Interfaces;
diff --git a/DD.Persistence.Client/Clients/Interfaces/Refit/IRefitChangeLogClient.cs b/DD.Persistence.Client/Clients/Interfaces/Refit/IRefitChangeLogClient.cs
index 958e24e..8e35b4e 100644
--- a/DD.Persistence.Client/Clients/Interfaces/Refit/IRefitChangeLogClient.cs
+++ b/DD.Persistence.Client/Clients/Interfaces/Refit/IRefitChangeLogClient.cs
@@ -1,10 +1,11 @@
using DD.Persistence.Models;
+using DD.Persistence.Models.Common;
using DD.Persistence.Models.Requests;
using Refit;
namespace DD.Persistence.Client.Clients.Interfaces.Refit;
-public interface IRefitChangeLogClient : IDisposable
+public interface IRefitChangeLogClient : IRefitClient, IDisposable
{
private const string BaseRoute = "/api/ChangeLog";
diff --git a/DD.Persistence.Client/Clients/Interfaces/Refit/IRefitClient.cs b/DD.Persistence.Client/Clients/Interfaces/Refit/IRefitClient.cs
new file mode 100644
index 0000000..4a140e0
--- /dev/null
+++ b/DD.Persistence.Client/Clients/Interfaces/Refit/IRefitClient.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DD.Persistence.Client.Clients.Interfaces.Refit;
+
+///
+/// Базовый Refit интерфейс
+///
+public interface IRefitClient
+{
+}
diff --git a/DD.Persistence.Client/Clients/Interfaces/Refit/IRefitDataSourceSystemClient.cs b/DD.Persistence.Client/Clients/Interfaces/Refit/IRefitDataSourceSystemClient.cs
index a4b47eb..313d8cc 100644
--- a/DD.Persistence.Client/Clients/Interfaces/Refit/IRefitDataSourceSystemClient.cs
+++ b/DD.Persistence.Client/Clients/Interfaces/Refit/IRefitDataSourceSystemClient.cs
@@ -2,7 +2,7 @@
using Refit;
namespace DD.Persistence.Client.Clients.Interfaces.Refit;
-public interface IRefitDataSourceSystemClient : IDisposable
+public interface IRefitDataSourceSystemClient : IRefitClient, IDisposable
{
private const string BaseRoute = "/api/dataSourceSystem";
diff --git a/DD.Persistence.Client/Clients/Interfaces/Refit/IRefitSetpointClient.cs b/DD.Persistence.Client/Clients/Interfaces/Refit/IRefitSetpointClient.cs
index b6e021a..7931e6d 100644
--- a/DD.Persistence.Client/Clients/Interfaces/Refit/IRefitSetpointClient.cs
+++ b/DD.Persistence.Client/Clients/Interfaces/Refit/IRefitSetpointClient.cs
@@ -1,14 +1,19 @@
using DD.Persistence.Models;
+using DD.Persistence.Models.Common;
using Refit;
+using System.Text.Json;
namespace DD.Persistence.Client.Clients.Interfaces.Refit;
-public interface IRefitSetpointClient : IDisposable
+public interface IRefitSetpointClient : IRefitClient, IDisposable
{
private const string BaseRoute = "/api/setpoint";
+ //[Get($"{BaseRoute}/current")]
+ //Task>> GetCurrent([Query(CollectionFormat.Multi)] IEnumerable setpointKeys, CancellationToken token);
+
[Get($"{BaseRoute}/current")]
- Task>> GetCurrent([Query(CollectionFormat.Multi)] IEnumerable setpointKeys, CancellationToken token);
+ Task>> GetCurrent([Query(CollectionFormat.Multi)] IEnumerable setpointKeys, CancellationToken token);
[Get($"{BaseRoute}/history")]
Task>> GetHistory([Query(CollectionFormat.Multi)] IEnumerable setpointKeys, [Query] DateTimeOffset historyMoment, CancellationToken token);
diff --git a/DD.Persistence.Client/Clients/Interfaces/Refit/IRefitTechMessagesClient.cs b/DD.Persistence.Client/Clients/Interfaces/Refit/IRefitTechMessagesClient.cs
index 2638600..ef9496e 100644
--- a/DD.Persistence.Client/Clients/Interfaces/Refit/IRefitTechMessagesClient.cs
+++ b/DD.Persistence.Client/Clients/Interfaces/Refit/IRefitTechMessagesClient.cs
@@ -1,11 +1,11 @@
-using Microsoft.AspNetCore.Mvc;
-using DD.Persistence.Models;
+using DD.Persistence.Models;
using DD.Persistence.Models.Requests;
using Refit;
+using DD.Persistence.Models.Common;
namespace DD.Persistence.Client.Clients.Interfaces.Refit
{
- public interface IRefitTechMessagesClient : IDisposable
+ public interface IRefitTechMessagesClient : IRefitClient, IDisposable
{
private const string BaseRoute = "/api/techMessages";
diff --git a/DD.Persistence.Client/Clients/Interfaces/Refit/IRefitTimeSeriesClient.cs b/DD.Persistence.Client/Clients/Interfaces/Refit/IRefitTimeSeriesClient.cs
deleted file mode 100644
index 2edc8fe..0000000
--- a/DD.Persistence.Client/Clients/Interfaces/Refit/IRefitTimeSeriesClient.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-using DD.Persistence.Models;
-using Refit;
-
-namespace DD.Persistence.Client.Clients.Interfaces.Refit;
-public interface IRefitTimeSeriesClient : IDisposable
- where TDto : class, new()
-{
- private const string BaseRoute = "/api/dataSaub";
-
- [Post($"{BaseRoute}")]
- Task> AddRange(IEnumerable dtos, CancellationToken token);
-
- [Get($"{BaseRoute}")]
- Task>> Get(DateTimeOffset dateBegin, DateTimeOffset dateEnd, CancellationToken token);
-
- [Get($"{BaseRoute}/resampled")]
- Task>> GetResampledData(DateTimeOffset dateBegin, double intervalSec = 600d, int approxPointsCount = 1024, CancellationToken token = default);
-
- [Get($"{BaseRoute}/datesRange")]
- Task> GetDatesRange(CancellationToken token);
-}
diff --git a/DD.Persistence.Client/Clients/Interfaces/Refit/IRefitTimestampedSetClient.cs b/DD.Persistence.Client/Clients/Interfaces/Refit/IRefitTimestampedSetClient.cs
deleted file mode 100644
index 14db284..0000000
--- a/DD.Persistence.Client/Clients/Interfaces/Refit/IRefitTimestampedSetClient.cs
+++ /dev/null
@@ -1,24 +0,0 @@
-using DD.Persistence.Models;
-using Refit;
-
-namespace DD.Persistence.Client.Clients.Interfaces.Refit;
-
-public interface IRefitTimestampedSetClient : IDisposable
-{
- private const string baseUrl = "/api/TimestampedSet/{idDiscriminator}";
-
- [Post(baseUrl)]
- Task> AddRange(Guid idDiscriminator, IEnumerable sets, CancellationToken token);
-
- [Get(baseUrl)]
- Task>> Get(Guid idDiscriminator, [Query] DateTimeOffset? geTimestamp, [Query] IEnumerable? columnNames, int skip, int take, CancellationToken token);
-
- [Get($"{baseUrl}/last")]
- Task>> GetLast(Guid idDiscriminator, [Query] IEnumerable? columnNames, int take, CancellationToken token);
-
- [Get($"{baseUrl}/count")]
- Task> Count(Guid idDiscriminator, CancellationToken token);
-
- [Get($"{baseUrl}/datesRange")]
- Task> GetDatesRange(Guid idDiscriminator, CancellationToken token);
-}
diff --git a/DD.Persistence.Client/Clients/Interfaces/Refit/IRefitTimestampedValuesClient.cs b/DD.Persistence.Client/Clients/Interfaces/Refit/IRefitTimestampedValuesClient.cs
new file mode 100644
index 0000000..bd94136
--- /dev/null
+++ b/DD.Persistence.Client/Clients/Interfaces/Refit/IRefitTimestampedValuesClient.cs
@@ -0,0 +1,61 @@
+using DD.Persistence.Models;
+using DD.Persistence.Models.Common;
+using Refit;
+
+namespace DD.Persistence.Client.Clients.Interfaces.Refit;
+
+///
+/// Refit интерфейс для TimestampedValuesController
+///
+public interface IRefitTimestampedValuesClient : IRefitClient, IDisposable
+{
+ private const string baseUrl = "/api/TimestampedValues/{discriminatorId}";
+
+ ///
+ /// Записать новые данные
+ ///
+ [Post(baseUrl)]
+ Task> AddRange(Guid discriminatorId, IEnumerable dtos, CancellationToken token);
+
+ ///
+ /// Получение данных с фильтрацией
+ ///
+ [Get(baseUrl)]
+ Task>> Get(Guid discriminatorId, DateTimeOffset? timestampBegin, [Query(CollectionFormat.Multi)] IEnumerable? columnNames, int skip, int take, CancellationToken token);
+
+ ///
+ /// Получить данные, начиная с заданной отметки времени
+ ///
+ [Get($"{baseUrl}/gtdate")]
+ Task>> GetGtDate(Guid discriminatorId, DateTimeOffset timestampBegin, CancellationToken token);
+
+ ///
+ /// Получить данные c начала
+ ///
+ [Get($"{baseUrl}/first")]
+ Task>> GetFirst(Guid discriminatorId, int take, CancellationToken token);
+
+ ///
+ /// Получить данные c конца
+ ///
+ [Get($"{baseUrl}/last")]
+ Task>> GetLast(Guid discriminatorId, int take, CancellationToken token);
+
+ ///
+ /// Получить список объектов с прореживанием, удовлетворяющий диапазону временных отметок
+ ///
+ [Get($"{baseUrl}/resampled")]
+ Task>> GetResampledData(Guid discriminatorId, DateTimeOffset timestampBegin, double intervalSec = 600d, int approxPointsCount = 1024, CancellationToken token = default);
+
+ ///
+ /// Получить количество записей по указанному набору в БД. Для пагинации
+ ///
+ [Get($"{baseUrl}/count")]
+ Task> Count(Guid discriminatorId, CancellationToken token);
+
+ ///
+ /// Получить диапазон дат, в пределах которых хранятся даные
+ ///
+ [Get($"{baseUrl}/datesRange")]
+ Task> GetDatesRange(Guid discriminatorId, CancellationToken token);
+}
diff --git a/DD.Persistence.Client/Clients/Interfaces/Refit/IRefitWitsDataClient.cs b/DD.Persistence.Client/Clients/Interfaces/Refit/IRefitWitsDataClient.cs
index 57bff6f..233083a 100644
--- a/DD.Persistence.Client/Clients/Interfaces/Refit/IRefitWitsDataClient.cs
+++ b/DD.Persistence.Client/Clients/Interfaces/Refit/IRefitWitsDataClient.cs
@@ -1,9 +1,9 @@
-using Microsoft.AspNetCore.Mvc;
-using DD.Persistence.Models;
+using DD.Persistence.Models;
using Refit;
+using DD.Persistence.Models.Common;
namespace DD.Persistence.Client.Clients.Interfaces.Refit;
-public interface IRefitWitsDataClient : IDisposable
+public interface IRefitWitsDataClient : IRefitClient, IDisposable
{
private const string BaseRoute = "/api/witsData";
diff --git a/DD.Persistence.Client/Clients/SetpointClient.cs b/DD.Persistence.Client/Clients/SetpointClient.cs
index 4a990c5..dfb5026 100644
--- a/DD.Persistence.Client/Clients/SetpointClient.cs
+++ b/DD.Persistence.Client/Clients/SetpointClient.cs
@@ -1,33 +1,60 @@
-using Microsoft.Extensions.Logging;
+using Microsoft.Extensions.Logging;
using DD.Persistence.Client.Clients.Base;
using DD.Persistence.Client.Clients.Interfaces;
using DD.Persistence.Client.Clients.Interfaces.Refit;
using DD.Persistence.Models;
+using System.Text.Json;
+using System.Text.Json.Serialization;
+using System.Globalization;
+using DD.Persistence.Models.Common;
namespace DD.Persistence.Client.Clients;
public class SetpointClient : BaseClient, ISetpointClient
{
private readonly IRefitSetpointClient refitSetpointClient;
+ private readonly ISetpointConfigStorage setpointConfigStorage;
- public SetpointClient(IRefitSetpointClient refitSetpointClient, ILogger logger) : base(logger)
+ public SetpointClient(
+ IRefitClientFactory refitSetpointClientFactory,
+ ISetpointConfigStorage setpointConfigStorage,
+ ILogger logger) : base(logger)
{
- this.refitSetpointClient = refitSetpointClient;
- }
+ this.refitSetpointClient = refitSetpointClientFactory.Create();
+ this.setpointConfigStorage = setpointConfigStorage;
+ }
public async Task> GetCurrent(IEnumerable setpointKeys, CancellationToken token)
{
var result = await ExecuteGetResponse(
async () => await refitSetpointClient.GetCurrent(setpointKeys, token), token);
- return result!;
+ return result!.Select(x => new SetpointValueDto {
+ Key = x.Key,
+ Value = DeserializeValue(x.Key, x.Value)
+ });
}
- public async Task> GetHistory(IEnumerable setpointKeys, DateTimeOffset historyMoment, CancellationToken token)
+
+
+ public async Task> GetCurrentDictionary(IEnumerable setpointConfigs, CancellationToken token)
+ {
+ var result = await ExecuteGetResponse(
+ async () => await refitSetpointClient.GetCurrent(setpointConfigs, token), token);
+
+
+ return result!.ToDictionary(x => x.Key,x => DeserializeValue(x.Key,x.Value));
+ }
+
+ public async Task> GetHistory(IEnumerable setpointKeys, DateTimeOffset historyMoment, CancellationToken token)
{
var result = await ExecuteGetResponse(
async () => await refitSetpointClient.GetHistory(setpointKeys, historyMoment, token), token);
+ foreach(var dto in result)
+ dto.Value = DeserializeValue(dto.Key, (JsonElement)dto.Value);
+
+
return result!;
}
@@ -36,6 +63,9 @@ public class SetpointClient : BaseClient, ISetpointClient
var result = await ExecuteGetResponse(
async () => await refitSetpointClient.GetLog(setpointKeys, token), token);
+ foreach(var item in result)
+ DeserializeList(result[item.Key]);
+
return result!;
}
@@ -48,14 +78,18 @@ public class SetpointClient : BaseClient, ISetpointClient
}
public async Task> GetPart(DateTimeOffset dateBegin, int take, CancellationToken token)
- {
- var result = await ExecuteGetResponse(
- async () => await refitSetpointClient.GetPart(dateBegin, take, token), token);
+ {
+ var result = await ExecuteGetResponse(
+ async () => await refitSetpointClient.GetPart(dateBegin, take, token), token);
- return result!;
- }
+ DeserializeList(result);
- public async Task Add(Guid setpointKey, object newValue, CancellationToken token)
+ return result!;
+ }
+
+
+
+ public async Task Add(Guid setpointKey, object newValue, CancellationToken token)
{
await ExecutePostResponse(
async () => await refitSetpointClient.Add(setpointKey, newValue, token), token);
@@ -67,4 +101,21 @@ public class SetpointClient : BaseClient, ISetpointClient
GC.SuppressFinalize(this);
}
+
+
+ private object DeserializeValue(Guid key, JsonElement value)
+ {
+ if (setpointConfigStorage.TryGetType(key, out var type))
+ return value.Deserialize(type)!;
+
+ return value;
+ }
+ private void DeserializeList(IEnumerable? result)
+ {
+ foreach (var log in result)
+ log.Value = DeserializeValue(log.Key, (JsonElement)log.Value);
+
+ }
+
+
}
diff --git a/DD.Persistence.Client/Clients/TechMessagesClient.cs b/DD.Persistence.Client/Clients/TechMessagesClient.cs
index c981569..681e275 100644
--- a/DD.Persistence.Client/Clients/TechMessagesClient.cs
+++ b/DD.Persistence.Client/Clients/TechMessagesClient.cs
@@ -4,6 +4,7 @@ using DD.Persistence.Client.Clients.Interfaces;
using DD.Persistence.Client.Clients.Interfaces.Refit;
using DD.Persistence.Models;
using DD.Persistence.Models.Requests;
+using DD.Persistence.Models.Common;
namespace DD.Persistence.Client.Clients;
@@ -11,9 +12,9 @@ public class TechMessagesClient : BaseClient, ITechMessagesClient
{
private readonly IRefitTechMessagesClient refitTechMessagesClient;
- public TechMessagesClient(IRefitTechMessagesClient refitTechMessagesClient, ILogger logger) : base(logger)
+ public TechMessagesClient(IRefitClientFactory refitTechMessagesClientFactory, ILogger logger) : base(logger)
{
- this.refitTechMessagesClient = refitTechMessagesClient;
+ this.refitTechMessagesClient = refitTechMessagesClientFactory.Create();
}
public async Task> GetPage(PaginationRequest request, CancellationToken token)
diff --git a/DD.Persistence.Client/Clients/TimeSeriesClient.cs b/DD.Persistence.Client/Clients/TimeSeriesClient.cs
deleted file mode 100644
index 2c15938..0000000
--- a/DD.Persistence.Client/Clients/TimeSeriesClient.cs
+++ /dev/null
@@ -1,55 +0,0 @@
-using Microsoft.Extensions.Logging;
-using DD.Persistence.Client.Clients.Base;
-using DD.Persistence.Client.Clients.Interfaces;
-using DD.Persistence.Client.Clients.Interfaces.Refit;
-using DD.Persistence.Models;
-
-namespace DD.Persistence.Client.Clients;
-public class TimeSeriesClient : BaseClient, ITimeSeriesClient where TDto : class, new()
-{
- private readonly IRefitTimeSeriesClient timeSeriesClient;
-
- public TimeSeriesClient(IRefitTimeSeriesClient refitTechMessagesClient, ILogger> logger) : base(logger)
- {
- this.timeSeriesClient = refitTechMessagesClient;
- }
-
- public async Task AddRange(IEnumerable dtos, CancellationToken token)
- {
- var result = await ExecutePostResponse(
- async () => await timeSeriesClient.AddRange(dtos, token), token);
-
- return result;
- }
-
- public async Task> Get(DateTimeOffset dateBegin, DateTimeOffset dateEnd, CancellationToken token)
- {
- var result = await ExecuteGetResponse(
- async () => await timeSeriesClient.Get(dateBegin, dateEnd, token), token);
-
- return result!;
- }
-
- public async Task> GetResampledData(DateTimeOffset dateBegin, double intervalSec = 600d, int approxPointsCount = 1024, CancellationToken token = default)
- {
- var result = await ExecuteGetResponse(
- async () => await timeSeriesClient.GetResampledData(dateBegin, intervalSec, approxPointsCount, token), token);
-
- return result!;
- }
-
- public async Task GetDatesRange(CancellationToken token)
- {
- var result = await ExecuteGetResponse(
- async () => await timeSeriesClient.GetDatesRange(token), token);
-
- return result;
- }
-
- public void Dispose()
- {
- timeSeriesClient.Dispose();
-
- GC.SuppressFinalize(this);
- }
-}
diff --git a/DD.Persistence.Client/Clients/TimestampedSetClient.cs b/DD.Persistence.Client/Clients/TimestampedSetClient.cs
deleted file mode 100644
index 38828b6..0000000
--- a/DD.Persistence.Client/Clients/TimestampedSetClient.cs
+++ /dev/null
@@ -1,63 +0,0 @@
-using Microsoft.Extensions.Logging;
-using DD.Persistence.Client.Clients.Base;
-using DD.Persistence.Client.Clients.Interfaces;
-using DD.Persistence.Client.Clients.Interfaces.Refit;
-using DD.Persistence.Models;
-
-namespace DD.Persistence.Client.Clients;
-public class TimestampedSetClient : BaseClient, ITimestampedSetClient
-{
- private readonly IRefitTimestampedSetClient refitTimestampedSetClient;
-
- public TimestampedSetClient(IRefitTimestampedSetClient refitTimestampedSetClient, ILogger logger) : base(logger)
- {
- this.refitTimestampedSetClient = refitTimestampedSetClient;
- }
-
- public async Task AddRange(Guid idDiscriminator, IEnumerable sets, CancellationToken token)
- {
- var result = await ExecutePostResponse(
- async () => await refitTimestampedSetClient.AddRange(idDiscriminator, sets, token), token);
-
- return result;
- }
-
- public async Task> Get(Guid idDiscriminator, DateTimeOffset? geTimestamp, IEnumerable? columnNames, int skip, int take, CancellationToken token)
- {
- var result = await ExecuteGetResponse(
- async () => await refitTimestampedSetClient.Get(idDiscriminator, geTimestamp, columnNames, skip, take, token), token);
-
- return result!;
- }
-
- public async Task> GetLast(Guid idDiscriminator, IEnumerable? columnNames, int take, CancellationToken token)
- {
- var result = await ExecuteGetResponse(
- async () => await refitTimestampedSetClient.GetLast(idDiscriminator, columnNames, take, token), token);
-
- return result!;
- }
-
- public async Task Count(Guid idDiscriminator, CancellationToken token)
- {
- var result = await ExecuteGetResponse(
- async () => await refitTimestampedSetClient.Count(idDiscriminator, token), token);
-
- return result;
- }
-
- public async Task GetDatesRange(Guid idDiscriminator, CancellationToken token)
- {
- var result = await ExecuteGetResponse(
- async () => await refitTimestampedSetClient.GetDatesRange(idDiscriminator, token), token);
-
- return result;
- }
-
- public void Dispose()
- {
- refitTimestampedSetClient.Dispose();
-
- GC.SuppressFinalize(this);
- }
-}
diff --git a/DD.Persistence.Client/Clients/TimestampedValuesClient.cs b/DD.Persistence.Client/Clients/TimestampedValuesClient.cs
new file mode 100644
index 0000000..bafead6
--- /dev/null
+++ b/DD.Persistence.Client/Clients/TimestampedValuesClient.cs
@@ -0,0 +1,127 @@
+using DD.Persistence.Client.Clients.Base;
+using DD.Persistence.Client.Clients.Interfaces;
+using DD.Persistence.Client.Clients.Interfaces.Refit;
+using DD.Persistence.Models;
+using DD.Persistence.Models.Common;
+using Microsoft.Extensions.Logging;
+using System.Collections.Concurrent;
+
+namespace DD.Persistence.Client.Clients;
+
+///
+public class TimestampedValuesClient : BaseClient, ITimestampedValuesClient
+{
+ private readonly IRefitTimestampedValuesClient refitTimestampedSetClient;
+
+ ///
+ public TimestampedValuesClient(IRefitClientFactory refitTimestampedSetClientFactory, ILogger logger) : base(logger)
+ {
+ this.refitTimestampedSetClient = refitTimestampedSetClientFactory.Create();
+ }
+
+ ///
+ private readonly ConcurrentDictionary mapperCache = new();
+
+ ///
+ public async Task AddRange(Guid discriminatorId, IEnumerable sets, CancellationToken token)
+ {
+ var result = await ExecutePostResponse(
+ async () => await refitTimestampedSetClient.AddRange(discriminatorId, sets, token), token);
+
+ return result;
+ }
+
+ ///
+ public async Task> Get(Guid discriminatorId, DateTimeOffset? geTimestamp, IEnumerable? columnNames, int skip, int take, CancellationToken token)
+ {
+ var result = await ExecuteGetResponse(
+ async () => await refitTimestampedSetClient.Get(discriminatorId, geTimestamp, columnNames, skip, take, token), token);
+ return result;
+ }
+
+ ///
+ public async Task> GetGtDate(Guid discriminatorId, DateTimeOffset timestampBegin, CancellationToken token)
+ {
+ var result = await ExecuteGetResponse(
+ async () => await refitTimestampedSetClient.GetGtDate(discriminatorId, timestampBegin, token), token);
+
+ return result;
+ }
+
+ ///
+ public async Task> GetFirst(Guid discriminatorId, int take, CancellationToken token)
+ {
+ var result = await ExecuteGetResponse(
+ async () => await refitTimestampedSetClient.GetFirst(discriminatorId, take, token), token);
+
+ return result;
+ }
+
+ ///
+ public async Task> GetLast(Guid discriminatorId, int take, CancellationToken token)
+ {
+ var result = await ExecuteGetResponse(
+ async () => await refitTimestampedSetClient.GetLast(discriminatorId, take, token), token);
+
+ return result;
+ }
+
+ ///
+ public async Task> GetResampledData(Guid discriminatorId, DateTimeOffset dateBegin, double intervalSec = 600, int approxPointsCount = 1024, CancellationToken token = default)
+ {
+ var result = await ExecuteGetResponse(
+ async () => await refitTimestampedSetClient.GetResampledData(discriminatorId, dateBegin, intervalSec, approxPointsCount, token), token);
+
+ return result;
+ }
+
+ ///
+ public async Task Count(Guid discriminatorId, CancellationToken token)
+ {
+ var result = await ExecuteGetResponse(
+ async () => await refitTimestampedSetClient.Count(discriminatorId, token), token);
+
+ return result;
+ }
+
+ ///
+ public async Task GetDatesRange(Guid discriminatorId, CancellationToken token)
+ {
+ var result = await ExecuteGetResponse(
+ async () => await refitTimestampedSetClient.GetDatesRange(discriminatorId, token), token);
+
+ return result;
+ }
+
+ ///
+ public async Task> Get(Guid idDiscriminator, DateTimeOffset? geTimestamp, IEnumerable? columnNames, int skip, int take, CancellationToken token)
+ {
+ var data = await Get(idDiscriminator, geTimestamp, columnNames, skip, take, token);
+ var mapper = GetMapper(idDiscriminator);
+
+ return data.Select(mapper.DeserializeTimeStampedData);
+ }
+
+ ///
+ public async Task> GetLast(Guid idDiscriminator, int take, CancellationToken token)
+ {
+ var data = await GetLast(idDiscriminator, take, token);
+ var mapper = GetMapper(idDiscriminator);
+
+ return data.Select(mapper.DeserializeTimeStampedData);
+ }
+
+ ///
+ private TimestampedSetMapper GetMapper(Guid idDiscriminator)
+ {
+ return (TimestampedSetMapper)mapperCache.GetOrAdd(idDiscriminator, name => new TimestampedSetMapper(idDiscriminator));
+ }
+
+ ///
+ public void Dispose()
+ {
+ refitTimestampedSetClient.Dispose();
+
+ GC.SuppressFinalize(this);
+ }
+}
diff --git a/DD.Persistence.Client/Clients/WitsDataClient.cs b/DD.Persistence.Client/Clients/WitsDataClient.cs
index 3251194..d47f771 100644
--- a/DD.Persistence.Client/Clients/WitsDataClient.cs
+++ b/DD.Persistence.Client/Clients/WitsDataClient.cs
@@ -3,15 +3,16 @@ using DD.Persistence.Client.Clients.Base;
using DD.Persistence.Client.Clients.Interfaces;
using DD.Persistence.Client.Clients.Interfaces.Refit;
using DD.Persistence.Models;
+using DD.Persistence.Models.Common;
namespace DD.Persistence.Client.Clients;
public class WitsDataClient : BaseClient, IWitsDataClient
{
private readonly IRefitWitsDataClient refitWitsDataClient;
- public WitsDataClient(IRefitWitsDataClient refitWitsDataClient, ILogger logger) : base(logger)
+ public WitsDataClient(IRefitClientFactory refitWitsDataClientFactory, ILogger logger) : base(logger)
{
- this.refitWitsDataClient = refitWitsDataClient;
+ this.refitWitsDataClient = refitWitsDataClientFactory.Create();
}
public async Task AddRange(IEnumerable dtos, CancellationToken token)
diff --git a/DD.Persistence.Client/DD.Persistence.Client.csproj b/DD.Persistence.Client/DD.Persistence.Client.csproj
index d1ae186..1e0bc4a 100644
--- a/DD.Persistence.Client/DD.Persistence.Client.csproj
+++ b/DD.Persistence.Client/DD.Persistence.Client.csproj
@@ -9,13 +9,13 @@
True
- Persistence.Client
+ DD.Persistence.Client
- 1.0.$([System.DateTime]::UtcNow.ToString(yyMM.ddHH))
+ 1.5.$([System.DateTime]::UtcNow.ToString(yyMM.ddHH)).1
- 1.0.$([System.DateTime]::UtcNow.ToString(yyMM.ddHH))
+ 1.5.$([System.DateTime]::UtcNow.ToString(yyMM.ddHH)).1
- Persistence.Client
+ DD.Persistence.Client
Digital Drilling
@@ -33,15 +33,15 @@
snupkg
- C:\Projects\Nuget
+ C:\Projects\Nuget\Persistence
Readme.md
- 1.0.$([System.DateTime]::UtcNow.ToString(yyMM.ddHH))
- 1.0.$([System.DateTime]::UtcNow.ToString(yyMM.ddHH))
+ 1.5.$([System.DateTime]::UtcNow.ToString(yyMM.ddHH))
+ 1.5.$([System.DateTime]::UtcNow.ToString(yyMM.ddHH))
@@ -53,11 +53,12 @@
+
-
+
diff --git a/DD.Persistence.Client/DependencyInjection.cs b/DD.Persistence.Client/DependencyInjection.cs
new file mode 100644
index 0000000..89f65cf
--- /dev/null
+++ b/DD.Persistence.Client/DependencyInjection.cs
@@ -0,0 +1,34 @@
+using DD.Persistence.Client.Clients;
+using DD.Persistence.Client.Clients.Interfaces;
+using DD.Persistence.Models;
+using Microsoft.Extensions.DependencyInjection;
+
+namespace DD.Persistence.Client;
+
+///
+///
+///
+public static class DependencyInjection
+{
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static IServiceCollection AddPersistenceClients(this IServiceCollection services, Dictionary? setpointTypeConfigs = null)
+ {
+ services.AddTransient(typeof(IRefitClientFactory<>), typeof(RefitClientFactory<>));
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+
+ services.AddSingleton(provider =>
+ {
+ return new SetpointConfigStorage(setpointTypeConfigs);
+ });
+ return services;
+ }
+}
diff --git a/DD.Persistence.Client/IRefitClientFactory.cs b/DD.Persistence.Client/IRefitClientFactory.cs
new file mode 100644
index 0000000..0015a95
--- /dev/null
+++ b/DD.Persistence.Client/IRefitClientFactory.cs
@@ -0,0 +1,16 @@
+using DD.Persistence.Client.Clients.Interfaces.Refit;
+
+namespace DD.Persistence.Client;
+
+///
+/// Интерфейс для фабрики, которая создает refit-клиентов
+///
+///
+public interface IRefitClientFactory where T : IRefitClient
+{
+ ///
+ /// Создание refit-клиента
+ ///
+ ///
+ public T Create();
+}
diff --git a/DD.Persistence.Client/ISetpointConfigStorage.cs b/DD.Persistence.Client/ISetpointConfigStorage.cs
new file mode 100644
index 0000000..2c73783
--- /dev/null
+++ b/DD.Persistence.Client/ISetpointConfigStorage.cs
@@ -0,0 +1,11 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DD.Persistence.Client;
+public interface ISetpointConfigStorage
+{
+ bool TryGetType(Guid id, out Type type);
+}
diff --git a/DD.Persistence.Client/PersistenceClientFactory.cs b/DD.Persistence.Client/PersistenceClientFactory.cs
deleted file mode 100644
index ad7c817..0000000
--- a/DD.Persistence.Client/PersistenceClientFactory.cs
+++ /dev/null
@@ -1,146 +0,0 @@
-using Microsoft.Extensions.Configuration;
-using DD.Persistence.Client.Clients.Interfaces;
-using DD.Persistence.Client.Clients;
-using DD.Persistence.Client.Helpers;
-using Refit;
-using DD.Persistence.Factories;
-using DD.Persistence.Client.Clients.Interfaces.Refit;
-using Microsoft.Extensions.Logging;
-using Microsoft.Extensions.DependencyInjection;
-using System.Text.Json;
-
-namespace DD.Persistence.Client
-{
- ///
- /// Фабрика клиентов для доступа к Persistence - сервису
- ///
- public class PersistenceClientFactory
- {
- private static readonly JsonSerializerOptions JsonSerializerOptions = new()
- {
- PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
- PropertyNameCaseInsensitive = true
- };
- private static readonly RefitSettings RefitSettings = new(new SystemTextJsonContentSerializer(JsonSerializerOptions));
- private readonly IServiceProvider provider;
- private HttpClient httpClient;
- public PersistenceClientFactory(IHttpClientFactory httpClientFactory, IServiceProvider provider, IConfiguration configuration)
- {
- this.provider = provider;
-
- httpClient = httpClientFactory.CreateClient();
-
- httpClient.Authorize(configuration);
- }
-
- public PersistenceClientFactory(IHttpClientFactory httpClientFactory, IAuthTokenFactory authTokenFactory, IServiceProvider provider, IConfiguration configuration)
- {
- this.provider = provider;
-
- httpClient = httpClientFactory.CreateClient();
-
- var token = authTokenFactory.GetToken();
- httpClient.Authorize(token);
- }
-
- ///
- /// Получить клиент для работы с уставками
- ///
- ///
- public ISetpointClient GetSetpointClient()
- {
- var logger = provider.GetRequiredService>();
-
- var restClient = RestService.For(httpClient, RefitSettings);
- var client = new SetpointClient(restClient, logger);
-
- return client;
- }
-
- ///
- /// Получить клиент для работы с технологическими сообщениями
- ///
- ///
- public ITechMessagesClient GetTechMessagesClient()
- {
- var logger = provider.GetRequiredService>();
-
- var restClient = RestService.For(httpClient, RefitSettings);
- var client = new TechMessagesClient(restClient, logger);
-
- return client;
- }
-
- ///
- /// Получить клиент для работы с временными данными
- ///
- ///
- ///
- public ITimeSeriesClient GetTimeSeriesClient()
- where TDto : class, new()
- {
- var logger = provider.GetRequiredService>>();
-
- var restClient = RestService.For>(httpClient, RefitSettings);
- var client = new TimeSeriesClient(restClient, logger);
-
- return client;
- }
-
- ///
- /// Получить клиент для работы с данными с отметкой времени
- ///
- ///
- public ITimestampedSetClient GetTimestampedSetClient()
- {
- var logger = provider.GetRequiredService>();
-
- var restClient = RestService.For(httpClient, RefitSettings);
- var client = new TimestampedSetClient(restClient, logger);
-
- return client;
- }
-
- ///
- /// Получить клиент для работы с записями ChangeLog
- ///
- ///
- public IChangeLogClient GetChangeLogClient()
- {
- var logger = provider.GetRequiredService>();
-
- var restClient = RestService.For(httpClient, RefitSettings);
- var client = new ChangeLogClient(restClient, logger);
-
- return client;
- }
-
- ///
- /// Получить клиент для работы c параметрами Wits
- ///
- ///
- public IWitsDataClient GetWitsDataClient()
- {
- var logger = provider.GetRequiredService>();
-
- var restClient = RestService.For(httpClient, RefitSettings);
- var client = new WitsDataClient(restClient, logger);
-
- return client;
- }
-
- ///
- /// Получить клиент для работы c системами
- ///
- ///
- public IDataSourceSystemClient GetDataSourceSystemClient()
- {
- var logger = provider.GetRequiredService>();
-
- var restClient = RestService.For(httpClient, RefitSettings);
- var client = new DataSourceSystemClient(restClient, logger);
-
- return client;
- }
- }
-}
diff --git a/DD.Persistence.Client/Readme.md b/DD.Persistence.Client/Readme.md
index 1e09e2f..6bdae87 100644
--- a/DD.Persistence.Client/Readme.md
+++ b/DD.Persistence.Client/Readme.md
@@ -11,8 +11,7 @@ Persistence сервисом посредством обращения к кон
## Список предоставляемых клиентов
- `ISetpointClient` - Клиент для работы с уставками
- `ITechMessagesClient` - Клиент для работы с технологическими сообщениями
-- `ITimeSeriesClient` - Клиент для работы с временными данными
-- `ITimestampedSetClient` - Клиент для работы с данными с отметкой времени
+- `ITimestampedValuesClient` - Клиент для работы с наборами данных, имеющими отметку времени
- `IChangeLogClient` - Клиент для работы с записями ChangeLog
- `IWitsDataClient` - Клиент для работы с параметрами Wits
- `IDataSourceSystemClient` - Клиент для работы с системами
diff --git a/DD.Persistence.Client/RefitClientFactory.cs b/DD.Persistence.Client/RefitClientFactory.cs
new file mode 100644
index 0000000..9cd0bef
--- /dev/null
+++ b/DD.Persistence.Client/RefitClientFactory.cs
@@ -0,0 +1,52 @@
+using DD.Persistence.Client.Clients.Interfaces.Refit;
+using DD.Persistence.Client.Helpers;
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.Logging;
+using Refit;
+using System.Configuration;
+using System.Text.Json;
+
+namespace DD.Persistence.Client;
+
+///
+/// Фабрика, которая создает refit-клиентов
+///
+///
+public class RefitClientFactory : IRefitClientFactory where T : IRefitClient
+{
+ private HttpClient client;
+ private RefitSettings refitSettings;
+
+ ///
+ public RefitClientFactory(IConfiguration configuration, ILogger> logger, HttpClient client)
+ {
+ //this.client = factory.CreateClient();
+ this.client = client;
+
+ var baseUrl = configuration.GetSection("ClientUrl").Get();
+ if (String.IsNullOrEmpty(baseUrl))
+ {
+ var exception = new SettingsPropertyNotFoundException("В настройках конфигурации не указан адрес Persistence сервиса.");
+
+ logger.LogError(exception.Message);
+
+ throw exception;
+ }
+ client.BaseAddress = new Uri(baseUrl);
+
+ JsonSerializerOptions JsonSerializerOptions = new()
+ {
+ PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
+ PropertyNameCaseInsensitive = true
+ };
+ refitSettings = new(new SystemTextJsonContentSerializer(JsonSerializerOptions));
+ }
+ ///
+ /// создание клиента
+ ///
+ ///
+ public T Create()
+ {
+ return RestService.For(client, refitSettings);
+ }
+}
diff --git a/DD.Persistence.Client/SetpointConfigStorage.cs b/DD.Persistence.Client/SetpointConfigStorage.cs
new file mode 100644
index 0000000..5cfbabf
--- /dev/null
+++ b/DD.Persistence.Client/SetpointConfigStorage.cs
@@ -0,0 +1,20 @@
+namespace DD.Persistence.Client;
+internal class SetpointConfigStorage : ISetpointConfigStorage
+{
+ private readonly Dictionary setpointTypeConfigs;
+
+ public SetpointConfigStorage(Dictionary? setpointTypeConfigs)
+ {
+ this.setpointTypeConfigs = setpointTypeConfigs?? new Dictionary();
+ }
+
+ public bool TryGetType(Guid id, out Type type)
+ {
+ return setpointTypeConfigs.TryGetValue(id, out type);
+ }
+
+ public void AddOrReplace(Guid id, Type type)
+ {
+ setpointTypeConfigs[id] = type;
+ }
+}
diff --git a/DD.Persistence.Client/TimestampedSetMapper.cs b/DD.Persistence.Client/TimestampedSetMapper.cs
new file mode 100644
index 0000000..cf7463a
--- /dev/null
+++ b/DD.Persistence.Client/TimestampedSetMapper.cs
@@ -0,0 +1,135 @@
+using DD.Persistence.Models;
+using System.Collections.Concurrent;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Text.Json;
+
+namespace DD.Persistence.Client;
+
+internal abstract class TimestampedSetMapperBase
+{
+ public abstract object Map(TimestampedValuesDto data);
+
+}
+internal class TimestampedSetMapper : TimestampedSetMapperBase
+{
+ private readonly Type entityType = typeof(T);
+ public Guid IdDiscriminator { get; }
+ private readonly ConcurrentDictionary PropertyCache = new();
+
+ public TimestampedSetMapper(Guid idDiscriminator)
+ {
+ IdDiscriminator = idDiscriminator;
+ }
+
+ public override object Map(TimestampedValuesDto data)
+ {
+ return DeserializeTimeStampedData(data)!;
+ }
+
+ public T DeserializeTimeStampedData(TimestampedValuesDto data)
+ {
+
+ if (entityType.IsValueType)
+ return MapStruct(data);
+ else
+ return MapClass(data);
+ }
+
+ private T MapClass(TimestampedValuesDto data)
+ {
+ var entity = (T)RuntimeHelpers.GetUninitializedObject(typeof(T));
+ foreach (var (propertyName, value) in data.Values)
+ {
+ if (value is JsonElement jsonElement)
+ SetPropertyValueFromJson(ref entity, propertyName, jsonElement);
+ }
+ SetPropertyValue(ref entity, "Timestamp", data.Timestamp);
+ return entity;
+ }
+
+ private T MapStruct(TimestampedValuesDto data)
+ {
+ var entity = Activator.CreateInstance();
+ object boxedEntity = entity!;
+ foreach (var (propertyName, value) in data.Values)
+ {
+ if (value is JsonElement jsonElement)
+ SetPropertyValueForStructFromJson(ref boxedEntity, propertyName, jsonElement);
+ }
+ SetPropertyValueForStruct(ref boxedEntity, "Timestamp", data.Timestamp);
+
+ return (T)boxedEntity;
+ }
+
+ private void SetPropertyValueForStructFromJson(ref object entity, string propertyName, JsonElement element)
+ {
+ var property = GetPropertyInfo(propertyName);
+ if (property is null)
+ return;
+
+ try
+ {
+ var value = element.Deserialize(property.PropertyType);
+ property.SetValue(entity, value);
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+ private void SetPropertyValueForStruct(ref object entity, string propertyName, object value)
+ {
+ var property = GetPropertyInfo(propertyName);
+ if (property is null)
+ return;
+
+ try
+ {
+ var convertedValue = Convert.ChangeType(value, property.PropertyType);
+ property.SetValue(entity, convertedValue);
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+
+
+ private void SetPropertyValueFromJson(ref T entity, string propertyName, JsonElement jsonElement)
+ {
+ var property = GetPropertyInfo(propertyName);
+
+ if (property is null)
+ return;
+
+ try
+ {
+ var value = jsonElement.Deserialize(property.PropertyType);
+ property.SetValue(entity, value);
+ }
+ catch (Exception ex)
+ {
+
+ }
+ }
+
+ private void SetPropertyValue(ref T entity, string propertyName, object value)
+ {
+ var property = GetPropertyInfo(propertyName);
+ if (property is null)
+ return;
+
+ try
+ {
+ var convertedValue = Convert.ChangeType(value, property.PropertyType);
+ property.SetValue(entity, convertedValue);
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+
+ private PropertyInfo? GetPropertyInfo(string propertyName)
+ {
+ return PropertyCache.GetOrAdd(propertyName, name => entityType.GetProperty(name));
+ }
+}
diff --git a/DD.Persistence.Database.Postgres/Migrations/20241226122220_Init.Designer.cs b/DD.Persistence.Database.Postgres/Migrations/20250122120353_Init.Designer.cs
similarity index 67%
rename from DD.Persistence.Database.Postgres/Migrations/20241226122220_Init.Designer.cs
rename to DD.Persistence.Database.Postgres/Migrations/20250122120353_Init.Designer.cs
index 2317c3b..81695fb 100644
--- a/DD.Persistence.Database.Postgres/Migrations/20241226122220_Init.Designer.cs
+++ b/DD.Persistence.Database.Postgres/Migrations/20250122120353_Init.Designer.cs
@@ -1,5 +1,6 @@
//
using System;
+using System.Text.Json;
using DD.Persistence.Database.Model;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
@@ -12,7 +13,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace DD.Persistence.Database.Postgres.Migrations
{
[DbContext(typeof(PersistencePostgresContext))]
- [Migration("20241226122220_Init")]
+ [Migration("20250122120353_Init")]
partial class Init
{
///
@@ -25,6 +26,23 @@ namespace DD.Persistence.Database.Postgres.Migrations
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
+ modelBuilder.Entity("DD.Persistence.Database.Entity.DataScheme", b =>
+ {
+ b.Property("DiscriminatorId")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid")
+ .HasComment("Идентификатор схемы данных");
+
+ b.Property("PropNames")
+ .IsRequired()
+ .HasColumnType("jsonb")
+ .HasComment("Наименования полей в порядке индексации");
+
+ b.HasKey("DiscriminatorId");
+
+ b.ToTable("data_scheme");
+ });
+
modelBuilder.Entity("DD.Persistence.Database.Entity.DataSourceSystem", b =>
{
b.Property("SystemId")
@@ -105,27 +123,24 @@ namespace DD.Persistence.Database.Postgres.Migrations
b.ToTable("tech_message");
});
- modelBuilder.Entity("DD.Persistence.Database.Entity.TimestampedSet", b =>
+ modelBuilder.Entity("DD.Persistence.Database.Entity.TimestampedValues", b =>
{
- b.Property("IdDiscriminator")
+ b.Property("DiscriminatorId")
.HasColumnType("uuid")
- .HasComment("Дискриминатор ссылка на тип сохраняемых данных");
+ .HasComment("Дискриминатор системы");
b.Property("Timestamp")
.HasColumnType("timestamp with time zone")
- .HasComment("Отметка времени, строго в UTC");
+ .HasComment("Временная отметка");
- b.Property("Set")
+ b.Property("Values")
.IsRequired()
.HasColumnType("jsonb")
- .HasComment("Набор сохраняемых данных");
+ .HasComment("Данные");
- b.HasKey("IdDiscriminator", "Timestamp");
+ b.HasKey("DiscriminatorId", "Timestamp");
- b.ToTable("timestamped_set", t =>
- {
- t.HasComment("Общая таблица данных временных рядов");
- });
+ b.ToTable("timestamped_values");
});
modelBuilder.Entity("DD.Persistence.Database.Model.ChangeLog", b =>
@@ -181,96 +196,13 @@ namespace DD.Persistence.Database.Postgres.Migrations
b.ToTable("change_log");
});
- modelBuilder.Entity("DD.Persistence.Database.Model.DataSaub", b =>
- {
- b.Property("Date")
- .HasColumnType("timestamp with time zone")
- .HasColumnName("date");
-
- b.Property("AxialLoad")
- .HasColumnType("double precision")
- .HasColumnName("axialLoad");
-
- b.Property("BitDepth")
- .HasColumnType("double precision")
- .HasColumnName("bitDepth");
-
- b.Property("BlockPosition")
- .HasColumnType("double precision")
- .HasColumnName("blockPosition");
-
- b.Property("BlockSpeed")
- .HasColumnType("double precision")
- .HasColumnName("blockSpeed");
-
- b.Property("Flow")
- .HasColumnType("double precision")
- .HasColumnName("flow");
-
- b.Property("HookWeight")
- .HasColumnType("double precision")
- .HasColumnName("hookWeight");
-
- b.Property("IdFeedRegulator")
- .HasColumnType("integer")
- .HasColumnName("idFeedRegulator");
-
- b.Property("Mode")
- .HasColumnType("integer")
- .HasColumnName("mode");
-
- b.Property("Mse")
- .HasColumnType("double precision")
- .HasColumnName("mse");
-
- b.Property("MseState")
- .HasColumnType("smallint")
- .HasColumnName("mseState");
-
- b.Property("Pressure")
- .HasColumnType("double precision")
- .HasColumnName("pressure");
-
- b.Property("Pump0Flow")
- .HasColumnType("double precision")
- .HasColumnName("pump0Flow");
-
- b.Property("Pump1Flow")
- .HasColumnType("double precision")
- .HasColumnName("pump1Flow");
-
- b.Property("Pump2Flow")
- .HasColumnType("double precision")
- .HasColumnName("pump2Flow");
-
- b.Property("RotorSpeed")
- .HasColumnType("double precision")
- .HasColumnName("rotorSpeed");
-
- b.Property("RotorTorque")
- .HasColumnType("double precision")
- .HasColumnName("rotorTorque");
-
- b.Property("User")
- .HasColumnType("text")
- .HasColumnName("user");
-
- b.Property("WellDepth")
- .HasColumnType("double precision")
- .HasColumnName("wellDepth");
-
- b.HasKey("Date");
-
- b.ToTable("data_saub");
- });
-
modelBuilder.Entity("DD.Persistence.Database.Model.Setpoint", b =>
{
b.Property("Key")
.HasColumnType("uuid")
.HasComment("Ключ");
- b.Property("Created")
+ b.Property("Timestamp")
.HasColumnType("timestamp with time zone")
.HasComment("Дата создания уставки");
@@ -278,12 +210,11 @@ namespace DD.Persistence.Database.Postgres.Migrations
.HasColumnType("uuid")
.HasComment("Id автора последнего изменения");
- b.Property