2022-03-04 18:59:44 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text.Json;
|
2022-04-10 12:35:53 +00:00
|
|
|
using Elsa.Runtime.Protos;
|
2022-03-04 18:59:44 +00:00
|
|
|
|
|
|
|
|
namespace Elsa.Runtime.ProtoActor.Extensions;
|
|
|
|
|
|
|
|
|
|
public static class ProtoInputExtensions
|
|
|
|
|
{
|
2022-04-07 11:06:16 +00:00
|
|
|
public static IDictionary<string, object?> Deserialize(this Input input) => input.Data.ToDictionary(x => x.Key, x => JsonSerializer.Deserialize<object>(x.Value.Text));
|
2022-03-04 18:59:44 +00:00
|
|
|
|
2022-04-07 11:06:16 +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)
|
|
|
|
|
{
|
|
|
|
|
data[key] = new Json
|
|
|
|
|
{
|
|
|
|
|
Text = JsonSerializer.Serialize(value)
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|