/// <summary> /// Modify the workflow definition in code /// </summary> /// <param name="workflow"></param> private static void ModifyWorkflow(Activity workflow) { //locate the activity to change WriteMessageActivity wmActivity = workflow.GetActivityByName("writeMessagePositive") as WriteMessageActivity; if (wmActivity != null) { //change the message wmActivity.Message = "This is a revised message"; } }
/// <summary> /// Create a workflow by hand /// </summary> /// <returns></returns> private static Activity CreateWorkflowInCode() { MarkupOnlyBaseWorkflow workflow = null; //create the root workflow object workflow = new MarkupOnlyBaseWorkflow(); workflow.Name = "CodedWorkflow"; //create an IfElseActivity IfElseActivity ifElse = new IfElseActivity("ifElseActivity1"); // //Add the left side branch to the IfElseActivity // IfElseBranchActivity branch = new IfElseBranchActivity("ifElseBranchActivity1"); #if COMPILE_RULES_WORKFLOW //add a rule condition to the branch RuleConditionReference ruleCondition = new RuleConditionReference(); ruleCondition.ConditionName = "IsNumberPositive"; branch.Condition = ruleCondition; #else //add a condition to the branch CodeCondition condition = new CodeCondition(); //bind the ConditionEvent to the IsNumberPositive member ActivityBind bind = new ActivityBind( "CodedWorkflow", "IsNumberPositive"); condition.SetBinding(CodeCondition.ConditionEvent, bind); branch.Condition = condition; #endif //add a custom WriteMessageActivity to the branch WriteMessageActivity writeMessage = new WriteMessageActivity(); writeMessage.Name = "writeMessagePositive"; writeMessage.Message = "The number is positive"; branch.Activities.Add(writeMessage); //add the branch to the IfElseActivity ifElse.Activities.Add(branch); // //add the right side branch to the IfElseActivity // branch = new IfElseBranchActivity("ifElseBranchActivity2"); //add a custom WriteMessageActivity to the branch writeMessage = new WriteMessageActivity(); writeMessage.Name = "writeMessageNotPositive"; writeMessage.Message = "The number is NOT positive"; branch.Activities.Add(writeMessage); //add the branch to the IfElseActivity ifElse.Activities.Add(branch); //add the IfElseActivity to the workflow workflow.Activities.Add(ifElse); #if COMPILE_WORKFLOW //provide a class name for the new workflow workflow.SetValue(WorkflowMarkupSerializer.XClassProperty, "ProWF.MyNewWorkflowClass"); #endif return(workflow); }