我有一个自定义活动的列表(用代码编写,C#),每个活动都是从NativeActivity派生的,现在我在foreach循环的帮助下将所有这些活动添加到一个序列中。现在的问题是,如果我需要从一个活动中获得一些价值,并将其传递给另一个活动,我应该如何继续。
比方说,activity1将字符串属性值设置为“某个文件名”(让图像文件路径),并根据它旁边的活动,在for循环的帮助下将其添加到序列中,将其作为输入来翻转该图像。
获取文件的逻辑在activity1的Execute方法中是thre,在activity2的Execute方法中翻转图像的逻辑也是如此。
提前感谢
发布于 2011-09-16 11:31:42
var workflow = new Sequence();
Variable<Dictionary<string,object>> variable = new Variable<Dictionary<string,object>>
{
Name = "SharedData"
};
workflow.Variables.Add(variable);
foreach (MyCustomActivity activity in mAddedActivities)
{
workflow.Activities.Add(activity);
}
WorkflowInvoker invoker = new WorkflowInvoker(workflow);
invoker.Invoke();
这就是我在实际实现中所做的,不需要任何入参数/出参数,变量“共享数据”足以跨活动保存数据。
现在,在覆盖的代码活动"Execute“方法中的每个活动级别,您必须使用此代码摘录来获取输入/获取此工作流变量"SharedData”的值。
WorkflowDataContext dataContext = context.DataContext;
PropertyDescriptorCollection propertyDescriptorCollection = dataContext.GetProperties();
foreach (PropertyDescriptor propertyDesc in propertyDescriptorCollection)
{
if (propertyDesc.Name == "SharedData")
{
myData = propertyDesc.GetValue(dataContext) as Dictionary<string, object>;
if (myData == null) //this to check if its the initial(1st) activity.
myData = new Dictionary<string, object>();
//I'm adding here an additional value into the workflow variable
//its having signature same as that of workflow variable
//dictionary's key as what it is and value as an object
//which user can cast to what actually one wants.
myData.Add("islogonrequired", Boolean.TrueString);
//here I'm fetching some value, as i entered it in my previous activity.
string filePath = myData["filepath"].ToString();
propertyDesc.SetValue(dataContext, myData);
break;
}
}
希望这能对其他人有所帮助。感谢其他所有人的帮助和支持。
发布于 2011-09-13 20:10:20
var workflow = new Sequence();
//Variable<string> v = new Variable<string>
//{
// Name = "str"
//};
//workflow.Variables.Add(v);
Dictionary<string, object> abc = new Dictionary<string, object>();
abc.Add("thedata", "myValue");
foreach (MyCustomActivity activity in mAddedActivities)
{
if (activity.ActivityResult == null)
activity.ActivityResult = new Dictionary<string, object>();
activity.ActivityResult = abc;
workflow.Activities.Add(activity);
//new Assign<string>
// {
// To = v,
// Value = activity.ActivityResult["thedata"].ToString()
// };
}
WorkflowInvoker invoker = new WorkflowInvoker(workflow);
invoker.Invoke();
这就是我所做的,不知何故,它起作用了。我不确定它是不是正确的方法,给我一些建议!!,这里的ActivityResult是通过某种接口成员在各种添加的活动之间共享的属性。
https://stackoverflow.com/questions/7370306
复制