diff --git a/src/clients/Elsa.Client/Models/ActivityBlueprint.cs b/src/clients/Elsa.Client/Models/ActivityBlueprint.cs index 1cdf7bc8a..68b3be1e8 100644 --- a/src/clients/Elsa.Client/Models/ActivityBlueprint.cs +++ b/src/clients/Elsa.Client/Models/ActivityBlueprint.cs @@ -7,10 +7,12 @@ namespace Elsa.Client.Models { [DataMember(Order = 1)] public string Id { get; set; } = default!; [DataMember(Order = 2)] public string? Name { get; set; } - [DataMember(Order = 3)] public string Type { get; set; } = default!; - [DataMember(Order = 4)] public bool PersistWorkflow { get; set; } - [DataMember(Order = 5)] public bool LoadWorkflowContext { get; set; } - [DataMember(Order = 6)] public bool SaveWorkflowContext { get; set; } - [DataMember(Order = 7)] public Variables Properties { get; set; } = new(); + [DataMember(Order = 3)] public string? DisplayName { get; set; } + [DataMember(Order = 4)] public string? Description { get; set;} + [DataMember(Order = 5)] public string Type { get; set; } = default!; + [DataMember(Order = 6)] public bool PersistWorkflow { get; set; } + [DataMember(Order = 7)] public bool LoadWorkflowContext { get; set; } + [DataMember(Order = 8)] public bool SaveWorkflowContext { get; set; } + [DataMember(Order = 9)] public Variables Properties { get; set; } = new(); } } \ No newline at end of file diff --git a/src/clients/Elsa.Client/Models/WorkflowBlueprint.cs b/src/clients/Elsa.Client/Models/WorkflowBlueprint.cs index 80a279130..c62f5dca7 100644 --- a/src/clients/Elsa.Client/Models/WorkflowBlueprint.cs +++ b/src/clients/Elsa.Client/Models/WorkflowBlueprint.cs @@ -9,31 +9,30 @@ namespace Elsa.Client.Models [DataMember(Order = 2)] public string? TenantId { get; set;} [DataMember(Order = 3)] public bool IsSingleton { get; set;} [DataMember(Order = 4)] public bool IsEnabled { get; set;} - [DataMember(Order = 5)] public string? Description { get; set;} - [DataMember(Order = 6)] public bool IsPublished { get; set;} - [DataMember(Order = 7)] public bool IsLatest { get; set;} + [DataMember(Order = 5)] public bool IsPublished { get; set;} + [DataMember(Order = 6)] public bool IsLatest { get; set;} /// /// An initial set of variables available to workflow instances. /// - [DataMember(Order = 8)] + [DataMember(Order = 7)] public Variables Variables { get; set;} = new(); /// /// An optional context type around which this workflow revolves. For example, a document, a leave request or a job application. /// - [DataMember(Order = 9)] + [DataMember(Order = 8)] public WorkflowContextOptions? ContextOptions { get; set; } - [DataMember(Order = 10)] public WorkflowPersistenceBehavior PersistenceBehavior { get; set;} - [DataMember(Order = 11)] public bool DeleteCompletedInstances { get; set;} + [DataMember(Order = 9)] public WorkflowPersistenceBehavior PersistenceBehavior { get; set;} + [DataMember(Order = 10)] public bool DeleteCompletedInstances { get; set;} /// /// A dictionary to store application-specific properties for a given workflow. /// - [DataMember(Order = 12)] + [DataMember(Order = 11)] public Variables CustomAttributes { get; set;} = new(); - [DataMember(Order = 13)] public string? DisplayName { get; set; } + [DataMember(Order = 12)] public string? DisplayName { get; set; } } } \ No newline at end of file diff --git a/src/core/Elsa.Abstractions/Builders/IActivityBuilder.cs b/src/core/Elsa.Abstractions/Builders/IActivityBuilder.cs index 84a89a2d2..a98cc3c4b 100644 --- a/src/core/Elsa.Abstractions/Builders/IActivityBuilder.cs +++ b/src/core/Elsa.Abstractions/Builders/IActivityBuilder.cs @@ -20,8 +20,10 @@ namespace Elsa.Builders IOutcomeBuilder When(string outcome); IActivityBuilder Then(IActivityBuilder targetActivity); IConnectionBuilder Then(string activityName); - IActivityBuilder WithId(string? id); - IActivityBuilder WithName(string? name); + IActivityBuilder WithId(string? value); + IActivityBuilder WithName(string? value); + IActivityBuilder WithDisplayName(string? value); + IActivityBuilder WithDescription(string? value); IActivityBuilder LoadWorkflowContext(bool value = true); IActivityBuilder SaveWorkflowContext(bool value = true); } diff --git a/src/core/Elsa.Abstractions/Services/Models/ActivityBlueprint.cs b/src/core/Elsa.Abstractions/Services/Models/ActivityBlueprint.cs index d1b27f68a..daff0e560 100644 --- a/src/core/Elsa.Abstractions/Services/Models/ActivityBlueprint.cs +++ b/src/core/Elsa.Abstractions/Services/Models/ActivityBlueprint.cs @@ -10,6 +10,7 @@ string id, string? name, string? displayName, + string? description, string type, bool persistWorkflow, bool loadWorkflowContext, @@ -18,6 +19,7 @@ Id = id; Name = name; DisplayName = displayName; + Description = description; Type = type; PersistWorkflow = persistWorkflow; LoadWorkflowContext = loadWorkflowContext; @@ -27,6 +29,7 @@ public string Id { get; set; } = default!; public string? Name { get; set; } public string? DisplayName { get; } + public string? Description { get; } public string Type { get; set; } = default!; public bool PersistWorkflow { get; set; } public bool LoadWorkflowContext { get; set; } diff --git a/src/core/Elsa.Abstractions/Services/Models/CompositeActivityBlueprint.cs b/src/core/Elsa.Abstractions/Services/Models/CompositeActivityBlueprint.cs index 8a7afb528..3816cb606 100644 --- a/src/core/Elsa.Abstractions/Services/Models/CompositeActivityBlueprint.cs +++ b/src/core/Elsa.Abstractions/Services/Models/CompositeActivityBlueprint.cs @@ -15,10 +15,11 @@ namespace Elsa.Services.Models string id, string? name, string? displayName, + string? description, string type, bool persistWorkflow, bool loadWorkflowContext, - bool saveWorkflowContext) : base(id, name, displayName, type, persistWorkflow, loadWorkflowContext, saveWorkflowContext) + bool saveWorkflowContext) : base(id, name, displayName, description, type, persistWorkflow, loadWorkflowContext, saveWorkflowContext) { } diff --git a/src/core/Elsa.Abstractions/Services/Models/IActivityBlueprint.cs b/src/core/Elsa.Abstractions/Services/Models/IActivityBlueprint.cs index 8678627eb..98971865c 100644 --- a/src/core/Elsa.Abstractions/Services/Models/IActivityBlueprint.cs +++ b/src/core/Elsa.Abstractions/Services/Models/IActivityBlueprint.cs @@ -5,6 +5,7 @@ string Id { get; } string? Name { get; } string? DisplayName { get; } + string? Description { get; } string Type { get; } bool PersistWorkflow { get; } bool LoadWorkflowContext { get; set; } diff --git a/src/core/Elsa.Abstractions/Services/Models/WorkflowBlueprint.cs b/src/core/Elsa.Abstractions/Services/Models/WorkflowBlueprint.cs index 6c0850f76..44835f7e5 100644 --- a/src/core/Elsa.Abstractions/Services/Models/WorkflowBlueprint.cs +++ b/src/core/Elsa.Abstractions/Services/Models/WorkflowBlueprint.cs @@ -31,7 +31,7 @@ namespace Elsa.Services.Models bool deleteCompletedInstances, IEnumerable activities, IEnumerable connections, - IActivityPropertyProviders activityPropertyValueProviders) : base(id, name, displayName, id, true, false, false) + IActivityPropertyProviders activityPropertyValueProviders) : base(id, name, displayName, description, id, true, false, false) { Id = id; Version = version; @@ -44,7 +44,6 @@ namespace Elsa.Services.Models Variables = variables ?? new Variables(); CustomAttributes = customAttributes ?? new Variables(); Name = name; - Description = description; PersistenceBehavior = persistenceBehavior; DeleteCompletedInstances = deleteCompletedInstances; Activities = activities.ToList(); @@ -56,7 +55,6 @@ namespace Elsa.Services.Models public string? TenantId { get; set; } public bool IsSingleton { get; set; } public bool IsEnabled { get; set; } - public string? Description { get; set; } public bool IsPublished { get; set; } public bool IsLatest { get; set; } public Variables Variables { get; set; } diff --git a/src/core/Elsa.Core/Builders/ActivityBuilder.cs b/src/core/Elsa.Core/Builders/ActivityBuilder.cs index 410a6ec47..c8c6a6590 100644 --- a/src/core/Elsa.Core/Builders/ActivityBuilder.cs +++ b/src/core/Elsa.Core/Builders/ActivityBuilder.cs @@ -60,21 +60,27 @@ namespace Elsa.Builders () => this, () => WorkflowBuilder.Activities.First(x => x.Name == activityName)); - public IActivityBuilder WithId(string? id) + public IActivityBuilder WithId(string? value) { - ActivityId = id!; + ActivityId = value!; return this; } - public IActivityBuilder WithName(string? name) + public IActivityBuilder WithName(string? value) { - Name = name; + Name = value; return this; } - public IActivityBuilder WithDisplay(string? name) + public IActivityBuilder WithDisplayName(string? value) { - Name = name; + DisplayName = value; + return this; + } + + public IActivityBuilder WithDescription(string? value) + { + Description = value; return this; } diff --git a/src/core/Elsa.Core/Builders/CompositeActivityBuilder.cs b/src/core/Elsa.Core/Builders/CompositeActivityBuilder.cs index 571bac05b..4f4d81e15 100644 --- a/src/core/Elsa.Core/Builders/CompositeActivityBuilder.cs +++ b/src/core/Elsa.Core/Builders/CompositeActivityBuilder.cs @@ -189,8 +189,8 @@ namespace Elsa.Builders { var isComposite = typeof(CompositeActivity).IsAssignableFrom(builder.ActivityType); return isComposite - ? new CompositeActivityBlueprint(builder.ActivityId, builder.Name, builder.DisplayName, builder.ActivityType.Name, builder.PersistWorkflow, builder.LoadWorkflowContextEnabled, builder.SaveWorkflowContextEnabled) - : new ActivityBlueprint(builder.ActivityId, builder.Name, builder.DisplayName, builder.ActivityType.Name, builder.PersistWorkflow, builder.LoadWorkflowContextEnabled, builder.SaveWorkflowContextEnabled); + ? new CompositeActivityBlueprint(builder.ActivityId, builder.Name, builder.DisplayName, builder.Description, builder.ActivityType.Name, builder.PersistWorkflow, builder.LoadWorkflowContextEnabled, builder.SaveWorkflowContextEnabled) + : new ActivityBlueprint(builder.ActivityId, builder.Name, builder.DisplayName, builder.Description, builder.ActivityType.Name, builder.PersistWorkflow, builder.LoadWorkflowContextEnabled, builder.SaveWorkflowContextEnabled); } } } \ No newline at end of file diff --git a/src/core/Elsa.Core/ElsaOptions.cs b/src/core/Elsa.Core/ElsaOptions.cs index 393a255f0..d698427ea 100644 --- a/src/core/Elsa.Core/ElsaOptions.cs +++ b/src/core/Elsa.Core/ElsaOptions.cs @@ -118,6 +118,8 @@ namespace Elsa WorkflowFactory.Add(workflow.GetType(), workflow); return this; } + + public ElsaOptions AddWorkflowsFrom() => AddWorkflowsFrom(typeof(T).Assembly); public ElsaOptions AddWorkflowsFrom(Assembly assembly) { diff --git a/src/dashboards/blazor/ElsaDashboard.Abstractions/Models/ActivityDisplayDescriptor.cs b/src/dashboards/blazor/ElsaDashboard.Abstractions/Models/ActivityDisplayDescriptor.cs index 39e1bfe63..719e0797e 100644 --- a/src/dashboards/blazor/ElsaDashboard.Abstractions/Models/ActivityDisplayDescriptor.cs +++ b/src/dashboards/blazor/ElsaDashboard.Abstractions/Models/ActivityDisplayDescriptor.cs @@ -1,4 +1,6 @@ using System; +using ElsaDashboard.Components; +using ElsaDashboard.Extensions; using Microsoft.AspNetCore.Components; namespace ElsaDashboard.Models @@ -8,5 +10,12 @@ namespace ElsaDashboard.Models public string ActivityType { get; init; } = default!; public Func? RenderBody { get; init; } public Func? RenderIcon { get; init; } + + public static ActivityDisplayDescriptor For(string activityType) where T : ActivityDisplayComponent => + new() + { + ActivityType = activityType, + RenderBody = context => builder => builder.AddActivityDisplayComponent(context) + }; } } \ No newline at end of file diff --git a/src/dashboards/blazor/ElsaDashboard.Application/Activities/Console/WriteLineActivity.razor b/src/dashboards/blazor/ElsaDashboard.Application/Activities/Console/WriteLineActivity.razor new file mode 100644 index 000000000..8985d37dd --- /dev/null +++ b/src/dashboards/blazor/ElsaDashboard.Application/Activities/Console/WriteLineActivity.razor @@ -0,0 +1,3 @@ +@inherits ActivityDisplayComponent + +

Output "@(DisplayContext.Properties.Get("Text"))"

\ No newline at end of file diff --git a/src/dashboards/blazor/ElsaDashboard.Application/Activities/Timers/CronActivity.razor b/src/dashboards/blazor/ElsaDashboard.Application/Activities/Timers/CronActivity.razor new file mode 100644 index 000000000..45d3eb396 --- /dev/null +++ b/src/dashboards/blazor/ElsaDashboard.Application/Activities/Timers/CronActivity.razor @@ -0,0 +1,3 @@ +@inherits ActivityDisplayComponent + +

Every @(DisplayContext.Properties.Get("CronExpression"))

\ No newline at end of file diff --git a/src/dashboards/blazor/ElsaDashboard.Application/Activities/Timers/StartAtActivity.razor b/src/dashboards/blazor/ElsaDashboard.Application/Activities/Timers/StartAtActivity.razor new file mode 100644 index 000000000..fba78b3be --- /dev/null +++ b/src/dashboards/blazor/ElsaDashboard.Application/Activities/Timers/StartAtActivity.razor @@ -0,0 +1,4 @@ +@using NodaTime +@inherits ActivityDisplayComponent + +

Start At @(DisplayContext.Properties.Get("Instant"))

\ No newline at end of file diff --git a/src/dashboards/blazor/ElsaDashboard.Application/Activities/TimerActivity.razor b/src/dashboards/blazor/ElsaDashboard.Application/Activities/Timers/TimerActivity.razor similarity index 100% rename from src/dashboards/blazor/ElsaDashboard.Application/Activities/TimerActivity.razor rename to src/dashboards/blazor/ElsaDashboard.Application/Activities/Timers/TimerActivity.razor diff --git a/src/dashboards/blazor/ElsaDashboard.Application/Display/ConsoleDisplayProvider.cs b/src/dashboards/blazor/ElsaDashboard.Application/Display/ConsoleDisplayProvider.cs new file mode 100644 index 000000000..8e8d7c56f --- /dev/null +++ b/src/dashboards/blazor/ElsaDashboard.Application/Display/ConsoleDisplayProvider.cs @@ -0,0 +1,15 @@ +using System.Collections.Generic; +using ElsaDashboard.Application.Activities.Console; +using ElsaDashboard.Models; +using ElsaDashboard.Services; + +namespace ElsaDashboard.Application.Display +{ + public class ConsoleDisplayProvider : ActivityDisplayProvider + { + protected override IEnumerable GetDescriptors() + { + yield return ActivityDisplayDescriptor.For("WriteLine"); + } + } +} \ No newline at end of file diff --git a/src/dashboards/blazor/ElsaDashboard.Application/Display/TimerDisplayProvider.cs b/src/dashboards/blazor/ElsaDashboard.Application/Display/TimersDisplayProvider.cs similarity index 52% rename from src/dashboards/blazor/ElsaDashboard.Application/Display/TimerDisplayProvider.cs rename to src/dashboards/blazor/ElsaDashboard.Application/Display/TimersDisplayProvider.cs index 39931a00f..b0e0de157 100644 --- a/src/dashboards/blazor/ElsaDashboard.Application/Display/TimerDisplayProvider.cs +++ b/src/dashboards/blazor/ElsaDashboard.Application/Display/TimersDisplayProvider.cs @@ -1,20 +1,18 @@ using System.Collections.Generic; using ElsaDashboard.Application.Activities; +using ElsaDashboard.Application.Activities.Timers; using ElsaDashboard.Extensions; using ElsaDashboard.Models; using ElsaDashboard.Services; namespace ElsaDashboard.Application.Display { - public class TimerDisplayProvider : ActivityDisplayProvider + public class TimersDisplayProvider : ActivityDisplayProvider { protected override IEnumerable GetDescriptors() { - yield return new ActivityDisplayDescriptor - { - ActivityType = "Timer", - RenderBody = context => builder => builder.AddActivityDisplayComponent(context) - }; + yield return ActivityDisplayDescriptor.For("Timer"); + yield return ActivityDisplayDescriptor.For("Cron"); } } } \ No newline at end of file diff --git a/src/dashboards/blazor/ElsaDashboard.Application/Extensions/ServiceCollectionExtensions.cs b/src/dashboards/blazor/ElsaDashboard.Application/Extensions/ServiceCollectionExtensions.cs index 54a6f9b94..820a2b9c0 100644 --- a/src/dashboards/blazor/ElsaDashboard.Application/Extensions/ServiceCollectionExtensions.cs +++ b/src/dashboards/blazor/ElsaDashboard.Application/Extensions/ServiceCollectionExtensions.cs @@ -1,4 +1,6 @@ using Blazored.Modal; +using ElsaDashboard.Application.Activities; +using ElsaDashboard.Application.Activities.Console; using ElsaDashboard.Application.Display; using ElsaDashboard.Application.Services; using ElsaDashboard.Extensions; @@ -16,7 +18,8 @@ namespace Microsoft.Extensions.DependencyInjection .AddScoped() .AddScoped() .AddSingleton() - .AddActivityDisplayProvider(); + .AddActivityDisplayProvider() + .AddActivityDisplayProvider(); } } } \ No newline at end of file diff --git a/src/dashboards/blazor/ElsaDashboard.Application/Pages/WorkflowRegistry/Viewer.razor.cs b/src/dashboards/blazor/ElsaDashboard.Application/Pages/WorkflowRegistry/Viewer.razor.cs index 65f2d7dcd..9661dd022 100644 --- a/src/dashboards/blazor/ElsaDashboard.Application/Pages/WorkflowRegistry/Viewer.razor.cs +++ b/src/dashboards/blazor/ElsaDashboard.Application/Pages/WorkflowRegistry/Viewer.razor.cs @@ -57,10 +57,10 @@ namespace ElsaDashboard.Application.Pages.WorkflowRegistry { Name = activityBlueprint.Name, Type = activityBlueprint.Type, - DisplayName = descriptor.DisplayName, + DisplayName = activityBlueprint.DisplayName ?? descriptor.DisplayName, Outcomes = descriptor.Outcomes, ActivityId = activityBlueprint.Id, - Description = descriptor.Description, + Description = activityBlueprint.Description ?? descriptor.Description, Properties = activityBlueprint.Properties, DisplayDescriptor = displayDescriptor }; diff --git a/src/dashboards/blazor/ElsaDashboard.Backend/Rpc/WorkflowRegistryService.cs b/src/dashboards/blazor/ElsaDashboard.Backend/Rpc/WorkflowRegistryService.cs index 860522cdb..41af5a428 100644 --- a/src/dashboards/blazor/ElsaDashboard.Backend/Rpc/WorkflowRegistryService.cs +++ b/src/dashboards/blazor/ElsaDashboard.Backend/Rpc/WorkflowRegistryService.cs @@ -14,6 +14,10 @@ namespace ElsaDashboard.Backend.Rpc public Task> ListAsync(ListWorkflowBlueprintsRequest request, CallContext context = default) => _elsaClient.WorkflowRegistry.ListAsync(request.Page, request.PageSize, request.VersionOptions, context.CancellationToken); - public Task GetById(GetWorkflowBlueprintByIdRequest request, CallContext context = default) => _elsaClient.WorkflowRegistry.GetByIdAsync(request.Id, request.VersionOptions, context.CancellationToken); + public async Task GetById(GetWorkflowBlueprintByIdRequest request, CallContext context = default) + { + var result = await _elsaClient.WorkflowRegistry.GetByIdAsync(request.Id, request.VersionOptions, context.CancellationToken); + return result; + } } } \ No newline at end of file diff --git a/src/server/Elsa.Server.Api/Endpoints/WorkflowRegistry/Models.cs b/src/server/Elsa.Server.Api/Endpoints/WorkflowRegistry/Models.cs index 5dc5e0b76..a0015835f 100644 --- a/src/server/Elsa.Server.Api/Endpoints/WorkflowRegistry/Models.cs +++ b/src/server/Elsa.Server.Api/Endpoints/WorkflowRegistry/Models.cs @@ -37,13 +37,15 @@ namespace Elsa.Server.Api.Endpoints.WorkflowRegistry { public string Id { get; set; } = default!; public string? Name { get; set; } + public string? DisplayName { get; set; } + public string? Description { get; set; } public string Type { get; set; } = default!; public bool PersistWorkflow { get; set; } public bool LoadWorkflowContext { get; set; } public bool SaveWorkflowContext { get; set; } public Variables Properties { get; set; } = new(); } - + public class WorkflowBlueprintSummaryModel { public string Id { get; set; } = default!; diff --git a/src/server/Elsa.Server.Api/Mapping/ActivityBlueprintConverter.cs b/src/server/Elsa.Server.Api/Mapping/ActivityBlueprintConverter.cs index 78ab467e7..63a759080 100644 --- a/src/server/Elsa.Server.Api/Mapping/ActivityBlueprintConverter.cs +++ b/src/server/Elsa.Server.Api/Mapping/ActivityBlueprintConverter.cs @@ -16,6 +16,8 @@ namespace Elsa.Server.Api.Mapping { Id = source.Id, Name = source.Name, + DisplayName = source.DisplayName, + Description = source.Description, Type = source.Type, PersistWorkflow = source.PersistWorkflow, LoadWorkflowContext = source.LoadWorkflowContext, diff --git a/src/server/Elsa.Server.Host/Startup.cs b/src/server/Elsa.Server.Host/Startup.cs index cf2c4df2b..674d8775f 100644 --- a/src/server/Elsa.Server.Host/Startup.cs +++ b/src/server/Elsa.Server.Host/Startup.cs @@ -32,11 +32,7 @@ namespace Elsa.Server.Host .AddHttpActivities(elsaSection.GetSection("Http").Bind) .AddEmailActivities(elsaSection.GetSection("Smtp").Bind) .AddQuartzTimerActivities() - .AddWorkflow() - .AddWorkflow() - .AddWorkflow() - .AddWorkflow() - .AddWorkflow() + .AddWorkflowsFrom() ); services diff --git a/src/server/Elsa.Server.Host/Workflows/ConditionWorkflow.cs b/src/server/Elsa.Server.Host/Workflows/ConditionWorkflow.cs index 25a3db66b..561a421e9 100644 --- a/src/server/Elsa.Server.Host/Workflows/ConditionWorkflow.cs +++ b/src/server/Elsa.Server.Host/Workflows/ConditionWorkflow.cs @@ -14,15 +14,14 @@ namespace Elsa.Server.Host.Workflows { workflow .WithDisplayName("Conditions") - .Then(() => Console.WriteLine("What is your age?")) + .Then(() => Console.WriteLine("What is your age?")).WithDisplayName("Write").WithDescription("What is your age?") .ReadLine() .Timer(Duration.FromMinutes(5)) .SetVariable("Age", context => int.Parse(context.GetInput())) - .IfElse(context => context.GetVariable("Age") < 18, ifElse => - { - ifElse.When(OutcomeNames.True).WriteLine("You are not allowed to drink beer."); - ifElse.When(OutcomeNames.False).WriteLine("Enjoy your beer!"); - }); + .IfElse( + context => context.GetVariable("Age") < 18, + whenTrue => whenTrue.WriteLine("You are not allowed to drink beer."), + whenFalse => whenFalse.WriteLine("Enjoy your beer!")); } } } \ No newline at end of file