56 lines
1.8 KiB
C#
56 lines
1.8 KiB
C#
using Microsoft.Extensions.Logging;
|
|
using DD.Persistence.Client.Clients.Base;
|
|
using DD.Persistence.Client.Clients.Interfaces;
|
|
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
|
|
{
|
|
private readonly IRefitTimeSeriesClient<TDto> timeSeriesClient;
|
|
|
|
public TimeSeriesClient(IRefitClientFactory<IRefitTimeSeriesClient<TDto>> refitTechMessagesClientFactory, ILogger<TimeSeriesClient<TDto>> logger) : base(logger)
|
|
{
|
|
this.timeSeriesClient = refitTechMessagesClientFactory.Create();
|
|
}
|
|
|
|
public async Task<int> AddRange(IEnumerable<TDto> dtos, CancellationToken token)
|
|
{
|
|
var result = await ExecutePostResponse(
|
|
async () => await timeSeriesClient.AddRange(dtos, token), token);
|
|
|
|
return result;
|
|
}
|
|
|
|
public async Task<IEnumerable<TDto>> Get(DateTimeOffset dateBegin, DateTimeOffset dateEnd, CancellationToken token)
|
|
{
|
|
var result = await ExecuteGetResponse(
|
|
async () => await timeSeriesClient.Get(dateBegin, dateEnd, token), token);
|
|
|
|
return result!;
|
|
}
|
|
|
|
public async Task<IEnumerable<TDto>> GetResampledData(DateTimeOffset dateBegin, double intervalSec = 600d, int approxPointsCount = 1024, CancellationToken token = default)
|
|
{
|
|
var result = await ExecuteGetResponse(
|
|
async () => await timeSeriesClient.GetResampledData(dateBegin, intervalSec, approxPointsCount, token), token);
|
|
|
|
return result!;
|
|
}
|
|
|
|
public async Task<DatesRangeDto?> GetDatesRange(CancellationToken token)
|
|
{
|
|
var result = await ExecuteGetResponse(
|
|
async () => await timeSeriesClient.GetDatesRange(token), token);
|
|
|
|
return result;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
timeSeriesClient.Dispose();
|
|
|
|
GC.SuppressFinalize(this);
|
|
}
|
|
}
|