设置内部活动的参数 [英] Set arguments on inner activities

查看:97
本文介绍了设置内部活动的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们希望制作最终用户设计的工作流程。

我能够在数据库中存储一些工作流程定义,重新加载它们并使它们在服务中工作。



为了使用户能够创建工作流程,我们需要创建自己的活动。我想将非简单参数(即List< guid>,List< string>)传递给内部活动。我阅读了很多关于传递参数的文章,但我找不到符合我需求的文章,所有文章都展示了如何仅将参数传递给主工作流活动(在WorkflowInvoker.Invoke方法中使用Dictionary< string,>)。



我们有一个带有CodeActivity Activity1的库,其参数为Arg1(List< string>)。

最终用户将使用此库创建一个新的活动(例如序列)。





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);





如何用列表初始化参数? (以前的代码以'Literal'失败:Literal只支持值类型和不可变类型System.String。)





有没有将这些参数传递给内部活动的方法或将这些参数以编程方式转换为VisualBasicValue或CSharpValue以允许序列化工作流定义的方法?我们不希望每次运行工作流时都设置这些参数,我们希望将值存储在定义中。



任何帮助将不胜感激: - )



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 :-)

推荐答案

我找到的唯一方法是将序列包装到DynamicActivity中并将参数传递给WorkflowApplication(或WorkflowInvoker):



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

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...


这篇关于设置内部活动的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆