locked
WorkflowInvoker Dynamic Type RRS feed

  • Question

  • Is it possible to use the WorkFlowInvoker on Workflow types which are defined at runtime?  In otherwords, if I for instance had a list of workflow types in string format, say in an SQL datatable could I invoke them in a foreach loop?

    If not, would it change things if they all had the same parameter signatures  (delegate maybe)?

    Tuesday, October 19, 2010 9:35 PM

Answers

  • Hi Jerry,

    Have a look at my recently article Enterprise Variables for WF4 for detail implementation. The following code snippet shows an example of dynamically invoking any expression text by WorkflowInvoker:

     

    public static dynamic Evaluation(string expressionText, string variableType)

    {

      string typeName = variableType.IndexOf(".") > 0 ? variableType : "System." + variableType;

     

      Type type = GetFullType(typeName);

     

      Type typeVB = typeof(Microsoft.VisualBasic.Activities.VisualBasicValue<>).MakeGenericType(new Type[] { type });

     

      var activity = (System.Activities.Activity)Activator.CreateInstance(typeVB, new object[] { expressionText });

     

      var setting = new VisualBasicSettings();

      setting.ImportReferences.Add(new VisualBasicImportReference { Assembly = "mscorlib", Import = "System" });

       

      // more imports

     

      VisualBasic.SetSettings(activity, setting);

     

      return WorkflowInvoker.Invoke(activity)["Result"];

    }

     

    Thanks

     

    Roman

     


    Roman Kiss, MVP Connected System Developer
    • Marked as answer by Jerry Lanp Wednesday, October 27, 2010 4:41 PM
    Tuesday, October 19, 2010 11:10 PM
  • If you just have a list of types in your database, like "MyApplication.GetCustomerWorkflow", you can get the type and then create an instance of the workflow definition, and pass that definition to WorkflowInvoker. Here is how to get an instance from a type name:

    http://en.csharp-online.net/CSharp_FAQ:_How_create_an_instance_of_a_type_using_only_its_name

    Does each workflow have a different set of input arguments? Does your application/database provide the mapping between each type and the input arguments it expects? If you need to inspect the workflow definition to see what arguments it expects, you can do it like this:

    http://social.technet.microsoft.com/wiki/contents/articles/how-to-determine-the-arguments-of-an-arbitrary-activity-wf.aspx

    Do these help? Good article Roman!

     

    Steve Danielson [Microsoft]
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm

     

    • Marked as answer by Jerry Lanp Wednesday, October 27, 2010 4:41 PM
    Wednesday, October 20, 2010 12:31 PM

All replies

  • Hi Jerry,

    Have a look at my recently article Enterprise Variables for WF4 for detail implementation. The following code snippet shows an example of dynamically invoking any expression text by WorkflowInvoker:

     

    public static dynamic Evaluation(string expressionText, string variableType)

    {

      string typeName = variableType.IndexOf(".") > 0 ? variableType : "System." + variableType;

     

      Type type = GetFullType(typeName);

     

      Type typeVB = typeof(Microsoft.VisualBasic.Activities.VisualBasicValue<>).MakeGenericType(new Type[] { type });

     

      var activity = (System.Activities.Activity)Activator.CreateInstance(typeVB, new object[] { expressionText });

     

      var setting = new VisualBasicSettings();

      setting.ImportReferences.Add(new VisualBasicImportReference { Assembly = "mscorlib", Import = "System" });

       

      // more imports

     

      VisualBasic.SetSettings(activity, setting);

     

      return WorkflowInvoker.Invoke(activity)["Result"];

    }

     

    Thanks

     

    Roman

     


    Roman Kiss, MVP Connected System Developer
    • Marked as answer by Jerry Lanp Wednesday, October 27, 2010 4:41 PM
    Tuesday, October 19, 2010 11:10 PM
  • If you just have a list of types in your database, like "MyApplication.GetCustomerWorkflow", you can get the type and then create an instance of the workflow definition, and pass that definition to WorkflowInvoker. Here is how to get an instance from a type name:

    http://en.csharp-online.net/CSharp_FAQ:_How_create_an_instance_of_a_type_using_only_its_name

    Does each workflow have a different set of input arguments? Does your application/database provide the mapping between each type and the input arguments it expects? If you need to inspect the workflow definition to see what arguments it expects, you can do it like this:

    http://social.technet.microsoft.com/wiki/contents/articles/how-to-determine-the-arguments-of-an-arbitrary-activity-wf.aspx

    Do these help? Good article Roman!

     

    Steve Danielson [Microsoft]
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm

     

    • Marked as answer by Jerry Lanp Wednesday, October 27, 2010 4:41 PM
    Wednesday, October 20, 2010 12:31 PM
  • Thanks guys,

    Good info.

    Wednesday, October 27, 2010 4:42 PM