persistence/Persistence.Client/Clients/SetpointClient.cs

69 lines
2.2 KiB
C#

using Microsoft.Extensions.Logging;
using Persistence.Client.Clients.Base;
using Persistence.Client.Clients.Interfaces;
using Persistence.Client.Clients.Interfaces.Refit;
using Persistence.Models;
namespace Persistence.Client.Clients;
public class SetpointClient : BaseClient, ISetpointClient
{
private readonly IRefitSetpointClient refitSetpointClient;
public SetpointClient(IRefitSetpointClient refitSetpointClient, ILogger<SetpointClient> logger) : base(logger)
{
this.refitSetpointClient = refitSetpointClient;
}
public async Task<IEnumerable<SetpointValueDto>> GetCurrent(IEnumerable<Guid> setpointKeys, CancellationToken token)
{
var result = await ExecuteGetResponse<IEnumerable<SetpointValueDto>>(
async () => await refitSetpointClient.GetCurrent(setpointKeys, token), token);
return result;
}
public async Task<IEnumerable<SetpointValueDto>> GetHistory(IEnumerable<Guid> setpointKeys, DateTimeOffset historyMoment, CancellationToken token)
{
var result = await ExecuteGetResponse<IEnumerable<SetpointValueDto>>(
async () => await refitSetpointClient.GetHistory(setpointKeys, historyMoment, token), token);
return result;
}
public async Task<Dictionary<Guid, IEnumerable<SetpointLogDto>>> GetLog(IEnumerable<Guid> setpointKeys, CancellationToken token)
{
var result = await ExecuteGetResponse<Dictionary<Guid, IEnumerable<SetpointLogDto>>>(
async () => await refitSetpointClient.GetLog(setpointKeys, token), token);
return result;
}
public async Task<DatesRangeDto> GetDatesRangeAsync(CancellationToken token)
{
var result = await ExecuteGetResponse<DatesRangeDto>(
async () => await refitSetpointClient.GetDatesRangeAsync(token), token);
return result;
}
public async Task<IEnumerable<SetpointLogDto>> GetPart(DateTimeOffset dateBegin, int take, CancellationToken token)
{
var result = await ExecuteGetResponse<IEnumerable<SetpointLogDto>>(
async () => await refitSetpointClient.GetPart(dateBegin, take, token), token);
return result;
}
public async Task Add(Guid setpointKey, object newValue, CancellationToken token)
{
await ExecutePostResponse(
async () => await refitSetpointClient.Add(setpointKey, newValue, token), token);
}
public void Dispose()
{
refitSetpointClient.Dispose();
}
}