如何在NativeActivity中封装序列? [英] How to encapsulate a sequence in a NativeActivity?
问题描述
你好,
我试图在NativeActivity中封装一个NativeActivity序列,但是我很难将参数传递给我的子"活动.尝试了许多不同的方法,但最终以WF的所有可能例外而告终.
我写了一小段代码来说明问题所在,输出应该是
在主菜单中设置"Before TEST After"(稍后将在"TEST TEST"中进行设置(稍后,我将向此ParentActivity返回一个double值)).
任何帮助将非常!
干杯,
Hello,
I try to encapsulate a Sequence of NativeActivity''s in a NativeActivity, but I''m having trouble passing arguments to my "child" Activities. Tried a lot of different ways, just ended up with all possible exceptions of WF.
I wrote a small piece of code to illustrate the problematic, ouput should be
"Before TEST After", "TEST" being set in the main (and I will return a double as a result to this ParentActivity later).
Any help would be much appreciated!
Cheers,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities;
using System.Activities.Statements;
using Microsoft.VisualBasic.Activities;
using System.Activities.Expressions;
using System.Reflection;
namespace ConsoleApplication1
{
public class ChildActivity : NativeActivity<double>
{
public InArgument<String> MyChildInArgument { get; set; }
protected override void Execute(NativeActivityContext context)
{
String test = MyChildInArgument.Get(context);
}
}
public class ParentActivity : NativeActivity<double>
{
public InArgument<String> MyParentInArgument { get; set; }
private DynamicActivity myDynamicActivity { get; set; }
protected override void CacheMetadata(NativeActivityMetadata metadata)
{
base.CacheMetadata(metadata);
metadata.AddImplementationChild(myDynamicActivity);
}
public ParentActivity()
{
myDynamicActivity = new DynamicActivity()
{
Properties =
{
new DynamicActivityProperty
{
Name = "MyProperty1",
Type = typeof(InArgument<String>),
Value = new InArgument<String>(),
},
new DynamicActivityProperty
{
Name = "MyProperty2",
Type = typeof(String),
Value = "DEFAULT",
},
},
Implementation = () => new Sequence()
{
Variables =
{
},
Activities =
{
new WriteLine()
{
Text = "Before",
},
new ChildActivity()
{
MyChildInArgument = (InArgument<String>)this.myDynamicActivity.Properties["MyProperty1"].Value,
},
new WriteLine()
{
Text = "After",
},
},
},
};
}
protected override void Execute(NativeActivityContext context)
{
context.ScheduleActivity(myDynamicActivity);
}
}
class Program
{
static void Main(string[] args)
{
ParentActivity myTest = new ParentActivity()
{
MyParentInArgument = new InArgument<string>("TEST"),
};
WorkflowInvoker.Invoke(myTest);
}
}
}
推荐答案
毕竟,我能够这样做.不完全是我想要的,但它应该做.
希望能对某人有所帮助:
After all I was able to do it this way. Not exactly what I wanted but it should do.
Hope it will help someone:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities;
using System.Activities.Statements;
using Microsoft.VisualBasic.Activities;
using System.Activities.Expressions;
using System.Reflection;
namespace ConsoleApplication1
{
public class ChildActivity : NativeActivity<double>
{
public InArgument<String> MyChildInArgument { get; set; }
public OutArgument<String> MyChildOutArgument { get; set; }
protected override void Execute(NativeActivityContext context)
{
String test = MyChildInArgument.Get(context);
}
}
public class ParentActivity : Activity
{
public InArgument<String> MyParentInArgument { get; set; }
public OutArgument<String> MyParentOutArgument { get; set; }
protected override Func<Activity> Implementation
{
get
{
return () =>
{
Sequence seq = new Sequence
{
Activities =
{
new WriteLine()
{
Text = "Before",
},
new ChildActivity()
{
MyChildInArgument = new InArgument<String>(new VisualBasicValue<String>("MyParentInArgument")),
},
new WriteLine()
{
Text = "After",
},
new Assign
{
To = new OutArgument<string>(new VisualBasicReference<string>("MyParentOutArgument")),
Value = new InArgument<string>(new VisualBasicValue<string>("MyParentInArgument"))
},
}
};
return seq;
};
}
set
{
base.Implementation = value;
}
}
}
class Program
{
static void Main(string[] args)
{
ParentActivity myTest = new ParentActivity()
{
MyParentInArgument = new InArgument<string>("TEST"),
};
var output = WorkflowInvoker.Invoke(myTest);
}
}
}
这篇关于如何在NativeActivity中封装序列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!