Dynamically load workflow from XOML

I am trying to implement an action like InvokeWorkflow, which can dynamically load the XOML file, create an action tree from it and use it as its only child.

This will be similar to InvokeWorkflow, except that operations that are dynamically loaded are built into the main workflow (which is better from a monitoring point of view).

I saw XamlReader as a potential way to do this, but it seems to be unsuitable for loading workflows (only for UI files).

Thanks Julien

+2
source share
2 answers

Thanks a lot to Anthony.

, , . , Jon Flander CallWorkflowActivity.

, XOML, ( WF 3.5):

  • x: XOML

  • VS, XOML ( , XOML, , )

  • XOML VS ,

  • , VS 2008 , XOML...

  • ,

+1

, , , : -

XOML WorkflowMarkupSerializer, System.Workflow.ComponentModel.Serialization.

var serializer = new WorkflowMarkupSerializer();
object root = serializer.Deserialize(myXmlReader);

"" , , CompositeActivity, CompostiteActivityMarkupSerializer.

. WorkflowChanges , .

- , . : -

  • ApplyWorkflowChanges, protected .
  • , .

, , , .

, , , SequenceActivity, "InvokeWorkflow", , , .

, : -

internal interface IModifiableWorkflow
{
     void ApplyWorkflowChanges(WorkflowChanges workflowChanges);
}

: -

public class CustomSequentialActivity : SequentialWorkflowActivity, IModifiableWorkflow
{
    void IModifiableWorkflow.ApplyWorkflowChanges(WorkflowChanges workflowChanges)
    {
        base.ApplyWorkflowChanges(workflowChanges);
    }
}

Execute InvokeWorkflow: -

// Get root activity     
var root = this.Parent;
while (root.Parent != null) { root = root.Parent; }

// Create an instance of WorkflowChanges based on the root activity
var changes = new WorkflowChanges(root);

//Find the parent sequence activity in the transient workflow definition
var target = changes.TransientWorkflow.GetActivityByName(this.Parent.Name);

Activity newActivity = YourCodeToLoadActivityDetailsFromXoml();

target.Activities.Add(newActivity);

//Apply the new changes
((IModifiableWorkflow)root).ApplyWorkflowChanges(changes);

. , , .

+2

Source: https://habr.com/ru/post/1730110/


All Articles