2022-03-04 18:59:44 +00:00
|
|
|
using System.Text.Json;
|
2022-12-21 18:36:40 +00:00
|
|
|
using Elsa.ProtoActor.Protos;
|
2023-06-28 16:15:32 +00:00
|
|
|
using Elsa.Workflows.Core.Serialization.Converters;
|
2022-03-04 18:59:44 +00:00
|
|
|
|
2022-05-26 10:47:31 +00:00
|
|
|
namespace Elsa.ProtoActor.Extensions;
|
2022-03-04 18:59:44 +00:00
|
|
|
|
2022-12-21 18:36:40 +00:00
|
|
|
internal static class ProtoInputExtensions
|
2022-03-04 18:59:44 +00:00
|
|
|
{
|
2023-06-28 16:15:32 +00:00
|
|
|
public static IDictionary<string, object> Deserialize(this Input input)
|
|
|
|
|
{
|
|
|
|
|
var jsonSerializerOptions = new JsonSerializerOptions();
|
|
|
|
|
jsonSerializerOptions.Converters.Add(new ExpandoObjectConverterFactory());
|
|
|
|
|
|
|
|
|
|
return input.Data.ToDictionary(x => x.Key, x => JsonSerializer.Deserialize<object>(x.Value.Text, jsonSerializerOptions)!);
|
|
|
|
|
}
|
2022-03-04 18:59:44 +00:00
|
|
|
|
2022-04-30 09:10:08 +00:00
|
|
|
public static Input Serialize(this IDictionary<string, object> input)
|
2022-03-04 18:59:44 +00:00
|
|
|
{
|
|
|
|
|
var result = new Input();
|
|
|
|
|
var data = result.Data;
|
|
|
|
|
|
|
|
|
|
foreach (var (key, value) in input)
|
|
|
|
|
{
|
2022-09-02 11:18:53 +00:00
|
|
|
data[key] = new Json
|
2022-03-04 18:59:44 +00:00
|
|
|
{
|
|
|
|
|
Text = JsonSerializer.Serialize(value)
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|