自定义 NativeActivity 以在重新托管的设计器上显示参数
我有一个带有一堆 InArguments 的自定义 NativeActivity。当客户在重新托管的设计器上编辑其工作流程时,它将始终是根活动。到目前为止,一切都很好。
问题是,虽然 InArguments 显示在 PropertyInspector 上,但没有显示“Arguments”选项卡。我理解为什么会发生这种情况,但我真的想让这个 NativeActivity 成为根 Activity,原因有多种:我可以按照自己的方式自定义它,我可以给它一个自定义设计器,等等。
我如何才能将参数属性设置为NativeActivity 以某种方式将它们显示在设计器内的“参数”选项卡上,使它们可用,并允许客户使用 InArguments 执行任何他/她想要的操作,而无需声明“'argumentName'”。它可能无法访问,因为它的保护水平”认为?
我尝试过的:
- 就像变量一样,我们可以使用 Collection{Variable} 并且设计者将其识别为活动变量所在的位置,我尝试过 Collection{Argument}。运气不好!
- 只需在 NativeActivity 中编写 InArgument 即可。它们显示在属性检查器上,但无法通过设计器在工作流程中使用。同样,它们无法解析,并且“'argumentName'未声明。由于其保护级别,它可能无法访问”。
- 使用metadata.AddArgument() 和metadata.Bind() 通过CacheMetadata() 将先前的InArguments 绑定到RuntimeArguments。没有任何运气。
我知道 ActivityBuilder 可能是解决这个问题的最佳方法。我成功地尝试了类似的方法:
ActivityBuilder builder = new ActivityBuilder();
builder.Implementation = new MyCustomNativeActivity();
DynamicActivityProperty property = new DynamicActivityProperty()
{
Name = "TestArg",
Type = typeof(InArgument<string>),
};
builder.Properties.Add(property);
Designer.Load(builder);
但这会导致错误的代码,因为我在加载设计器时必须有参数。这使我无法拥有一个将自定义活动与表单代码本身分开的库。主要是因为 ActivityBuilder 是一个密封类,很像 DynamicActivity,我认为它也可以工作。
有没有什么方法可以模拟 ActivityBuilder 行为,允许在代码时添加属性,但使用可以轻松继承和自定义的 NativeActivity?
我希望我已经说清楚了。
PS:我也看了IExecutionProperty,但我不太明白它是如何工作的,它的目的是什么以及它是否可以应用在这里。
谢谢
I've a custom NativeActivity with a bunch of InArguments. It will always be the root activity when the client is editing it's workflow on a rehosted designer. So far so good.
The problem is, although InArguments are showed on PropertyInspector, no 'Arguments' tab is showed. I understand why it happens but I really want to make this NativeActivity to be the root activity for a variety of reasons: I can customize it on my way, I can give it a custom Designer, etc.
How can I had argument properties to a NativeActivity in a way that they're showed on 'Arguments' tab within the designer making them available and allowing the client to do whatever he/she wants with the InArguments without the "'argumentName' is not declared. It may be inaccessible due to its protection level" think?
What I've tried:
- Just like variables, where we can use a Collection{Variable} and the designer recognizes it as the place where the activity variables are, I've tried Collection{Argument}. No luck!
- Simply write InArgument within NativeActivity. They're showed on Property Inspector but can't be used within the workflow through the designer. Again they cannot be resolved and"'argumentName' is not declared. It may be inaccessible due to its protection level" happens.
- Bind previous InArguments to RuntimeArguments through CacheMetadata() using metadata.AddArgument() and metadata.Bind(). No luck whatsoever.
I known that ActivityBuilder is probably the best way to solve this. I successfully tried something like:
ActivityBuilder builder = new ActivityBuilder();
builder.Implementation = new MyCustomNativeActivity();
DynamicActivityProperty property = new DynamicActivityProperty()
{
Name = "TestArg",
Type = typeof(InArgument<string>),
};
builder.Properties.Add(property);
Designer.Load(builder);
But this leads to bad code because I've to had the arguments when I'm loading the designer. This prevents me from having a library with my custom activities separated from the forms code itself. Mainly because ActivityBuilder is a sealed class, much like DynamicActivity which, I assume, would work too.
Is there any way to simulate the ActivityBuilder behaviour, that allow to add properties at codetime, but using a NativeActivity which can be easily inherited and customized?
I hope I've made myself clear.
P.S.: I also took a look at IExecutionProperty but I didn't understand well how it works, what's its purpose and if it can be applied here.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不太确定你的问题在这里。也就是说,就在昨天,我通过直接从 Activity 派生而不是使用 NativeActivity 作为工作流程的根解决了另一个问题。不确定它是否对您的情况有帮助,但它可能会起作用。
所以像这样:
注意:在记事本中输入,因此未经测试,请小心拼写错误。
Not really sure bout your problem here. That said only yesterday I solved another problem by deriving from Activity directly and not using NativeActivity for a root of the workflow. Not sure if it will help in your case but it might just do it.
So something like this:
Note: Typed in notepad so not tested and be careful with typos.
看来我的问题是已知的,并且没有计划在下一个 WF 版本中支持它。
包含说明和一些解决方法的链接:这里和此处。
It seems that my problem is known and there's no plan to support it on next WF releases.
Links with explanations and a few workarounds: here and here.