2024-11-25 10:09:38 +05:00
|
|
|
|
using Microsoft.Extensions.Configuration;
|
2024-12-16 15:38:46 +05:00
|
|
|
|
using DD.Persistence.Client.Clients.Interfaces;
|
|
|
|
|
using DD.Persistence.Client.Clients;
|
|
|
|
|
using DD.Persistence.Client.Helpers;
|
2024-11-25 10:09:38 +05:00
|
|
|
|
using Refit;
|
2024-12-16 15:38:46 +05:00
|
|
|
|
using DD.Persistence.Factories;
|
|
|
|
|
using DD.Persistence.Client.Clients.Interfaces.Refit;
|
2024-12-09 14:45:35 +05:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
2024-12-10 13:55:01 +05:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2024-12-09 13:19:55 +05:00
|
|
|
|
using System.Text.Json;
|
2024-11-21 14:50:36 +05:00
|
|
|
|
|
2024-12-16 15:38:46 +05:00
|
|
|
|
namespace DD.Persistence.Client
|
2024-11-21 14:50:36 +05:00
|
|
|
|
{
|
2024-11-25 14:29:42 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Фабрика клиентов для доступа к Persistence - сервису
|
|
|
|
|
/// </summary>
|
2024-11-25 10:09:38 +05:00
|
|
|
|
public class PersistenceClientFactory
|
2024-11-21 14:50:36 +05:00
|
|
|
|
{
|
|
|
|
|
private static readonly JsonSerializerOptions JsonSerializerOptions = new()
|
|
|
|
|
{
|
|
|
|
|
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
|
|
|
|
PropertyNameCaseInsensitive = true
|
|
|
|
|
};
|
|
|
|
|
private static readonly RefitSettings RefitSettings = new(new SystemTextJsonContentSerializer(JsonSerializerOptions));
|
2024-12-10 13:55:01 +05:00
|
|
|
|
private readonly IServiceProvider provider;
|
2024-11-25 10:09:38 +05:00
|
|
|
|
private HttpClient httpClient;
|
2024-12-10 13:55:01 +05:00
|
|
|
|
public PersistenceClientFactory(IHttpClientFactory httpClientFactory, IServiceProvider provider, IConfiguration configuration)
|
2024-11-21 14:50:36 +05:00
|
|
|
|
{
|
2024-12-10 13:55:01 +05:00
|
|
|
|
this.provider = provider;
|
2024-12-09 14:45:35 +05:00
|
|
|
|
|
|
|
|
|
httpClient = httpClientFactory.CreateClient();
|
2024-11-21 14:50:36 +05:00
|
|
|
|
|
2024-11-25 10:09:38 +05:00
|
|
|
|
httpClient.Authorize(configuration);
|
2024-11-21 14:50:36 +05:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-10 13:55:01 +05:00
|
|
|
|
public PersistenceClientFactory(IHttpClientFactory httpClientFactory, IAuthTokenFactory authTokenFactory, IServiceProvider provider, IConfiguration configuration)
|
2024-12-09 14:45:35 +05:00
|
|
|
|
{
|
2024-12-10 13:55:01 +05:00
|
|
|
|
this.provider = provider;
|
2024-12-09 14:45:35 +05:00
|
|
|
|
|
|
|
|
|
httpClient = httpClientFactory.CreateClient();
|
|
|
|
|
|
|
|
|
|
var token = authTokenFactory.GetToken();
|
|
|
|
|
httpClient.Authorize(token);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получить клиент для работы с уставками
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public ISetpointClient GetSetpointClient()
|
|
|
|
|
{
|
2024-12-10 13:55:01 +05:00
|
|
|
|
var logger = provider.GetRequiredService<ILogger<SetpointClient>>();
|
|
|
|
|
|
2024-12-09 14:45:35 +05:00
|
|
|
|
var restClient = RestService.For<IRefitSetpointClient>(httpClient, RefitSettings);
|
|
|
|
|
var client = new SetpointClient(restClient, logger);
|
|
|
|
|
|
|
|
|
|
return client;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получить клиент для работы с технологическими сообщениями
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public ITechMessagesClient GetTechMessagesClient()
|
2024-11-21 14:50:36 +05:00
|
|
|
|
{
|
2024-12-10 13:55:01 +05:00
|
|
|
|
var logger = provider.GetRequiredService<ILogger<TechMessagesClient>>();
|
|
|
|
|
|
2024-12-09 14:45:35 +05:00
|
|
|
|
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()
|
|
|
|
|
{
|
2024-12-10 13:55:01 +05:00
|
|
|
|
var logger = provider.GetRequiredService<ILogger<TimeSeriesClient<TDto>>>();
|
|
|
|
|
|
2024-12-09 14:45:35 +05:00
|
|
|
|
var restClient = RestService.For<IRefitTimeSeriesClient<TDto>>(httpClient, RefitSettings);
|
|
|
|
|
var client = new TimeSeriesClient<TDto>(restClient, logger);
|
|
|
|
|
|
|
|
|
|
return client;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получить клиент для работы с данными с отметкой времени
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public ITimestampedSetClient GetTimestampedSetClient()
|
|
|
|
|
{
|
2024-12-10 13:55:01 +05:00
|
|
|
|
var logger = provider.GetRequiredService<ILogger<TimestampedSetClient>>();
|
|
|
|
|
|
2024-12-09 14:45:35 +05:00
|
|
|
|
var restClient = RestService.For<IRefitTimestampedSetClient>(httpClient, RefitSettings);
|
|
|
|
|
var client = new TimestampedSetClient(restClient, logger);
|
|
|
|
|
|
|
|
|
|
return client;
|
2024-11-21 14:50:36 +05:00
|
|
|
|
}
|
2024-12-10 13:55:01 +05:00
|
|
|
|
|
|
|
|
|
/// <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;
|
|
|
|
|
}
|
2024-12-11 11:29:50 +05:00
|
|
|
|
|
|
|
|
|
/// <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;
|
|
|
|
|
}
|
2024-12-12 17:05:47 +05:00
|
|
|
|
|
|
|
|
|
/// <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;
|
|
|
|
|
}
|
2024-11-21 14:50:36 +05:00
|
|
|
|
}
|
|
|
|
|
}
|