Add FlowSwitch resolver to API client
This commit is contained in:
parent
816a6f3f8e
commit
336e55a230
19
src/clients/Elsa.Api.Client/Activities/FlowSwitch.cs
Normal file
19
src/clients/Elsa.Api.Client/Activities/FlowSwitch.cs
Normal 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!;
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
|
@ -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";
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 ?? "";
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
10
src/clients/Elsa.Api.Client/Models/Case.cs
Normal file
10
src/clients/Elsa.Api.Client/Models/Case.cs
Normal 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("");
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
Loading…
Reference in a new issue