From 5350febaba84122e604559a8f32b77285c3c6100 Mon Sep 17 00:00:00 2001 From: Alex Shibalkin Date: Mon, 20 Jan 2025 10:29:30 +0500 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=B4=D0=B5=D1=81=D0=B5=D1=80=D0=B8=D0=B0=D0=BB?= =?UTF-8?q?=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20=D0=B2=20=D0=BE=D1=81?= =?UTF-8?q?=D1=82=D0=B0=D0=BB=D1=8C=D0=BD=D1=8B=D0=B5=20=D1=87=D0=B0=D1=81?= =?UTF-8?q?=D1=82=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Clients/SetpointClient.cs | 69 +++++++++---------- 1 file changed, 34 insertions(+), 35 deletions(-) diff --git a/DD.Persistence.Client/Clients/SetpointClient.cs b/DD.Persistence.Client/Clients/SetpointClient.cs index 3078d9d..0e8df6a 100644 --- a/DD.Persistence.Client/Clients/SetpointClient.cs +++ b/DD.Persistence.Client/Clients/SetpointClient.cs @@ -34,13 +34,7 @@ public class SetpointClient : BaseClient, ISetpointClient }); } - private object DeserializeValue(Guid key, JsonElement value) - { - if (setpointConfigStorage.TryGetType(key, out var type)) - return value.Deserialize(type)!; - - return value; - } + public async Task> GetCurrentDictionary(IEnumerable setpointConfigs, CancellationToken token) { @@ -51,32 +45,15 @@ public class SetpointClient : BaseClient, ISetpointClient return result!.ToDictionary(x => x.Key,x => DeserializeValue(x.Key,x.Value)); } - - //private Dictionary DeserializeResultToDict(IEnumerable data) - //{ - // var dict = new Dictionary(); - - - // foreach (var valueDto in data) - // { - // if (valueDto.Value is not null && - // valueDto.Value is JsonElement element && - // setpointConfigStorage.TryGetType(valueDto.Key, out var type) && - // type is not null) - - // dict[valueDto.Key] = element.Deserialize(type) ?? valueDto.Value; - // else - // dict[valueDto.Key] = valueDto.Value; - // } - - // return dict; - //} - public async Task> GetHistory(IEnumerable setpointKeys, DateTimeOffset historyMoment, CancellationToken token) { var result = await ExecuteGetResponse( async () => await refitSetpointClient.GetHistory(setpointKeys, historyMoment, token), token); + foreach(var dto in result) + dto.Value = DeserializeValue(dto.Key, (JsonElement)dto.Value); + + return result!; } @@ -85,6 +62,9 @@ public class SetpointClient : BaseClient, ISetpointClient var result = await ExecuteGetResponse( async () => await refitSetpointClient.GetLog(setpointKeys, token), token); + foreach(var item in result) + DeserializeList(result[item.Key]); + return result!; } @@ -97,14 +77,18 @@ public class SetpointClient : BaseClient, ISetpointClient } public async Task> GetPart(DateTimeOffset dateBegin, int take, CancellationToken token) - { - var result = await ExecuteGetResponse( - async () => await refitSetpointClient.GetPart(dateBegin, take, token), token); + { + var result = await ExecuteGetResponse( + async () => await refitSetpointClient.GetPart(dateBegin, take, token), token); - return result!; - } + DeserializeList(result); - public async Task Add(Guid setpointKey, object newValue, CancellationToken token) + return result!; + } + + + + public async Task Add(Guid setpointKey, object newValue, CancellationToken token) { await ExecutePostResponse( async () => await refitSetpointClient.Add(setpointKey, newValue, token), token); @@ -117,5 +101,20 @@ public class SetpointClient : BaseClient, ISetpointClient 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? result) + { + foreach (var log in result) + log.Value = DeserializeValue(log.Key, (JsonElement)log.Value); + + } + + }