From 734ac7c06a473ff1023a432e9084fa3c07febcbc Mon Sep 17 00:00:00 2001 From: "bojan.malinic" Date: Tue, 16 Jan 2024 20:29:44 +0100 Subject: [PATCH 1/6] Move class --- .../Metadata}/OriginalNameAttribute.cs | 2 +- .../Builders/Metadata/VersionAttribute.cs | 9 +++++++++ .../Builders/SubWorkflowTaskBuilder.cs | 1 + .../Builders/WorkflowDefinitionBuilder.cs | 1 + src/ConductorSharp.Engine/Util/NamingUtil.cs | 1 + src/ConductorSharp.Engine/Util/VersionAttribute.cs | 12 ------------ 6 files changed, 13 insertions(+), 13 deletions(-) rename src/ConductorSharp.Engine/{Util => Builders/Metadata}/OriginalNameAttribute.cs (84%) create mode 100644 src/ConductorSharp.Engine/Builders/Metadata/VersionAttribute.cs delete mode 100644 src/ConductorSharp.Engine/Util/VersionAttribute.cs diff --git a/src/ConductorSharp.Engine/Util/OriginalNameAttribute.cs b/src/ConductorSharp.Engine/Builders/Metadata/OriginalNameAttribute.cs similarity index 84% rename from src/ConductorSharp.Engine/Util/OriginalNameAttribute.cs rename to src/ConductorSharp.Engine/Builders/Metadata/OriginalNameAttribute.cs index 9f4a00ab..37ad78f5 100644 --- a/src/ConductorSharp.Engine/Util/OriginalNameAttribute.cs +++ b/src/ConductorSharp.Engine/Builders/Metadata/OriginalNameAttribute.cs @@ -1,6 +1,6 @@ using System; -namespace ConductorSharp.Engine.Util +namespace ConductorSharp.Engine.Builders.Metadata { [AttributeUsage(AttributeTargets.Class)] public class OriginalNameAttribute : Attribute diff --git a/src/ConductorSharp.Engine/Builders/Metadata/VersionAttribute.cs b/src/ConductorSharp.Engine/Builders/Metadata/VersionAttribute.cs new file mode 100644 index 00000000..6f5332f7 --- /dev/null +++ b/src/ConductorSharp.Engine/Builders/Metadata/VersionAttribute.cs @@ -0,0 +1,9 @@ +using System; + +namespace ConductorSharp.Engine.Builders.Metadata; + +[AttributeUsage(AttributeTargets.Class)] +public class VersionAttribute(int version) : Attribute +{ + internal int Version { get; } = version; +} \ No newline at end of file diff --git a/src/ConductorSharp.Engine/Builders/SubWorkflowTaskBuilder.cs b/src/ConductorSharp.Engine/Builders/SubWorkflowTaskBuilder.cs index 51af984c..c70f0445 100644 --- a/src/ConductorSharp.Engine/Builders/SubWorkflowTaskBuilder.cs +++ b/src/ConductorSharp.Engine/Builders/SubWorkflowTaskBuilder.cs @@ -1,4 +1,5 @@ using ConductorSharp.Client.Model.Common; +using ConductorSharp.Engine.Builders.Metadata; using ConductorSharp.Engine.Interface; using ConductorSharp.Engine.Model; using ConductorSharp.Engine.Util; diff --git a/src/ConductorSharp.Engine/Builders/WorkflowDefinitionBuilder.cs b/src/ConductorSharp.Engine/Builders/WorkflowDefinitionBuilder.cs index a5c50c3c..34635bee 100644 --- a/src/ConductorSharp.Engine/Builders/WorkflowDefinitionBuilder.cs +++ b/src/ConductorSharp.Engine/Builders/WorkflowDefinitionBuilder.cs @@ -1,4 +1,5 @@ using ConductorSharp.Client.Model.Common; +using ConductorSharp.Engine.Builders.Metadata; using ConductorSharp.Engine.Interface; using ConductorSharp.Engine.Util; using ConductorSharp.Engine.Util.Builders; diff --git a/src/ConductorSharp.Engine/Util/NamingUtil.cs b/src/ConductorSharp.Engine/Util/NamingUtil.cs index 9b75e27d..dfde99cd 100644 --- a/src/ConductorSharp.Engine/Util/NamingUtil.cs +++ b/src/ConductorSharp.Engine/Util/NamingUtil.cs @@ -4,6 +4,7 @@ using ConductorSharp.Client; using Newtonsoft.Json; using System.Text.Json.Serialization; +using ConductorSharp.Engine.Builders.Metadata; namespace ConductorSharp.Engine.Util { diff --git a/src/ConductorSharp.Engine/Util/VersionAttribute.cs b/src/ConductorSharp.Engine/Util/VersionAttribute.cs deleted file mode 100644 index ca5debd9..00000000 --- a/src/ConductorSharp.Engine/Util/VersionAttribute.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; - -namespace ConductorSharp.Engine.Util -{ - [AttributeUsage(AttributeTargets.Class)] - public class VersionAttribute : Attribute - { - internal int Version { get; } - - public VersionAttribute(int version) => Version = version; - } -} From dd062521091d35fd918cc72bb54d369f216d9983 Mon Sep 17 00:00:00 2001 From: "bojan.malinic" Date: Wed, 17 Jan 2024 01:08:48 +0100 Subject: [PATCH 2/6] Add WorkflowMetadata attribute --- .../Handlers/PrepareEmailHandler.cs | 1 + .../Generated/Task.cs | 3 +- .../Workflows/CSharpLambdaWorkflow.cs | 4 +- .../Workflows/HandleNotificationFailure.cs | 3 +- .../Workflows/SendCustomerNotification.cs | 9 +-- .../Handlers/GetCustomerHandler.cs | 1 + .../Metadata/WorkflowMetadataAttribute.cs | 12 +++ .../Builders/WorkflowDefinitionBuilder.cs | 34 ++++---- .../Util/Builders/BuildContext.cs | 1 - .../Util/WorkflowOptions.cs | 79 ------------------- .../Tasks/CSharpLambdaTask.cs | 1 + .../Tasks/ReadWorkflowTasks.cs | 1 + .../Tasks/WaitSeconds.cs | 1 + .../Samples/Tasks/CustomerGetV1.cs | 4 +- .../Samples/Tasks/EmailPrepareV1.cs | 4 +- .../Samples/Tasks/NestedObjects.cs | 1 + .../Samples/Tasks/VersionSubworkflow.cs | 1 + .../Samples/Workers/GetCustomerHandler.cs | 1 + .../Samples/Workers/PrepareEmailHandler.cs | 4 +- .../Samples/Workflows/CSharpLambdaWorkflow.cs | 6 +- ...itionallySendCustomerNotificationOutput.cs | 4 +- .../Samples/Workflows/DecisionInDecision.cs | 1 + .../Samples/Workflows/DynamicTask.cs | 1 + .../Samples/Workflows/OptionalTaskWorkflow.cs | 1 + .../Workflows/PassthroughTaskWorkflow.cs | 2 - .../Samples/Workflows/ScaffoldedWorkflows.cs | 1 + .../Workflows/SendCustomerNotification.cs | 3 +- .../Samples/Workflows/StringAddition.cs | 1 + .../Samples/Workflows/StringInterpolation.cs | 1 + .../TaskInputInitializationMemberInit.cs | 1 + .../Workflows/TaskInputInitializationNew.cs | 1 + 31 files changed, 67 insertions(+), 121 deletions(-) create mode 100644 src/ConductorSharp.Engine/Builders/Metadata/WorkflowMetadataAttribute.cs delete mode 100644 src/ConductorSharp.Engine/Util/WorkflowOptions.cs diff --git a/examples/ConductorSharp.ApiEnabled/Handlers/PrepareEmailHandler.cs b/examples/ConductorSharp.ApiEnabled/Handlers/PrepareEmailHandler.cs index a6c63983..5a09b719 100644 --- a/examples/ConductorSharp.ApiEnabled/Handlers/PrepareEmailHandler.cs +++ b/examples/ConductorSharp.ApiEnabled/Handlers/PrepareEmailHandler.cs @@ -2,6 +2,7 @@ using ConductorSharp.Engine.Util; using MediatR; using System.Text; +using ConductorSharp.Engine.Builders.Metadata; namespace ConductorSharp.ApiEnabled.Handlers; diff --git a/examples/ConductorSharp.Definitions/Generated/Task.cs b/examples/ConductorSharp.Definitions/Generated/Task.cs index 36df88a6..4f35fa52 100644 --- a/examples/ConductorSharp.Definitions/Generated/Task.cs +++ b/examples/ConductorSharp.Definitions/Generated/Task.cs @@ -1,4 +1,5 @@ -using ConductorSharp.Engine.Model; +using ConductorSharp.Engine.Builders.Metadata; +using ConductorSharp.Engine.Model; using ConductorSharp.Engine.Util; using MediatR; diff --git a/examples/ConductorSharp.Definitions/Workflows/CSharpLambdaWorkflow.cs b/examples/ConductorSharp.Definitions/Workflows/CSharpLambdaWorkflow.cs index 7acc8a7a..31722348 100644 --- a/examples/ConductorSharp.Definitions/Workflows/CSharpLambdaWorkflow.cs +++ b/examples/ConductorSharp.Definitions/Workflows/CSharpLambdaWorkflow.cs @@ -1,4 +1,5 @@ using ConductorSharp.Engine.Builders; +using ConductorSharp.Engine.Builders.Metadata; using ConductorSharp.Engine.Model; using ConductorSharp.Patterns.Builders; using ConductorSharp.Patterns.Model; @@ -14,6 +15,7 @@ public class CSharpLambdaWorkflowInput : WorkflowInput { public class LambdaTaskInput : IRequest @@ -79,8 +81,6 @@ public override void BuildDefinition() } } ); - - _builder.SetOptions(options => options.OwnerEmail = "test@test.com"); } } } diff --git a/examples/ConductorSharp.Definitions/Workflows/HandleNotificationFailure.cs b/examples/ConductorSharp.Definitions/Workflows/HandleNotificationFailure.cs index da4dd25f..20fea63c 100644 --- a/examples/ConductorSharp.Definitions/Workflows/HandleNotificationFailure.cs +++ b/examples/ConductorSharp.Definitions/Workflows/HandleNotificationFailure.cs @@ -8,6 +8,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using ConductorSharp.Engine.Builders.Metadata; namespace ConductorSharp.Definitions.Workflows { @@ -20,6 +21,7 @@ public class HandleNotificationFailureInput : WorkflowInput { public HandleNotificationFailure( @@ -31,7 +33,6 @@ WorkflowDefinitionBuilder a.ReadExecutedTasks, b => new() { TaskNames = "dynamic_handler", WorkflowId = b.WorkflowInput.WorkflowId }); - _builder.SetOptions(options => options.OwnerEmail = "test@test.com"); } } } diff --git a/examples/ConductorSharp.Definitions/Workflows/SendCustomerNotification.cs b/examples/ConductorSharp.Definitions/Workflows/SendCustomerNotification.cs index febef7d9..2d0db96f 100644 --- a/examples/ConductorSharp.Definitions/Workflows/SendCustomerNotification.cs +++ b/examples/ConductorSharp.Definitions/Workflows/SendCustomerNotification.cs @@ -1,6 +1,7 @@ using ConductorSharp.Client.Model.Common; using ConductorSharp.Definitions.Generated; using ConductorSharp.Engine.Builders; +using ConductorSharp.Engine.Builders.Metadata; using ConductorSharp.Engine.Model; using ConductorSharp.Engine.Util; using ConductorSharp.Engine.Util.Builders; @@ -27,6 +28,7 @@ public class ExpectedDynamicInput : CustomerGetV1Input, IRequest { public SendCustomerNotification( @@ -62,13 +64,6 @@ public override void BuildDefinition() Constant = 500 } ); - - _builder.SetOptions(options => - { - options.Version = 1; - options.FailureWorkflow = typeof(HandleNotificationFailure); - options.OwnerEmail = "example@example.local"; - }); } } } diff --git a/examples/ConductorSharp.NoApi/Handlers/GetCustomerHandler.cs b/examples/ConductorSharp.NoApi/Handlers/GetCustomerHandler.cs index 407ef99f..b9b12055 100644 --- a/examples/ConductorSharp.NoApi/Handlers/GetCustomerHandler.cs +++ b/examples/ConductorSharp.NoApi/Handlers/GetCustomerHandler.cs @@ -2,6 +2,7 @@ using ConductorSharp.Engine.Util; using MediatR; using System.ComponentModel.DataAnnotations; +using ConductorSharp.Engine.Builders.Metadata; namespace ConductorSharp.NoApi.Handlers; diff --git a/src/ConductorSharp.Engine/Builders/Metadata/WorkflowMetadataAttribute.cs b/src/ConductorSharp.Engine/Builders/Metadata/WorkflowMetadataAttribute.cs new file mode 100644 index 00000000..4b4b34e6 --- /dev/null +++ b/src/ConductorSharp.Engine/Builders/Metadata/WorkflowMetadataAttribute.cs @@ -0,0 +1,12 @@ +using System; + +namespace ConductorSharp.Engine.Builders.Metadata; + +[AttributeUsage(AttributeTargets.Class)] +public class WorkflowMetadataAttribute : Attribute +{ + public string OwnerApp { get; set; } + public string OwnerEmail { get; set; } + public string Description { get; set; } + public Type FailureWorkflow { get; set; } +} diff --git a/src/ConductorSharp.Engine/Builders/WorkflowDefinitionBuilder.cs b/src/ConductorSharp.Engine/Builders/WorkflowDefinitionBuilder.cs index 34635bee..7d414f6c 100644 --- a/src/ConductorSharp.Engine/Builders/WorkflowDefinitionBuilder.cs +++ b/src/ConductorSharp.Engine/Builders/WorkflowDefinitionBuilder.cs @@ -22,14 +22,6 @@ public static void SetOutput(this WorkflowDefinitionBuilder(this WorkflowDefinitionBuilder builder, Action adjustOptions) - where FWorkflow : Workflow - where F : WorkflowInput - where G : WorkflowOutput - { - adjustOptions?.Invoke(builder.BuildContext.WorkflowOptions); - } } public class WorkflowDefinitionBuilder : ITaskSequenceBuilder @@ -61,18 +53,23 @@ WorkflowBuildItemRegistry workflowBuildRegistry public WorkflowDefinition Build() { + var metadataAttribute = _workflowType.GetCustomAttribute(); + var ownerApp = metadataAttribute?.OwnerApp; + var ownerEmail = metadataAttribute?.OwnerEmail; + var description = metadataAttribute?.Description; + var failureWorkflow = metadataAttribute?.FailureWorkflow; + if (!string.IsNullOrEmpty(BuildConfiguration?.DefaultOwnerApp)) { - BuildContext.WorkflowOptions.OwnerApp = BuildConfiguration.DefaultOwnerApp; + ownerApp = BuildConfiguration.DefaultOwnerApp; } if (!string.IsNullOrEmpty(BuildConfiguration?.DefaultOwnerEmail)) { - BuildContext.WorkflowOptions.OwnerEmail = BuildConfiguration.DefaultOwnerEmail; + ownerEmail = BuildConfiguration.DefaultOwnerEmail; } - BuildContext.WorkflowOptions.Version = - _workflowType.GetCustomAttribute()?.Version ?? BuildContext.WorkflowOptions.Version; + var version = _workflowType.GetCustomAttribute()?.Version ?? 1; BuildContext.Inputs = new(); var input = _workflowType.BaseType.GenericTypeArguments[1]; @@ -88,16 +85,13 @@ public WorkflowDefinition Build() { Name = BuildContext.WorkflowName, Tasks = _taskBuilders.SelectMany(a => a.Build()).ToList(), - FailureWorkflow = - BuildContext.WorkflowOptions.FailureWorkflow != null - ? NamingUtil.DetermineRegistrationName(BuildContext.WorkflowOptions.FailureWorkflow) - : null, - Description = BuildContext.WorkflowOptions.Description, + FailureWorkflow = failureWorkflow != null ? NamingUtil.DetermineRegistrationName(failureWorkflow) : null, + Description = description, InputParameters = BuildContext.Inputs.ToArray(), OutputParameters = BuildContext.Outputs, - OwnerApp = BuildContext.WorkflowOptions.OwnerApp, - OwnerEmail = BuildContext.WorkflowOptions.OwnerEmail, - Version = BuildContext.WorkflowOptions.Version + OwnerApp = ownerApp, + OwnerEmail = ownerEmail, + Version = version }; } diff --git a/src/ConductorSharp.Engine/Util/Builders/BuildContext.cs b/src/ConductorSharp.Engine/Util/Builders/BuildContext.cs index 8ec8f8a5..68434af5 100644 --- a/src/ConductorSharp.Engine/Util/Builders/BuildContext.cs +++ b/src/ConductorSharp.Engine/Util/Builders/BuildContext.cs @@ -11,7 +11,6 @@ public class BuildContext { public List Inputs { get; set; } public JObject Outputs { get; set; } - public WorkflowOptions WorkflowOptions { get; } = new(); public string WorkflowName { get; set; } } } diff --git a/src/ConductorSharp.Engine/Util/WorkflowOptions.cs b/src/ConductorSharp.Engine/Util/WorkflowOptions.cs deleted file mode 100644 index d76a19a1..00000000 --- a/src/ConductorSharp.Engine/Util/WorkflowOptions.cs +++ /dev/null @@ -1,79 +0,0 @@ -using System; -using System.Linq; -using System.Net.Mail; -using System.Text.RegularExpressions; - -namespace ConductorSharp.Engine.Util -{ - public class WorkflowOptions - { - private int _version = 1; - private string _description; - private string _ownerApp; - private string _ownerEmail; - private Type _failureWorkflow; - - public int Version - { - get => _version; - set - { - if (value < 0) - throw new ArgumentException("Value must be greater than zero", nameof(Version)); - _version = value; - } - } - public string Description - { - get => _description; - set - { - if (string.IsNullOrEmpty(value)) - throw new ArgumentException("Value must not be empty", nameof(Description)); - - _description = value; - } - } - - public string OwnerApp - { - get => _ownerApp; - set - { - if (string.IsNullOrEmpty(value)) - throw new ArgumentException("Value cannot be empty", nameof(OwnerApp)); - - if (value.Length > 255) - throw new ArgumentException("Value cannot be longer than 255 characters", nameof(OwnerApp)); - - _ownerApp = value; - } - } - public string OwnerEmail - { - get => _ownerEmail; - set - { - try - { - var parsedEmail = new MailAddress(value); - _ownerEmail = parsedEmail.Address; - } - catch (Exception) - { - throw new ArgumentException("Value must be a valid email address", nameof(OwnerEmail)); - } - } - } - - public Type FailureWorkflow - { - get => _failureWorkflow; - set - { - // TODO: Add a check to make sure the type is actually a workflow model - _failureWorkflow = value; - } - } - } -} diff --git a/src/ConductorSharp.Patterns/Tasks/CSharpLambdaTask.cs b/src/ConductorSharp.Patterns/Tasks/CSharpLambdaTask.cs index fc8b710d..0f483b04 100644 --- a/src/ConductorSharp.Patterns/Tasks/CSharpLambdaTask.cs +++ b/src/ConductorSharp.Patterns/Tasks/CSharpLambdaTask.cs @@ -1,5 +1,6 @@ using ConductorSharp.Client; using ConductorSharp.Engine.Builders; +using ConductorSharp.Engine.Builders.Metadata; using ConductorSharp.Engine.Exceptions; using ConductorSharp.Engine.Interface; using ConductorSharp.Engine.Util; diff --git a/src/ConductorSharp.Patterns/Tasks/ReadWorkflowTasks.cs b/src/ConductorSharp.Patterns/Tasks/ReadWorkflowTasks.cs index 8164619e..590671ea 100644 --- a/src/ConductorSharp.Patterns/Tasks/ReadWorkflowTasks.cs +++ b/src/ConductorSharp.Patterns/Tasks/ReadWorkflowTasks.cs @@ -11,6 +11,7 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; +using ConductorSharp.Engine.Builders.Metadata; namespace ConductorSharp.Patterns.Tasks { diff --git a/src/ConductorSharp.Patterns/Tasks/WaitSeconds.cs b/src/ConductorSharp.Patterns/Tasks/WaitSeconds.cs index e4b8cb20..354f1728 100644 --- a/src/ConductorSharp.Patterns/Tasks/WaitSeconds.cs +++ b/src/ConductorSharp.Patterns/Tasks/WaitSeconds.cs @@ -9,6 +9,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; +using ConductorSharp.Engine.Builders.Metadata; namespace ConductorSharp.Patterns.Tasks { diff --git a/test/ConductorSharp.Engine.Tests/Samples/Tasks/CustomerGetV1.cs b/test/ConductorSharp.Engine.Tests/Samples/Tasks/CustomerGetV1.cs index 479ead43..e1290d9f 100644 --- a/test/ConductorSharp.Engine.Tests/Samples/Tasks/CustomerGetV1.cs +++ b/test/ConductorSharp.Engine.Tests/Samples/Tasks/CustomerGetV1.cs @@ -1,4 +1,6 @@ -namespace ConductorSharp.Engine.Tests.Samples.Tasks; +using ConductorSharp.Engine.Builders.Metadata; + +namespace ConductorSharp.Engine.Tests.Samples.Tasks; public partial class CustomerGetV1Input : IRequest { diff --git a/test/ConductorSharp.Engine.Tests/Samples/Tasks/EmailPrepareV1.cs b/test/ConductorSharp.Engine.Tests/Samples/Tasks/EmailPrepareV1.cs index e5b10e9b..387ed5eb 100644 --- a/test/ConductorSharp.Engine.Tests/Samples/Tasks/EmailPrepareV1.cs +++ b/test/ConductorSharp.Engine.Tests/Samples/Tasks/EmailPrepareV1.cs @@ -1,4 +1,6 @@ -namespace ConductorSharp.Engine.Tests.Samples.Tasks; +using ConductorSharp.Engine.Builders.Metadata; + +namespace ConductorSharp.Engine.Tests.Samples.Tasks; public partial class EmailPrepareV1Input : IRequest { diff --git a/test/ConductorSharp.Engine.Tests/Samples/Tasks/NestedObjects.cs b/test/ConductorSharp.Engine.Tests/Samples/Tasks/NestedObjects.cs index 4301d5c6..f6c7700c 100644 --- a/test/ConductorSharp.Engine.Tests/Samples/Tasks/NestedObjects.cs +++ b/test/ConductorSharp.Engine.Tests/Samples/Tasks/NestedObjects.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using ConductorSharp.Engine.Builders.Metadata; namespace ConductorSharp.Engine.Tests.Samples.Tasks { diff --git a/test/ConductorSharp.Engine.Tests/Samples/Tasks/VersionSubworkflow.cs b/test/ConductorSharp.Engine.Tests/Samples/Tasks/VersionSubworkflow.cs index a4d993e8..5fcd557c 100644 --- a/test/ConductorSharp.Engine.Tests/Samples/Tasks/VersionSubworkflow.cs +++ b/test/ConductorSharp.Engine.Tests/Samples/Tasks/VersionSubworkflow.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using ConductorSharp.Engine.Builders.Metadata; namespace ConductorSharp.Engine.Tests.Samples.Tasks { diff --git a/test/ConductorSharp.Engine.Tests/Samples/Workers/GetCustomerHandler.cs b/test/ConductorSharp.Engine.Tests/Samples/Workers/GetCustomerHandler.cs index 40e8ba1b..4eb452c5 100644 --- a/test/ConductorSharp.Engine.Tests/Samples/Workers/GetCustomerHandler.cs +++ b/test/ConductorSharp.Engine.Tests/Samples/Workers/GetCustomerHandler.cs @@ -1,4 +1,5 @@ using System.ComponentModel.DataAnnotations; +using ConductorSharp.Engine.Builders.Metadata; namespace ConductorSharp.Engine.Tests.Samples.Workers; diff --git a/test/ConductorSharp.Engine.Tests/Samples/Workers/PrepareEmailHandler.cs b/test/ConductorSharp.Engine.Tests/Samples/Workers/PrepareEmailHandler.cs index 3c5a0acb..7039b55a 100644 --- a/test/ConductorSharp.Engine.Tests/Samples/Workers/PrepareEmailHandler.cs +++ b/test/ConductorSharp.Engine.Tests/Samples/Workers/PrepareEmailHandler.cs @@ -1,4 +1,6 @@ -namespace ConductorSharp.Engine.Tests.Samples.Workers; +using ConductorSharp.Engine.Builders.Metadata; + +namespace ConductorSharp.Engine.Tests.Samples.Workers; public class PrepareEmailRequest : IRequest { diff --git a/test/ConductorSharp.Engine.Tests/Samples/Workflows/CSharpLambdaWorkflow.cs b/test/ConductorSharp.Engine.Tests/Samples/Workflows/CSharpLambdaWorkflow.cs index 11b78d88..1562f207 100644 --- a/test/ConductorSharp.Engine.Tests/Samples/Workflows/CSharpLambdaWorkflow.cs +++ b/test/ConductorSharp.Engine.Tests/Samples/Workflows/CSharpLambdaWorkflow.cs @@ -1,4 +1,5 @@ -using ConductorSharp.Patterns.Builders; +using ConductorSharp.Engine.Builders.Metadata; +using ConductorSharp.Patterns.Builders; using ConductorSharp.Patterns.Model; namespace ConductorSharp.Engine.Tests.Samples.Workflows @@ -11,6 +12,7 @@ public class CSharpLambdaWorkflowInput : WorkflowInput { public class LambdaTaskInput : IRequest @@ -76,8 +78,6 @@ public override void BuildDefinition() } } ); - - _builder.SetOptions(options => options.OwnerEmail = "test@test.com"); } } } diff --git a/test/ConductorSharp.Engine.Tests/Samples/Workflows/ConditionallySendCustomerNotificationOutput.cs b/test/ConductorSharp.Engine.Tests/Samples/Workflows/ConditionallySendCustomerNotificationOutput.cs index 08dbc32f..0ea6193e 100644 --- a/test/ConductorSharp.Engine.Tests/Samples/Workflows/ConditionallySendCustomerNotificationOutput.cs +++ b/test/ConductorSharp.Engine.Tests/Samples/Workflows/ConditionallySendCustomerNotificationOutput.cs @@ -1,4 +1,6 @@ -namespace ConductorSharp.Engine.Tests.Samples.Workflows; +using ConductorSharp.Engine.Builders.Metadata; + +namespace ConductorSharp.Engine.Tests.Samples.Workflows; #region models public class ConditionallySendCustomerNotificationInput : WorkflowInput diff --git a/test/ConductorSharp.Engine.Tests/Samples/Workflows/DecisionInDecision.cs b/test/ConductorSharp.Engine.Tests/Samples/Workflows/DecisionInDecision.cs index 45328b01..e6ed58bf 100644 --- a/test/ConductorSharp.Engine.Tests/Samples/Workflows/DecisionInDecision.cs +++ b/test/ConductorSharp.Engine.Tests/Samples/Workflows/DecisionInDecision.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using ConductorSharp.Engine.Builders.Metadata; namespace ConductorSharp.Engine.Tests.Samples.Workflows { diff --git a/test/ConductorSharp.Engine.Tests/Samples/Workflows/DynamicTask.cs b/test/ConductorSharp.Engine.Tests/Samples/Workflows/DynamicTask.cs index 10db6443..e1f1a7d2 100644 --- a/test/ConductorSharp.Engine.Tests/Samples/Workflows/DynamicTask.cs +++ b/test/ConductorSharp.Engine.Tests/Samples/Workflows/DynamicTask.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using ConductorSharp.Engine.Builders.Metadata; namespace ConductorSharp.Engine.Tests.Samples.Workflows { diff --git a/test/ConductorSharp.Engine.Tests/Samples/Workflows/OptionalTaskWorkflow.cs b/test/ConductorSharp.Engine.Tests/Samples/Workflows/OptionalTaskWorkflow.cs index 414bdc4f..14567200 100644 --- a/test/ConductorSharp.Engine.Tests/Samples/Workflows/OptionalTaskWorkflow.cs +++ b/test/ConductorSharp.Engine.Tests/Samples/Workflows/OptionalTaskWorkflow.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using ConductorSharp.Engine.Builders.Metadata; namespace ConductorSharp.Engine.Tests.Samples.Workflows { diff --git a/test/ConductorSharp.Engine.Tests/Samples/Workflows/PassthroughTaskWorkflow.cs b/test/ConductorSharp.Engine.Tests/Samples/Workflows/PassthroughTaskWorkflow.cs index 6f68c331..4cdbcd97 100644 --- a/test/ConductorSharp.Engine.Tests/Samples/Workflows/PassthroughTaskWorkflow.cs +++ b/test/ConductorSharp.Engine.Tests/Samples/Workflows/PassthroughTaskWorkflow.cs @@ -56,8 +56,6 @@ public override void BuildDefinition() } } ); - - _builder.SetOptions(opts => opts.Version = 1); } } } diff --git a/test/ConductorSharp.Engine.Tests/Samples/Workflows/ScaffoldedWorkflows.cs b/test/ConductorSharp.Engine.Tests/Samples/Workflows/ScaffoldedWorkflows.cs index 21ac2b93..e0b9fc03 100644 --- a/test/ConductorSharp.Engine.Tests/Samples/Workflows/ScaffoldedWorkflows.cs +++ b/test/ConductorSharp.Engine.Tests/Samples/Workflows/ScaffoldedWorkflows.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using ConductorSharp.Engine.Builders.Metadata; namespace ConductorSharp.Engine.Tests.Samples.Workflows { diff --git a/test/ConductorSharp.Engine.Tests/Samples/Workflows/SendCustomerNotification.cs b/test/ConductorSharp.Engine.Tests/Samples/Workflows/SendCustomerNotification.cs index 3346a130..3e9434b5 100644 --- a/test/ConductorSharp.Engine.Tests/Samples/Workflows/SendCustomerNotification.cs +++ b/test/ConductorSharp.Engine.Tests/Samples/Workflows/SendCustomerNotification.cs @@ -1,4 +1,5 @@ -using ConductorSharp.Engine.Tests.Samples.Workers; +using ConductorSharp.Engine.Builders.Metadata; +using ConductorSharp.Engine.Tests.Samples.Workers; namespace ConductorSharp.Engine.Tests.Samples.Workflows; diff --git a/test/ConductorSharp.Engine.Tests/Samples/Workflows/StringAddition.cs b/test/ConductorSharp.Engine.Tests/Samples/Workflows/StringAddition.cs index da1eb6e3..69e9e284 100644 --- a/test/ConductorSharp.Engine.Tests/Samples/Workflows/StringAddition.cs +++ b/test/ConductorSharp.Engine.Tests/Samples/Workflows/StringAddition.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using ConductorSharp.Engine.Builders.Metadata; namespace ConductorSharp.Engine.Tests.Samples.Workflows { diff --git a/test/ConductorSharp.Engine.Tests/Samples/Workflows/StringInterpolation.cs b/test/ConductorSharp.Engine.Tests/Samples/Workflows/StringInterpolation.cs index d62a1d05..6f3ef532 100644 --- a/test/ConductorSharp.Engine.Tests/Samples/Workflows/StringInterpolation.cs +++ b/test/ConductorSharp.Engine.Tests/Samples/Workflows/StringInterpolation.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using ConductorSharp.Engine.Builders.Metadata; namespace ConductorSharp.Engine.Tests.Samples.Workflows { diff --git a/test/ConductorSharp.Engine.Tests/Samples/Workflows/TaskInputInitializationMemberInit.cs b/test/ConductorSharp.Engine.Tests/Samples/Workflows/TaskInputInitializationMemberInit.cs index 26a9ecf0..0f6d1cef 100644 --- a/test/ConductorSharp.Engine.Tests/Samples/Workflows/TaskInputInitializationMemberInit.cs +++ b/test/ConductorSharp.Engine.Tests/Samples/Workflows/TaskInputInitializationMemberInit.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using ConductorSharp.Engine.Builders.Metadata; namespace ConductorSharp.Engine.Tests.Samples.Workflows { diff --git a/test/ConductorSharp.Engine.Tests/Samples/Workflows/TaskInputInitializationNew.cs b/test/ConductorSharp.Engine.Tests/Samples/Workflows/TaskInputInitializationNew.cs index 5e1ff708..89ebead3 100644 --- a/test/ConductorSharp.Engine.Tests/Samples/Workflows/TaskInputInitializationNew.cs +++ b/test/ConductorSharp.Engine.Tests/Samples/Workflows/TaskInputInitializationNew.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using ConductorSharp.Engine.Builders.Metadata; namespace ConductorSharp.Engine.Tests.Samples.Workflows { From e6c262a5482509fb82029007d7995a114a43aabe Mon Sep 17 00:00:00 2001 From: "bojan.malinic" Date: Tue, 23 Jan 2024 15:10:18 +0100 Subject: [PATCH 3/6] Add missing namespaces, specify missing properties --- .../Builders/SubWorkflowTaskBuilder.cs | 1 + .../Builders/WorkflowDefinitionBuilder.cs | 6 +++--- src/ConductorSharp.Patterns/Tasks/CSharpLambdaTask.cs | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/ConductorSharp.Engine/Builders/SubWorkflowTaskBuilder.cs b/src/ConductorSharp.Engine/Builders/SubWorkflowTaskBuilder.cs index f27256cf..2fded7eb 100644 --- a/src/ConductorSharp.Engine/Builders/SubWorkflowTaskBuilder.cs +++ b/src/ConductorSharp.Engine/Builders/SubWorkflowTaskBuilder.cs @@ -3,6 +3,7 @@ using System.Linq.Expressions; using System.Reflection; using ConductorSharp.Client.Generated; +using ConductorSharp.Engine.Builders.Metadata; using ConductorSharp.Engine.Interface; using ConductorSharp.Engine.Model; using ConductorSharp.Engine.Util; diff --git a/src/ConductorSharp.Engine/Builders/WorkflowDefinitionBuilder.cs b/src/ConductorSharp.Engine/Builders/WorkflowDefinitionBuilder.cs index ebb8be2f..d47f9a62 100644 --- a/src/ConductorSharp.Engine/Builders/WorkflowDefinitionBuilder.cs +++ b/src/ConductorSharp.Engine/Builders/WorkflowDefinitionBuilder.cs @@ -4,7 +4,6 @@ using System.Linq.Expressions; using System.Reflection; using ConductorSharp.Client.Generated; -using ConductorSharp.Client.Model.Common; using ConductorSharp.Engine.Builders.Metadata; using ConductorSharp.Engine.Interface; using ConductorSharp.Engine.Util; @@ -87,10 +86,11 @@ public WorkflowDef Build() FailureWorkflow = failureWorkflow != null ? NamingUtil.DetermineRegistrationName(failureWorkflow) : null, Description = description, InputParameters = BuildContext.Inputs.ToArray(), - OutputParameters = BuildContext.Outputs, + OutputParameters = (BuildContext.Outputs ?? []).ToObject>(), OwnerApp = ownerApp, OwnerEmail = ownerEmail, - Version = version + Version = version, + SchemaVersion = 2 }; } diff --git a/src/ConductorSharp.Patterns/Tasks/CSharpLambdaTask.cs b/src/ConductorSharp.Patterns/Tasks/CSharpLambdaTask.cs index b10e0913..3cbc570c 100644 --- a/src/ConductorSharp.Patterns/Tasks/CSharpLambdaTask.cs +++ b/src/ConductorSharp.Patterns/Tasks/CSharpLambdaTask.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using ConductorSharp.Client; using ConductorSharp.Engine.Builders; +using ConductorSharp.Engine.Builders.Metadata; using ConductorSharp.Engine.Interface; using ConductorSharp.Engine.Util; using ConductorSharp.Patterns.Exceptions; From c5c117501e4c335673b380e92b76ced74ae35588 Mon Sep 17 00:00:00 2001 From: "bojan.malinic" Date: Wed, 24 Jan 2024 10:52:12 +0100 Subject: [PATCH 4/6] Add missing namespace --- .../Workflows/HandleNotificationFailure.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/ConductorSharp.Definitions/Workflows/HandleNotificationFailure.cs b/examples/ConductorSharp.Definitions/Workflows/HandleNotificationFailure.cs index 02c109e3..b231be8f 100644 --- a/examples/ConductorSharp.Definitions/Workflows/HandleNotificationFailure.cs +++ b/examples/ConductorSharp.Definitions/Workflows/HandleNotificationFailure.cs @@ -1,4 +1,5 @@ using ConductorSharp.Engine.Builders; +using ConductorSharp.Engine.Builders.Metadata; using ConductorSharp.Engine.Util; using ConductorSharp.Patterns.Tasks; using Newtonsoft.Json; From 35d6532418d707d35a1f3831f925e5284b190a0f Mon Sep 17 00:00:00 2001 From: "bojan.malinic" Date: Wed, 24 Jan 2024 12:00:31 +0100 Subject: [PATCH 5/6] Add missing namespace --- src/ConductorSharp.Toolkit/Util/TaskModelGenerator.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ConductorSharp.Toolkit/Util/TaskModelGenerator.cs b/src/ConductorSharp.Toolkit/Util/TaskModelGenerator.cs index e4b5a830..352cbae1 100644 --- a/src/ConductorSharp.Toolkit/Util/TaskModelGenerator.cs +++ b/src/ConductorSharp.Toolkit/Util/TaskModelGenerator.cs @@ -1,7 +1,7 @@ -using Microsoft.CodeAnalysis; +using System.Text; +using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; -using System.Text; namespace ConductorSharp.Toolkit.Util { @@ -50,7 +50,7 @@ public string Build() _compilationUnit = _compilationUnit.AddUsings( CreateUsings( "ConductorSharp.Engine.Model", - "ConductorSharp.Engine.Util", + "ConductorSharp.Engine.Builders.Metadata", "MediatR", "Newtonsoft.Json", "ConductorSharp.Engine.Builders" From 96bfe5d2bd744def5554e5b7aa60d56b84d16f57 Mon Sep 17 00:00:00 2001 From: "bojan.malinic" Date: Wed, 24 Jan 2024 12:16:04 +0100 Subject: [PATCH 6/6] Add test case --- .../ConductorSharp.Engine.Tests.csproj | 2 ++ .../Integration/WorkflowBuilderTests.cs | 9 +++++ .../Workflows/WorkflowMetadataWorkflow.cs | 25 ++++++++++++++ .../Workflows/WorkflowMetadataWorkflow.json | 33 +++++++++++++++++++ 4 files changed, 69 insertions(+) create mode 100644 test/ConductorSharp.Engine.Tests/Samples/Workflows/WorkflowMetadataWorkflow.cs create mode 100644 test/ConductorSharp.Engine.Tests/Samples/Workflows/WorkflowMetadataWorkflow.json diff --git a/test/ConductorSharp.Engine.Tests/ConductorSharp.Engine.Tests.csproj b/test/ConductorSharp.Engine.Tests/ConductorSharp.Engine.Tests.csproj index 0707d91e..d0279b9f 100644 --- a/test/ConductorSharp.Engine.Tests/ConductorSharp.Engine.Tests.csproj +++ b/test/ConductorSharp.Engine.Tests/ConductorSharp.Engine.Tests.csproj @@ -34,6 +34,7 @@ + @@ -67,6 +68,7 @@ + diff --git a/test/ConductorSharp.Engine.Tests/Integration/WorkflowBuilderTests.cs b/test/ConductorSharp.Engine.Tests/Integration/WorkflowBuilderTests.cs index 982559e4..98751454 100644 --- a/test/ConductorSharp.Engine.Tests/Integration/WorkflowBuilderTests.cs +++ b/test/ConductorSharp.Engine.Tests/Integration/WorkflowBuilderTests.cs @@ -244,6 +244,15 @@ public void BuilderReturnsCorrectDefinitionNonEvaluatableWorkflow() Assert.Throws(GetDefinitionFromWorkflow); } + [Fact] + public void BuilderReturnsCorrectDefinitionWorkflowMetadataWorkflow() + { + var definition = GetDefinitionFromWorkflow(); + var expectedDefinition = EmbeddedFileHelper.GetLinesFromEmbeddedFile("~/Samples/Workflows/WorkflowMetadataWorkflow.json"); + + Assert.Equal(expectedDefinition, definition); + } + private static string GetDefinitionFromWorkflow() where TWorkflow : IConfigurableWorkflow { diff --git a/test/ConductorSharp.Engine.Tests/Samples/Workflows/WorkflowMetadataWorkflow.cs b/test/ConductorSharp.Engine.Tests/Samples/Workflows/WorkflowMetadataWorkflow.cs new file mode 100644 index 00000000..8f1c9031 --- /dev/null +++ b/test/ConductorSharp.Engine.Tests/Samples/Workflows/WorkflowMetadataWorkflow.cs @@ -0,0 +1,25 @@ +using ConductorSharp.Engine.Builders.Metadata; + +namespace ConductorSharp.Engine.Tests.Samples.Workflows; + +public class WorkflowMetadataWorkflowInput : WorkflowInput { } + +public class WorkflowMetadataWorkflowOutput : WorkflowOutput { } + +[WorkflowMetadata( + OwnerEmail = "test@test.com", + Description = "This is description", + OwnerApp = "Owner", + FailureWorkflow = typeof(ConditionallySendCustomerNotification) +)] +public class WorkflowMetadataWorkflow( + WorkflowDefinitionBuilder builder +) : Workflow(builder) +{ + public CustomerGetV1 GetCustomer { get; set; } + + public override void BuildDefinition() + { + _builder.AddTask(wf => wf.GetCustomer, wf => new() { CustomerId = 1 }); + } +} diff --git a/test/ConductorSharp.Engine.Tests/Samples/Workflows/WorkflowMetadataWorkflow.json b/test/ConductorSharp.Engine.Tests/Samples/Workflows/WorkflowMetadataWorkflow.json new file mode 100644 index 00000000..3345104c --- /dev/null +++ b/test/ConductorSharp.Engine.Tests/Samples/Workflows/WorkflowMetadataWorkflow.json @@ -0,0 +1,33 @@ +{ + "ownerApp": "Owner", + "createTime": 0, + "updateTime": 0, + "name": "workflow_metadata_workflow", + "description": "This is description", + "version": 1, + "tasks": [ + { + "name": "CUSTOMER_get", + "taskReferenceName": "get_customer", + "inputParameters": { + "customer_id": 1 + }, + "type": "SIMPLE", + "startDelay": 0, + "optional": false, + "rateLimited": false, + "asyncComplete": false, + "retryCount": 0, + "workflowTaskType": "SIMPLE" + } + ], + "inputParameters": [], + "outputParameters": {}, + "failureWorkflow": "NOTIFICATION_conditionally_send_to_customer", + "schemaVersion": 2, + "restartable": false, + "workflowStatusListenerEnabled": false, + "ownerEmail": "test@test.com", + "timeoutPolicy": "TIME_OUT_WF", + "timeoutSeconds": 0 +} \ No newline at end of file