Rehydrating instances persisted in previous execution

Hello,

My project is similar to expense reporting. Someone sends an order, it is stored into a list in memory, and then the workflow waits for an event (Reviewed). I've just added the default SQL persistence service and it works fine. I've subscrived to the idled, unloaded, persisted and loaded events and I see that once it receives the order and it starts waiting for the reviewed event, the instance is unloaded, and once the event arrives it is rehydrated and completed successfully.

What I want to do now is: say I start the host, and I receive 2 orders. One is reviewed and accepted, so its removed from the persistence database. The other isnt, so its still kept inside the DB. Then the host closes. Later, the host is re-opened and a manager opens the manager application to check not-reviewed orders. Then my idea is to look into the persistence DB, see that there is still one persisted instance and get its info to put it into my memory list, so that the manager can see it in its list of pending orders and accept/reject them.

Is there a way I can get the persisted instances and get their info (their properties, like InstanceId, Name, Amount...) so that I can put them into the memory list and so the manager can view them in the order list

Thank you very much,

Ruben



Answer this question

Rehydrating instances persisted in previous execution

  • cronholio

    I've been having a look at the persistence tables in SQL Express and I see that it has a field for the InstanceId and another one for binary data (appart from other fields). Does someone know what is exactly stored in the binary data field I'm wondering if it stores the EventArgs or not...

    Thanks,

    Ruben


  • Dave Chong

    What is inside the field is your workflow instance (in a compressed, binary serialized form). See the persistence service section in this article.

    I wouldn't want to use the workflow persistence service to store my business data for me, I'd look at moving order information into its own table.



  • ernisj

    I would also like to know that...
  • Greg Allen

    You can use the following code to enumerate through the persisted workflow instances:

    Dim objPersistenceService As SqlWorkflowPersistenceService
    objPersistenceService = objWorkflowRuntime.GetService(Of SqlWorkflowPersistenceService)()

    For Each objItem As SqlPersistenceWorkflowInstanceDescription In objPersistenceService.GetAllWorkflows()
    ...
    Next

    See for a description of the class:
    http://windowssdk.msdn.microsoft.com/en-us/library/system.workflow.runtime.hosting.sqlpersistenceworkflowinstancedescription.aspx


  • K.S.RamakrishnaPrasanna

    Thank you guys for your answers.

    I've tried Bastaan's solution with some little changes and it works fine, now I can have the instanceId of the workflows stored in the persistence DB. But I need to get the values of some properties related to that instance. For example in my manager application I show the order code (a string, not the instanceId) and a concepts field (another string), both are part of my PurchaseOrder type. Now that I have the instanceId of the workflow where the purchase order is stored, I was wondering: is it possible to do something like manually rehydrating the persisted instance, getting those properties' information and then persisting it again If so, it would be very helpful if you could give me some guidelines on how to do it.

    Thanks,

    Ruben


  • RBowdenJr

    you can query the instanceState table of the persistence db to get the instanceid.And to get more infos about your workflow, there is the tracking service.

    Serge



  • Naheem

    I was thinking that maybe that information (purchase order associated to workflow instance) doesnt get persisted. Are the EventArgs persisted Or is there any way I can persist the purchase order so when I recover the instance I can recover the purchase order associated to it too I've thought of a way, but I think its not very "nice". I could create a different database to store them, but if there's a better way of doing that it would be good to know.

    Suggestions are welcome!

    Ruben


  • Rehydrating instances persisted in previous execution