diff --git a/DD.Persistence.Client/Clients/Mapping/Abstractions/ITimestampedMappingClient.cs b/DD.Persistence.Client/Clients/Mapping/Abstractions/ITimestampedMappingClient.cs
index 29908ff..6be0e58 100644
--- a/DD.Persistence.Client/Clients/Mapping/Abstractions/ITimestampedMappingClient.cs
+++ b/DD.Persistence.Client/Clients/Mapping/Abstractions/ITimestampedMappingClient.cs
@@ -3,12 +3,12 @@
namespace DD.Persistence.Client.Clients.Mapping.Abstractions;
///
-///
+/// Маппинг - обертка для клиента по работе с данными
///
public interface ITimestampedMappingClient : ITimestampedValuesClient
{
///
- /// Получить данные с фильтрацией для нескольких систем. Значение фильтра null - отключен
+ /// Получить данные с преобразованием к заданному типу
///
///
///
@@ -17,17 +17,29 @@ public interface ITimestampedMappingClient : ITimestampedValuesClient
///
///
///
- Task> Get(Guid discriminatorId, DateTimeOffset? geTimestamp, string? filterTree, IEnumerable? columnNames, int skip, int take, CancellationToken token);
- Task> Gett(IEnumerable discriminatorIds, string? filterTree, DateTimeOffset? timestampBegin, IEnumerable? columnNames, int skip, int take, CancellationToken token);
+ Task> GetMapped(Guid discriminatorId, DateTimeOffset? geTimestamp, string? filterTree, IEnumerable? columnNames, int skip, int take, CancellationToken token);
+
+ ///
+ /// Получить набор данных, преобразованных к соответствующим типам из заданного конфига
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task>> GetMultiMapped(IEnumerable discriminatorIds, DateTimeOffset? timestampBegin, string? filterTree, IEnumerable? columnNames, int skip, int take, CancellationToken token);
///
- ///
+ /// Получить данные с конца с преобразованием к заданному типу
///
///
///
///
///
///
- Task> GetLast(Guid idDiscriminator, int take, CancellationToken token);
+ Task> GetLastMapped(Guid idDiscriminator, int take, CancellationToken token);
}
diff --git a/DD.Persistence.Client/Clients/Mapping/Clients/SetpointMappingClient.cs b/DD.Persistence.Client/Clients/Mapping/Clients/SetpointMappingClient.cs
index fed7187..010d2c0 100644
--- a/DD.Persistence.Client/Clients/Mapping/Clients/SetpointMappingClient.cs
+++ b/DD.Persistence.Client/Clients/Mapping/Clients/SetpointMappingClient.cs
@@ -5,16 +5,11 @@ using DD.Persistence.Models.Common;
using System.Text.Json;
namespace DD.Persistence.Client.Clients.Mapping.Clients;
-internal class SetpointMappingClient(ISetpointClient setpointClient, Dictionary mappingConfigs) : ISetpointMappingClient
+
+///
+public class SetpointMappingClient(ISetpointClient setpointClient, Dictionary 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> GetCurrent(IEnumerable setpointKeys, CancellationToken token)
=> (await setpointClient.GetCurrent(setpointKeys, token))
.Select(x => new SetpointValueDto
@@ -23,15 +18,16 @@ internal class SetpointMappingClient(ISetpointClient setpointClient, Dictionary<
Value = DeserializeValue(x.Key, (JsonElement)x.Value)
});
+ ///
public async Task> GetCurrentDictionary(IEnumerable setpointConfigs, CancellationToken token)
{
- return (await setpointClient.GetCurrent(setpointConfigs, token))
+ var result = (await setpointClient.GetCurrent(setpointConfigs, token))
.ToDictionary(x => x.Key, x => DeserializeValue(x.Key, (JsonElement)x.Value));
+
+ return result;
}
- public async Task GetDatesRangeAsync(CancellationToken token)
- => await setpointClient.GetDatesRangeAsync(token);
-
+ ///
public async Task> GetHistory(IEnumerable setpointKeys, DateTimeOffset historyMoment, CancellationToken token)
{
var result = await setpointClient.GetHistory(setpointKeys, historyMoment, token);
@@ -42,6 +38,7 @@ internal class SetpointMappingClient(ISetpointClient setpointClient, Dictionary<
return result;
}
+ ///
public async Task>> GetLog(IEnumerable setpointKeys, CancellationToken token)
{
var result = await setpointClient.GetLog(setpointKeys, token);
@@ -52,6 +49,7 @@ internal class SetpointMappingClient(ISetpointClient setpointClient, Dictionary<
return result;
}
+ ///
public async Task> GetPart(DateTimeOffset dateBegin, int take, CancellationToken token)
{
var res = await setpointClient.GetPart(dateBegin, take, token);
@@ -61,7 +59,19 @@ internal class SetpointMappingClient(ISetpointClient setpointClient, Dictionary<
return res;
}
+ ///
+ public async Task Add(Guid setpointKey, object newValue, CancellationToken token)
+ => await setpointClient.Add(setpointKey, newValue, token);
+ ///
+ public async Task GetDatesRangeAsync(CancellationToken token)
+ => await setpointClient.GetDatesRangeAsync(token);
+
+ ///
+ public void Dispose()
+ {
+ setpointClient.Dispose();
+ }
private object DeserializeValue(Guid key, JsonElement value)
{
@@ -72,8 +82,10 @@ internal class SetpointMappingClient(ISetpointClient setpointClient, Dictionary<
}
private void DeserializeList(IEnumerable? result)
{
+ if (result is null)
+ return;
+
foreach (var log in result)
log.Value = DeserializeValue(log.Key, (JsonElement)log.Value);
-
}
}
diff --git a/DD.Persistence.Client/Clients/Mapping/Clients/TimestampedMappingClient.cs b/DD.Persistence.Client/Clients/Mapping/Clients/TimestampedMappingClient.cs
index d9ada9c..4a7a87b 100644
--- a/DD.Persistence.Client/Clients/Mapping/Clients/TimestampedMappingClient.cs
+++ b/DD.Persistence.Client/Clients/Mapping/Clients/TimestampedMappingClient.cs
@@ -3,93 +3,123 @@ 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? mappingConfigs) : ITimestampedMappingClient
{
- ///
- private readonly ConcurrentDictionary mapperCache = new();
+ private readonly ConcurrentDictionary mapperCache = new();
+ ///
+ public async Task> GetMapped(Guid discriminatorId, DateTimeOffset? geTimestamp,
+ string? filterTree, IEnumerable? columnNames, int skip, int take, CancellationToken token)
+ {
+ var data = await Get([discriminatorId], geTimestamp, filterTree, columnNames, skip, take, token);
+ var mapper = GetMapper(discriminatorId);
+
+ var mappedDtos = data.Select(mapper.DeserializeTimeStampedData).OfType();
+
+ return mappedDtos;
+ }
+
+ ///
+ public async Task> GetLastMapped(Guid idDiscriminator, int take, CancellationToken token)
+ {
+ var data = await GetLast(idDiscriminator, take, token);
+ var mapper = GetMapper(idDiscriminator);
+
+ var mappedDtos = data.Select(mapper.DeserializeTimeStampedData).OfType();
+
+ return mappedDtos;
+ }
+
+ ///
+ public async Task>> GetMultiMapped(IEnumerable discriminatorIds, DateTimeOffset? geTimestamp,
+ string? filterTree, IEnumerable? columnNames, int skip, int take, CancellationToken token)
+ {
+ var data = await client.Get(discriminatorIds, geTimestamp, filterTree, columnNames, skip, take, token);
+
+ var result = discriminatorIds
+ .ToDictionary(discriminatorId => discriminatorId, discriminatorId =>
+ {
+ if (mappingConfigs is null)
+ throw new ArgumentNullException(nameof(mappingConfigs));
+
+ if (!mappingConfigs.TryGetValue(discriminatorId, out var type))
+ throw new InvalidCastException();
+
+ var mapper = GetMapper(discriminatorId, type);
+
+ var mappedDtos = data
+ .Where(e => e.DiscriminatorId == discriminatorId)
+ .Select(mapper.DeserializeTimeStampedData);
+
+ return mappedDtos;
+ });
+
+ //var genericMapperType = typeof(TimestampedSetMapper<>).MakeGenericType(type);
+
+ //var ttype = typeof(TimestampedSetMapper