Compare commits

..

10 Commits

85 changed files with 923 additions and 539 deletions

View File

@ -16,6 +16,12 @@ namespace DD.Persistence.API;
public static class DependencyInjection
{
//public static void MapsterSetup()
//{
// TypeAdapterConfig.GlobalSettings.Default.Config
// .ForType<TechMessageDto, TechMessage>()
// .Ignore(dest => dest.System, dest => dest.SystemId);
//}
public static void AddSwagger(this IServiceCollection services, IConfiguration configuration)
{
services.AddSwaggerGen(c =>

View File

@ -26,6 +26,8 @@ public class Startup
services.AddJWTAuthentication(Configuration);
services.AddMemoryCache();
services.AddServices();
//DependencyInjection.MapsterSetup();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)

View File

@ -1,10 +1,10 @@
{
"DbConnection": {
"Host": "postgres",
"Host": "localhost",
"Port": 5432,
"Database": "persistence",
"Username": "postgres",
"Password": "postgres"
"Password": "q"
},
"NeedUseKeyCloak": false,
"AuthUser": {

View File

@ -2,7 +2,8 @@
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
"Microsoft.AspNetCore": "Warning",
"Microsoft.EntityFrameworkCore.Database.Command": "Error"
}
},
"ConnectionStrings": {
@ -20,6 +21,5 @@
"clientId": "webapi",
"grantType": "password",
"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier": "7d9f3574-6574-4ca3-845a-0276eb4aa8f6"
},
"ClientUrl": "http://localhost:5000/"
}
}

View File

@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="9.0.0" />
<PackageReference Include="System.Drawing.Common" Version="9.0.0" />
<PackageReference Include="xunit.extensibility.core" Version="2.9.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DD.Persistence.API\DD.Persistence.API.csproj" />
<ProjectReference Include="..\DD.Persistence.App\DD.Persistence.App.csproj" />
<ProjectReference Include="..\DD.Persistence.Client\DD.Persistence.Client.csproj" />
<ProjectReference Include="..\DD.Persistence.Database.Postgres\DD.Persistence.Database.Postgres.csproj" />
<ProjectReference Include="..\DD.Persistence.Database\DD.Persistence.Database.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,14 @@
namespace Persistence.Benchmark.Database;
public class DbConnection
{
public string Host { get; set; } = null!;
public int Port { get; set; }
public string Username { get; set; } = null!;
public string Password { get; set; } = null!;
public string GetConnectionString() =>
$"Host={Host};Database=persistence;Port={Port};Username={Username};Password={Password};Persist Security Info=True;Include Error Detail=True";
}

View File

@ -0,0 +1,10 @@
using Persistence.Benchmark.Tests;
public class Program
{
private static void Main(string[] args)
{
var count = Convert.ToInt32(Console.ReadLine());
WitsDataBenchmark.ExecuteTest(count).Wait();
}
}

View File

@ -0,0 +1,28 @@
# Тестирование скорости работы с данными Wits
Данный проект предназначен для замеров времени сохранения / получения данных с параметром и отметкой времени. Осуществляется сравнение скорости работы стандартных таблиц и гипертаблиц (timescale), а также сохранения параметра в формате string и jsonb, составного ключа и int ключа.
## Партиционирование (timescale) | Формат параметра - Jsonb | Составной ПК
|Кол-во|Сохранение|Вычитка|
|-|--------|---|
|1.000.000|55 сек.|6.83 сек.|
|2.000.000|1 мин. 57 сек.|11 сек.|
|5.000.000|4 мин. 11 сек.|35 сек.|
|10.000.000|8 мин. 20 сек.|58 сек.|
|80.000.000|>100 мин.|20 мин. 3 сек.|
## Без партиционирования | Формат параметра - String | Составной ПК
|Кол-во|Сохранение|Вычитка|
|-|--------|---|
|1.000.000|40 сек.|26 сек.|
|2.000.000|1 мин. 26 сек.|48 сек.|
|5.000.000|3 мин. 5 сек.|2 мин. 28 сек.|
|10.000.000|8 мин. 42 сек.|4 мин. 49 сек.|
## Без партиционирования | Формат параметра - String | Int ПК
|Кол-во|Сохранение|Вычитка|
|-|--------|---|
|1.000.000|42 сек.|21 сек.|
|2.000.000|1 мин. 22 сек.|51 сек.|
|5.000.000|3 мин. 19 сек.|2 мин. 23 сек.|
|10.000.000|8 мин. 31 сек.|4 мин. 55 сек.|

View File

@ -0,0 +1,18 @@
namespace Persistence.Benchmark;
/// <summary>
/// Фабрика HTTP клиентов для интеграционных тестов
/// </summary>
public class TestHttpClientFactory : IHttpClientFactory
{
private readonly WebAppFactoryFixture factory;
public TestHttpClientFactory(WebAppFactoryFixture factory)
{
this.factory = factory;
}
public HttpClient CreateClient(string name)
{
return factory.CreateClient();
}
}

View File

@ -0,0 +1,100 @@
using DD.Persistence.Client;
using DD.Persistence.Models;
using Microsoft.Extensions.DependencyInjection;
using System.Diagnostics;
namespace Persistence.Benchmark.Tests;
public static class WitsDataBenchmark
{
private const string discriminatorId = "fef21bfd-e924-473d-b6c8-e4377e38245d";
private const int chunkSize = 25_000;
public static async Task ExecuteTest(int count)
{
try
{
var factory = new WebAppFactoryFixture();
var scope = factory.Services.CreateScope();
var persistenceClientFactory = scope.ServiceProvider
.GetRequiredService<PersistenceClientFactory>();
var client = persistenceClientFactory.GetWitsDataClient();
var source = new CancellationTokenSource(TimeSpan.FromSeconds(6000));
var data = GenerateData(count);
var sw = new Stopwatch();
var saved = 0;
foreach (var item in data)
{
var time = sw.Elapsed;
sw.Start();
var response = await client.AddRange(item, source.Token);
sw.Stop();
saved = saved + response;
Console.WriteLine($"Сохранено: {saved.ToString()}");
}
Console.WriteLine($"Затрачено времени на сохранение: {sw.Elapsed}");
var discriminator = Guid.Parse(discriminatorId);
var date = DateTime.Now.AddDays(-365);
Console.WriteLine($"\nВычитка...");
sw = new Stopwatch();
sw.Start();
var get = await client.GetPart(discriminator, date, count, source.Token);
sw.Stop();
Console.WriteLine($"Затрачено времени на вычитку {get.SelectMany(e => e.Values).Count()} записей: {sw.Elapsed}");
}
catch (Exception ex) {
Console.WriteLine(ex.Message);
}
}
private static IEnumerable<IEnumerable<WitsDataDto>> GenerateData(int countToCreate)
{
var result = new List<List<WitsDataDto>>();
var time = DateTimeOffset.UtcNow;
var seconds = -1;
int enumerableCount = countToCreate / chunkSize + (countToCreate % chunkSize == 0 ? 0 : 1);
for (var k = 0; k < enumerableCount; k++)
{
var dtos = new List<WitsDataDto>();
for (var j = 0; j < 1000; j++)
{
for (var i = 0; i < chunkSize / 1000; i++)
{
var random = new Random();
var timestamped = time.AddSeconds(seconds);
seconds = seconds - 1;
dtos.Add(new WitsDataDto()
{
DiscriminatorId = Guid.Parse(discriminatorId),
Timestamped = timestamped.AddSeconds(i),
Values = new List<WitsValueDto>()
{
new WitsValueDto()
{
RecordId = i + 1,
ItemId = i + 1,
Value = random.Next(1, 100)
}
}
});
}
}
result.Add(dtos);
}
return result;
}
}

View File

@ -0,0 +1,69 @@
using DD.Persistence.Client;
using DD.Persistence.Database.Model;
using DD.Persistence.Database.Postgres;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Logging;
using Persistence.Benchmark.Database;
namespace Persistence.Benchmark;
public class WebAppFactoryFixture : WebApplicationFactory<DD.Persistence.App.Program>
{
private string connectionString = string.Empty;
protected override void ConfigureWebHost(IWebHostBuilder builder)
{
builder.ConfigureAppConfiguration((hostingContext, config) =>
{
config.AddJsonFile("appsettings.Tests.json");
var dbConnection = config.Build().GetSection("DbConnection").Get<DbConnection>()!;
connectionString = dbConnection.GetConnectionString();
});
builder.ConfigureServices(services =>
{
var descriptor = services.SingleOrDefault(d => d.ServiceType == typeof(DbContextOptions<PersistencePostgresContext>));
if (descriptor != null)
services.Remove(descriptor);
services.AddDbContext<PersistencePostgresContext>(options =>
options.UseNpgsql(connectionString));
services.AddLogging(builder => builder.AddConsole());
services.RemoveAll<IHttpClientFactory>();
services.AddSingleton<IHttpClientFactory>(provider =>
{
return new TestHttpClientFactory(this);
});
services.AddSingleton<PersistenceClientFactory>();
var serviceProvider = services.BuildServiceProvider();
using var scope = serviceProvider.CreateScope();
var scopedServices = scope.ServiceProvider;
var dbContext = scopedServices.GetRequiredService<PersistencePostgresContext>();
//dbContext.Database.EnsureCreatedAndMigrated();
dbContext.SaveChanges();
});
}
public override async ValueTask DisposeAsync()
{
var dbContext = new PersistencePostgresContext(
new DbContextOptionsBuilder<PersistencePostgresContext>()
.UseNpgsql(connectionString)
.Options);
await dbContext.Database.EnsureDeletedAsync();
GC.SuppressFinalize(this);
}
}

View File

@ -3,16 +3,15 @@ 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;
namespace DD.Persistence.Client.Clients;
public class ChangeLogClient : BaseClient, IChangeLogClient
{
private readonly IRefitChangeLogClient refitChangeLogClient;
private readonly Interfaces.Refit.IRefitChangeLogClient refitChangeLogClient;
public ChangeLogClient(IRefitClientFactory<IRefitChangeLogClient> refitClientFactory, ILogger<ChangeLogClient> logger) : base(logger)
public ChangeLogClient(Interfaces.Refit.IRefitChangeLogClient refitChangeLogClient, ILogger<ChangeLogClient> logger) : base(logger)
{
this.refitChangeLogClient = refitClientFactory.Create();
this.refitChangeLogClient = refitChangeLogClient;
}
public async Task<int> ClearAndAddRange(Guid idDiscriminator, IEnumerable<DataWithWellDepthAndSectionDto> dtos, CancellationToken token)

View File

@ -9,9 +9,9 @@ public class DataSourceSystemClient : BaseClient, IDataSourceSystemClient
{
private readonly IRefitDataSourceSystemClient dataSourceSystemClient;
public DataSourceSystemClient(IRefitClientFactory<IRefitDataSourceSystemClient> dataSourceSystemClientFactory, ILogger<DataSourceSystemClient> logger) : base(logger)
public DataSourceSystemClient(IRefitDataSourceSystemClient dataSourceSystemClient, ILogger<DataSourceSystemClient> logger) : base(logger)
{
this.dataSourceSystemClient = dataSourceSystemClientFactory.Create();
this.dataSourceSystemClient = dataSourceSystemClient;
}
public async Task Add(DataSourceSystemDto dataSourceSystemDto, CancellationToken token)

View File

@ -6,7 +6,7 @@ namespace DD.Persistence.Client.Clients.Interfaces;
/// Клиент для работы с временными данными
/// </summary>
/// <typeparam name="TDto"></typeparam>
public interface ITimeSeriesClient<TDto> : IDisposable where TDto : class, ITimeSeriesAbstractDto
public interface ITimeSeriesClient<TDto> : IDisposable where TDto : class, new()
{
/// <summary>
/// Добавление записей

View File

@ -4,7 +4,7 @@ using Refit;
namespace DD.Persistence.Client.Clients.Interfaces.Refit;
public interface IRefitChangeLogClient : IRefitClient, IDisposable
public interface IRefitChangeLogClient : IDisposable
{
private const string BaseRoute = "/api/ChangeLog";

View File

@ -2,7 +2,7 @@
using Refit;
namespace DD.Persistence.Client.Clients.Interfaces.Refit;
public interface IRefitDataSourceSystemClient : IRefitClient, IDisposable
public interface IRefitDataSourceSystemClient : IDisposable
{
private const string BaseRoute = "/api/dataSourceSystem";

View File

@ -3,7 +3,7 @@ using Refit;
namespace DD.Persistence.Client.Clients.Interfaces.Refit;
public interface IRefitSetpointClient : IRefitClient, IDisposable
public interface IRefitSetpointClient : IDisposable
{
private const string BaseRoute = "/api/setpoint";

View File

@ -1,10 +1,11 @@
using DD.Persistence.Models;
using Microsoft.AspNetCore.Mvc;
using DD.Persistence.Models;
using DD.Persistence.Models.Requests;
using Refit;
namespace DD.Persistence.Client.Clients.Interfaces.Refit
{
public interface IRefitTechMessagesClient : IRefitClient, IDisposable
public interface IRefitTechMessagesClient : IDisposable
{
private const string BaseRoute = "/api/techMessages";

View File

@ -2,8 +2,8 @@ using DD.Persistence.Models;
using Refit;
namespace DD.Persistence.Client.Clients.Interfaces.Refit;
public interface IRefitTimeSeriesClient<TDto> : IRefitClient, IDisposable
where TDto : class, ITimeSeriesAbstractDto
public interface IRefitTimeSeriesClient<TDto> : IDisposable
where TDto : class, new()
{
private const string BaseRoute = "/api/dataSaub";

View File

@ -3,7 +3,7 @@ using Refit;
namespace DD.Persistence.Client.Clients.Interfaces.Refit;
public interface IRefitTimestampedSetClient : IRefitClient, IDisposable
public interface IRefitTimestampedSetClient : IDisposable
{
private const string baseUrl = "/api/TimestampedSet/{idDiscriminator}";

View File

@ -1,8 +1,9 @@
using DD.Persistence.Models;
using Microsoft.AspNetCore.Mvc;
using DD.Persistence.Models;
using Refit;
namespace DD.Persistence.Client.Clients.Interfaces.Refit;
public interface IRefitWitsDataClient : IRefitClient, IDisposable
public interface IRefitWitsDataClient : IDisposable
{
private const string BaseRoute = "/api/witsData";

View File

@ -10,9 +10,9 @@ public class SetpointClient : BaseClient, ISetpointClient
{
private readonly IRefitSetpointClient refitSetpointClient;
public SetpointClient(IRefitClientFactory<IRefitSetpointClient> refitSetpointClientFactory, ILogger<SetpointClient> logger) : base(logger)
public SetpointClient(IRefitSetpointClient refitSetpointClient, ILogger<SetpointClient> logger) : base(logger)
{
this.refitSetpointClient = refitSetpointClientFactory.Create();
this.refitSetpointClient = refitSetpointClient;
}
public async Task<IEnumerable<SetpointValueDto>> GetCurrent(IEnumerable<Guid> setpointKeys, CancellationToken token)

View File

@ -11,9 +11,9 @@ public class TechMessagesClient : BaseClient, ITechMessagesClient
{
private readonly IRefitTechMessagesClient refitTechMessagesClient;
public TechMessagesClient(IRefitClientFactory<IRefitTechMessagesClient> refitTechMessagesClientFactory, ILogger<TechMessagesClient> logger) : base(logger)
public TechMessagesClient(IRefitTechMessagesClient refitTechMessagesClient, ILogger<TechMessagesClient> logger) : base(logger)
{
this.refitTechMessagesClient = refitTechMessagesClientFactory.Create();
this.refitTechMessagesClient = refitTechMessagesClient;
}
public async Task<PaginationContainer<TechMessageDto>> GetPage(PaginationRequest request, CancellationToken token)

View File

@ -5,13 +5,13 @@ using DD.Persistence.Client.Clients.Interfaces.Refit;
using DD.Persistence.Models;
namespace DD.Persistence.Client.Clients;
public class TimeSeriesClient<TDto> : BaseClient, ITimeSeriesClient<TDto> where TDto : class, ITimeSeriesAbstractDto
public class TimeSeriesClient<TDto> : BaseClient, ITimeSeriesClient<TDto> where TDto : class, new()
{
private readonly IRefitTimeSeriesClient<TDto> timeSeriesClient;
public TimeSeriesClient(IRefitClientFactory<IRefitTimeSeriesClient<TDto>> refitTechMessagesClientFactory, ILogger<TimeSeriesClient<TDto>> logger) : base(logger)
public TimeSeriesClient(IRefitTimeSeriesClient<TDto> refitTechMessagesClient, ILogger<TimeSeriesClient<TDto>> logger) : base(logger)
{
this.timeSeriesClient = refitTechMessagesClientFactory.Create();
this.timeSeriesClient = refitTechMessagesClient;
}
public async Task<int> AddRange(IEnumerable<TDto> dtos, CancellationToken token)

View File

@ -9,9 +9,9 @@ public class TimestampedSetClient : BaseClient, ITimestampedSetClient
{
private readonly IRefitTimestampedSetClient refitTimestampedSetClient;
public TimestampedSetClient(IRefitClientFactory<IRefitTimestampedSetClient> refitTimestampedSetClientFactory, ILogger<TimestampedSetClient> logger) : base(logger)
public TimestampedSetClient(IRefitTimestampedSetClient refitTimestampedSetClient, ILogger<TimestampedSetClient> logger) : base(logger)
{
this.refitTimestampedSetClient = refitTimestampedSetClientFactory.Create();
this.refitTimestampedSetClient = refitTimestampedSetClient;
}
public async Task<int> AddRange(Guid idDiscriminator, IEnumerable<TimestampedSetDto> sets, CancellationToken token)

View File

@ -9,9 +9,9 @@ public class WitsDataClient : BaseClient, IWitsDataClient
{
private readonly IRefitWitsDataClient refitWitsDataClient;
public WitsDataClient(IRefitClientFactory<IRefitWitsDataClient> refitWitsDataClientFactory, ILogger<WitsDataClient> logger) : base(logger)
public WitsDataClient(IRefitWitsDataClient refitWitsDataClient, ILogger<WitsDataClient> logger) : base(logger)
{
this.refitWitsDataClient = refitWitsDataClientFactory.Create();
this.refitWitsDataClient = refitWitsDataClient;
}
public async Task<int> AddRange(IEnumerable<WitsDataDto> dtos, CancellationToken token)

View File

@ -9,13 +9,13 @@
<!--Генерация NuGet пакета при сборке-->
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<!--Наименование-->
<Title>DD.Persistence.Client</Title>
<Title>Persistence.Client</Title>
<!--Версия пакета-->
<VersionPrefix>1.0.$([System.DateTime]::UtcNow.ToString(yyMM.ddHH))</VersionPrefix>
<!--Версия сборки-->
<AssemblyVersion>1.0.$([System.DateTime]::UtcNow.ToString(yyMM.ddHH))</AssemblyVersion>
<!--Id пакета-->
<PackageId>DD.Persistence.Client</PackageId>
<PackageId>Persistence.Client</PackageId>
<!--Автор-->
<Authors>Digital Drilling</Authors>
@ -33,7 +33,7 @@
<!--Формат пакета с символами-->
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<!--Путь к пакету-->
<PackageOutputPath>C:\Projects\Nuget\Persistence\Client</PackageOutputPath>
<PackageOutputPath>C:\Projects\Nuget</PackageOutputPath>
<!--Readme-->
<PackageReadmeFile>Readme.md</PackageReadmeFile>
@ -53,12 +53,11 @@
<PackageReference Include="Refit" Version="8.0.0" />
<PackageReference Include="Refit.HttpClientFactory" Version="8.0.0" />
<PackageReference Include="RestSharp" Version="112.1.0" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="9.0.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.3.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DD.Persistence.Models\DD.Persistence.Models.csproj" />
<ProjectReference Include="..\DD.Persistence\DD.Persistence.csproj" />
</ItemGroup>
</Project>

View File

@ -1,30 +0,0 @@
using DD.Persistence.Client.Clients;
using DD.Persistence.Client.Clients.Interfaces;
using DD.Persistence.Models;
using Microsoft.Extensions.DependencyInjection;
namespace DD.Persistence.Client;
/// <summary>
///
/// </summary>
public static class DependencyInjection
{
/// <summary>
///
/// </summary>
/// <param name="services"></param>
/// <returns></returns>
public static IServiceCollection AddPersistenceClients(this IServiceCollection services)
{
services.AddTransient(typeof(IRefitClientFactory<>), typeof(RefitClientFactory<>));
services.AddTransient<IChangeLogClient, ChangeLogClient>();
services.AddTransient<IDataSourceSystemClient, DataSourceSystemClient>();
services.AddTransient<ISetpointClient, SetpointClient>();
services.AddTransient<ITechMessagesClient, TechMessagesClient>();
services.AddTransient<ITimeSeriesClient<DataSaubDto>, TimeSeriesClient<DataSaubDto>>();
services.AddTransient<ITimestampedSetClient, TimestampedSetClient>();
services.AddTransient<IWitsDataClient, WitsDataClient>();
return services;
}
}

View File

@ -1,16 +0,0 @@
using DD.Persistence.Client.Clients.Interfaces.Refit;
namespace DD.Persistence.Client;
/// <summary>
/// Интерфейс для фабрики, которая создает refit-клиентов
/// </summary>
/// <typeparam name="T"></typeparam>
public interface IRefitClientFactory<T> where T : IRefitClient
{
/// <summary>
/// Создание refit-клиента
/// </summary>
/// <returns></returns>
public T Create();
}

View File

@ -0,0 +1,150 @@
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
{
/// <summary>
/// Фабрика клиентов для доступа к Persistence - сервису
/// </summary>
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);
httpClient.Timeout = TimeSpan.FromSeconds(6000);
}
public PersistenceClientFactory(IHttpClientFactory httpClientFactory, IAuthTokenFactory authTokenFactory, IServiceProvider provider, IConfiguration configuration)
{
this.provider = provider;
httpClient = httpClientFactory.CreateClient();
var token = authTokenFactory.GetToken();
httpClient.Authorize(token);
httpClient.Timeout = TimeSpan.FromSeconds(6000);
}
/// <summary>
/// Получить клиент для работы с уставками
/// </summary>
/// <returns></returns>
public ISetpointClient GetSetpointClient()
{
var logger = provider.GetRequiredService<ILogger<SetpointClient>>();
var restClient = RestService.For<IRefitSetpointClient>(httpClient, RefitSettings);
var client = new SetpointClient(restClient, logger);
return client;
}
/// <summary>
/// Получить клиент для работы с технологическими сообщениями
/// </summary>
/// <returns></returns>
public ITechMessagesClient GetTechMessagesClient()
{
var logger = provider.GetRequiredService<ILogger<TechMessagesClient>>();
var restClient = RestService.For<IRefitTechMessagesClient>(httpClient, RefitSettings);
var client = new TechMessagesClient(restClient, logger);
return client;
}
/// <summary>
/// Получить клиент для работы с временными данными
/// </summary>
/// <typeparam name="TDto"></typeparam>
/// <returns></returns>
public ITimeSeriesClient<TDto> GetTimeSeriesClient<TDto>()
where TDto : class, new()
{
var logger = provider.GetRequiredService<ILogger<TimeSeriesClient<TDto>>>();
var restClient = RestService.For<IRefitTimeSeriesClient<TDto>>(httpClient, RefitSettings);
var client = new TimeSeriesClient<TDto>(restClient, logger);
return client;
}
/// <summary>
/// Получить клиент для работы с данными с отметкой времени
/// </summary>
/// <returns></returns>
public ITimestampedSetClient GetTimestampedSetClient()
{
var logger = provider.GetRequiredService<ILogger<TimestampedSetClient>>();
var restClient = RestService.For<IRefitTimestampedSetClient>(httpClient, RefitSettings);
var client = new TimestampedSetClient(restClient, logger);
return client;
}
/// <summary>
/// Получить клиент для работы с записями ChangeLog
/// </summary>
/// <returns></returns>
public IChangeLogClient GetChangeLogClient()
{
var logger = provider.GetRequiredService<ILogger<ChangeLogClient>>();
var restClient = RestService.For<IRefitChangeLogClient>(httpClient, RefitSettings);
var client = new ChangeLogClient(restClient, logger);
return client;
}
/// <summary>
/// Получить клиент для работы c параметрами Wits
/// </summary>
/// <returns></returns>
public IWitsDataClient GetWitsDataClient()
{
var logger = provider.GetRequiredService<ILogger<WitsDataClient>>();
var restClient = RestService.For<IRefitWitsDataClient>(httpClient, RefitSettings);
var client = new WitsDataClient(restClient, logger);
return client;
}
/// <summary>
/// Получить клиент для работы c системами
/// </summary>
/// <returns></returns>
public IDataSourceSystemClient GetDataSourceSystemClient()
{
var logger = provider.GetRequiredService<ILogger<DataSourceSystemClient>>();
var restClient = RestService.For<IRefitDataSourceSystemClient>(httpClient, RefitSettings);
var client = new DataSourceSystemClient(restClient, logger);
return client;
}
}
}

View File

@ -1,52 +0,0 @@
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;
/// <summary>
/// Фабрика, которая создает refit-клиентов
/// </summary>
/// <typeparam name="T"></typeparam>
public class RefitClientFactory<T> : IRefitClientFactory<T> where T : IRefitClient
{
private HttpClient client;
private RefitSettings refitSettings;
/// <inheritdoc/>
public RefitClientFactory(IConfiguration configuration, ILogger<IRefitClientFactory<T>> logger, HttpClient client)
{
//this.client = factory.CreateClient();
this.client = client;
var baseUrl = configuration.GetSection("ClientUrl").Get<string>();
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));
}
/// <summary>
/// создание клиента
/// </summary>
/// <returns></returns>
public T Create()
{
return RestService.For<T>(client, refitSettings);
}
}

View File

@ -12,7 +12,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace DD.Persistence.Database.Postgres.Migrations
{
[DbContext(typeof(PersistencePostgresContext))]
[Migration("20241220062251_Init")]
[Migration("20241225122815_Init")]
partial class Init
{
/// <inheritdoc />
@ -20,7 +20,7 @@ namespace DD.Persistence.Database.Postgres.Migrations
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.10")
.HasAnnotation("ProductVersion", "9.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
@ -43,7 +43,7 @@ namespace DD.Persistence.Database.Postgres.Migrations
b.HasKey("SystemId");
b.ToTable("DataSourceSystem");
b.ToTable("data_source_system");
});
modelBuilder.Entity("DD.Persistence.Database.Entity.ParameterData", b =>
@ -60,14 +60,14 @@ namespace DD.Persistence.Database.Postgres.Migrations
.HasColumnType("timestamp with time zone")
.HasComment("Временная отметка");
b.Property<string>("Value")
b.Property<object>("Value")
.IsRequired()
.HasColumnType("varchar(256)")
.HasComment("Значение параметра в виде строки");
.HasColumnType("jsonb")
.HasComment("Значение параметра");
b.HasKey("DiscriminatorId", "ParameterId", "Timestamp");
b.ToTable("ParameterData");
b.ToTable("parameter_data");
});
modelBuilder.Entity("DD.Persistence.Database.Entity.TechMessage", b =>
@ -102,7 +102,7 @@ namespace DD.Persistence.Database.Postgres.Migrations
b.HasIndex("SystemId");
b.ToTable("TechMessage");
b.ToTable("tech_message");
});
modelBuilder.Entity("DD.Persistence.Database.Entity.TimestampedSet", b =>
@ -122,7 +122,7 @@ namespace DD.Persistence.Database.Postgres.Migrations
b.HasKey("IdDiscriminator", "Timestamp");
b.ToTable("TimestampedSets", t =>
b.ToTable("timestamped_set", t =>
{
t.HasComment("Общая таблица данных временных рядов");
});
@ -178,7 +178,7 @@ namespace DD.Persistence.Database.Postgres.Migrations
b.HasKey("Id");
b.ToTable("ChangeLog");
b.ToTable("change_log");
});
modelBuilder.Entity("DD.Persistence.Database.Model.DataSaub", b =>
@ -261,7 +261,7 @@ namespace DD.Persistence.Database.Postgres.Migrations
b.HasKey("Date");
b.ToTable("DataSaub");
b.ToTable("data_saub");
});
modelBuilder.Entity("DD.Persistence.Database.Model.Setpoint", b =>
@ -285,7 +285,7 @@ namespace DD.Persistence.Database.Postgres.Migrations
b.HasKey("Key", "Created");
b.ToTable("Setpoint");
b.ToTable("setpoint");
});
modelBuilder.Entity("DD.Persistence.Database.Entity.TechMessage", b =>

View File

@ -12,7 +12,7 @@ namespace DD.Persistence.Database.Postgres.Migrations
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "ChangeLog",
name: "change_log",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false, comment: "Ключ записи"),
@ -29,11 +29,11 @@ namespace DD.Persistence.Database.Postgres.Migrations
},
constraints: table =>
{
table.PrimaryKey("PK_ChangeLog", x => x.Id);
table.PrimaryKey("PK_change_log", x => x.Id);
});
migrationBuilder.CreateTable(
name: "DataSaub",
name: "data_saub",
columns: table => new
{
date = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
@ -58,11 +58,11 @@ namespace DD.Persistence.Database.Postgres.Migrations
},
constraints: table =>
{
table.PrimaryKey("PK_DataSaub", x => x.date);
table.PrimaryKey("PK_data_saub", x => x.date);
});
migrationBuilder.CreateTable(
name: "DataSourceSystem",
name: "data_source_system",
columns: table => new
{
SystemId = table.Column<Guid>(type: "uuid", nullable: false, comment: "Id системы - источника данных"),
@ -71,25 +71,25 @@ namespace DD.Persistence.Database.Postgres.Migrations
},
constraints: table =>
{
table.PrimaryKey("PK_DataSourceSystem", x => x.SystemId);
table.PrimaryKey("PK_data_source_system", x => x.SystemId);
});
migrationBuilder.CreateTable(
name: "ParameterData",
name: "parameter_data",
columns: table => new
{
DiscriminatorId = table.Column<Guid>(type: "uuid", nullable: false, comment: "Дискриминатор системы"),
ParameterId = table.Column<int>(type: "integer", nullable: false, comment: "Id параметра"),
Timestamp = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, comment: "Временная отметка"),
Value = table.Column<string>(type: "varchar(256)", nullable: false, comment: "Значение параметра в виде строки")
Value = table.Column<object>(type: "jsonb", nullable: false, comment: "Значение параметра")
},
constraints: table =>
{
table.PrimaryKey("PK_ParameterData", x => new { x.DiscriminatorId, x.ParameterId, x.Timestamp });
table.PrimaryKey("PK_parameter_data", x => new { x.DiscriminatorId, x.ParameterId, x.Timestamp });
});
migrationBuilder.CreateTable(
name: "Setpoint",
name: "setpoint",
columns: table => new
{
Key = table.Column<Guid>(type: "uuid", nullable: false, comment: "Ключ"),
@ -99,11 +99,11 @@ namespace DD.Persistence.Database.Postgres.Migrations
},
constraints: table =>
{
table.PrimaryKey("PK_Setpoint", x => new { x.Key, x.Created });
table.PrimaryKey("PK_setpoint", x => new { x.Key, x.Created });
});
migrationBuilder.CreateTable(
name: "TimestampedSets",
name: "timestamped_set",
columns: table => new
{
IdDiscriminator = table.Column<Guid>(type: "uuid", nullable: false, comment: "Дискриминатор ссылка на тип сохраняемых данных"),
@ -112,12 +112,12 @@ namespace DD.Persistence.Database.Postgres.Migrations
},
constraints: table =>
{
table.PrimaryKey("PK_TimestampedSets", x => new { x.IdDiscriminator, x.Timestamp });
table.PrimaryKey("PK_timestamped_set", x => new { x.IdDiscriminator, x.Timestamp });
},
comment: "Общая таблица данных временных рядов");
migrationBuilder.CreateTable(
name: "TechMessage",
name: "tech_message",
columns: table => new
{
EventId = table.Column<Guid>(type: "uuid", nullable: false, comment: "Id события"),
@ -129,44 +129,47 @@ namespace DD.Persistence.Database.Postgres.Migrations
},
constraints: table =>
{
table.PrimaryKey("PK_TechMessage", x => x.EventId);
table.PrimaryKey("PK_tech_message", x => x.EventId);
table.ForeignKey(
name: "FK_TechMessage_DataSourceSystem_SystemId",
name: "FK_tech_message_data_source_system_SystemId",
column: x => x.SystemId,
principalTable: "DataSourceSystem",
principalTable: "data_source_system",
principalColumn: "SystemId",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_TechMessage_SystemId",
table: "TechMessage",
name: "IX_tech_message_SystemId",
table: "tech_message",
column: "SystemId");
migrationBuilder.Sql
("SELECT create_hypertable('parameter_data','Timestamp','ParameterId',2,chunk_time_interval => INTERVAL '5 day');");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "ChangeLog");
name: "change_log");
migrationBuilder.DropTable(
name: "DataSaub");
name: "data_saub");
migrationBuilder.DropTable(
name: "ParameterData");
name: "parameter_data");
migrationBuilder.DropTable(
name: "Setpoint");
name: "setpoint");
migrationBuilder.DropTable(
name: "TechMessage");
name: "tech_message");
migrationBuilder.DropTable(
name: "TimestampedSets");
name: "timestamped_set");
migrationBuilder.DropTable(
name: "DataSourceSystem");
name: "data_source_system");
}
}
}

View File

@ -17,7 +17,7 @@ namespace DD.Persistence.Database.Postgres.Migrations
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.10")
.HasAnnotation("ProductVersion", "9.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
@ -40,7 +40,7 @@ namespace DD.Persistence.Database.Postgres.Migrations
b.HasKey("SystemId");
b.ToTable("DataSourceSystem");
b.ToTable("data_source_system");
});
modelBuilder.Entity("DD.Persistence.Database.Entity.ParameterData", b =>
@ -57,14 +57,14 @@ namespace DD.Persistence.Database.Postgres.Migrations
.HasColumnType("timestamp with time zone")
.HasComment("Временная отметка");
b.Property<string>("Value")
b.Property<object>("Value")
.IsRequired()
.HasColumnType("varchar(256)")
.HasComment("Значение параметра в виде строки");
.HasColumnType("jsonb")
.HasComment("Значение параметра");
b.HasKey("DiscriminatorId", "ParameterId", "Timestamp");
b.ToTable("ParameterData");
b.ToTable("parameter_data");
});
modelBuilder.Entity("DD.Persistence.Database.Entity.TechMessage", b =>
@ -99,7 +99,7 @@ namespace DD.Persistence.Database.Postgres.Migrations
b.HasIndex("SystemId");
b.ToTable("TechMessage");
b.ToTable("tech_message");
});
modelBuilder.Entity("DD.Persistence.Database.Entity.TimestampedSet", b =>
@ -119,7 +119,7 @@ namespace DD.Persistence.Database.Postgres.Migrations
b.HasKey("IdDiscriminator", "Timestamp");
b.ToTable("TimestampedSets", t =>
b.ToTable("timestamped_set", t =>
{
t.HasComment("Общая таблица данных временных рядов");
});
@ -175,7 +175,7 @@ namespace DD.Persistence.Database.Postgres.Migrations
b.HasKey("Id");
b.ToTable("ChangeLog");
b.ToTable("change_log");
});
modelBuilder.Entity("DD.Persistence.Database.Model.DataSaub", b =>
@ -258,7 +258,7 @@ namespace DD.Persistence.Database.Postgres.Migrations
b.HasKey("Date");
b.ToTable("DataSaub");
b.ToTable("data_saub");
});
modelBuilder.Entity("DD.Persistence.Database.Model.Setpoint", b =>
@ -282,7 +282,7 @@ namespace DD.Persistence.Database.Postgres.Migrations
b.HasKey("Key", "Created");
b.ToTable("Setpoint");
b.ToTable("setpoint");
});
modelBuilder.Entity("DD.Persistence.Database.Entity.TechMessage", b =>

View File

@ -9,6 +9,7 @@ namespace DD.Persistence.Database.Model;
/// <summary>
/// Часть записи, описывающая изменение
/// </summary>
[Table("change_log")]
public class ChangeLog : IChangeLog, IWithSectionPart
{
[Key, Comment("Ключ записи")]

View File

@ -2,6 +2,8 @@
using System.ComponentModel.DataAnnotations.Schema;
namespace DD.Persistence.Database.Model;
[Table("data_saub")]
public class DataSaub : ITimestampedData
{
[Key, Column("date")]

View File

@ -3,6 +3,8 @@ using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace DD.Persistence.Database.Entity;
[Table("data_source_system")]
public class DataSourceSystem
{
[Key, Comment("Id системы - источника данных")]

View File

@ -4,6 +4,7 @@ using System.ComponentModel.DataAnnotations.Schema;
namespace DD.Persistence.Database.Entity;
[Table("parameter_data")]
[PrimaryKey(nameof(DiscriminatorId), nameof(ParameterId), nameof(Timestamp))]
public class ParameterData
{
@ -13,8 +14,8 @@ public class ParameterData
[Comment("Id параметра")]
public int ParameterId { get; set; }
[Column(TypeName = "varchar(256)"), Comment("Значение параметра в виде строки")]
public required string Value { get; set; }
[Column(TypeName = "jsonb"), Comment("Значение параметра")]
public required object Value { get; set; }
[Comment("Временная отметка")]
public DateTimeOffset Timestamp { get; set; }

View File

@ -3,6 +3,7 @@ using System.ComponentModel.DataAnnotations.Schema;
namespace DD.Persistence.Database.Model
{
[Table("setpoint")]
[PrimaryKey(nameof(Key), nameof(Created))]
public class Setpoint
{

View File

@ -4,6 +4,7 @@ using System.ComponentModel.DataAnnotations.Schema;
namespace DD.Persistence.Database.Entity
{
[Table("tech_message")]
public class TechMessage
{
[Key, Comment("Id события")]

View File

@ -3,6 +3,7 @@ using System.ComponentModel.DataAnnotations.Schema;
namespace DD.Persistence.Database.Entity;
[Table("timestamped_set")]
[Comment("Общая таблица данных временных рядов")]
[PrimaryKey(nameof(IdDiscriminator), nameof(Timestamp))]
public record TimestampedSet(

View File

@ -4,7 +4,9 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DD.Persistence.Client.Clients.Interfaces.Refit;
public interface IRefitClient
namespace DD.Persistence.Database.UsefulQueries
{
class partition_function
{
}
}

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DD.Persistence.Database.UsefulQueries
{
class partition_function
{
}
}

View File

@ -7,11 +7,6 @@ using DD.Persistence.Models.Requests;
using Xunit;
using DD.Persistence.Client.Clients.Interfaces;
using DD.Persistence.Client;
using DD.Persistence.Client.Clients.Interfaces.Refit;
using DD.Persistence.Client.Clients;
using Microsoft.Extensions.Logging;
using Refit;
using System.Net.Http;
namespace DD.Persistence.IntegrationTests.Controllers;
public class ChangeLogControllerTest : BaseIntegrationTest
@ -21,12 +16,10 @@ public class ChangeLogControllerTest : BaseIntegrationTest
public ChangeLogControllerTest(WebAppFactoryFixture factory) : base(factory)
{
var refitClientFactory = scope.ServiceProvider
.GetRequiredService<IRefitClientFactory<IRefitChangeLogClient>>();
var logger = scope.ServiceProvider.GetRequiredService<ILogger<ChangeLogClient>>();
var persistenceClientFactory = scope.ServiceProvider
.GetRequiredService<PersistenceClientFactory>();
client = scope.ServiceProvider
.GetRequiredService<IChangeLogClient>();
client = persistenceClientFactory.GetChangeLogClient();
}
[Fact]

View File

@ -6,8 +6,6 @@ using DD.Persistence.Client.Clients.Interfaces;
using DD.Persistence.Database.Entity;
using DD.Persistence.Models;
using Xunit;
using DD.Persistence.Client.Clients.Interfaces.Refit;
using Microsoft.Extensions.Logging;
namespace DD.Persistence.IntegrationTests.Controllers
{
@ -18,12 +16,11 @@ namespace DD.Persistence.IntegrationTests.Controllers
private readonly IMemoryCache memoryCache;
public DataSourceSystemControllerTest(WebAppFactoryFixture factory) : base(factory)
{
var refitClientFactory = scope.ServiceProvider
.GetRequiredService<IRefitClientFactory<IRefitDataSourceSystemClient>>();
var logger = scope.ServiceProvider.GetRequiredService<ILogger<DataSourceSystemClient>>();
var scope = factory.Services.CreateScope();
var persistenceClientFactory = scope.ServiceProvider
.GetRequiredService<PersistenceClientFactory>();
dataSourceSystemClient = scope.ServiceProvider
.GetRequiredService<IDataSourceSystemClient>();
dataSourceSystemClient = persistenceClientFactory.GetDataSourceSystemClient();
memoryCache = scope.ServiceProvider.GetRequiredService<IMemoryCache>();
}

View File

@ -4,9 +4,6 @@ using DD.Persistence.Client.Clients.Interfaces;
using DD.Persistence.Database.Model;
using System.Net;
using Xunit;
using DD.Persistence.Client.Clients.Interfaces.Refit;
using DD.Persistence.Client.Clients;
using Microsoft.Extensions.Logging;
namespace DD.Persistence.IntegrationTests.Controllers
{
@ -20,12 +17,11 @@ namespace DD.Persistence.IntegrationTests.Controllers
}
public SetpointControllerTest(WebAppFactoryFixture factory) : base(factory)
{
var refitClientFactory = scope.ServiceProvider
.GetRequiredService<IRefitClientFactory<IRefitSetpointClient>>();
var logger = scope.ServiceProvider.GetRequiredService<ILogger<SetpointClient>>();
var scope = factory.Services.CreateScope();
var persistenceClientFactory = scope.ServiceProvider
.GetRequiredService<PersistenceClientFactory>();
setpointClient = scope.ServiceProvider
.GetRequiredService<ISetpointClient>();
setpointClient = persistenceClientFactory.GetSetpointClient();
}
[Fact]

View File

@ -1,14 +1,12 @@
using DD.Persistence.Client;
using DD.Persistence.Client.Clients;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.DependencyInjection;
using DD.Persistence.Client;
using DD.Persistence.Client.Clients.Interfaces;
using DD.Persistence.Client.Clients.Interfaces.Refit;
using DD.Persistence.Database.Entity;
using DD.Persistence.Models;
using DD.Persistence.Models.Enumerations;
using DD.Persistence.Models.Requests;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System.Net;
using Xunit;
namespace DD.Persistence.IntegrationTests.Controllers
@ -20,12 +18,11 @@ namespace DD.Persistence.IntegrationTests.Controllers
private readonly IMemoryCache memoryCache;
public TechMessagesControllerTest(WebAppFactoryFixture factory) : base(factory)
{
var refitClientFactory = scope.ServiceProvider
.GetRequiredService<IRefitClientFactory<IRefitTechMessagesClient>>();
var logger = scope.ServiceProvider.GetRequiredService<ILogger<TechMessagesClient>>();
var scope = factory.Services.CreateScope();
var persistenceClientFactory = scope.ServiceProvider
.GetRequiredService<PersistenceClientFactory>();
techMessagesClient = scope.ServiceProvider
.GetRequiredService<ITechMessagesClient>();
techMessagesClient = persistenceClientFactory.GetTechMessagesClient();
memoryCache = scope.ServiceProvider.GetRequiredService<IMemoryCache>();
}

View File

@ -1,19 +1,16 @@
using DD.Persistence.Client;
using DD.Persistence.Client.Clients;
using DD.Persistence.Client.Clients.Interfaces;
using DD.Persistence.Client.Clients.Interfaces.Refit;
using DD.Persistence.Database.Model;
using DD.Persistence.Models;
using Mapster;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using DD.Persistence.Client;
using DD.Persistence.Client.Clients.Interfaces;
using DD.Persistence.Database.Model;
using System.Net;
using Xunit;
namespace DD.Persistence.IntegrationTests.Controllers;
public abstract class TimeSeriesBaseControllerTest<TEntity, TDto> : BaseIntegrationTest
where TEntity : class, ITimestampedData, new()
where TDto : class, ITimeSeriesAbstractDto, new()
where TDto : class, new()
{
private readonly ITimeSeriesClient<TDto> timeSeriesClient;
@ -21,12 +18,11 @@ public abstract class TimeSeriesBaseControllerTest<TEntity, TDto> : BaseIntegrat
{
dbContext.CleanupDbSet<TEntity>();
var refitClientFactory = scope.ServiceProvider
.GetRequiredService<IRefitClientFactory<IRefitTimeSeriesClient<TDto>>>();
var logger = scope.ServiceProvider.GetRequiredService<ILogger<TimeSeriesClient<TDto>>>();
var scope = factory.Services.CreateScope();
var persistenceClientFactory = scope.ServiceProvider
.GetRequiredService<PersistenceClientFactory>();
timeSeriesClient = scope.ServiceProvider
.GetRequiredService<ITimeSeriesClient<TDto>>();
timeSeriesClient = persistenceClientFactory.GetTimeSeriesClient<TDto>();
}
public async Task InsertRangeSuccess(TDto dto)

View File

@ -3,9 +3,6 @@ using DD.Persistence.Client;
using DD.Persistence.Client.Clients.Interfaces;
using DD.Persistence.Models;
using Xunit;
using DD.Persistence.Client.Clients.Interfaces.Refit;
using DD.Persistence.Client.Clients;
using Microsoft.Extensions.Logging;
namespace DD.Persistence.IntegrationTests.Controllers;
public class TimestampedSetControllerTest : BaseIntegrationTest
@ -14,12 +11,10 @@ public class TimestampedSetControllerTest : BaseIntegrationTest
public TimestampedSetControllerTest(WebAppFactoryFixture factory) : base(factory)
{
var refitClientFactory = scope.ServiceProvider
.GetRequiredService<IRefitClientFactory<IRefitTimestampedSetClient>>();
var logger = scope.ServiceProvider.GetRequiredService<ILogger<TimestampedSetClient>>();
var persistenceClientFactory = scope.ServiceProvider
.GetRequiredService<PersistenceClientFactory>();
client = scope.ServiceProvider
.GetRequiredService<ITimestampedSetClient>();
client = persistenceClientFactory.GetTimestampedSetClient();
}
[Fact]

View File

@ -1,12 +1,10 @@
using DD.Persistence.Client;
using DD.Persistence.Client.Clients;
using DD.Persistence.Client.Clients.Interfaces;
using DD.Persistence.Client.Clients.Interfaces.Refit;
using DD.Persistence.Database.Entity;
using DD.Persistence.Models;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using DD.Persistence.Models;
using System.Net;
using Xunit;
using DD.Persistence.Client.Clients.Interfaces;
using DD.Persistence.Client;
using DD.Persistence.Database.Entity;
namespace DD.Persistence.IntegrationTests.Controllers;
public class WitsDataControllerTest : BaseIntegrationTest
@ -15,12 +13,11 @@ public class WitsDataControllerTest : BaseIntegrationTest
public WitsDataControllerTest(WebAppFactoryFixture factory) : base(factory)
{
var refitClientFactory = scope.ServiceProvider
.GetRequiredService<IRefitClientFactory<IRefitWitsDataClient>>();
var logger = scope.ServiceProvider.GetRequiredService<ILogger<WitsDataClient>>();
var scope = factory.Services.CreateScope();
var persistenceClientFactory = scope.ServiceProvider
.GetRequiredService<PersistenceClientFactory>();
witsDataClient = scope.ServiceProvider
.GetRequiredService<IWitsDataClient>();
witsDataClient = persistenceClientFactory.GetWitsDataClient();
}
[Fact]

View File

@ -1,7 +1,4 @@
using DD.Persistence.Client.Helpers;
using Microsoft.Extensions.Configuration;
namespace DD.Persistence.IntegrationTests
namespace DD.Persistence.IntegrationTests
{
/// <summary>
/// Фабрика HTTP клиентов для интеграционных тестов
@ -9,19 +6,14 @@ namespace DD.Persistence.IntegrationTests
public class TestHttpClientFactory : IHttpClientFactory
{
private readonly WebAppFactoryFixture factory;
private readonly IConfiguration configuration;
public TestHttpClientFactory(WebAppFactoryFixture factory, IConfiguration configuration)
public TestHttpClientFactory(WebAppFactoryFixture factory)
{
this.factory = factory;
this.configuration = configuration;
}
public HttpClient CreateClient(string name)
{
var client = factory.CreateClient();
client.Authorize(configuration);
return client;
return factory.CreateClient();
}
}
}

View File

@ -11,9 +11,6 @@ using DD.Persistence.Database.Model;
using DD.Persistence.Database.Postgres;
using RestSharp;
using DD.Persistence.App;
using DD.Persistence.Client.Helpers;
using DD.Persistence.Factories;
using System.Net;
namespace DD.Persistence.IntegrationTests;
public class WebAppFactoryFixture : WebApplicationFactory<Program>
@ -43,12 +40,12 @@ public class WebAppFactoryFixture : WebApplicationFactory<Program>
services.AddLogging(builder => builder.AddConsole());
services.RemoveAll<IHttpClientFactory>();
services.AddSingleton<IHttpClientFactory>((provider) =>
services.AddSingleton<IHttpClientFactory>(provider =>
{
return new TestHttpClientFactory(this, provider.GetRequiredService<IConfiguration>());
return new TestHttpClientFactory(this);
});
services.AddHttpClient();
services.AddPersistenceClients();
services.AddSingleton<PersistenceClientFactory>();
var serviceProvider = services.BuildServiceProvider();

View File

@ -1,43 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<!--Генерация NuGet пакета при сборке-->
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<!--Наименование-->
<Title>DD.Persistence.Models</Title>
<!--Версия пакета-->
<VersionPrefix>1.0.$([System.DateTime]::UtcNow.ToString(yyMM.ddHH))</VersionPrefix>
<!--Версия сборки-->
<AssemblyVersion>1.0.$([System.DateTime]::UtcNow.ToString(yyMM.ddHH))</AssemblyVersion>
<!--Id пакета-->
<PackageId>DD.Persistence.Models</PackageId>
<!--Автор-->
<Authors>Digital Drilling</Authors>
<!--Компания-->
<Company>Digital Drilling</Company>
<!--Описание-->
<Description>Пакет для получения dtos для работы с Persistence сервисом</Description>
<!--Url репозитория-->
<RepositoryUrl>https://git.ddrilling.ru/on.nemtina/persistence.git</RepositoryUrl>
<!--тип репозитория-->
<RepositoryType>git</RepositoryType>
<!--Символы отладки-->
<IncludeSymbols>true</IncludeSymbols>
<!--Формат пакета с символами-->
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<!--Путь к пакету-->
<PackageOutputPath>C:\Projects\Nuget\Persistence\Models</PackageOutputPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="8.3.0" />
</ItemGroup>
</Project>

View File

@ -1,8 +1,8 @@
using Mapster;
using Microsoft.EntityFrameworkCore;
using DD.Persistence.Database.Entity;
using DD.Persistence.Models;
using DD.Persistence.Repositories;
using DD.Persistence.Database.Entity;
namespace DD.Persistence.Repository.Repositories;
public class ParameterRepository : IParameterRepository
@ -83,4 +83,105 @@ public class ParameterRepository : IParameterRepository
return result;
}
//public async Task<int> AddRange(IEnumerable<ParameterDto> dtos, CancellationToken token)
//{
// int result = 0;
// var groups = dtos.GroupBy(e => e.ParameterId / 1000);
// foreach (var group in groups)
// {
// switch (group.Key)
// {
// case 1:
// result += await AddRange<ParameterData1>(dtos, token);
// break;
// case 2:
// result += await AddRange<ParameterData2>(dtos, token);
// break;
// case 3:
// result += await AddRange<ParameterData3>(dtos, token);
// break;
// case 4:
// result += await AddRange<ParameterData4>(dtos, token);
// break;
// case 5:
// result += await AddRange<ParameterData5>(dtos, token);
// break;
// case 6:
// result += await AddRange<ParameterData6>(dtos, token);
// break;
// case 7:
// result += await AddRange<ParameterData7>(dtos, token);
// break;
// case 8:
// result += await AddRange<ParameterData8>(dtos, token);
// break;
// case 9:
// result += await AddRange<ParameterData9>(dtos, token);
// break;
// case 10:
// result += await AddRange<ParameterData10>(dtos, token);
// break;
// case 11:
// result += await AddRange<ParameterData11>(dtos, token);
// break;
// case 12:
// result += await AddRange<ParameterData12>(dtos, token);
// break;
// case 13:
// result += await AddRange<ParameterData13>(dtos, token);
// break;
// case 14:
// result += await AddRange<ParameterData14>(dtos, token);
// break;
// case 15:
// result += await AddRange<ParameterData15>(dtos, token);
// break;
// case 16:
// result += await AddRange<ParameterData16>(dtos, token);
// break;
// case 17:
// result += await AddRange<ParameterData17>(dtos, token);
// break;
// case 18:
// result += await AddRange<ParameterData18>(dtos, token);
// break;
// case 19:
// result += await AddRange<ParameterData19>(dtos, token);
// break;
// case 20:
// result += await AddRange<ParameterData20>(dtos, token);
// break;
// case 21:
// result += await AddRange<ParameterData21>(dtos, token);
// break;
// case 22:
// result += await AddRange<ParameterData22>(dtos, token);
// break;
// case 23:
// result += await AddRange<ParameterData23>(dtos, token);
// break;
// case 24:
// result += await AddRange<ParameterData24>(dtos, token);
// break;
// case 25:
// result += await AddRange<ParameterData25>(dtos, token);
// break;
// }
// }
// return result;
//}
//private async Task<int> AddRange<T>(IEnumerable<ParameterDto> dtos, CancellationToken token)
// where T : ParameterData
//{
// var t = dtos.Where(e => e.Value == null);
// var entities = dtos.Select(e => e.Adapt<T>());
// var tt = entities.Where(e => e.Value == null);
// await db.Set<T>().AddRangeAsync(entities, token);
// var result = await db.SaveChangesAsync(token);
// return result;
//}
}

View File

@ -91,7 +91,6 @@ namespace DD.Persistence.Repository.Repositories
await CreateSystemIfNotExist(systemId, token);
entity.SystemId = systemId;
entity.Timestamp = dto.Timestamp.ToUniversalTime();
entities.Add(entity);
}

View File

@ -1,4 +1,3 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34714.143
@ -19,7 +18,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DD.Persistence.Client", "DD
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DD.Persistence.App", "DD.Persistence.App\DD.Persistence.App.csproj", "{063238BF-E982-43FA-9DDB-7D7D279086D8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DD.Persistence.Models", "DD.Persistence.Models\DD.Persistence.Models.csproj", "{698B4571-BB7A-4A42-8B0B-6C7F2F5360FB}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DD.Persistence.Benchmark", "DD.Persistence.Benchmark\DD.Persistence.Benchmark.csproj", "{89975A38-C78B-4464-A04D-D63E8745062D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -59,10 +58,10 @@ Global
{063238BF-E982-43FA-9DDB-7D7D279086D8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{063238BF-E982-43FA-9DDB-7D7D279086D8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{063238BF-E982-43FA-9DDB-7D7D279086D8}.Release|Any CPU.Build.0 = Release|Any CPU
{698B4571-BB7A-4A42-8B0B-6C7F2F5360FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{698B4571-BB7A-4A42-8B0B-6C7F2F5360FB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{698B4571-BB7A-4A42-8B0B-6C7F2F5360FB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{698B4571-BB7A-4A42-8B0B-6C7F2F5360FB}.Release|Any CPU.Build.0 = Release|Any CPU
{89975A38-C78B-4464-A04D-D63E8745062D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{89975A38-C78B-4464-A04D-D63E8745062D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{89975A38-C78B-4464-A04D-D63E8745062D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{89975A38-C78B-4464-A04D-D63E8745062D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -18,10 +18,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DD.Persistence.Models\DD.Persistence.Models.csproj" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="8.3.0" />
</ItemGroup>
</Project>

View File

@ -19,7 +19,6 @@ namespace DD.Persistence.Repositories
/// <summary>
/// Добавление новых сообщений
/// </summary>
/// <param name="systemId"></param>
/// <param name="dtos"></param>
/// <param name="token"></param>
/// <returns></returns>

View File

@ -0,0 +1,22 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Persistence.Benchmark.Database.Entities;
public class ParameterData
{
[Key]
public Guid Id { get; set; }
[Required, Comment("Дискриминатор системы")]
public Guid DiscriminatorId { get; set; }
[Comment("Id параметра")]
public int ParameterId { get; set; }
[Column(TypeName = "varchar(256)"), Comment("Значение параметра в виде строки")]
public required string Value { get; set; }
[Comment("Временная отметка")]
public DateTimeOffset Timestamp { get; set; }
}