1

我正在尝试重新托管设计器,但每次我将工作流程添加到设计器时:

_workflowDesigner = new WorkflowDesigner();
// added to UI here
Properties.Content = _workflowDesigner.PropertyInspectorView;
_workflowDesigner.Load(myWorkflowInstance);

myWorkflowInstance在引用程序集中定义的工作流在哪里。我已经完成了Register注册默认活动元数据的魔法:

new DesignerMetadata().Register();

我已经注册了我所有的自定义 NativeActivity:

public static void Register(IEnumerable<Type> activityTypes)
{            
    // activityTypes are all my custom NativeActivities
    // and all workflows (root of System.Activities.Activity)
    var builder = new AttributeTableBuilder();
    var attrGroups =
        from x in activityTypes
        from y in x.GetCustomAttributes(true).OfType<Attribute>()
        group y by x into g 
        select g;

    foreach (var typeGroup in attrGroups)
        builder.AddCustomAttributes(typeGroup.Key, typeGroup.ToArray());
    MetadataStore.AddAttributeTable(builder.CreateTable());
}

然而,当我在设计器中加载一个活动时,这就是我得到的:

为什么ru崩溃了?

我在这里想念什么?


我认为这与这些工作流已编译并且仅存在于 Activity 的 Implementation 属性中的事实有关...

4

2 回答 2

1

您的工作流实例是否包含在 ActivityBuilder 中?

更新:在这里进一步调查我发现了一种使用 WorkflowInspectionServices 的可能解决方案。

var activities = WorkflowInspectionServices.GetActivities(new DemoWorkflow());
designer.Load(activities.First());
于 2010-11-16T07:51:10.580 回答
0

一点反光和反​​思使我陷入了这种讽刺:

var impl = (typeof(DemoWorkflow)
            .GetProperty("Implementation", 
                         BindingFlags.NonPublic | BindingFlags.Instance)
            .GetValue(new DemoWorkflow(), new object[0]) 
            as System.Func<System.Activities.Activity>)();

_workflowDesigner.Load(new ActivityBuilder { Implementation = impl });

是这个吗?严重地?知道是我写的,我感到恶心。肮脏的。

我在反射器中注意到,工作流的 xaml 实际上嵌入在资源流的程序集中: Reflector 中的流

但所有使用它的尝试都失败了。

var target = typeof(DemoWorkflow);
var name = string.Format("{0}.obj.Debug.{1}.g.xaml", 
                         target.Assembly.GetName().Name, 
                         target.Name);
Activity derp = null;
using (var stream = assy.Assembly.GetManifestResourceStream(name))
{
    var reader = new XamlXmlReader(stream, new XamlSchemaContext());
    // throws an exception as the property Implementation is in the xaml;
    // it is protected and cannot be set, so deserialization blows up
    derp = ActivityXamlServices.Load(reader);
}

在这一点上,我没有看到任何其他选择。

于 2010-11-16T21:00:37.197 回答