2024-12-09 14:45:35 +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;
|
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;
|
|
|
|
|
|
2024-12-27 00:37:52 +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();
|
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);
|
|
|
|
|
|
2024-12-13 17:30:35 +05:00
|
|
|
|
return result!;
|
2024-12-09 14:45:35 +05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<SetpointValueDto>> GetHistory(IEnumerable<Guid> setpointKeys, DateTimeOffset historyMoment, 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.GetHistory(setpointKeys, historyMoment, token), token);
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
2024-12-13 15:30:11 +05:00
|
|
|
|
var result = await ExecuteGetResponse(
|
2024-12-09 14:45:35 +05:00
|
|
|
|
async () => await refitSetpointClient.GetPart(dateBegin, take, token), token);
|
|
|
|
|
|
2024-12-13 17:30:35 +05:00
|
|
|
|
return result!;
|
2024-12-09 14:45:35 +05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task Add(Guid setpointKey, object newValue, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
}
|