2023-07-16 13:08:13 +00:00
|
|
|
using System.Text.Json.Nodes;
|
2023-07-07 11:53:44 +00:00
|
|
|
using Elsa.Api.Client.Shared.Models;
|
2023-06-19 13:32:26 +00:00
|
|
|
|
|
|
|
|
namespace Elsa.Api.Client.Extensions;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2023-07-16 13:08:13 +00:00
|
|
|
/// Provides extension methods for <see cref="JsonObject"/>.
|
2023-06-19 13:32:26 +00:00
|
|
|
/// </summary>
|
|
|
|
|
public static class ActivityExtensions
|
|
|
|
|
{
|
2023-07-16 13:08:13 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the type name of the specified activity.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static string GetTypeName(this JsonObject activity) => activity.GetProperty<string>("type")!;
|
2023-10-25 20:46:06 +00:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the type name of the specified activity.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static void SetTypeName(this JsonObject activity, string value) => activity.SetProperty(JsonValue.Create(value), "type");
|
|
|
|
|
|
2023-07-18 09:20:00 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the version of the specified activity.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static int GetVersion(this JsonObject activity) => activity.GetProperty<int>("version");
|
2023-07-16 13:08:13 +00:00
|
|
|
|
2023-10-25 20:46:06 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the version of the specified activity.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static void SetVersion(this JsonObject activity, int value) => activity.SetProperty(JsonValue.Create(value), "version");
|
|
|
|
|
|
2023-07-16 13:08:13 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the ID of the specified activity.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static string GetId(this JsonObject activity) => activity.GetProperty<string>("id")!;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the ID of the specified activity.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static void SetId(this JsonObject activity, string value) => activity.SetProperty(JsonValue.Create(value), "id");
|
2023-10-25 20:46:06 +00:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the node ID of the specified activity.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static string GetNodeId(this JsonObject activity) => activity.GetProperty<string>("nodeId")!;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the node ID of the specified activity.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static void SetNodeId(this JsonObject activity, string value) => activity.SetProperty(JsonValue.Create(value), "nodeId");
|
|
|
|
|
|
2023-07-16 13:08:13 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the name of the specified activity.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static string? GetName(this JsonObject activity) => activity.GetProperty<string>("name");
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the name of the specified activity.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static void SetName(this JsonObject activity, string? value) => activity.SetProperty(JsonValue.Create(value), "name");
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the designer metadata for the specified activity.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static JsonObject? GetMetadata(this JsonObject activity) => activity.GetProperty("metadata")?.AsObject();
|
|
|
|
|
|
2023-06-19 13:32:26 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the designer metadata for the specified activity.
|
|
|
|
|
/// </summary>
|
2023-07-16 13:08:13 +00:00
|
|
|
public static void SetDesignerMetadata(this JsonObject activity, ActivityDesignerMetadata designerMetadata) => activity.SetProperty(designerMetadata.SerializeToNode(), "metadata", "designer");
|
2023-06-19 13:32:26 +00:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the designer metadata for the specified activity.
|
|
|
|
|
/// </summary>
|
2023-07-16 13:08:13 +00:00
|
|
|
public static ActivityDesignerMetadata GetDesignerMetadata(this JsonObject activity) => activity.GetProperty<ActivityDesignerMetadata>("metadata", "designer") ?? new ActivityDesignerMetadata();
|
|
|
|
|
|
2023-06-30 13:52:53 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the display text for the specified activity.
|
|
|
|
|
/// </summary>
|
2023-07-16 13:08:13 +00:00
|
|
|
public static string? GetDisplayText(this JsonObject activity) => activity.GetProperty("metadata", "displayText")?.GetValue<string>();
|
|
|
|
|
|
2023-06-30 13:52:53 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the display text for the specified activity.
|
|
|
|
|
/// </summary>
|
2023-07-16 13:08:13 +00:00
|
|
|
public static void SetDisplayText(this JsonObject activity, string? value)
|
2023-06-30 13:52:53 +00:00
|
|
|
{
|
2023-07-16 13:08:13 +00:00
|
|
|
activity.SetProperty(JsonValue.Create(value), "metadata", "displayText");
|
2023-06-30 13:52:53 +00:00
|
|
|
}
|
2023-07-16 13:08:13 +00:00
|
|
|
|
2023-06-30 13:52:53 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the description for the specified activity.
|
|
|
|
|
/// </summary>
|
2023-07-16 13:08:13 +00:00
|
|
|
public static string? GetDescription(this JsonObject activity) => activity.GetProperty("metadata", "description")?.GetValue<string>();
|
|
|
|
|
|
2023-06-30 13:52:53 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the description for the specified activity.
|
|
|
|
|
/// </summary>
|
2023-07-16 13:08:13 +00:00
|
|
|
public static void SetDescription(this JsonObject activity, string value) => activity.SetProperty(JsonValue.Create(value), "metadata", "description");
|
|
|
|
|
|
2023-06-30 13:52:53 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a value indicating whether the description for the specified activity should be shown.
|
|
|
|
|
/// </summary>
|
2023-07-16 13:08:13 +00:00
|
|
|
public static bool? GetShowDescription(this JsonObject activity) => activity.GetProperty<bool>("metadata", "showDescription");
|
|
|
|
|
|
2023-06-30 13:52:53 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Sets a value indicating whether the description for the specified activity should be shown.
|
|
|
|
|
/// </summary>
|
2023-07-16 13:08:13 +00:00
|
|
|
public static void SetShowDescription(this JsonObject activity, bool value) => activity.SetProperty(JsonValue.Create(value), "metadata", "showDescription");
|
|
|
|
|
|
2023-07-01 09:39:40 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a value indicating whether the specified activity can trigger the workflow.
|
|
|
|
|
/// </summary>
|
2023-07-16 13:08:13 +00:00
|
|
|
public static bool? GetCanStartWorkflow(this JsonObject activity) => activity.GetProperty<bool>("customProperties", "canStartWorkflow");
|
|
|
|
|
|
2023-07-01 09:39:40 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Sets a value indicating whether the specified activity can trigger the workflow.
|
|
|
|
|
/// </summary>
|
2023-07-16 13:08:13 +00:00
|
|
|
public static void SetCanStartWorkflow(this JsonObject activity, bool value) => activity.SetProperty(JsonValue.Create(value), "customProperties", "canStartWorkflow");
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the activities in the specified flowchart.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static IEnumerable<JsonObject> GetActivities(this JsonObject flowchart) => flowchart.GetProperty("activities")?.AsArray().AsEnumerable().Cast<JsonObject>() ?? Array.Empty<JsonObject>();
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the activities in the specified flowchart.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static void SetActivities(this JsonObject flowchart, JsonArray activities) => flowchart.SetProperty(activities, "activities");
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the connections in the specified flowchart.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static IEnumerable<Connection> GetConnections(this JsonObject flowchart) => flowchart.GetProperty<ICollection<Connection>>("connections") ?? new List<Connection>();
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the connections in the specified flowchart.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static void SetConnections(this JsonObject flowchart, IEnumerable<Connection> connections) => flowchart.SetProperty(JsonValue.Create(connections), "connections");
|
2023-10-25 20:46:06 +00:00
|
|
|
|
2023-08-08 18:50:21 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the root activity in the specified activity.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static JsonObject? GetRoot(this JsonObject activity) => activity.GetProperty("root") as JsonObject;
|
2023-10-25 20:46:06 +00:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the root activity in the specified activity.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static void SetRoot(this JsonObject container, JsonObject root) => container.SetProperty(root, "root");
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the root activity in the specified activity.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static string? GetWorkflowDefinitionId(this JsonObject activity) => activity.GetProperty<string?>("workflowDefinitionId");
|
2023-12-11 11:44:19 +00:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Determines whether the given activity is a workflow definition activity.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="activity">The JsonObject representing the activity.</param>
|
|
|
|
|
/// <returns>Returns true if the activity is a workflow definition activity; otherwise, false.</returns>
|
|
|
|
|
public static bool GetIsWorkflowDefinitionActivity(this JsonObject activity) => activity.ContainsKey("workflowDefinitionId") && activity.ContainsKey("workflowDefinitionVersionId");
|
2023-12-18 15:04:21 +00:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a value indicating whether the specified activity can trigger the workflow.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static bool? GetRunAsynchronously(this JsonObject activity) => activity.GetProperty<bool>("customProperties", "runAsynchronously");
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets a value indicating whether the specified activity can trigger the workflow.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static void SetRunAsynchronously(this JsonObject activity, bool value) => activity.SetProperty(JsonValue.Create(value), "customProperties", "runAsynchronously");
|
2023-06-19 13:32:26 +00:00
|
|
|
}
|