Variable<TaskDataOutput> var = new Variable<TaskDataOutput>();
string INPUT = "Test Data Input";
Start start = new Start();
End end = new End
{
Exit = new System.Activities.Statements.WriteLine
{
Text = new InArgument(Finished)
}
};
Task<TaskDataInput, TaskDataOutput> task1 = new Task<TaskDataInput, TaskDataOutput>
{
TaskDataIn = new InArgument<TaskDataInput>((env) => new TaskDataInput { Data = INPUT }),
TaskDataOut = new OutArgument<TaskDataOutput>(var),
Exit = new System.Activities.Statements.WriteLine
{
Text = new InArgument<string>((env) => var.Get(env).Data)
}
};
start.Transitions.Add(new Transition
{
Target = task1
});
task1.Transitions.Add(new Transition
{
Target = end
});
Swimlane swimlane = new Swimlane
{
Activities = { start, task1, end },
};
Process process = new Process
{
Swimlanes = { swimlane },
Variables = { var }
};
string message = "there we go";
List<TaskDataOutput> outputs = new List<TaskDataOutput>
{
new TaskDataOutput { Data = message },
};
List<Tuple<HumanTask, TaskDataInput>> inputs = new List<Tuple<HumanTask, TaskDataInput>>();
ProcessHelper.RunInApplication<TaskDataInput, TaskDataOutput>(process, inputs, outputs);
...
public class TaskDataInput
{
public string Data { get; set; }
}
public class TaskDataOutput
{
public string Data { get; set; }
}
...
static string[] RunInApplication<T1, T2>(Process process, IList<Tuple<HumanTask, T1>> inputTasks, IList<T2> outputObjects)
{
MemoryWorkflowInstanceStore store = new MemoryWorkflowInstanceStore();
using (System.IO.StringWriter writer = new System.IO.StringWriter())
{
Console.SetOut(writer);
AutoResetEvent applicationUnloaded = new AutoResetEvent(false);
WorkflowApplication application = new WorkflowApplication(process);
Guid id = application.Id;
application.InstanceStore = store;
application.Extensions.Add(new BusinessProcessExtension());
application.PersistableIdle = (e) => { return PersistableIdleAction.Unload; };
application.Unloaded = e => applicationUnloaded.Set();
application.Run();
applicationUnloaded.WaitOne();
ITaskRepository repository = TaskRepositoryFactory.Create(TaskRepositoryType.Memory);
for (int i = 0; i < outputObjects.Count; i++)
{
IList<HumanTask> humanTasks = repository.GetAllTasksFor(id);
inputTasks.Add(Tuple.Create(
humanTasks[0],
PersistanceHelper.Deserialize<T1>(humanTasks[0].Content.Value)));
application = new WorkflowApplication(process);
application.InstanceStore = store;
application.Extensions.Add(new BusinessProcessExtension());
application.PersistableIdle = (e) => { return PersistableIdleAction.Unload; };
application.Unloaded = e => applicationUnloaded.Set();
application.Load(id);
application.ResumeBookmark(humanTasks[0].Id.ToString(),
new TaskOutcome
{
Action = TaskAction.Submit,
Content = PersistanceHelper.Serialize<T2>(outputObjects[i])
});
applicationUnloaded.Reset();
applicationUnloaded.WaitOne();
}
return writer.ToString().Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
}
}