[英]Windows Workflow: Output from CodeActivity to input on next CodeActivity
I'm trying to figure out how I can pass data from one custom CodeActivity as a result, into the next CodeActivity in the sequence as an input. 我试图找出如何将数据从一个自定义CodeActivity传递到序列中的下一个CodeActivity作为输入。
Here is the code I have so far: 这是我到目前为止的代码:
private static void DemoWorkflow()
{
var s = new Sequence()
{
DisplayName = "Sequence1",
Variables =
{
new Variable<string>
{
Name = "TestParam",
Default = "Hello"
}
},
Activities =
{
new Method1() { Text = "Test1234"},
new Method2()
}
};
var settings = new TextExpressionCompilerSettings
{
AlwaysGenerateSource = true,
ActivityName = "Sequence",
ActivityNamespace = "System.Activities.Statements",
ForImplementation = false,
Activity = s,
Language = "C#",
RootNamespace = null,
GenerateAsPartialClass = false
};
var results = new TextExpressionCompiler(settings).Compile();
if (results.HasErrors)
{
throw new Exception("Compilation failed.");
}
var compiledExpressionRoot = Activator.CreateInstance(results.ResultType,
new object[] {s}) as ICompiledExpressionRoot;
CompiledExpressionInvoker.SetCompiledExpressionRoot(s, compiledExpressionRoot);
WorkflowInvoker.Invoke(s);
}
}
public class Method1 : CodeActivity<string>
{
[RequiredArgument]
public InArgument<string> Text { get; set; }
protected override string Execute(CodeActivityContext context)
{
var inText = this.Text.Get(context);
Console.WriteLine(inText);
return "Text from Method1: " + inText;
}
}
public class Method2 : CodeActivity
{
public InArgument<string> Text { get; set; }
protected override void Execute(CodeActivityContext context)
{
var inText = this.Text.Get(context);
Console.WriteLine(inText);
}
}
I feel Method2 should print "Text from Method 1: Test1234" but it currently does not. 我觉得Method2应该打印“方法1中的文本:Test1234”,但它目前没有。
You're not binding the variable to Method1::Result
OutArgument<string>
or the Method2::Text
InArgument<string>
. 您没有将变量绑定到Method1::Result
OutArgument<string>
或InArgument<string>
Method2::Text
InArgument<string>
。 Try this setup instead: 请尝试此设置:
var v = new Variable<string>
{
Name = "TestParam",
Default = "Hello"
};
var s = new Sequence()
{
DisplayName = "Sequence1",
Variables =
{
v
},
Activities =
{
new Method1() { Text = "Test1234", Result = new OutArgument<string>(v)},
new Method2() { Text = new InArgument<string>(v) }
}
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.