locked
Evaluate Multiple VisualBasicValue values dynamicly during the execution of workflow RRS feed

  • Question

  • Hi, I have an activity that requires some inputs from users and need to evaluate their values during execution. My thought is to add a VisualBasicValue activity into my activity and evaluate in the Execute method. But the problem is I don't know how to achieve this. My code is below:

    public sealed class MyActivity : NativeActivity
    {
        VisualBasicValue<object> vbExp;
    
        protected override void CacheMetadata(NativeActivityMetadata metadata)
        {
          base.CacheMetadata(metadata);
          metadata.AddImplementationChild(vbExp);
        }
    
        public MyActivity()
        {
          vbExp = new VisualBasicValue<object>();
        }
    
        protected override void Execute(NativeActivityContext context)
        {
          // Set the expression text here doesn't work for my purpose, I want to dynamicly change the code to get a value here
          vbExp.ExpressionText = "Date.Now";
          context.ScheduleActivity<object>(vbExp, this.CompletionCallback);
    
        }
    
        private void CompletionCallback(NativeActivityContext context, ActivityInstance completedInstance, object result)
        {
          string testResult = result.ToString();
        }
    }
    Anyone who has any experience doing this before? Actually I want to let user to write some code in the form of text such as <%=Date.Now%> and replace the value during the runtime. Thank you.
    Thursday, March 31, 2011 5:04 AM

Answers

  • Hello Han,

    Do variables in your workflow also need to be available to the user? Or do you just want them to do things like evaluate the mathematical expressions?

    A basic rule which prevents solution such as you proposed is that you can't change the workflow definition (definition of child activities which you do ScheduleActivity) while the workflow is executing.

    But it is legal to instead construct a new temporary Workflow (e.g. just a VisualBasicValue), and pass that to WorkflowInvoker.Invoke() (inside Execute() method).

    If you need the variables available to your expressions it becomes more complex - I think you have to be able to retrieve the variable values and pass them into the WorkflowInvoker as arguments explicitly, since your two workflows are not connected to each other in any implicit way. Also basically the only way of retrieving the variable values in the first place is to have them passed to MyActivity as arguments.
    Tim

    • Marked as answer by Andrew_Zhu Thursday, April 7, 2011 12:54 AM
    Thursday, March 31, 2011 7:03 PM