我正在尝试制作一个可以在 xaml 中重用的本机 Activity,它基本上复制了 WF3.x 中 PolicyActivity 的功能,WF3.x 是一个带有 GUI 来编辑规则的规则引擎。
我的问题是,当我调用 时WorkflowInvoker.Invoke
,它说 Model,即 is InArgument
,Null
我知道这不是因为这段代码作为一个返回 Activity 的函数工作,就像它在 Frode Nilsen 的博客中所做的那样:
Using WF 4 as a Rules Engine My问题是,我InArgument
是否从 Xaml 活动中获得了正确的信息?
public sealed class RuleSequenceAcitvity : NativeActivity<Sequence>
{
private Sequence _sequence;
InArgument<HomeIndexViewModel> Model { get; set; } //Same name as inArgument in xaml
protected override void Execute(NativeActivityContext context)
{
populateSequence();
var input = new Dictionary<string, object>();
//The following line is giving me the Null Argument Exception
var model = context.GetValue<HomeIndexViewModel>(this.Model);
input.Add("Model", model);
WorkflowInvoker.Invoke(_sequence, input);
}
private void populateSequence()
{
//get the list of rules from repository
var rules = ObjectFactory.Container.GetInstance<IRuleRepository>().Rules.ToList();
//Declare a dynamic property as the view model
var inProperty = new DynamicActivityProperty
{
Name = "Model",
Type = typeof(InArgument<HomeIndexViewModel>),
Value = Model
};
var activity = new DynamicActivity() { Properties = { inProperty } };
//Import references
Common.AddVbSetting(activity);
_sequence = new Sequence();
activity.Implementation = () => _sequence;
//Sort Descending - those added first are lowest priority
var sortedRules = rules.OrderBy(x => x.Priority).ToList();
foreach (var inRule in rules)
{
var outRule = RuleConverter.ToIfActivity(inRule);
_sequence.Activities.Add(outRule);
}
}
}
}