Added time fields to Workflow
This commit is contained in:
parent
02d8cd071b
commit
0af3ff541b
|
|
@ -23,14 +23,11 @@ namespace Elsa.Models
|
|||
Metadata = new WorkflowMetadata();
|
||||
}
|
||||
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public WorkflowStatus Status { get; set; }
|
||||
|
||||
public Instant CreatedAt { get; set; }
|
||||
public Instant? StartedAt { get; set; }
|
||||
public Instant? HaltedAt { get; set; }
|
||||
public Instant? FinishedAt { get; set; }
|
||||
|
||||
public IList<IActivity> Activities { get; set; } = new List<IActivity>();
|
||||
public IList<Connection> Connections { get; set; } = new List<Connection>();
|
||||
public Stack<WorkflowExecutionScope> Scopes { get; set; }
|
||||
|
|
|
|||
|
|
@ -7,9 +7,11 @@ using Elsa.Activities;
|
|||
using Elsa.Extensions;
|
||||
using Elsa.Models;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using NodaTime;
|
||||
using NodaTime.Extensions;
|
||||
using NodaTime.Serialization.JsonNet;
|
||||
|
||||
namespace Elsa.Serialization.Tokenizers
|
||||
|
|
@ -18,19 +20,23 @@ namespace Elsa.Serialization.Tokenizers
|
|||
{
|
||||
private readonly ITokenizerInvoker tokenizerInvoker;
|
||||
private readonly IActivityLibrary activityLibrary;
|
||||
private readonly IClock clock;
|
||||
private readonly JsonSerializer jsonSerializer;
|
||||
|
||||
public WorkflowTokenizer(ITokenizerInvoker tokenizerInvoker, IActivityLibrary activityLibrary)
|
||||
public WorkflowTokenizer(ITokenizerInvoker tokenizerInvoker, IActivityLibrary activityLibrary, IClock clock)
|
||||
{
|
||||
this.tokenizerInvoker = tokenizerInvoker;
|
||||
this.activityLibrary = activityLibrary;
|
||||
|
||||
jsonSerializer = JsonSerializer.Create(
|
||||
new JsonSerializerSettings
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver()
|
||||
}
|
||||
.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb));
|
||||
this.clock = clock;
|
||||
|
||||
var settings = new JsonSerializerSettings
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver()
|
||||
}
|
||||
.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb);
|
||||
|
||||
settings.Converters.Add(new StringEnumConverter());
|
||||
jsonSerializer = JsonSerializer.Create(settings);
|
||||
}
|
||||
|
||||
public async Task<JToken> TokenizeWorkflowAsync(Workflow value, CancellationToken cancellationToken)
|
||||
|
|
@ -48,11 +54,15 @@ namespace Elsa.Serialization.Tokenizers
|
|||
{
|
||||
{ "metadata", JToken.FromObject(workflow.Metadata, jsonSerializer) },
|
||||
{ "status", workflow.Status.ToString() },
|
||||
{ "createdAt", SerializeInstant(workflow.CreatedAt) },
|
||||
{ "startedAt", SerializeInstant(workflow.StartedAt) },
|
||||
{ "finishedAt", SerializeInstant(workflow.FinishedAt) },
|
||||
{ "haltedAt", SerializeInstant(workflow.HaltedAt) },
|
||||
{ "activities", await SerializeActivitiesAsync(context, cancellationToken) },
|
||||
{ "connections", SerializeConnections(context, workflow) },
|
||||
{ "haltedActivities", SerializeHaltedActivities(context, workflow) },
|
||||
{ "scopes", SerializeScopes(context, scopeIdLookup) },
|
||||
{ "currentScope", SerializeCurrentScope(workflow, scopeIdLookup) }
|
||||
{ "currentScope", SerializeCurrentScope(workflow, scopeIdLookup) },
|
||||
};
|
||||
|
||||
return token;
|
||||
|
|
@ -72,6 +82,10 @@ namespace Elsa.Serialization.Tokenizers
|
|||
{
|
||||
Metadata = token["metadata"].ToObject<WorkflowMetadata>(jsonSerializer),
|
||||
Status = (WorkflowStatus) Enum.Parse(typeof(WorkflowStatus), token["status"].Value<string>()),
|
||||
CreatedAt = DeserializeInstant(token["createdAt"]) ?? clock.GetCurrentInstant(),
|
||||
StartedAt = DeserializeInstant(token["startedAt"]),
|
||||
FinishedAt = DeserializeInstant(token["finishedAt"]),
|
||||
HaltedAt = DeserializeInstant(token["haltedAt"]),
|
||||
Activities = activityDictionary.Values.ToList(),
|
||||
Connections = DeserializeConnections(token, activityDictionary).ToList(),
|
||||
BlockingActivities = DeserializeHaltedActivities(token, activityDictionary).ToList(),
|
||||
|
|
@ -263,6 +277,16 @@ namespace Elsa.Serialization.Tokenizers
|
|||
|
||||
return dictionary;
|
||||
}
|
||||
|
||||
private Instant? DeserializeInstant(JToken token)
|
||||
{
|
||||
return token?.ToObject<DateTime?>(jsonSerializer)?.ToInstant();
|
||||
}
|
||||
|
||||
private JToken SerializeInstant(Instant? value)
|
||||
{
|
||||
return value != null ? JToken.FromObject(value.Value, jsonSerializer) : null;
|
||||
}
|
||||
|
||||
private Task<ActivityDescriptor> GetActivityDescriptorAsync(string activityName, CancellationToken cancellationToken)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
},
|
||||
"AllowedHosts": "*",
|
||||
"FileStore": {
|
||||
"RootDirectory": "C:\\Activities\\Projects\\Elsa\\src\\samples\\SampleDashboard.Web\\App_Data\\Sites\\Default\\elsa\\workflows",
|
||||
"RootDirectory": "C:\\Activities\\Projects\\Elsa\\src\\samples\\SampleDashboard.Web\\App_Data\\Sites\\Default\\workflows",
|
||||
"Format": "YAML"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue