Compare commits
2 Commits
feature-ma
...
master
Author | SHA1 | Date | |
---|---|---|---|
a5037b8967 | |||
27b9728912 |
@ -1,4 +1,4 @@
|
|||||||
using DD.Persistence.Models;
|
using DD.Persistence.Models;
|
||||||
using DD.Persistence.Models.Common;
|
using DD.Persistence.Models.Common;
|
||||||
|
|
||||||
namespace DD.Persistence.Client.Clients.Interfaces;
|
namespace DD.Persistence.Client.Clients.Interfaces;
|
||||||
@ -37,6 +37,18 @@ public interface ITimestampedValuesClient : IDisposable
|
|||||||
int take,
|
int take,
|
||||||
CancellationToken token);
|
CancellationToken token);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получить данные с фильтрацией для нескольких систем. Значение фильтра null - отключен
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="discriminatorId"></param>
|
||||||
|
/// <param name="geTimestamp"></param>
|
||||||
|
/// <param name="filterTree"></param>
|
||||||
|
/// <param name="columnNames">Фильтр свойств набора</param>
|
||||||
|
/// <param name="skip"></param>
|
||||||
|
/// <param name="take"></param>
|
||||||
|
/// <param name="token"></param>
|
||||||
|
Task<IEnumerable<T>> Get<T>(Guid discriminatorId, DateTimeOffset? geTimestamp, string? filterTree, IEnumerable<string>? columnNames, int skip, int take, CancellationToken token);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получить данные, начиная с заданной отметки времени
|
/// Получить данные, начиная с заданной отметки времени
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -85,6 +97,13 @@ public interface ITimestampedValuesClient : IDisposable
|
|||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
Task<DatesRangeDto?> GetDatesRange(Guid discriminatorId, CancellationToken token);
|
Task<DatesRangeDto?> GetDatesRange(Guid discriminatorId, CancellationToken token);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <param name="idDiscriminator"></param>
|
||||||
|
/// <param name="take"></param>
|
||||||
|
/// <param name="token"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<IEnumerable<T>> GetLast<T>(Guid idDiscriminator, int take, CancellationToken token);
|
||||||
}
|
}
|
@ -1,6 +0,0 @@
|
|||||||
using DD.Persistence.Client.Clients.Interfaces;
|
|
||||||
|
|
||||||
namespace DD.Persistence.Client.Clients.Mapping.Abstractions;
|
|
||||||
public interface ISetpointMappingClient : ISetpointClient
|
|
||||||
{
|
|
||||||
}
|
|
@ -1,33 +0,0 @@
|
|||||||
using DD.Persistence.Client.Clients.Interfaces;
|
|
||||||
|
|
||||||
namespace DD.Persistence.Client.Clients.Mapping.Abstractions;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public interface ITimestampedMappingClient : ITimestampedValuesClient
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Получить данные с фильтрацией для нескольких систем. Значение фильтра null - отключен
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="discriminatorId"></param>
|
|
||||||
/// <param name="geTimestamp"></param>
|
|
||||||
/// <param name="columnNames">Фильтр свойств набора</param>
|
|
||||||
/// <param name="filterTree"></param>
|
|
||||||
/// <param name="skip"></param>
|
|
||||||
/// <param name="take"></param>
|
|
||||||
/// <param name="token"></param>
|
|
||||||
Task<IEnumerable<T>> Get<T>(Guid discriminatorId, DateTimeOffset? geTimestamp, string? filterTree, IEnumerable<string>? columnNames, int skip, int take, CancellationToken token);
|
|
||||||
Task<IDictionary<Guid, object>> Gett(IEnumerable<Guid> discriminatorIds, string? filterTree, DateTimeOffset? timestampBegin, IEnumerable<string>? columnNames, int skip, int take, CancellationToken token);
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T"></typeparam>
|
|
||||||
/// <param name="idDiscriminator"></param>
|
|
||||||
/// <param name="take"></param>
|
|
||||||
/// <param name="token"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
Task<IEnumerable<T>> GetLast<T>(Guid idDiscriminator, int take, CancellationToken token);
|
|
||||||
}
|
|
@ -1,79 +0,0 @@
|
|||||||
using DD.Persistence.Client.Clients.Interfaces;
|
|
||||||
using DD.Persistence.Client.Clients.Mapping.Abstractions;
|
|
||||||
using DD.Persistence.Models;
|
|
||||||
using DD.Persistence.Models.Common;
|
|
||||||
using System.Text.Json;
|
|
||||||
|
|
||||||
namespace DD.Persistence.Client.Clients.Mapping.Clients;
|
|
||||||
internal class SetpointMappingClient(ISetpointClient setpointClient, Dictionary<Guid, Type> mappingConfigs) : ISetpointMappingClient
|
|
||||||
{
|
|
||||||
public async Task Add(Guid setpointKey, object newValue, CancellationToken token)
|
|
||||||
=> await setpointClient.Add(setpointKey, newValue, token);
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
setpointClient.Dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<IEnumerable<SetpointValueDto>> GetCurrent(IEnumerable<Guid> setpointKeys, CancellationToken token)
|
|
||||||
=> (await setpointClient.GetCurrent(setpointKeys, token))
|
|
||||||
.Select(x => new SetpointValueDto
|
|
||||||
{
|
|
||||||
Key = x.Key,
|
|
||||||
Value = DeserializeValue(x.Key, (JsonElement)x.Value)
|
|
||||||
});
|
|
||||||
|
|
||||||
public async Task<Dictionary<Guid, object>> GetCurrentDictionary(IEnumerable<Guid> setpointConfigs, CancellationToken token)
|
|
||||||
{
|
|
||||||
return (await setpointClient.GetCurrent(setpointConfigs, token))
|
|
||||||
.ToDictionary(x => x.Key, x => DeserializeValue(x.Key, (JsonElement)x.Value));
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<DatesRangeDto> GetDatesRangeAsync(CancellationToken token)
|
|
||||||
=> await setpointClient.GetDatesRangeAsync(token);
|
|
||||||
|
|
||||||
public async Task<IEnumerable<SetpointValueDto>> GetHistory(IEnumerable<Guid> setpointKeys, DateTimeOffset historyMoment, CancellationToken token)
|
|
||||||
{
|
|
||||||
var result = await setpointClient.GetHistory(setpointKeys, historyMoment, token);
|
|
||||||
|
|
||||||
foreach (var dto in result)
|
|
||||||
dto.Value = DeserializeValue(dto.Key, (JsonElement)dto.Value);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<Dictionary<Guid, IEnumerable<SetpointLogDto>>> GetLog(IEnumerable<Guid> setpointKeys, CancellationToken token)
|
|
||||||
{
|
|
||||||
var result = await setpointClient.GetLog(setpointKeys, token);
|
|
||||||
|
|
||||||
foreach (var item in result)
|
|
||||||
DeserializeList(result[item.Key]);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<IEnumerable<SetpointLogDto>> GetPart(DateTimeOffset dateBegin, int take, CancellationToken token)
|
|
||||||
{
|
|
||||||
var res = await setpointClient.GetPart(dateBegin, take, token);
|
|
||||||
|
|
||||||
DeserializeList(res);
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private object DeserializeValue(Guid key, JsonElement value)
|
|
||||||
{
|
|
||||||
if (mappingConfigs.TryGetValue(key, out var type))
|
|
||||||
return value.Deserialize(type)!;
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
private void DeserializeList(IEnumerable<SetpointLogDto>? result)
|
|
||||||
{
|
|
||||||
foreach (var log in result)
|
|
||||||
log.Value = DeserializeValue(log.Key, (JsonElement)log.Value);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,95 +0,0 @@
|
|||||||
using DD.Persistence.Client.Clients.Interfaces;
|
|
||||||
using DD.Persistence.Client.Clients.Mapping.Abstractions;
|
|
||||||
using DD.Persistence.Models;
|
|
||||||
using DD.Persistence.Models.Common;
|
|
||||||
using System.Collections.Concurrent;
|
|
||||||
using System.Reflection;
|
|
||||||
|
|
||||||
namespace DD.Persistence.Client.Clients.Mapping.Clients;
|
|
||||||
public class TimestampedMappingClient(ITimestampedValuesClient client, Dictionary<Guid, Type>? mappingConfigs) : ITimestampedMappingClient
|
|
||||||
{
|
|
||||||
/// <inheritdoc/>
|
|
||||||
private readonly ConcurrentDictionary<Guid, TimestampedSetMapperBase> mapperCache = new();
|
|
||||||
|
|
||||||
public async Task<int> AddRange(Guid discriminatorId, IEnumerable<TimestampedValuesDto> dtos, CancellationToken token)
|
|
||||||
=> await client.AddRange(discriminatorId, dtos, token);
|
|
||||||
|
|
||||||
public async Task<int> Count(Guid discriminatorId, CancellationToken token)
|
|
||||||
=> await client.Count(discriminatorId, token);
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
client.Dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc/>
|
|
||||||
public async Task<IEnumerable<T>> Get<T>(Guid discriminatorId, DateTimeOffset? geTimestamp, string? filterTree, IEnumerable<string>? columnNames, int skip, int take, CancellationToken token)
|
|
||||||
{
|
|
||||||
var data = await Get([discriminatorId], geTimestamp, filterTree, columnNames, skip, take, token);
|
|
||||||
var mapper = GetMapper<T>(discriminatorId);
|
|
||||||
|
|
||||||
return data.Select(mapper.DeserializeTimeStampedData);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc/>
|
|
||||||
public async Task<IEnumerable<T>> GetLast<T>(Guid idDiscriminator, int take, CancellationToken token)
|
|
||||||
{
|
|
||||||
var data = await GetLast(idDiscriminator, take, token);
|
|
||||||
var mapper = GetMapper<T>(idDiscriminator);
|
|
||||||
|
|
||||||
return data.Select(mapper.DeserializeTimeStampedData);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<IDictionary<Guid, object>> Gett(IEnumerable<Guid> discriminatorIds, string? filterTree, DateTimeOffset? timestampBegin, IEnumerable<string>? columnNames, int skip, int take, CancellationToken token)
|
|
||||||
{
|
|
||||||
var data = await client.Get(discriminatorIds, timestampBegin, filterTree, columnNames, skip, take, token);
|
|
||||||
|
|
||||||
// ToDo: рефакторинг
|
|
||||||
foreach (var discriminatorId in discriminatorIds)
|
|
||||||
{
|
|
||||||
if (mappingConfigs.TryGetValue(discriminatorId, out var type))
|
|
||||||
{
|
|
||||||
var genericType = typeof(TimestampedSetMapper<>).MakeGenericType(type);
|
|
||||||
|
|
||||||
var mapper =
|
|
||||||
typeof(TimestampedMappingClient)
|
|
||||||
.GetMethod(nameof(GetMapper))!
|
|
||||||
.MakeGenericMethod([type])
|
|
||||||
.Invoke(this, [discriminatorId]);
|
|
||||||
var mapperInstance = Activator.CreateInstance(genericType, mapper); // ToDo: возможно не нужно
|
|
||||||
|
|
||||||
var deserializeMethod = genericType
|
|
||||||
.GetMethod("DeserializeTimeStampedData")!;
|
|
||||||
|
|
||||||
var d = data.Select(e => deserializeMethod.Invoke(mapperInstance, [e]));
|
|
||||||
// ToDo: приводим к Dictionary
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Dictionary<Guid, object>();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc/>
|
|
||||||
private TimestampedSetMapper<T> GetMapper<T>(Guid idDiscriminator)
|
|
||||||
{
|
|
||||||
return (TimestampedSetMapper<T>)mapperCache.GetOrAdd(idDiscriminator, name => new TimestampedSetMapper<T>(idDiscriminator));
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<IEnumerable<TimestampedValuesDto>> Get(IEnumerable<Guid> discriminatorIds, DateTimeOffset? timestampBegin, string? filterTree, IEnumerable<string>? columnNames, int skip, int take, CancellationToken token)
|
|
||||||
=> await client.Get(discriminatorIds, timestampBegin, filterTree, columnNames, skip, take, token);
|
|
||||||
|
|
||||||
public async Task<DatesRangeDto?> GetDatesRange(Guid discriminatorId, CancellationToken token)
|
|
||||||
=> await client.GetDatesRange(discriminatorId, token);
|
|
||||||
|
|
||||||
public async Task<IEnumerable<TimestampedValuesDto>> GetFirst(Guid discriminatorId, int take, CancellationToken token)
|
|
||||||
=> await client.GetFirst(discriminatorId, take, token);
|
|
||||||
|
|
||||||
public async Task<IEnumerable<TimestampedValuesDto>> GetGtDate(Guid discriminatorId, DateTimeOffset timestampBegin, CancellationToken token)
|
|
||||||
=> await client.GetGtDate(discriminatorId, timestampBegin, token);
|
|
||||||
|
|
||||||
public async Task<IEnumerable<TimestampedValuesDto>> GetLast(Guid discriminatorId, int take, CancellationToken token)
|
|
||||||
=> await client.GetLast(discriminatorId, take, token);
|
|
||||||
|
|
||||||
public async Task<IEnumerable<TimestampedValuesDto>> GetResampledData(Guid discriminatorId, DateTimeOffset timestampBegin, double intervalSec = 600, int approxPointsCount = 1024, CancellationToken token = default)
|
|
||||||
=> await client.GetResampledData(discriminatorId, timestampBegin, intervalSec, approxPointsCount, token);
|
|
||||||
}
|
|
@ -3,6 +3,9 @@ using DD.Persistence.Client.Clients.Base;
|
|||||||
using DD.Persistence.Client.Clients.Interfaces;
|
using DD.Persistence.Client.Clients.Interfaces;
|
||||||
using DD.Persistence.Client.Clients.Interfaces.Refit;
|
using DD.Persistence.Client.Clients.Interfaces.Refit;
|
||||||
using DD.Persistence.Models;
|
using DD.Persistence.Models;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
using System.Globalization;
|
||||||
using DD.Persistence.Models.Common;
|
using DD.Persistence.Models.Common;
|
||||||
|
|
||||||
namespace DD.Persistence.Client.Clients;
|
namespace DD.Persistence.Client.Clients;
|
||||||
@ -10,12 +13,15 @@ namespace DD.Persistence.Client.Clients;
|
|||||||
public class SetpointClient : BaseClient, ISetpointClient
|
public class SetpointClient : BaseClient, ISetpointClient
|
||||||
{
|
{
|
||||||
private readonly IRefitSetpointClient refitSetpointClient;
|
private readonly IRefitSetpointClient refitSetpointClient;
|
||||||
|
private readonly ISetpointConfigStorage setpointConfigStorage;
|
||||||
|
|
||||||
public SetpointClient(
|
public SetpointClient(
|
||||||
IRefitClientFactory<IRefitSetpointClient> refitSetpointClientFactory,
|
IRefitClientFactory<IRefitSetpointClient> refitSetpointClientFactory,
|
||||||
|
ISetpointConfigStorage setpointConfigStorage,
|
||||||
ILogger<SetpointClient> logger) : base(logger)
|
ILogger<SetpointClient> logger) : base(logger)
|
||||||
{
|
{
|
||||||
this.refitSetpointClient = refitSetpointClientFactory.Create();
|
this.refitSetpointClient = refitSetpointClientFactory.Create();
|
||||||
|
this.setpointConfigStorage = setpointConfigStorage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<SetpointValueDto>> GetCurrent(IEnumerable<Guid> setpointKeys, CancellationToken token)
|
public async Task<IEnumerable<SetpointValueDto>> GetCurrent(IEnumerable<Guid> setpointKeys, CancellationToken token)
|
||||||
@ -25,7 +31,7 @@ public class SetpointClient : BaseClient, ISetpointClient
|
|||||||
|
|
||||||
return result!.Select(x => new SetpointValueDto {
|
return result!.Select(x => new SetpointValueDto {
|
||||||
Key = x.Key,
|
Key = x.Key,
|
||||||
Value = x.Value
|
Value = DeserializeValue(x.Key, x.Value)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,7 +43,7 @@ public class SetpointClient : BaseClient, ISetpointClient
|
|||||||
async () => await refitSetpointClient.GetCurrent(setpointConfigs, token), token);
|
async () => await refitSetpointClient.GetCurrent(setpointConfigs, token), token);
|
||||||
|
|
||||||
|
|
||||||
return result!.ToDictionary(x => x.Key,x => (object)x.Value);
|
return result!.ToDictionary(x => x.Key,x => DeserializeValue(x.Key,x.Value));
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<SetpointValueDto>> GetHistory(IEnumerable<Guid> setpointKeys, DateTimeOffset historyMoment, CancellationToken token)
|
public async Task<IEnumerable<SetpointValueDto>> GetHistory(IEnumerable<Guid> setpointKeys, DateTimeOffset historyMoment, CancellationToken token)
|
||||||
@ -45,6 +51,9 @@ public class SetpointClient : BaseClient, ISetpointClient
|
|||||||
var result = await ExecuteGetResponse(
|
var result = await ExecuteGetResponse(
|
||||||
async () => await refitSetpointClient.GetHistory(setpointKeys, historyMoment, token), token);
|
async () => await refitSetpointClient.GetHistory(setpointKeys, historyMoment, token), token);
|
||||||
|
|
||||||
|
foreach(var dto in result)
|
||||||
|
dto.Value = DeserializeValue(dto.Key, (JsonElement)dto.Value);
|
||||||
|
|
||||||
|
|
||||||
return result!;
|
return result!;
|
||||||
}
|
}
|
||||||
@ -54,6 +63,9 @@ public class SetpointClient : BaseClient, ISetpointClient
|
|||||||
var result = await ExecuteGetResponse(
|
var result = await ExecuteGetResponse(
|
||||||
async () => await refitSetpointClient.GetLog(setpointKeys, token), token);
|
async () => await refitSetpointClient.GetLog(setpointKeys, token), token);
|
||||||
|
|
||||||
|
foreach(var item in result)
|
||||||
|
DeserializeList(result[item.Key]);
|
||||||
|
|
||||||
return result!;
|
return result!;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,6 +82,8 @@ public class SetpointClient : BaseClient, ISetpointClient
|
|||||||
var result = await ExecuteGetResponse(
|
var result = await ExecuteGetResponse(
|
||||||
async () => await refitSetpointClient.GetPart(dateBegin, take, token), token);
|
async () => await refitSetpointClient.GetPart(dateBegin, take, token), token);
|
||||||
|
|
||||||
|
DeserializeList(result);
|
||||||
|
|
||||||
return result!;
|
return result!;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,4 +101,21 @@ public class SetpointClient : BaseClient, ISetpointClient
|
|||||||
|
|
||||||
GC.SuppressFinalize(this);
|
GC.SuppressFinalize(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private object DeserializeValue(Guid key, JsonElement value)
|
||||||
|
{
|
||||||
|
if (setpointConfigStorage.TryGetType(key, out var type))
|
||||||
|
return value.Deserialize(type)!;
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
private void DeserializeList(IEnumerable<SetpointLogDto>? result)
|
||||||
|
{
|
||||||
|
foreach (var log in result)
|
||||||
|
log.Value = DeserializeValue(log.Key, (JsonElement)log.Value);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using DD.Persistence.Client.Clients.Base;
|
using DD.Persistence.Client.Clients.Base;
|
||||||
using DD.Persistence.Client.Clients.Interfaces;
|
using DD.Persistence.Client.Clients.Interfaces;
|
||||||
using DD.Persistence.Client.Clients.Interfaces.Refit;
|
using DD.Persistence.Client.Clients.Interfaces.Refit;
|
||||||
using DD.Persistence.Models;
|
using DD.Persistence.Models;
|
||||||
@ -19,7 +19,8 @@ public class TimestampedValuesClient : BaseClient, ITimestampedValuesClient
|
|||||||
this.refitTimestampedSetClient = refitTimestampedSetClientFactory.Create();
|
this.refitTimestampedSetClient = refitTimestampedSetClientFactory.Create();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
private readonly ConcurrentDictionary<Guid, TimestampedSetMapperBase> mapperCache = new();
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public async Task<int> AddRange(Guid discriminatorId, IEnumerable<TimestampedValuesDto> sets, CancellationToken token)
|
public async Task<int> AddRange(Guid discriminatorId, IEnumerable<TimestampedValuesDto> sets, CancellationToken token)
|
||||||
@ -38,6 +39,15 @@ public class TimestampedValuesClient : BaseClient, ITimestampedValuesClient
|
|||||||
return result!;
|
return result!;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public async Task<IEnumerable<T>> Get<T>(Guid discriminatorId, DateTimeOffset? geTimestamp, string? filterTree, IEnumerable<string>? columnNames, int skip, int take, CancellationToken token)
|
||||||
|
{
|
||||||
|
var data = await Get([discriminatorId], geTimestamp, filterTree, columnNames, skip, take, token);
|
||||||
|
var mapper = GetMapper<T>(discriminatorId);
|
||||||
|
|
||||||
|
return data.Select(mapper.DeserializeTimeStampedData);
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public async Task<IEnumerable<TimestampedValuesDto>> GetGtDate(Guid discriminatorId, DateTimeOffset timestampBegin, CancellationToken token)
|
public async Task<IEnumerable<TimestampedValuesDto>> GetGtDate(Guid discriminatorId, DateTimeOffset timestampBegin, CancellationToken token)
|
||||||
{
|
{
|
||||||
@ -92,7 +102,20 @@ public class TimestampedValuesClient : BaseClient, ITimestampedValuesClient
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public async Task<IEnumerable<T>> GetLast<T>(Guid idDiscriminator, int take, CancellationToken token)
|
||||||
|
{
|
||||||
|
var data = await GetLast(idDiscriminator, take, token);
|
||||||
|
var mapper = GetMapper<T>(idDiscriminator);
|
||||||
|
|
||||||
|
return data.Select(mapper.DeserializeTimeStampedData);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
private TimestampedSetMapper<T> GetMapper<T>(Guid idDiscriminator)
|
||||||
|
{
|
||||||
|
return (TimestampedSetMapper<T>)mapperCache.GetOrAdd(idDiscriminator, name => new TimestampedSetMapper<T>(idDiscriminator));
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
using DD.Persistence.Client.Clients;
|
using DD.Persistence.Client.Clients;
|
||||||
using DD.Persistence.Client.Clients.Interfaces;
|
using DD.Persistence.Client.Clients.Interfaces;
|
||||||
using DD.Persistence.Client.Clients.Mapping.Abstractions;
|
|
||||||
using DD.Persistence.Client.Clients.Mapping.Clients;
|
|
||||||
using DD.Persistence.Models;
|
using DD.Persistence.Models;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
@ -27,21 +25,9 @@ public static class DependencyInjection
|
|||||||
services.AddTransient<ITimestampedValuesClient, TimestampedValuesClient>();
|
services.AddTransient<ITimestampedValuesClient, TimestampedValuesClient>();
|
||||||
services.AddTransient<IWitsDataClient, WitsDataClient>();
|
services.AddTransient<IWitsDataClient, WitsDataClient>();
|
||||||
|
|
||||||
return services;
|
services.AddSingleton<ISetpointConfigStorage, SetpointConfigStorage>(provider =>
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static IServiceCollection AddPersistenceMapping(this IServiceCollection services, Dictionary<Guid, Type>? mappingConfigs)
|
|
||||||
{
|
{
|
||||||
services.AddTransient<ISetpointMappingClient, SetpointMappingClient>(provider =>
|
return new SetpointConfigStorage(setpointTypeConfigs);
|
||||||
{
|
|
||||||
var client = provider.GetRequiredService<ISetpointClient>();
|
|
||||||
return new SetpointMappingClient(client, mappingConfigs);
|
|
||||||
});
|
|
||||||
services.AddTransient<ITimestampedMappingClient, TimestampedMappingClient>(provider =>
|
|
||||||
{
|
|
||||||
var client = provider.GetRequiredService<ITimestampedValuesClient>();
|
|
||||||
return new TimestampedMappingClient(client, mappingConfigs);
|
|
||||||
});
|
});
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
11
DD.Persistence.Client/ISetpointConfigStorage.cs
Normal file
11
DD.Persistence.Client/ISetpointConfigStorage.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DD.Persistence.Client;
|
||||||
|
public interface ISetpointConfigStorage
|
||||||
|
{
|
||||||
|
bool TryGetType(Guid id, out Type type);
|
||||||
|
}
|
20
DD.Persistence.Client/SetpointConfigStorage.cs
Normal file
20
DD.Persistence.Client/SetpointConfigStorage.cs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
namespace DD.Persistence.Client;
|
||||||
|
internal class SetpointConfigStorage : ISetpointConfigStorage
|
||||||
|
{
|
||||||
|
private readonly Dictionary<Guid, Type> setpointTypeConfigs;
|
||||||
|
|
||||||
|
public SetpointConfigStorage(Dictionary<Guid, Type>? setpointTypeConfigs)
|
||||||
|
{
|
||||||
|
this.setpointTypeConfigs = setpointTypeConfigs?? new Dictionary<Guid, Type>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool TryGetType(Guid id, out Type type)
|
||||||
|
{
|
||||||
|
return setpointTypeConfigs.TryGetValue(id, out type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddOrReplace(Guid id, Type type)
|
||||||
|
{
|
||||||
|
setpointTypeConfigs[id] = type;
|
||||||
|
}
|
||||||
|
}
|
@ -4,7 +4,7 @@ using System.Reflection;
|
|||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
|
||||||
namespace DD.Persistence.Client.Clients.Mapping;
|
namespace DD.Persistence.Client;
|
||||||
|
|
||||||
internal abstract class TimestampedSetMapperBase
|
internal abstract class TimestampedSetMapperBase
|
||||||
{
|
{
|
@ -12,7 +12,7 @@ public class DataSourceSystemRepository : IDataSourceSystemRepository
|
|||||||
{
|
{
|
||||||
this.db = db;
|
this.db = db;
|
||||||
}
|
}
|
||||||
protected virtual IQueryable<DataSourceSystem> GetQueryReadOnly() => db.Set<DataSourceSystem>();
|
protected IQueryable<DataSourceSystem> GetQueryReadOnly() => db.Set<DataSourceSystem>();
|
||||||
|
|
||||||
public virtual async Task Add(DataSourceSystemDto dataSourceSystemDto, CancellationToken token)
|
public virtual async Task Add(DataSourceSystemDto dataSourceSystemDto, CancellationToken token)
|
||||||
{
|
{
|
||||||
|
@ -15,7 +15,7 @@ public class ParameterRepository : IParameterRepository
|
|||||||
this.db = db;
|
this.db = db;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual IQueryable<ParameterData> GetQueryReadOnly() => db.Set<ParameterData>();
|
protected IQueryable<ParameterData> GetQueryReadOnly() => db.Set<ParameterData>();
|
||||||
|
|
||||||
public async Task<DatesRangeDto> GetDatesRangeAsync(Guid idDiscriminator, CancellationToken token)
|
public async Task<DatesRangeDto> GetDatesRangeAsync(Guid idDiscriminator, CancellationToken token)
|
||||||
{
|
{
|
||||||
|
@ -12,7 +12,7 @@ public class SchemePropertyRepository : ISchemePropertyRepository
|
|||||||
{
|
{
|
||||||
this.db = db;
|
this.db = db;
|
||||||
}
|
}
|
||||||
protected virtual IQueryable<SchemeProperty> GetQueryReadOnly() => db.Set<SchemeProperty>();
|
protected IQueryable<SchemeProperty> GetQueryReadOnly() => db.Set<SchemeProperty>();
|
||||||
|
|
||||||
public virtual async Task AddRange(DataSchemeDto dataSchemeDto, CancellationToken token)
|
public virtual async Task AddRange(DataSchemeDto dataSchemeDto, CancellationToken token)
|
||||||
{
|
{
|
||||||
|
@ -16,7 +16,7 @@ namespace DD.Persistence.Database.Postgres.Repositories
|
|||||||
this.db = db;
|
this.db = db;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual IQueryable<Setpoint> GetQueryReadOnly() => db.Set<Setpoint>();
|
protected IQueryable<Setpoint> GetQueryReadOnly() => db.Set<Setpoint>();
|
||||||
|
|
||||||
public async Task<IEnumerable<SetpointValueDto>> GetCurrent(
|
public async Task<IEnumerable<SetpointValueDto>> GetCurrent(
|
||||||
IEnumerable<Guid> setpointKeys,
|
IEnumerable<Guid> setpointKeys,
|
||||||
|
@ -20,7 +20,7 @@ namespace DD.Persistence.Database.Postgres.Repositories
|
|||||||
this.sourceSystemRepository = sourceSystemRepository;
|
this.sourceSystemRepository = sourceSystemRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual IQueryable<TechMessage> GetQueryReadOnly() => db.Set<TechMessage>()
|
protected IQueryable<TechMessage> GetQueryReadOnly() => db.Set<TechMessage>()
|
||||||
.Include(e => e.System);
|
.Include(e => e.System);
|
||||||
|
|
||||||
public async Task<PaginationContainer<TechMessageDto>> GetPage(PaginationRequest request, CancellationToken token)
|
public async Task<PaginationContainer<TechMessageDto>> GetPage(PaginationRequest request, CancellationToken token)
|
||||||
|
@ -17,9 +17,9 @@ public class TimestampedValuesRepository : ITimestampedValuesRepository
|
|||||||
this.schemePropertyRepository = schemePropertyRepository;
|
this.schemePropertyRepository = schemePropertyRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual IQueryable<TimestampedValues> GetQueryReadOnly() => db.Set<TimestampedValues>();
|
protected IQueryable<TimestampedValues> GetQueryReadOnly() => db.Set<TimestampedValues>();
|
||||||
|
|
||||||
public async virtual Task<int> AddRange(Guid discriminatorId, IEnumerable<TimestampedValuesDto> dtos, CancellationToken token)
|
public async Task<int> AddRange(Guid discriminatorId, IEnumerable<TimestampedValuesDto> dtos, CancellationToken token)
|
||||||
{
|
{
|
||||||
var timestampedValuesEntities = dtos.Select(dto => new TimestampedValues()
|
var timestampedValuesEntities = dtos.Select(dto => new TimestampedValues()
|
||||||
{
|
{
|
||||||
@ -35,7 +35,7 @@ public class TimestampedValuesRepository : ITimestampedValuesRepository
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async virtual Task<IDictionary<Guid, IEnumerable<(DateTimeOffset Timestamp, object[] Values)>>> Get(IEnumerable<Guid> discriminatorIds,
|
public async Task<IDictionary<Guid, IEnumerable<(DateTimeOffset Timestamp, object[] Values)>>> Get(IEnumerable<Guid> discriminatorIds,
|
||||||
DateTimeOffset? geTimestamp,
|
DateTimeOffset? geTimestamp,
|
||||||
TNode? filterTree,
|
TNode? filterTree,
|
||||||
IEnumerable<string>? columnNames,
|
IEnumerable<string>? columnNames,
|
||||||
@ -76,7 +76,7 @@ public class TimestampedValuesRepository : ITimestampedValuesRepository
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async virtual Task<IEnumerable<(DateTimeOffset Timestamp, object[] Values)>> GetFirst(Guid discriminatorId, int takeCount, CancellationToken token)
|
public async Task<IEnumerable<(DateTimeOffset Timestamp, object[] Values)>> GetFirst(Guid discriminatorId, int takeCount, CancellationToken token)
|
||||||
{
|
{
|
||||||
var query = GetQueryReadOnly()
|
var query = GetQueryReadOnly()
|
||||||
.OrderBy(e => e.Timestamp)
|
.OrderBy(e => e.Timestamp)
|
||||||
@ -91,7 +91,7 @@ public class TimestampedValuesRepository : ITimestampedValuesRepository
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async virtual Task<IEnumerable<(DateTimeOffset Timestamp, object[] Values)>> GetLast(Guid discriminatorId, int takeCount, CancellationToken token)
|
public async Task<IEnumerable<(DateTimeOffset Timestamp, object[] Values)>> GetLast(Guid discriminatorId, int takeCount, CancellationToken token)
|
||||||
{
|
{
|
||||||
var query = GetQueryReadOnly()
|
var query = GetQueryReadOnly()
|
||||||
.OrderByDescending(e => e.Timestamp)
|
.OrderByDescending(e => e.Timestamp)
|
||||||
@ -107,7 +107,7 @@ public class TimestampedValuesRepository : ITimestampedValuesRepository
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ToDo: прореживание должно осуществляться до материализации
|
// ToDo: прореживание должно осуществляться до материализации
|
||||||
public async virtual Task<IEnumerable<(DateTimeOffset Timestamp, object[] Values)>> GetResampledData(
|
public async Task<IEnumerable<(DateTimeOffset Timestamp, object[] Values)>> GetResampledData(
|
||||||
Guid discriminatorId,
|
Guid discriminatorId,
|
||||||
DateTimeOffset dateBegin,
|
DateTimeOffset dateBegin,
|
||||||
double intervalSec = 600d,
|
double intervalSec = 600d,
|
||||||
@ -128,7 +128,7 @@ public class TimestampedValuesRepository : ITimestampedValuesRepository
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async virtual Task<IEnumerable<(DateTimeOffset Timestamp, object[] Values)>> GetGtDate(Guid discriminatorId, DateTimeOffset gtTimestamp, CancellationToken token)
|
public async Task<IEnumerable<(DateTimeOffset Timestamp, object[] Values)>> GetGtDate(Guid discriminatorId, DateTimeOffset gtTimestamp, CancellationToken token)
|
||||||
{
|
{
|
||||||
var gtTimestampUtc = gtTimestamp.ToUniversalTime();
|
var gtTimestampUtc = gtTimestamp.ToUniversalTime();
|
||||||
var query = GetQueryReadOnly()
|
var query = GetQueryReadOnly()
|
||||||
@ -143,7 +143,7 @@ public class TimestampedValuesRepository : ITimestampedValuesRepository
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async virtual Task<DatesRangeDto?> GetDatesRange(Guid discriminatorId, CancellationToken token)
|
public async Task<DatesRangeDto?> GetDatesRange(Guid discriminatorId, CancellationToken token)
|
||||||
{
|
{
|
||||||
var query = GetQueryReadOnly()
|
var query = GetQueryReadOnly()
|
||||||
.GroupBy(entity => entity.DiscriminatorId)
|
.GroupBy(entity => entity.DiscriminatorId)
|
||||||
@ -168,7 +168,7 @@ public class TimestampedValuesRepository : ITimestampedValuesRepository
|
|||||||
return dto;
|
return dto;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async virtual Task<int> Count(Guid discriminatorId, CancellationToken token)
|
public async Task<int> Count(Guid discriminatorId, CancellationToken token)
|
||||||
{
|
{
|
||||||
var query = GetQueryReadOnly()
|
var query = GetQueryReadOnly()
|
||||||
.Where(e => e.DiscriminatorId == discriminatorId);
|
.Where(e => e.DiscriminatorId == discriminatorId);
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
using DD.Persistence.Client;
|
using DD.Persistence.Client;
|
||||||
|
using DD.Persistence.Client.Clients;
|
||||||
using DD.Persistence.Client.Clients.Interfaces;
|
using DD.Persistence.Client.Clients.Interfaces;
|
||||||
using DD.Persistence.Client.Clients.Interfaces.Refit;
|
using DD.Persistence.Client.Clients.Interfaces.Refit;
|
||||||
using DD.Persistence.Client.Clients.Mapping.Clients;
|
|
||||||
using DD.Persistence.Database.Entity;
|
using DD.Persistence.Database.Entity;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
@ -12,14 +13,17 @@ namespace DD.Persistence.IntegrationTests.Controllers
|
|||||||
public class SetpointControllerTest : BaseIntegrationTest
|
public class SetpointControllerTest : BaseIntegrationTest
|
||||||
{
|
{
|
||||||
private readonly ISetpointClient setpointClient;
|
private readonly ISetpointClient setpointClient;
|
||||||
|
private readonly SetpointConfigStorage configStorage;
|
||||||
public SetpointControllerTest(WebAppFactoryFixture factory) : base(factory)
|
public SetpointControllerTest(WebAppFactoryFixture factory) : base(factory)
|
||||||
{
|
{
|
||||||
var refitClientFactory = scope.ServiceProvider
|
var refitClientFactory = scope.ServiceProvider
|
||||||
.GetRequiredService<IRefitClientFactory<IRefitSetpointClient>>();
|
.GetRequiredService<IRefitClientFactory<IRefitSetpointClient>>();
|
||||||
|
var logger = scope.ServiceProvider.GetRequiredService<ILogger<SetpointClient>>();
|
||||||
|
|
||||||
setpointClient = scope.ServiceProvider
|
setpointClient = scope.ServiceProvider
|
||||||
.GetRequiredService<ISetpointClient>();
|
.GetRequiredService<ISetpointClient>();
|
||||||
|
|
||||||
|
configStorage = (SetpointConfigStorage)scope.ServiceProvider.GetRequiredService<ISetpointConfigStorage>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -28,16 +32,12 @@ namespace DD.Persistence.IntegrationTests.Controllers
|
|||||||
{
|
{
|
||||||
var id = Guid.Parse("e0fcad22-1761-476e-a729-a3c59d51ba41");
|
var id = Guid.Parse("e0fcad22-1761-476e-a729-a3c59d51ba41");
|
||||||
|
|
||||||
var config = new Dictionary<Guid, Type>();
|
configStorage.AddOrReplace(id, typeof(float));
|
||||||
config[id] = typeof(float);
|
|
||||||
|
|
||||||
var setpointMapper = new SetpointMappingClient(setpointClient, config);
|
|
||||||
|
|
||||||
|
|
||||||
await setpointClient.Add(id, 48.3f, CancellationToken.None);
|
await setpointClient.Add(id, 48.3f, CancellationToken.None);
|
||||||
|
|
||||||
//act
|
//act
|
||||||
var response = await setpointMapper.GetCurrent([id], CancellationToken.None);
|
var response = await setpointClient.GetCurrent([id], CancellationToken.None);
|
||||||
|
|
||||||
//assert
|
//assert
|
||||||
Assert.NotNull(response);
|
Assert.NotNull(response);
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\DD.Persistence.Client\DD.Persistence.Client.csproj" />
|
|
||||||
<ProjectReference Include="..\DD.Persistence.Database.Postgres\DD.Persistence.Database.Postgres.csproj" />
|
<ProjectReference Include="..\DD.Persistence.Database.Postgres\DD.Persistence.Database.Postgres.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
@ -1,40 +0,0 @@
|
|||||||
using DD.Persistence.Client.Clients.Interfaces;
|
|
||||||
using DD.Persistence.Client.Clients.Mapping.Abstractions;
|
|
||||||
using DD.Persistence.Client.Clients.Mapping.Clients;
|
|
||||||
using DD.Persistence.Repositories;
|
|
||||||
using DD.Persistence.Services.Interfaces;
|
|
||||||
using NSubstitute;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace DD.Persistence.Test;
|
|
||||||
public class MappingClientsTest
|
|
||||||
{
|
|
||||||
private readonly ITimestampedValuesClient timestampedValuesClient = Substitute.For<ITimestampedValuesClient>();
|
|
||||||
private readonly TimestampedMappingClient timestampedMappingClient;
|
|
||||||
public record TestDto
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
public string? Value { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
private readonly Dictionary<Guid, Type> mappingConfigs = new Dictionary<Guid, Type>()
|
|
||||||
{
|
|
||||||
{ Guid.NewGuid(), typeof(TestDto) }
|
|
||||||
};
|
|
||||||
|
|
||||||
public MappingClientsTest()
|
|
||||||
{
|
|
||||||
timestampedMappingClient = new TimestampedMappingClient(timestampedValuesClient, mappingConfigs);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public async void Test()
|
|
||||||
{
|
|
||||||
var discriminatorIds = mappingConfigs.Keys;
|
|
||||||
var result = await timestampedMappingClient.Gett(discriminatorIds, null, null, null, 0, 1, CancellationToken.None);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user