Add FlowSwitch resolver to API client

This commit is contained in:
Sipke Schoorstra 2023-06-29 14:51:00 +02:00
parent 816a6f3f8e
commit 336e55a230
8 changed files with 52 additions and 5 deletions

View file

@ -0,0 +1,19 @@
using Elsa.Api.Client.Extensions;
using Elsa.Api.Client.Models;
namespace Elsa.Api.Client.Activities;
/// <summary>
/// Represents a flow switch activity.
/// </summary>
public class FlowSwitch : Activity
{
/// <summary>
/// Gets or sets the cases.
/// </summary>
public ICollection<Case>? Cases
{
get => this.TryGetValue<ICollection<Case>>("cases");
set => this["cases"] = value!;
}
}

View file

@ -0,0 +1,17 @@
using Elsa.Api.Client.Abstractions;
using Elsa.Api.Client.Activities;
using Elsa.Api.Client.Contracts;
namespace Elsa.Api.Client.ActivityProviders;
/// <summary>
/// Constructs a <see cref="Flowchart"/> activity.
/// </summary>
public class FlowSwitchTypeResolver : ActivityTypeResolverBase
{
/// <inheritdoc />
protected override bool GetSupportsType(ActivityTypeResolverContext context) => context.ActivityTypeName == "Elsa.FlowSwitch";
/// <inheritdoc />
protected override Type ResolveType(ActivityTypeResolverContext context) => typeof(FlowSwitch);
}

View file

@ -7,7 +7,7 @@ namespace Elsa.Api.Client.ActivityProviders;
/// <summary>
/// Constructs a <see cref="Flowchart"/> activity.
/// </summary>
public class FlowchartActivityTypeResolver : ActivityTypeResolverBase
public class FlowchartTypeResolver : ActivityTypeResolverBase
{
/// <inheritdoc />
protected override bool GetSupportsType(ActivityTypeResolverContext context) => context.ActivityTypeName == "Elsa.Flowchart";

View file

@ -27,7 +27,7 @@ public class ActivityJsonConverter : JsonConverter<Activity>
var activityRoot = doc.RootElement;
var activityTypeName = activityRoot.GetProperty("type").GetString()!;
var activityType = _activityTypeService.ResolveType(activityTypeName);
var newOptions = new JsonSerializerOptions();
var newOptions = new JsonSerializerOptions(options);
var activity = (Activity)JsonSerializer.Deserialize(activityRoot.GetRawText(), activityType, newOptions)!;
return activity;

View file

@ -32,5 +32,5 @@ public class ObjectExpression : IExpression
/// <summary>
/// Returns the string representation of the expression.
/// </summary>
public override string ToString() => Value?.ToString() ?? "";
public override string ToString() => Value ?? "";
}

View file

@ -43,7 +43,8 @@ public static class DependencyInjectionExtensions
{
services.AddSingleton<IActivityTypeService, DefaultActivityTypeService>();
services.AddActivityTypeResolver<DefaultActivityTypeResolver>();
services.AddActivityTypeResolver<FlowchartActivityTypeResolver>();
services.AddActivityTypeResolver<FlowchartTypeResolver>();
services.AddActivityTypeResolver<FlowSwitchTypeResolver>();
return services;
}

View file

@ -0,0 +1,10 @@
using Elsa.Api.Client.Contracts;
using Elsa.Api.Client.Expressions;
namespace Elsa.Api.Client.Models;
public class Case
{
public string Label { get; set; } = default!;
public IExpression Condition { get; set; } = new JavaScriptExpression("");
}

View file

@ -23,5 +23,5 @@ public class Port
/// <summary>
/// Gets or sets the visibility of the port.
/// </summary>
public bool IsBrowsable { get; set; } = true;
public bool? IsBrowsable { get; set; } = true;
}