Answered WF4 State Machine set next State at runtime

  • Thursday, August 02, 2012 3:50 PM
     
     

    Helo,

    I have implemented a state machine with sereral activities.

    I would like to enable the client to cancel  the execution of the flow at any time,

    and when he does that, i would like to go to an activity that generate report,

    and  finish the execution.

    What is the best way to implement that behaviour.

All Replies

  • Tuesday, August 07, 2012 3:50 AM
    Moderator
     
     

    Hi,

    Currently, the native State Machine workflow doesn't support manually set state. You'll need to configure transition to define the movement from a specified activity to report activity. If it doesn't apply to our scenario, you can control the execution of the workflow by uisng WorkflowControlClient, then call a plain WCF service to generate report on server side. Hope this information helps, thanks.


    Leo Tang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

  • Tuesday, August 07, 2012 5:30 AM
     
     

    Leo,

    Thanks for the reply.

    Is it possible to load the xaml file at run time, and add transition in code,

    from each state to the report state, before the workflowapplication run method is invoked ?

  • Tuesday, August 07, 2012 9:28 AM
     
     Answered

    Hi,

    I think you can add one inputArgument at workflow and use this to branch your transsition. When user take action to cancel the workflow you can pass this as parameter to your workflow and put condition into the transition (Statmachine transtion activity) to take differnt path which will generate report and complete the workflow.

    Declare a InArgument in workflow say (UserResponse) and user this to decide the flow of the workflow.

    Like in Transtion T1 put condition  

    UserResponse = 'Second' and in T2 transtion put Userresponse = 'Cancel' Hope this will help.

    Madhur


    MB

  • Thursday, August 09, 2012 8:59 AM
    Moderator
     
     Answered Has Code

    Hi,

    ->Is it possible to load the xaml file at run time, and add transition in code,

    ->from each state to the report state, before the workflowapplication run method is invoked ?

    Yes, you can load workflow definition into an ActivityBuilder instance, then you can inspect and modify it. For example, inspect a StateMachine workflow:

                ActivityBuilder ab = XamlServices.Load(ActivityXamlServices.CreateBuilderReader(new XamlXmlReader(@"C:\Code\WF\WFStateMachineProgram\WFStateMachineProgram\Workflow1.xaml"))) as ActivityBuilder;
    
                StateMachine sm = ab.Implementation as StateMachine;
    
                foreach (State sa in sm.States)
                {
                    Console.WriteLine(sa.DisplayName);
                    foreach (Transition ts in sa.Transitions)
                    {
                        Console.WriteLine(ts.DisplayName);
                        Console.WriteLine(ts.To.DisplayName);
                    }
                }

    Programmatically manipulate states in StateMachines

    http://social.msdn.microsoft.com/Forums/en-US/wfprerelease/thread/54ecce90-b177-4029-9656-1ee59e916a02


    Leo Tang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.