你好,有人谁我从来没有见过,只是碰巧分享我的IP。
要么你正在使用的活动的DLL不是最新的,要么工作流定义已经过时,不能保存你认为它所做的事情。或者完全不同。
我已经精简了你的代码并将其压缩成一个示例项目。我们想在这里看到它:
public sealed class AnTrigger : NativeActivity<bool>
{
public bool ResultToSet { get; set; }
protected override void Execute(NativeActivityContext context)
{
Result.Set(context, ResultToSet);
}
}
很简单,不是吗?这是计算此条件的主机,如果返回true,则运行单个子活动。注意,我正在Create方法中构造活动,因此不必创建编辑器。
public sealed class AnTriggerHost : NativeActivity, IActivityTemplateFactory
{
public ActivityFunc<bool> Condition { get; set; }
public ActivityAction Child { get; set; }
protected override void Execute(NativeActivityContext context)
{
context.ScheduleFunc(Condition, OnConditionComplete);
}
private void OnConditionComplete(
NativeActivityContext context,
ActivityInstance completedInstance,
bool result)
{
if (result)
context.ScheduleAction(Child);
}
Activity IActivityTemplateFactory.Create(System.Windows.DependencyObject target)
{
// so I don't have to create UI for these, here's a couple samples
// seq is the first child and will run as the first AnTrigger is configured to return true
// so the first trigger evals to true and the first child runs, which
var seq = new Sequence
{
DisplayName = "Chief Runs After First Trigger Evals True"
};
// prints this message to the console and
seq.Activities.Add(new WriteLine { Text = "See this? It worked." });
// runs this second trigger host, which
seq.Activities.Add(
new AnTriggerHost
{
DisplayName = "This is the SECOND host",
Condition = new ActivityFunc<bool>
{
// will NOT be triggered, so you will never see
Handler = new AnTrigger
{
ResultToSet = false,
DisplayName = "I return false guize"
}
},
Child = new ActivityAction
{
// this activity write to the console.
Handler = new WriteLine
{
Text = "you won't see me"
}
}
});
return new AnTriggerHost
{
DisplayName = "This is the FIRST host",
Condition = new ActivityFunc<bool>
{
Handler = new AnTrigger
{
ResultToSet = true,
DisplayName = "I return true!"
}
},
Child = new ActivityAction
{
Handler = seq
}
};
}
}
将这两个放到工作流控制台应用程序中,并将AnTriggerHost放到工作流中。设置几个断点,看着它飞起来。以下是工作流xaml:
<local:AnTriggerHost DisplayName="This is the FIRST host" >
<local:AnTriggerHost.Child>
<ActivityAction>
<Sequence DisplayName="Chief Runs After First Trigger Evals True">
<WriteLine Text="See this? It worked." />
<local:AnTriggerHost DisplayName="This is the SECOND host">
<local:AnTriggerHost.Child>
<ActivityAction>
<WriteLine Text="you won't see me" />
</ActivityAction>
</local:AnTriggerHost.Child>
<local:AnTriggerHost.Condition>
<ActivityFunc x:TypeArguments="x:Boolean">
<local:AnTrigger DisplayName="I return false guize" ResultToSet="False" />
</ActivityFunc>
</local:AnTriggerHost.Condition>
</local:AnTriggerHost>
</Sequence>
</ActivityAction>
</local:AnTriggerHost.Child>
<local:AnTriggerHost.Condition>
<ActivityFunc x:TypeArguments="x:Boolean">
<local:AnTrigger DisplayName="I return true!" ResultToSet="True" />
</ActivityFunc>
</local:AnTriggerHost.Condition>
</local:AnTriggerHost>
供将来参考。。。当这种情况发生在我身上,原因是我
Result
在IActivityTemplateFactory的Create方法中
Activity IActivityTemplateFactory.Create(System.Windows.DependencyObject target)
{
return new Child
{
InputText = new InArgument<string>(
new VisualBasicValue<string>(Parent.InputTextVariable)),
// the following demonstrates what NOT to do in the Create method.
// this BREAKS your ActivityFunc, which will ALWAYS return default(T)
// DO NOT SET Result AT ANY TIME OR IN ANY PLACE
// BEGIN ERROR
Result = new OutArgument<string>()
// END ERROR
};
}
<!--If you see ActivityFunc.Result in your workflow, DELETE IT -->
<ActivityFunc.Result>
<DelegateOutArgument x:TypeArguments="x:String" />
</ActivityFunc.Result>