none
How get InArgument from a RuntimeArgument RRS feed

  • Question

  • Hello Everyone,

         Let's say I have gathered all the RuntimeArguments in my workflow.  Now I would like to separate this list into an InArgument list and an OutArgument list.  I am slightly baffled as to how I turn a RuntimeArgument into an In or Out argument.  I could also go for a solution which goes through my workflow and creates the two lists from the beginning, but not sure how to go about that either.

    Thanks in advance,

    Bob
    Tuesday, August 4, 2009 4:48 AM

Answers

  • Bob,

    - the following code snippet is an example how to get a bound argument of the RuntimeArgument for a specific activity from the xaml:

     private Argument GetArgument(string xaml, string activityDisplayName,  string activityArgumentName)
            {
                WorkflowElement we = null;
                WorkflowDesigner wd = new WorkflowDesigner();
                object workflow = wd.DeserializeString(xaml);
                if (workflow is ActivitySchemaType)
                    we = (workflow as ActivitySchemaType).Body;
                else
                    we = workflow as WorkflowElement;
    
                if (we != null)
                {
                    var wl = we.GetChildren().FirstOrDefault(le => le.DisplayName == activityDisplayName) as WorkflowElement;
                    if (wl != null)
                    {
                        var list = wl.GetType().GetProperty("RuntimeArguments", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(wl, null) as List<RuntimeArgument>;
                        var ra = list.FirstOrDefault(e => e.Name == activityArgumentName);
                        if (ra != null)
                        {
                            Argument boundArgument = ra.GetType().GetProperty("BoundArgument", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(ra, null) as Argument ;
                            return boundArgument;
                        }
                    }
                }
                return null;
            }
    



    Note, that the RuntimeArguments and BoundArgument are internal properties, therefore we have to use a Reflection.


    Thanks

    Roman


    Roman Kiss, MVP Connected System Developer
    Tuesday, August 4, 2009 5:41 AM

All replies

  •  

    Hay,

    I guess\hope u define Runtimearguments as below.

    Protected override void OnGetArguments(IList<RuntimeArgument> arguments)
    {
      RuntimeArgument argument = new RuntimeArgument("MethodName", typeof(string),ArgumentDirection.In);
      Argument.Bind(this.MethodName, argument);
      arguments.Add(argument);
    }

    Where "MethodName" is an InArgument<String>....

    If you do show your RunTimeArugments autometcially bind with In\Out Arguments. 

    else I guess you have to extract the value from RuntimeArgument using Get function and Set into and InArgument\OutArgument using Set function that can either accept context(In case Activity is executing) or LocationEnviornment(In case of writing expression)

    Hope my words may help you out.

    let me know if you have second with this.

    Thanks.

    Regards
    Darshak Vaishnav

     

    Tuesday, August 4, 2009 5:21 AM
  • Bob,

    - the following code snippet is an example how to get a bound argument of the RuntimeArgument for a specific activity from the xaml:

     private Argument GetArgument(string xaml, string activityDisplayName,  string activityArgumentName)
            {
                WorkflowElement we = null;
                WorkflowDesigner wd = new WorkflowDesigner();
                object workflow = wd.DeserializeString(xaml);
                if (workflow is ActivitySchemaType)
                    we = (workflow as ActivitySchemaType).Body;
                else
                    we = workflow as WorkflowElement;
    
                if (we != null)
                {
                    var wl = we.GetChildren().FirstOrDefault(le => le.DisplayName == activityDisplayName) as WorkflowElement;
                    if (wl != null)
                    {
                        var list = wl.GetType().GetProperty("RuntimeArguments", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(wl, null) as List<RuntimeArgument>;
                        var ra = list.FirstOrDefault(e => e.Name == activityArgumentName);
                        if (ra != null)
                        {
                            Argument boundArgument = ra.GetType().GetProperty("BoundArgument", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(ra, null) as Argument ;
                            return boundArgument;
                        }
                    }
                }
                return null;
            }
    



    Note, that the RuntimeArguments and BoundArgument are internal properties, therefore we have to use a Reflection.


    Thanks

    Roman


    Roman Kiss, MVP Connected System Developer
    Tuesday, August 4, 2009 5:41 AM
  • Roman,

        Another perfect answer!  Thanks a million!

    Bob
    Tuesday, August 4, 2009 3:54 PM
  • Can you elaborate on what you are trying to do here?
    Monday, August 17, 2009 7:08 PM
    Moderator