Geoff Bennett
Geoff Bennett

Reputation: 2553

Determining Workflow Arguments at Runtime Prior to Execution

Is there a way to determine the arguments to a workflow prior to executing it?

I've developed an application that rehosts the designer, so end users can develop their own workflows. In doing this, a user is able to add their own arguments to the workflow.

I'm looking for a way to inspect the workflow prior to execution, and try to resolve the arguments. I've looked at the WorkflowInspectionServices class, but I can't seem to ask for a particular type of item from it.

Ideally, I'd like to construct a workflow from metadata stored in the database using something like:

var workflow = ActivityXamlServices.Load(new XamlReader(new StringReader(xamlText)));
var metadata = SomeUnknownMagicClass.Inspect(workflow);

var inputs = new Dictionary<string, object>()
forreach(var argument in metadata.Arguments)
{
    inputs.Add(argument.Name, MagicArgumentResolver.Resolve(argument.Name));
}

WorflowInvoker.Invoke(workflow, inputs);

I might be missing something, but WorkflowInspectionServices doesn't seem to do this. It has the method CacheMetadata which sounds promising when you read the MSDN docs, but basically turns up with nothing.

Thanks for any help.

Upvotes: 2

Views: 392

Answers (1)

Joao
Joao

Reputation: 7486

I guess that when you talk about metadata stored in the database you're referring to the XAML from the designer.

You can load that XAML as a DynamicActivity like this:

using (var reader = new StringReader(xamlString))
{
    var dynActivity = 
        ActivityXamlServices.Load(reader) as DynamicActivity;
}

Then you've access to all its arguments through DynamicActivity.Properties.

Upvotes: 2

Related Questions