1

I am using a class named:

public class ProcessFlowPersistenceIOParticipant : PersistenceIOParticipant

It inherits from System.Activities.Persistence.PersistenceIOParticipant in the WF4 framework.

I would like to override the BeginOnLoad(..) method.

In this override I would like to intercept the deserialization of the workflow instance and inject the business entity from the entity database into the entity workflow variable.

BeginOnLoad is fired when the workflow instance is loaded from the instance store.

via: workflowApplication.Load(workflowInstanceGuid);

I can see the workflow guid inside the readwritevalues dictionary.

Find the key in readWriteValues.Keys matching namespace "urn:schemas-microsoft-com:System.Activities/4.0/properties"

Then the guid is inside:

value = readWriteValues[xName]; _workflowInstanceId = ((System.Activities.Runtime.ActivityExecutor)value).WorkflowInstanceId;

It is accessible via a debugger but not in code as ActivityExecutor is an internal class.

So is there a way to determine what workflow instance is being loaded inside BeginOnLoad?

Any tips much appreciated.

Mike

This question is similar to Access workflow id from inside BeginOnSave. However in the case of BeginOnLoad there is no activity execution context available to get the workflow instance guid.

Community
  • 1
  • 1

2 Answers2

1

If you also implement the IWorkflowInstanceExtension interface in the ProcessFlowPersistenceIOParticipant you should be able to get at the workflow ID through the WorkflowInstanceProxy in the SetInstance() function.

Maurice
  • 27,582
  • 5
  • 49
  • 62
  • The SetInstance override method on my IOParticipant class is fired after BeginOnLoad() is called. Inside SetInstance I can retrieve the workflow instance id by using instanceProxy.Id. As I am seeing BeginOnLoad being called before SetInstance there is no way to use the instance id inside BeginOnLoad. Is there any way to use this id inside BeginOnLoad to essentially replace what I load from the instance store with data retrieved from another database? I specifically want to replace the contents of a workflow variable that contains a business entity. – Mike Nooney Nov 28 '12 at 01:57
  • 1
    In that case the only way would be to explicitely promote the InstanceId property from the workflow so you get its value. – Maurice Nov 28 '12 at 06:46
  • That is definitely a useful approach. Let's say I now have access to the workflow guid inside BeginOnLoad(). I want to replace the contents of a workflow variable in the instance with entity data retrieved from another db via the workflow guid. I can see the entity in the readWriteValues dictionary. I don't see a way to replace variable contents though. – Mike Nooney Nov 29 '12 at 01:19
0
public class TaskActivity : NativeActivity
{        
    protected override void Execute(NativeActivityContext context)
    {
        context.GetExtension<RelevantDataExtensionIO>().WorkflowInstanceId = context.WorkflowInstanceId;

    }
}

public class RelevantDataExtensionIO : PersistenceIOParticipant
{
    public const string NamespaceWorkflowInstanceId = "WorkflowInstanceId";
    public Guid WorkflowInstanceId { get; set; }

    public static XNamespace Namespace
    {
        get { return XNamespace.Get("http://sample.com/RelevantDataIO"); }
    } 

    public RelevantDataExtensionIO() 
        : base(false, false)
    {           
    }

    protected override void CollectValues(out IDictionary<XName, object> readWriteValues, out IDictionary<XName, object> writeOnlyValues)
    {
        readWriteValues = new Dictionary<XName, object>();
        readWriteValues.Add(Namespace.GetName(NamespaceWorkflowInstanceId), this.WorkflowInstanceId);

        writeOnlyValues = null; 
    }

    protected override IAsyncResult BeginOnLoad(IDictionary<XName, object> readWriteValues, TimeSpan timeout, AsyncCallback callback, object state)
    {
        Guid id = this.WorkflowInstanceId;
        return base.BeginOnLoad(readWriteValues, timeout, callback, state);                       
    }     
}
André Voltolini
  • 426
  • 8
  • 14