locked
Parsing Dynamic Activity Argument Default Values RRS feed

  • Question

  • Is it possibly to access the default value of a dynamic activity's argument through the API? I would like to do this outside of the scope of execution.

    So far I've attempted to load the XAML as a DynamicActivity and access the individual DynamicActivityProperty types. In a DynamicActivityProperty, there is a Value property, but it returns a type of InArgument with actual type of the argument set as a generic. I would like to get the actual value of the InArgument, rather than InArgument<T>. I would assume this would be the actual default value of my argument.

    The code I have so far looks something like this:

          System.Activities.Activity activity = null;
          DynamicActivity dynActivity = null;
    
          // Get bytes from string .xaml
          using (Stream stream = new MemoryStream(ASCIIEncoding.Default.GetBytes(xamlString)))
          {
            activity = ActivityXamlServices.Load(stream);
          }
    
          dynActivity = activity as DynamicActivity;
    
          // Iterate through workflow arguments
          foreach (DynamicActivityProperty prop in dynActivity.Properties)
          {
            InArgument<String> inArg = prop.Value as InArgument<String>;
          }
    

    It does not look like the InArgument class provides a facility to get the default value. Please remember that this is outside of any workflow execution context.

    Any ideas?

    Thanks!

    Friday, April 8, 2011 4:47 PM

Answers

  • I think the default value is determined from InArgument<T>.Value. But that would still be an expression, not an actual value. If you want to evaluate the default value expression, you could pull the expression out and just invoke that as a workflow, it should give you a value from the Result out argument.

    Example:
        static void Main(string[] args)
        {
          var xamlReader = ActivityXamlServices.CreateBuilderReader(new XamlXmlReader(@"..\..\Workflow1.xaml"));
          ActivityBuilder builder = (ActivityBuilder)XamlServices.Load(xamlReader);
          InArgument<int> Arg1 = (InArgument<int>)builder.Properties["Argument1"].Value;
          Activity<int> Expression = Arg1.Expression;
          int result = WorkflowInvoker.Invoke(Expression);
        }
    
    Tim
    Friday, April 8, 2011 6:12 PM

All replies

  • I think the default value is determined from InArgument<T>.Value. But that would still be an expression, not an actual value. If you want to evaluate the default value expression, you could pull the expression out and just invoke that as a workflow, it should give you a value from the Result out argument.

    Example:
        static void Main(string[] args)
        {
          var xamlReader = ActivityXamlServices.CreateBuilderReader(new XamlXmlReader(@"..\..\Workflow1.xaml"));
          ActivityBuilder builder = (ActivityBuilder)XamlServices.Load(xamlReader);
          InArgument<int> Arg1 = (InArgument<int>)builder.Properties["Argument1"].Value;
          Activity<int> Expression = Arg1.Expression;
          int result = WorkflowInvoker.Invoke(Expression);
        }
    
    Tim
    Friday, April 8, 2011 6:12 PM
  • That works well enough. Thanks, Tim!
    Friday, April 8, 2011 8:16 PM