Skip to content

ActivityName as expression. It solves #542 issue. (Activity Compound Key) #838

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 5 commits into from
Aug 27, 2022
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
10 changes: 10 additions & 0 deletions src/WorkflowCore/Interface/IWorkflowModifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,5 +152,15 @@ IContainerStepBuilder<TData, Recur, TStepBody> Recur(Expression<Func<TData, Time
IStepBuilder<TData, Activity> Activity(string activityName, Expression<Func<TData, object>> parameters = null,
Expression<Func<TData, DateTime>> effectiveDate = null, Expression<Func<TData, bool>> cancelCondition = null);

/// <summary>
/// Wait here until an external activity is complete
/// </summary>
/// <param name="activityName">The name used to identify the activity to wait for</param>
/// <param name="parameters">The data to pass the external activity worker</param>
/// <param name="effectiveDate">Listen for events as of this effective date</param>
/// <param name="cancelCondition">A conditon that when true will cancel this WaitFor</param>
/// <returns></returns>
IStepBuilder<TData, Activity> Activity(Expression<Func<TData, IStepExecutionContext, string>> activityName, Expression<Func<TData, object>> parameters = null,
Expression<Func<TData, DateTime>> effectiveDate = null, Expression<Func<TData, bool>> cancelCondition = null);
}
}
19 changes: 19 additions & 0 deletions src/WorkflowCore/Services/FluentBuilders/StepBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -522,5 +522,24 @@ public IStepBuilder<TData, Activity> Activity(string activityName, Expression<Fu
Step.Outcomes.Add(new ValueOutcome { NextStep = newStep.Id });
return stepBuilder;
}

public IStepBuilder<TData, Activity> Activity(Expression<Func<TData, IStepExecutionContext, string>> activityName, Expression<Func<TData, object>> parameters = null, Expression<Func<TData, DateTime>> effectiveDate = null, Expression<Func<TData, bool>> cancelCondition = null)
{
var newStep = new WorkflowStep<Activity>();
newStep.CancelCondition = cancelCondition;

WorkflowBuilder.AddStep(newStep);
var stepBuilder = new StepBuilder<TData, Activity>(WorkflowBuilder, newStep);
stepBuilder.Input((step) => step.ActivityName, activityName);

if (parameters != null)
stepBuilder.Input((step) => step.Parameters, parameters);

if (effectiveDate != null)
stepBuilder.Input((step) => step.EffectiveDate, effectiveDate);

Step.Outcomes.Add(new ValueOutcome { NextStep = newStep.Id });
return stepBuilder;
}
}
}
4 changes: 4 additions & 0 deletions src/WorkflowCore/Services/FluentBuilders/WorkflowBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,10 @@ public IStepBuilder<TData, Activity> Activity(string activityName, Expression<Fu
{
return Start().Activity(activityName, parameters, effectiveDate, cancelCondition);
}
public IStepBuilder<TData, Activity> Activity(Expression<Func<TData, IStepExecutionContext, string>> activityName, Expression<Func<TData, object>> parameters = null, Expression<Func<TData, DateTime>> effectiveDate = null, Expression<Func<TData, bool>> cancelCondition = null)
{
return Start().Activity(activityName, parameters, effectiveDate, cancelCondition);
}

private IStepBuilder<TData, InlineStepBody> Start()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using System;
using WorkflowCore.Interface;
using WorkflowCore.Models;
using Xunit;
using FluentAssertions;
using System.Linq;
using WorkflowCore.Testing;

namespace WorkflowCore.IntegrationTests.Scenarios
{
/*
* DISABLED for bug on build pipeline
public class ActivityScenario2 : WorkflowTest<ActivityScenario2.ActivityWorkflow, ActivityScenario2.MyDataClass>
{
public class MyDataClass
{
public object ActivityInput { get; set; }
public object ActivityOutput { get; set; }
}

public class ActivityInput
{
public string Value1 { get; set; }
public int Value2 { get; set; }
}

public class ActivityOutput
{
public string Value1 { get; set; }
public int Value2 { get; set; }
}

public class ActivityWorkflow : IWorkflow<MyDataClass>
{
public string Id => "ActivityWorkflow";
public int Version => 1;
public void Build(IWorkflowBuilder<MyDataClass> builder)
{
builder
.StartWith(context => ExecutionResult.Next())
.Activity((_, context) => "act-1-" + context.Workflow.Id, data => data.ActivityInput)
.Output(data => data.ActivityOutput, step => step.Result);
}
}

public ActivityScenario2()
{
Setup();
}

[Fact]
public void Scenario()
{
// compound key
var workflowId = StartWorkflow(new MyDataClass { ActivityInput = new ActivityInput { Value1 = "a", Value2 = 1 } });
var activity = Host.GetPendingActivity("act-1-" + workflowId, "worker1", TimeSpan.FromSeconds(30)).Result;

if (activity != null)
{
var actInput = (ActivityInput)activity.Parameters;
Host.SubmitActivitySuccess(activity.Token, new ActivityOutput
{
Value1 = actInput.Value1 + "1",
Value2 = actInput.Value2 + 1
});
}

WaitForWorkflowToComplete(workflowId, TimeSpan.FromSeconds(30));
GetStatus(workflowId).Should().Be(WorkflowStatus.Complete);
UnhandledStepErrors.Count.Should().Be(0);
GetData(workflowId).ActivityOutput.Should().BeOfType<ActivityOutput>();
var outData = (GetData(workflowId).ActivityOutput as ActivityOutput);
outData.Value1.Should().Be("a1");
outData.Value2.Should().Be(2);
}
}*/

}