Compare commits
10 Commits
master
...
Partitioni
Author | SHA1 | Date | |
---|---|---|---|
f06eda826b | |||
ff95cad258 | |||
50c535de5e | |||
df7148688d | |||
45fbfaf657 | |||
cdbbcce3bf | |||
7fe7357712 | |||
86ea991934 | |||
84731fbf3c | |||
74959284f3 |
@ -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 =>
|
||||
|
@ -26,6 +26,8 @@ public class Startup
|
||||
services.AddJWTAuthentication(Configuration);
|
||||
services.AddMemoryCache();
|
||||
services.AddServices();
|
||||
|
||||
//DependencyInjection.MapsterSetup();
|
||||
}
|
||||
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
|
@ -1,10 +1,10 @@
|
||||
{
|
||||
"DbConnection": {
|
||||
"Host": "postgres",
|
||||
"Host": "localhost",
|
||||
"Port": 5432,
|
||||
"Database": "persistence",
|
||||
"Username": "postgres",
|
||||
"Password": "postgres"
|
||||
"Password": "q"
|
||||
},
|
||||
"NeedUseKeyCloak": false,
|
||||
"AuthUser": {
|
||||
|
@ -2,7 +2,8 @@
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
"Microsoft.AspNetCore": "Warning",
|
||||
"Microsoft.EntityFrameworkCore.Database.Command": "Error"
|
||||
}
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
@ -19,7 +20,6 @@
|
||||
"password": 12345,
|
||||
"clientId": "webapi",
|
||||
"grantType": "password",
|
||||
"http://schemas.xmlsoap.org/ws/2005/05/identity /claims/nameidentifier": "7d9f3574-6574-4ca3-845a-0276eb4aa8f6"
|
||||
},
|
||||
"ClientUrl": "http://localhost:5000/"
|
||||
"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier": "7d9f3574-6574-4ca3-845a-0276eb4aa8f6"
|
||||
}
|
||||
}
|
||||
|
24
DD.Persistence.Benchmark/DD.Persistence.Benchmark.csproj
Normal file
24
DD.Persistence.Benchmark/DD.Persistence.Benchmark.csproj
Normal 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>
|
14
DD.Persistence.Benchmark/Database/DbConnection.cs
Normal file
14
DD.Persistence.Benchmark/Database/DbConnection.cs
Normal 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";
|
||||
}
|
10
DD.Persistence.Benchmark/Program.cs
Normal file
10
DD.Persistence.Benchmark/Program.cs
Normal 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();
|
||||
}
|
||||
}
|
28
DD.Persistence.Benchmark/Results.md
Normal file
28
DD.Persistence.Benchmark/Results.md
Normal 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 сек.|
|
18
DD.Persistence.Benchmark/TestHttpClientFactory.cs
Normal file
18
DD.Persistence.Benchmark/TestHttpClientFactory.cs
Normal 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();
|
||||
}
|
||||
}
|
100
DD.Persistence.Benchmark/Tests/WitsDataBenchmark.cs
Normal file
100
DD.Persistence.Benchmark/Tests/WitsDataBenchmark.cs
Normal 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;
|
||||
}
|
||||
}
|
69
DD.Persistence.Benchmark/WebAppFactoryFixture.cs
Normal file
69
DD.Persistence.Benchmark/WebAppFactoryFixture.cs
Normal 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);
|
||||
}
|
||||
}
|
@ -3,17 +3,16 @@ 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)
|
||||
{
|
||||
|
@ -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)
|
||||
|
@ -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>
|
||||
/// Добавление записей
|
||||
|
@ -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";
|
||||
|
||||
|
@ -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";
|
||||
|
||||
|
@ -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";
|
||||
|
||||
|
@ -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";
|
||||
|
||||
|
@ -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";
|
||||
|
||||
|
@ -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}";
|
||||
|
||||
|
@ -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";
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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>
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
150
DD.Persistence.Client/PersistenceClientFactory.cs
Normal file
150
DD.Persistence.Client/PersistenceClientFactory.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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 =>
|
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
@ -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 =>
|
||||
|
@ -9,6 +9,7 @@ namespace DD.Persistence.Database.Model;
|
||||
/// <summary>
|
||||
/// Часть записи, описывающая изменение
|
||||
/// </summary>
|
||||
[Table("change_log")]
|
||||
public class ChangeLog : IChangeLog, IWithSectionPart
|
||||
{
|
||||
[Key, Comment("Ключ записи")]
|
||||
|
@ -2,6 +2,8 @@
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace DD.Persistence.Database.Model;
|
||||
|
||||
[Table("data_saub")]
|
||||
public class DataSaub : ITimestampedData
|
||||
{
|
||||
[Key, Column("date")]
|
||||
|
@ -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 системы - источника данных")]
|
||||
|
@ -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; }
|
||||
|
@ -3,6 +3,7 @@ using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace DD.Persistence.Database.Model
|
||||
{
|
||||
[Table("setpoint")]
|
||||
[PrimaryKey(nameof(Key), nameof(Created))]
|
||||
public class Setpoint
|
||||
{
|
||||
|
@ -4,6 +4,7 @@ using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace DD.Persistence.Database.Entity
|
||||
{
|
||||
[Table("tech_message")]
|
||||
public class TechMessage
|
||||
{
|
||||
[Key, Comment("Id события")]
|
||||
|
@ -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(
|
||||
|
@ -21,7 +21,7 @@ public class PersistenceDbContext : DbContext
|
||||
|
||||
public DbSet<ParameterData> ParameterData => Set<ParameterData>();
|
||||
|
||||
public DbSet<DataSourceSystem> DataSourceSystem => Set<DataSourceSystem>();
|
||||
public DbSet<DataSourceSystem> DataSourceSystem => Set<DataSourceSystem>();
|
||||
|
||||
public PersistenceDbContext(DbContextOptions options)
|
||||
: base(options)
|
||||
|
@ -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
|
||||
{
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
|
@ -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
|
||||
{
|
||||
}
|
||||
}
|
@ -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]
|
||||
|
@ -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>();
|
||||
}
|
||||
|
||||
|
@ -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]
|
||||
|
@ -1,41 +1,38 @@
|
||||
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
|
||||
{
|
||||
public class TechMessagesControllerTest : BaseIntegrationTest
|
||||
{
|
||||
private static readonly string SystemCacheKey = $"{typeof(Database.Entity.DataSourceSystem).FullName}CacheKey";
|
||||
private readonly ITechMessagesClient techMessagesClient;
|
||||
private readonly IMemoryCache memoryCache;
|
||||
public TechMessagesControllerTest(WebAppFactoryFixture factory) : base(factory)
|
||||
{
|
||||
var refitClientFactory = scope.ServiceProvider
|
||||
.GetRequiredService<IRefitClientFactory<IRefitTechMessagesClient>>();
|
||||
var logger = scope.ServiceProvider.GetRequiredService<ILogger<TechMessagesClient>>();
|
||||
public class TechMessagesControllerTest : BaseIntegrationTest
|
||||
{
|
||||
private static readonly string SystemCacheKey = $"{typeof(Database.Entity.DataSourceSystem).FullName}CacheKey";
|
||||
private readonly ITechMessagesClient techMessagesClient;
|
||||
private readonly IMemoryCache memoryCache;
|
||||
public TechMessagesControllerTest(WebAppFactoryFixture factory) : base(factory)
|
||||
{
|
||||
var scope = factory.Services.CreateScope();
|
||||
var persistenceClientFactory = scope.ServiceProvider
|
||||
.GetRequiredService<PersistenceClientFactory>();
|
||||
|
||||
techMessagesClient = scope.ServiceProvider
|
||||
.GetRequiredService<ITechMessagesClient>();
|
||||
memoryCache = scope.ServiceProvider.GetRequiredService<IMemoryCache>();
|
||||
}
|
||||
techMessagesClient = persistenceClientFactory.GetTechMessagesClient();
|
||||
memoryCache = scope.ServiceProvider.GetRequiredService<IMemoryCache>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetPage_returns_success()
|
||||
{
|
||||
//arrange
|
||||
memoryCache.Remove(SystemCacheKey);
|
||||
dbContext.CleanupDbSet<TechMessage>();
|
||||
dbContext.CleanupDbSet<DataSourceSystem>();
|
||||
[Fact]
|
||||
public async Task GetPage_returns_success()
|
||||
{
|
||||
//arrange
|
||||
memoryCache.Remove(SystemCacheKey);
|
||||
dbContext.CleanupDbSet<TechMessage>();
|
||||
dbContext.CleanupDbSet<DataSourceSystem>();
|
||||
|
||||
var requestDto = new PaginationRequest()
|
||||
{
|
||||
@ -47,235 +44,235 @@ namespace DD.Persistence.IntegrationTests.Controllers
|
||||
//act
|
||||
var response = await techMessagesClient.GetPage(requestDto, CancellationToken.None);
|
||||
|
||||
//assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Empty(response.Items);
|
||||
Assert.Equal(requestDto.Skip, response.Skip);
|
||||
Assert.Equal(requestDto.Take, response.Take);
|
||||
}
|
||||
//assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Empty(response.Items);
|
||||
Assert.Equal(requestDto.Skip, response.Skip);
|
||||
Assert.Equal(requestDto.Take, response.Take);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetPage_AfterSave_returns_success()
|
||||
{
|
||||
//arrange
|
||||
var dtos = await InsertRange(Guid.NewGuid());
|
||||
var dtosCount = dtos.Count();
|
||||
var requestDto = new PaginationRequest()
|
||||
{
|
||||
Skip = 0,
|
||||
Take = 2,
|
||||
SortSettings = nameof(TechMessage.CategoryId)
|
||||
};
|
||||
[Fact]
|
||||
public async Task GetPage_AfterSave_returns_success()
|
||||
{
|
||||
//arrange
|
||||
var dtos = await InsertRange(Guid.NewGuid());
|
||||
var dtosCount = dtos.Count();
|
||||
var requestDto = new PaginationRequest()
|
||||
{
|
||||
Skip = 0,
|
||||
Take = 2,
|
||||
SortSettings = nameof(TechMessage.CategoryId)
|
||||
};
|
||||
|
||||
//act
|
||||
var response = await techMessagesClient.GetPage(requestDto, CancellationToken.None);
|
||||
|
||||
//assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Equal(dtosCount, response.Count);
|
||||
}
|
||||
//assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Equal(dtosCount, response.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task InsertRange_returns_success()
|
||||
{
|
||||
await InsertRange(Guid.NewGuid());
|
||||
}
|
||||
[Fact]
|
||||
public async Task InsertRange_returns_success()
|
||||
{
|
||||
await InsertRange(Guid.NewGuid());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task InsertRange_returns_BadRequest()
|
||||
{
|
||||
//arrange
|
||||
const string exceptionMessage = "Ошибка валидации, формата или маршрутизации запроса";
|
||||
var systemId = Guid.NewGuid();
|
||||
var dtos = new List<TechMessageDto>()
|
||||
{
|
||||
new TechMessageDto()
|
||||
{
|
||||
EventId = Guid.NewGuid(),
|
||||
CategoryId = -1, // < 0
|
||||
[Fact]
|
||||
public async Task InsertRange_returns_BadRequest()
|
||||
{
|
||||
//arrange
|
||||
const string exceptionMessage = "Ошибка валидации, формата или маршрутизации запроса";
|
||||
var systemId = Guid.NewGuid();
|
||||
var dtos = new List<TechMessageDto>()
|
||||
{
|
||||
new TechMessageDto()
|
||||
{
|
||||
EventId = Guid.NewGuid(),
|
||||
CategoryId = -1, // < 0
|
||||
Timestamp = DateTimeOffset.UtcNow,
|
||||
Text = string.Empty, // length < 0
|
||||
Text = string.Empty, // length < 0
|
||||
EventState = EventState.Triggered
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
//act
|
||||
var response = await techMessagesClient.AddRange(systemId, dtos, CancellationToken.None);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//assert
|
||||
Assert.Equal(exceptionMessage, ex.Message);
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
//act
|
||||
var response = await techMessagesClient.AddRange(systemId, dtos, CancellationToken.None);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//assert
|
||||
Assert.Equal(exceptionMessage, ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetSystems_returns_success()
|
||||
{
|
||||
//arrange
|
||||
memoryCache.Remove(SystemCacheKey);
|
||||
dbContext.CleanupDbSet<TechMessage>();
|
||||
dbContext.CleanupDbSet<DataSourceSystem>();
|
||||
[Fact]
|
||||
public async Task GetSystems_returns_success()
|
||||
{
|
||||
//arrange
|
||||
memoryCache.Remove(SystemCacheKey);
|
||||
dbContext.CleanupDbSet<TechMessage>();
|
||||
dbContext.CleanupDbSet<DataSourceSystem>();
|
||||
|
||||
//act
|
||||
var response = await techMessagesClient.GetSystems(CancellationToken.None);
|
||||
|
||||
//assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Empty(response);
|
||||
}
|
||||
//assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Empty(response);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetSystems_AfterSave_returns_success()
|
||||
{
|
||||
//arrange
|
||||
await InsertRange(Guid.NewGuid());
|
||||
[Fact]
|
||||
public async Task GetSystems_AfterSave_returns_success()
|
||||
{
|
||||
//arrange
|
||||
await InsertRange(Guid.NewGuid());
|
||||
|
||||
//act
|
||||
var response = await techMessagesClient.GetSystems(CancellationToken.None);
|
||||
|
||||
//assert
|
||||
Assert.NotNull(response);
|
||||
var expectedSystemCount = 1;
|
||||
Assert.Equal(expectedSystemCount, response!.Count());
|
||||
}
|
||||
//assert
|
||||
Assert.NotNull(response);
|
||||
var expectedSystemCount = 1;
|
||||
Assert.Equal(expectedSystemCount, response!.Count());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetStatistics_returns_success()
|
||||
{
|
||||
//arrange
|
||||
memoryCache.Remove(SystemCacheKey);
|
||||
dbContext.CleanupDbSet<TechMessage>();
|
||||
dbContext.CleanupDbSet<DataSourceSystem>();
|
||||
[Fact]
|
||||
public async Task GetStatistics_returns_success()
|
||||
{
|
||||
//arrange
|
||||
memoryCache.Remove(SystemCacheKey);
|
||||
dbContext.CleanupDbSet<TechMessage>();
|
||||
dbContext.CleanupDbSet<DataSourceSystem>();
|
||||
|
||||
var categoryIds = new[] { 1, 2 };
|
||||
var systemIds = new[] { Guid.NewGuid() };
|
||||
var categoryIds = new [] { 1, 2 };
|
||||
var systemIds = new [] { Guid.NewGuid() };
|
||||
|
||||
//act
|
||||
var response = await techMessagesClient.GetStatistics(systemIds, categoryIds, CancellationToken.None);
|
||||
|
||||
//assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Empty(response);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetStatistics_AfterSave_returns_success()
|
||||
{
|
||||
//arrange
|
||||
var categoryIds = new[] { 1 };
|
||||
var systemId = Guid.NewGuid();
|
||||
var dtos = await InsertRange(systemId);
|
||||
var filteredDtos = dtos.Where(e => categoryIds.Contains(e.CategoryId));
|
||||
|
||||
//act
|
||||
var response = await techMessagesClient.GetStatistics([systemId], categoryIds, CancellationToken.None);
|
||||
|
||||
//assert
|
||||
Assert.NotNull(response);
|
||||
Assert.NotEmpty(response);
|
||||
var categories = response
|
||||
.FirstOrDefault()!.Categories
|
||||
.Count();
|
||||
Assert.Equal(filteredDtos.Count(), categories);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetDatesRange_returns_NoContent()
|
||||
{
|
||||
//arrange
|
||||
memoryCache.Remove(SystemCacheKey);
|
||||
dbContext.CleanupDbSet<TechMessage>();
|
||||
dbContext.CleanupDbSet<DataSourceSystem>();
|
||||
|
||||
//act
|
||||
var response = await techMessagesClient.GetStatistics(systemIds, categoryIds, CancellationToken.None);
|
||||
|
||||
var response = await techMessagesClient.GetDatesRangeAsync(CancellationToken.None);
|
||||
|
||||
//assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Empty(response);
|
||||
}
|
||||
Assert.Null(response);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetStatistics_AfterSave_returns_success()
|
||||
{
|
||||
//arrange
|
||||
var categoryIds = new[] { 1 };
|
||||
var systemId = Guid.NewGuid();
|
||||
var dtos = await InsertRange(systemId);
|
||||
var filteredDtos = dtos.Where(e => categoryIds.Contains(e.CategoryId));
|
||||
|
||||
//act
|
||||
var response = await techMessagesClient.GetStatistics([systemId], categoryIds, CancellationToken.None);
|
||||
|
||||
//assert
|
||||
Assert.NotNull(response);
|
||||
Assert.NotEmpty(response);
|
||||
var categories = response
|
||||
.FirstOrDefault()!.Categories
|
||||
.Count();
|
||||
Assert.Equal(filteredDtos.Count(), categories);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetDatesRange_returns_NoContent()
|
||||
{
|
||||
//arrange
|
||||
memoryCache.Remove(SystemCacheKey);
|
||||
dbContext.CleanupDbSet<TechMessage>();
|
||||
dbContext.CleanupDbSet<DataSourceSystem>();
|
||||
[Fact]
|
||||
public async Task GetDatesRange_AfterSave_returns_success()
|
||||
{
|
||||
//arrange
|
||||
await InsertRange(Guid.NewGuid());
|
||||
|
||||
//act
|
||||
var response = await techMessagesClient.GetDatesRangeAsync(CancellationToken.None);
|
||||
|
||||
//assert
|
||||
Assert.Null(response);
|
||||
}
|
||||
//assert
|
||||
Assert.NotNull(response);
|
||||
Assert.NotNull(response?.From);
|
||||
Assert.NotNull(response?.To);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetDatesRange_AfterSave_returns_success()
|
||||
{
|
||||
//arrange
|
||||
await InsertRange(Guid.NewGuid());
|
||||
// [Fact]
|
||||
// public async Task GetPart_returns_success()
|
||||
// {
|
||||
// //arrange
|
||||
// var dateBegin = DateTimeOffset.UtcNow;
|
||||
// var take = 2;
|
||||
|
||||
//act
|
||||
var response = await techMessagesClient.GetDatesRangeAsync(CancellationToken.None);
|
||||
// //act
|
||||
// var response = await techMessagesClient.GetPart(dateBegin, take, CancellationToken.None);
|
||||
|
||||
//assert
|
||||
Assert.NotNull(response);
|
||||
Assert.NotNull(response?.From);
|
||||
Assert.NotNull(response?.To);
|
||||
}
|
||||
// //assert
|
||||
// Assert.NotNull(response);
|
||||
// Assert.Empty(response);
|
||||
//}
|
||||
|
||||
// [Fact]
|
||||
// public async Task GetPart_returns_success()
|
||||
// {
|
||||
// //arrange
|
||||
// var dateBegin = DateTimeOffset.UtcNow;
|
||||
// var take = 2;
|
||||
|
||||
// //act
|
||||
// var response = await techMessagesClient.GetPart(dateBegin, take, CancellationToken.None);
|
||||
|
||||
// //assert
|
||||
// Assert.NotNull(response);
|
||||
// Assert.Empty(response);
|
||||
//}
|
||||
|
||||
[Fact]
|
||||
public async Task GetPart_AfterSave_returns_success()
|
||||
{
|
||||
//arrange
|
||||
var dateBegin = DateTimeOffset.UtcNow;
|
||||
var take = 1;
|
||||
await InsertRange(Guid.NewGuid());
|
||||
[Fact]
|
||||
public async Task GetPart_AfterSave_returns_success()
|
||||
{
|
||||
//arrange
|
||||
var dateBegin = DateTimeOffset.UtcNow;
|
||||
var take = 1;
|
||||
await InsertRange(Guid.NewGuid());
|
||||
|
||||
//act
|
||||
var response = await techMessagesClient.GetPart(dateBegin, take, CancellationToken.None);
|
||||
|
||||
//assert
|
||||
Assert.NotNull(response);
|
||||
Assert.NotEmpty(response);
|
||||
}
|
||||
//assert
|
||||
Assert.NotNull(response);
|
||||
Assert.NotEmpty(response);
|
||||
}
|
||||
|
||||
private async Task<IEnumerable<TechMessageDto>> InsertRange(Guid systemId)
|
||||
{
|
||||
//arrange
|
||||
memoryCache.Remove(SystemCacheKey);
|
||||
dbContext.CleanupDbSet<TechMessage>();
|
||||
dbContext.CleanupDbSet<DataSourceSystem>();
|
||||
private async Task<IEnumerable<TechMessageDto>> InsertRange(Guid systemId)
|
||||
{
|
||||
//arrange
|
||||
memoryCache.Remove(SystemCacheKey);
|
||||
dbContext.CleanupDbSet<TechMessage>();
|
||||
dbContext.CleanupDbSet<DataSourceSystem>();
|
||||
|
||||
var dtos = new List<TechMessageDto>()
|
||||
{
|
||||
new TechMessageDto()
|
||||
{
|
||||
EventId = Guid.NewGuid(),
|
||||
CategoryId = 1,
|
||||
Timestamp = DateTimeOffset.UtcNow,
|
||||
Text = nameof(TechMessageDto.Text),
|
||||
EventState = Models.Enumerations.EventState.Triggered
|
||||
},
|
||||
new TechMessageDto()
|
||||
{
|
||||
EventId = Guid.NewGuid(),
|
||||
CategoryId = 2,
|
||||
Timestamp = DateTimeOffset.UtcNow,
|
||||
Text = nameof(TechMessageDto.Text),
|
||||
EventState = Models.Enumerations.EventState.Triggered
|
||||
}
|
||||
};
|
||||
var dtos = new List<TechMessageDto>()
|
||||
{
|
||||
new TechMessageDto()
|
||||
{
|
||||
EventId = Guid.NewGuid(),
|
||||
CategoryId = 1,
|
||||
Timestamp = DateTimeOffset.UtcNow,
|
||||
Text = nameof(TechMessageDto.Text),
|
||||
EventState = Models.Enumerations.EventState.Triggered
|
||||
},
|
||||
new TechMessageDto()
|
||||
{
|
||||
EventId = Guid.NewGuid(),
|
||||
CategoryId = 2,
|
||||
Timestamp = DateTimeOffset.UtcNow,
|
||||
Text = nameof(TechMessageDto.Text),
|
||||
EventState = Models.Enumerations.EventState.Triggered
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//act
|
||||
var response = await techMessagesClient.AddRange(systemId, dtos, CancellationToken.None);
|
||||
//act
|
||||
var response = await techMessagesClient.AddRange(systemId, dtos, CancellationToken.None);
|
||||
|
||||
//assert
|
||||
Assert.Equal(dtos.Count, response);
|
||||
//assert
|
||||
Assert.Equal(dtos.Count, response);
|
||||
|
||||
return dtos;
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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]
|
||||
|
@ -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]
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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) =>
|
||||
{
|
||||
return new TestHttpClientFactory(this, provider.GetRequiredService<IConfiguration>());
|
||||
});
|
||||
services.AddHttpClient();
|
||||
services.AddPersistenceClients();
|
||||
services.AddSingleton<IHttpClientFactory>(provider =>
|
||||
{
|
||||
return new TestHttpClientFactory(this);
|
||||
});
|
||||
|
||||
services.AddSingleton<PersistenceClientFactory>();
|
||||
|
||||
var serviceProvider = services.BuildServiceProvider();
|
||||
|
||||
|
@ -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>
|
@ -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;
|
||||
//}
|
||||
}
|
||||
|
@ -91,7 +91,6 @@ namespace DD.Persistence.Repository.Repositories
|
||||
await CreateSystemIfNotExist(systemId, token);
|
||||
|
||||
entity.SystemId = systemId;
|
||||
entity.Timestamp = dto.Timestamp.ToUniversalTime();
|
||||
|
||||
entities.Add(entity);
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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>
|
||||
|
@ -19,7 +19,6 @@ namespace DD.Persistence.Repositories
|
||||
/// <summary>
|
||||
/// Добавление новых сообщений
|
||||
/// </summary>
|
||||
/// <param name="systemId"></param>
|
||||
/// <param name="dtos"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
|
22
Persistence.Benchmark/Database/Entities/ParameterData.cs
Normal file
22
Persistence.Benchmark/Database/Entities/ParameterData.cs
Normal 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; }
|
||||
}
|
Loading…
Reference in New Issue
Block a user