在设计时在复合 WF4 活动中设置内部属性 [英] Setting internal properties in composite WF4 Activities at design time
问题描述
我想创建一个复合 Windows 工作流活动(在 .NET 4 下),其中包含一个预定义的 ReceiveAndSendReply 活动.一些属性是预定义的,但其他属性(特别是 ServiceContractName)需要在设计器中设置.
I want to create a composite Windows Workflow Activity (under .NET 4) that contains a predefined ReceiveAndSendReply Activity. Some of the properties are predefined, but others (particularly ServiceContractName) need to be set in the designer.
我可以将其实现为活动模板(与实现 ReceiveAndSendReply 的方式相同),但我宁愿不这样做.如果我稍后更改模板,则必须手动更新所有以前创建的工作流程.模板还允许其他开发人员更改应该修复的属性.
I could implement this as an Activity Template (the same way ReceiveAndSendReply is implemented), but would rather not. If I later change the template, I'd have to update all previously created workflows manually. A template would also permit other developers to change properties that should be fixed.
有没有办法从 Xaml 活动中做到这一点?我还没有找到将 Argument 值分配给嵌入活动的属性的方法.如果没有,你会建议什么技术?
Is there a way to do this from a Xaml Activity? I have not found a way to assign an Argument value to a property of an embedded Activity. If not, what technique would you suggest?
推荐答案
我没有使用复合 XAML 活动完成此操作,并且在尝试时遇到一些错误,但通过 NativeActivity 执行此操作没有问题.请参阅下面的示例代码.
I haven't done this using a composite XAML activity and am getting some errors when I try but doing so through a NativeActivity is no problem. See the example code below.
public class MyReceiveAndSendReply : NativeActivity
{
private Receive _receive;
private SendReply _sendReply;
public string ServiceContractName { get; set; }
public string OperationName { get; set; }
protected override bool CanInduceIdle
{
get { return true; }
}
protected override void CacheMetadata(NativeActivityMetadata metadata)
{
_receive = _receive ?? new Receive();
_sendReply = _sendReply ?? new SendReply();
_receive.CanCreateInstance = true;
metadata.AddImplementationChild(_receive);
metadata.AddImplementationChild(_sendReply);
_receive.ServiceContractName = ServiceContractName;
_receive.OperationName = OperationName;
var args = new ReceiveParametersContent();
args.Parameters["firstName"] = new OutArgument<string>();
_receive.Content = args;
_sendReply.Request = _receive;
var results = new SendParametersContent();
results.Parameters["greeting"] = new InArgument<string>("Hello there");
_sendReply.Content = results;
base.CacheMetadata(metadata);
}
protected override void Execute(NativeActivityContext context)
{
context.ScheduleActivity(_receive, ReceiveCompleted);
}
private void ReceiveCompleted(NativeActivityContext context, ActivityInstance completedInstance)
{
context.ScheduleActivity(_sendReply);
}
}
这篇关于在设计时在复合 WF4 活动中设置内部属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!