2025-01-20 17:24:01 +05:00
|
|
|
using Microsoft.Extensions.Logging;
|
2024-12-16 15:38:46 +05:00
|
|
|
using DD.Persistence.Client.Clients.Base;
|
|
|
|
using DD.Persistence.Client.Clients.Interfaces;
|
|
|
|
using DD.Persistence.Client.Clients.Interfaces.Refit;
|
|
|
|
using DD.Persistence.Models;
|
2025-01-13 17:45:49 +05:00
|
|
|
using DD.Persistence.Models.Common;
|
2024-12-09 14:45:35 +05:00
|
|
|
|
2024-12-16 15:38:46 +05:00
|
|
|
namespace DD.Persistence.Client.Clients;
|
2024-12-09 14:45:35 +05:00
|
|
|
|
|
|
|
public class SetpointClient : BaseClient, ISetpointClient
|
|
|
|
{
|
|
|
|
private readonly IRefitSetpointClient refitSetpointClient;
|
|
|
|
|
2025-01-17 16:39:36 +05:00
|
|
|
public SetpointClient(
|
|
|
|
IRefitClientFactory<IRefitSetpointClient> refitSetpointClientFactory,
|
|
|
|
ILogger<SetpointClient> logger) : base(logger)
|
2024-12-09 14:45:35 +05:00
|
|
|
{
|
2024-12-27 00:37:52 +05:00
|
|
|
this.refitSetpointClient = refitSetpointClientFactory.Create();
|
2025-01-17 16:39:36 +05:00
|
|
|
}
|
2024-12-09 14:45:35 +05:00
|
|
|
|
|
|
|
public async Task<IEnumerable<SetpointValueDto>> GetCurrent(IEnumerable<Guid> setpointKeys, CancellationToken token)
|
|
|
|
{
|
2024-12-13 15:30:11 +05:00
|
|
|
var result = await ExecuteGetResponse(
|
2024-12-09 14:45:35 +05:00
|
|
|
async () => await refitSetpointClient.GetCurrent(setpointKeys, token), token);
|
|
|
|
|
2025-01-17 16:39:36 +05:00
|
|
|
return result!.Select(x => new SetpointValueDto {
|
|
|
|
Key = x.Key,
|
2025-02-12 15:14:14 +05:00
|
|
|
Value = x.Value
|
2025-01-17 16:39:36 +05:00
|
|
|
});
|
2024-12-09 14:45:35 +05:00
|
|
|
}
|
|
|
|
|
2025-01-20 10:29:30 +05:00
|
|
|
|
2025-01-16 15:57:53 +05:00
|
|
|
|
2025-01-17 16:39:36 +05:00
|
|
|
public async Task<Dictionary<Guid, object>> GetCurrentDictionary(IEnumerable<Guid> setpointConfigs, CancellationToken token)
|
2025-01-16 15:57:53 +05:00
|
|
|
{
|
2025-01-17 16:39:36 +05:00
|
|
|
var result = await ExecuteGetResponse(
|
|
|
|
async () => await refitSetpointClient.GetCurrent(setpointConfigs, token), token);
|
|
|
|
|
|
|
|
|
2025-02-12 15:14:14 +05:00
|
|
|
return result!.ToDictionary(x => x.Key,x => (object)x.Value);
|
2025-01-17 16:39:36 +05:00
|
|
|
}
|
|
|
|
|
2025-01-16 15:57:53 +05:00
|
|
|
public async Task<IEnumerable<SetpointValueDto>> GetHistory(IEnumerable<Guid> setpointKeys, DateTimeOffset historyMoment, CancellationToken token)
|
2024-12-09 14:45:35 +05:00
|
|
|
{
|
2024-12-13 15:30:11 +05:00
|
|
|
var result = await ExecuteGetResponse(
|
2024-12-09 14:45:35 +05:00
|
|
|
async () => await refitSetpointClient.GetHistory(setpointKeys, historyMoment, token), token);
|
2025-01-20 10:29:30 +05:00
|
|
|
|
|
|
|
|
2024-12-13 17:30:35 +05:00
|
|
|
return result!;
|
2024-12-09 14:45:35 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
public async Task<Dictionary<Guid, IEnumerable<SetpointLogDto>>> GetLog(IEnumerable<Guid> setpointKeys, CancellationToken token)
|
|
|
|
{
|
2024-12-13 15:30:11 +05:00
|
|
|
var result = await ExecuteGetResponse(
|
2024-12-09 14:45:35 +05:00
|
|
|
async () => await refitSetpointClient.GetLog(setpointKeys, token), token);
|
|
|
|
|
2024-12-13 17:30:35 +05:00
|
|
|
return result!;
|
2024-12-09 14:45:35 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
public async Task<DatesRangeDto> GetDatesRangeAsync(CancellationToken token)
|
|
|
|
{
|
2024-12-13 15:30:11 +05:00
|
|
|
var result = await ExecuteGetResponse(
|
2024-12-09 14:45:35 +05:00
|
|
|
async () => await refitSetpointClient.GetDatesRangeAsync(token), token);
|
|
|
|
|
2024-12-13 17:30:35 +05:00
|
|
|
return result!;
|
2024-12-09 14:45:35 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
public async Task<IEnumerable<SetpointLogDto>> GetPart(DateTimeOffset dateBegin, int take, CancellationToken token)
|
2025-01-20 10:29:30 +05:00
|
|
|
{
|
|
|
|
var result = await ExecuteGetResponse(
|
|
|
|
async () => await refitSetpointClient.GetPart(dateBegin, take, token), token);
|
2024-12-09 14:45:35 +05:00
|
|
|
|
2025-01-20 10:29:30 +05:00
|
|
|
return result!;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-12-09 14:45:35 +05:00
|
|
|
|
2025-01-20 10:29:30 +05:00
|
|
|
public async Task Add(Guid setpointKey, object newValue, CancellationToken token)
|
2024-12-09 14:45:35 +05:00
|
|
|
{
|
|
|
|
await ExecutePostResponse(
|
|
|
|
async () => await refitSetpointClient.Add(setpointKey, newValue, token), token);
|
|
|
|
}
|
2024-12-10 13:55:01 +05:00
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
refitSetpointClient.Dispose();
|
2024-12-13 15:30:11 +05:00
|
|
|
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
}
|
2024-12-09 14:45:35 +05:00
|
|
|
}
|