Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
We would like to make workflows designed by end users.
I was able to store some workflow definitions in the database, reload them and make them work in a service.

For the user to be able to create workflows, we need to create our own activities. I would like to pass non simple arguments (ie List<guid>, List<string>) to inner activities. I read many articles about passing arguments but I was unable to find one that suits my needs, all articles show how to pass argument to main workflow activity only (using Dictionary<string,> in WorkflowInvoker.Invoke method).

We have a library with a CodeActivity Activity1 with an argument Arg1 (List<string>).
End-user will use this library to create a new Activity (a sequence for example).


Activity1 act1 = new Activity1();
act1.Arg1 = new InArgument<List<string>>(new List<string> { "a", "b", "c" });

Sequence seq = new Sequence
{
    Activities = { act1 }; 
}

// Now serialize end user workflow
Stream newStream = ...;
XamlWriter l_xamlWriter = ActivityXamlServices.CreateBuilderWriter(new XamlXmlWriter(newStream, new XamlSchemaContext()));

XamlServices.Save(l_xamlWriter, seq);


How can I initialize argument with a list ? (the former code fails with 'Literal': Literal only supports value types and the immutable type System.String).


Is there a way to pass such arguments to inner activities or a way to translate these arguments into VisualBasicValue or CSharpValue programmatically to allow to serialize workflow definitions ? We don't want to set these arguments each time we run the workflow, we want the value to be stored in the definition.

Any help would be appreciated :-)
Posted
Updated 28-Oct-15 1:46am
v3

1 solution

The only way I found was to wrap the sequence into a DynamicActivity and to pass parameters to the WorkflowApplication (or WorkflowInvoker) :

C#
Activity1 act1 = new Activity1();
act1.Arg1 = new InArgument<collection><string>>(new VisualBasicValue<collection><string>>("MyVals"));

Sequence seq = new Sequence
{
    Activities = { act1 }; 
}

DynamicActivity da = new DynamicActivity()
{
    Name = "test",
    Implementation = () => seq,
    Properties = 
             {
                 new DynamicActivityProperty()
                 {
                     Name = "MyVals",
                     Type = typeof(InArgument<collection><string>>),
                     Value = null
                 },
             }
};



WorkflowInvoker.Invoke(da, new Dictionary<string,> { { "MyVals", new Collection<string>{ "a", "b", "c" } } });</string></string></collection></string></collection></string></collection>


So much code just to pass a list...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900