Добавлена десериализация в остальные части
All checks were successful
Unit tests / test (push) Successful in 1m21s
All checks were successful
Unit tests / test (push) Successful in 1m21s
This commit is contained in:
parent
e2b2fed68f
commit
5350febaba
@ -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<Dictionary<Guid, object>> GetCurrentDictionary(IEnumerable<Guid> 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<Guid, object?> DeserializeResultToDict(IEnumerable<SetpointValueDto> data)
|
||||
//{
|
||||
// var dict = new Dictionary<Guid, object?>();
|
||||
|
||||
|
||||
// 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<IEnumerable<SetpointValueDto>> GetHistory(IEnumerable<Guid> 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<IEnumerable<SetpointLogDto>> 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<SetpointLogDto>? result)
|
||||
{
|
||||
foreach (var log in result)
|
||||
log.Value = DeserializeValue(log.Key, (JsonElement)log.Value);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user