Skip to content

Fix fluent builders #76

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public class ContainerProcessDefinitionBuilder
/// </summary>
protected virtual string? Image { get; set; }

/// <summary>
/// Gets/sets the name of the container to run
/// </summary>
protected virtual string? Name { get; set; }

/// <summary>
/// Gets/sets the command, if any, to execute on the container
/// </summary>
Expand Down Expand Up @@ -56,6 +61,14 @@ public virtual IContainerProcessDefinitionBuilder WithImage(string image)
return this;
}

/// <inheritdoc/>
public virtual IContainerProcessDefinitionBuilder WithName(string name)
{
ArgumentException.ThrowIfNullOrWhiteSpace(name);
this.Name = name;
return this;
}

/// <inheritdoc/>
public virtual IContainerProcessDefinitionBuilder WithCommand(string command)
{
Expand Down Expand Up @@ -122,6 +135,7 @@ public override ContainerProcessDefinition Build()
return new()
{
Image = this.Image,
Name = this.Name,
Command = this.Command,
Ports = this.Ports,
Volumes = this.Volumes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ public interface IContainerProcessDefinitionBuilder
/// <returns>The configured <see cref="IContainerProcessDefinitionBuilder"/></returns>
IContainerProcessDefinitionBuilder WithImage(string image);

/// <summary>
/// Configures the container to use the specified name
/// </summary>
/// <param name="name">The container's name</param>
/// <returns>The configured <see cref="IContainerProcessDefinitionBuilder"/></returns>
IContainerProcessDefinitionBuilder WithName(string name);

/// <summary>
/// Configures the command, if any, to execute on the container
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ public interface IListenerTargetDefinitionBuilder
/// <returns>A new <see cref="IEventFilterDefinitionBuilder"/></returns>
IEventFilterDefinitionBuilder One();

/// <summary>
/// Configures the task to listen to any events until the specified condition expression matches
/// </summary>
/// <param name="expression">A runtime expression that represents the condition that must match for the task to stop consuming events</param>
void Until(string expression);

/// <summary>
/// Configures the task to listen to any events until the specified events are consumed
/// </summary>
/// <param name="setup">An <see cref="Action{T}"/> used to configure the events to consume for the task to stop consuming events</param>
void Until(Action<IListenerTargetDefinitionBuilder> setup);

/// <summary>
/// Builds the configured <see cref="EventConsumptionStrategyDefinition"/>
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ public class ListenerTargetDefinitionBuilder
/// </summary>
protected IEventFilterDefinitionBuilder? SingleEvent { get; set; }

/// <summary>
/// Gets the runtime expression that represents the condition that must match for the task to stop consuming events
/// </summary>
protected string? UntilExpression { get; private set; }

/// <summary>
/// Gets the strategy used to configure the events to consume for the task to stop consuming events
/// </summary>
protected EventConsumptionStrategyDefinition? UntilEvents { get; private set; }

/// <inheritdoc/>
public virtual IEventFilterDefinitionCollectionBuilder All()
{
Expand All @@ -56,6 +66,24 @@ public virtual IEventFilterDefinitionBuilder One()
return this.SingleEvent;
}

/// <inheritdoc/>
public virtual void Until(string expression)
{
ArgumentException.ThrowIfNullOrWhiteSpace(expression);
if (this.AnyEvents == null) throw new Exception("The until clause can only be specified when the strategy is used to consume any events");
this.UntilExpression = expression;
}

/// <inheritdoc/>
public virtual void Until(Action<IListenerTargetDefinitionBuilder> setup)
{
ArgumentNullException.ThrowIfNull(setup);
if (this.AnyEvents == null) throw new Exception("The until clause can only be specified when the strategy is used to consume any events");
var builder = new ListenerTargetDefinitionBuilder();
setup(builder);
this.UntilEvents = builder.Build();
}

/// <inheritdoc/>
public virtual EventConsumptionStrategyDefinition Build()
{
Expand All @@ -64,7 +92,9 @@ public virtual EventConsumptionStrategyDefinition Build()
{
All = this.AllEvents?.Build(),
Any = this.AnyEvents?.Build(),
One = this.SingleEvent?.Build()
One = this.SingleEvent?.Build(),
UntilExpression = this.UntilExpression,
Until = this.UntilEvents
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>alpha6.2</VersionSuffix>
<VersionSuffix>alpha6.3</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionPrefix)</FileVersion>
<NeutralLanguage>en</NeutralLanguage>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>alpha6.2</VersionSuffix>
<VersionSuffix>alpha6.3</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionPrefix)</FileVersion>
<NeutralLanguage>en</NeutralLanguage>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

namespace ServerlessWorkflow.Sdk.Models.Tasks;
namespace ServerlessWorkflow.Sdk.Models;

/// <summary>
/// Represents an object used to configure branches to perform concurrently
Expand Down
2 changes: 1 addition & 1 deletion src/ServerlessWorkflow.Sdk/Models/ForLoopDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace ServerlessWorkflow.Sdk.Models;
public record ForLoopDefinition
{

/// <summary>
/// <summary>
/// Gets/sets the name of the variable that represents each element in the collection during iteration
/// </summary>
[Required]
Expand Down
2 changes: 1 addition & 1 deletion src/ServerlessWorkflow.Sdk/Models/RaiseErrorDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public virtual string? ErrorReference
}

/// <summary>
/// Gets/sets the endpoint at which to get the defined resource
/// Gets/sets the error to raise
/// </summary>
[Required]
[DataMember(Name = "error", Order = 1), JsonInclude, JsonPropertyName("error"), JsonPropertyOrder(1), YamlMember(Alias = "error", Order = 1)]
Expand Down
2 changes: 1 addition & 1 deletion src/ServerlessWorkflow.Sdk/ServerlessWorkflow.Sdk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>alpha6.2</VersionSuffix>
<VersionSuffix>alpha6.3</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionPrefix)</FileVersion>
<NeutralLanguage>en</NeutralLanguage>
Expand Down
Loading