Pregunta

Estoy intentando rehost el diseñador, pero cada vez que una palmada a un flujo de trabajo en el diseñador:

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

donde myWorkflowInstance es un flujo de trabajo se definen en un conjunto de referencia. He hecho lo Register mágica para conseguir la actividad por defecto metadatos registrado:

new DesignerMetadata().Register();

y me he registrado todas mis NativeActivities personalizados:

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());
}

Sin embargo, cuando me carga una actividad en la que el diseñador esto es lo que me sale:

¿Por qué se derrumbó R u?

¿Qué me estoy perdiendo aquí?


Estoy pensando que tiene algo que ver con el hecho de que estos flujos de trabajo se compilan y sólo existe dentro de la propiedad implementación de una actividad ...

¿Fue útil?

Solución

Es el ejemplo de flujo de trabajo envuelto en una ActivityBuilder?

Actualización: Investigando un poco más aquí he encontrado una posible solución utilizando los WorkflowInspectionServices.

var activities = WorkflowInspectionServices.GetActivities(new DemoWorkflow());
designer.Load(activities.First());

Otros consejos

Un poco de reflector y la reflexión me ha llevado a esta farsa:

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 });

¿Es esto? ¿Seriamente? Me siento mal sabiendo que escribí eso. Sucia.

Me di cuenta de que el reflector xaml para el flujo de trabajo en realidad está integrado en el conjunto en una secuencia de recursos: la corriente en Reflector

pero todos los intentos de utilizar este fracasado.

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);
}

No veo ninguna otra opción en este punto.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top