locked
How to access the Worflow arguments and variables in custom activity RRS feed

  • Question

  • HI,

    I am creating the custom activity inheriting nativ activity ,where i need to get and set values of the workflow arguments and variables in execute method.

    Please suggest me how i can achieve this.

     

    Thanks,

    Naveen G


    Regards, Naveen G
    Tuesday, June 21, 2011 2:40 PM

Answers

  • To access the value of an InArgument, try this

    // If you don't want the Result argument remove <string> and use NativeActivity
    public sealed class NativeActivity1 : NativeActivity<string>
    {
      public NativeActivity1()
      {
        MyVariable = new Variable<string>();
      }
    
      // Define an activity input argument of type string
      public InArgument<string> Text { get; set; }
    
      public Variable<string> MyVariable { get; set; }
    
      protected override void CacheMetadata(NativeActivityMetadata metadata)
      {
        base.CacheMetadata(metadata);
        metadata.AddImplementationVariable(MyVariable);
      }
    
      protected override void Execute(NativeActivityContext context)
      {
        // Obtain the runtime value of the Text input argument
        string text = context.GetValue(this.Text);
    
        // Do something with a variable
        MyVariable.Set(context, "Test");
    
        Result.Set(context, string.Format("The text is {0}", text));
      }
    }
    


    Sr. Program Manager, AppFabric Development Platform (WF/WCF) http://blogs.msdn.com/rjacobs http://www.twitter.com/ronljacobs
    • Marked as answer by Andrew_Zhu Tuesday, June 28, 2011 2:12 AM
    Friday, June 24, 2011 5:54 PM

All replies

  • Please some one provide the solution, its urgent requirement for me

    Thanks,

    Naveen G


    Regards, Naveen G
    Thursday, June 23, 2011 11:34 AM
  • To access the value of an InArgument, try this

    // If you don't want the Result argument remove <string> and use NativeActivity
    public sealed class NativeActivity1 : NativeActivity<string>
    {
      public NativeActivity1()
      {
        MyVariable = new Variable<string>();
      }
    
      // Define an activity input argument of type string
      public InArgument<string> Text { get; set; }
    
      public Variable<string> MyVariable { get; set; }
    
      protected override void CacheMetadata(NativeActivityMetadata metadata)
      {
        base.CacheMetadata(metadata);
        metadata.AddImplementationVariable(MyVariable);
      }
    
      protected override void Execute(NativeActivityContext context)
      {
        // Obtain the runtime value of the Text input argument
        string text = context.GetValue(this.Text);
    
        // Do something with a variable
        MyVariable.Set(context, "Test");
    
        Result.Set(context, string.Format("The text is {0}", text));
      }
    }
    


    Sr. Program Manager, AppFabric Development Platform (WF/WCF) http://blogs.msdn.com/rjacobs http://www.twitter.com/ronljacobs
    • Marked as answer by Andrew_Zhu Tuesday, June 28, 2011 2:12 AM
    Friday, June 24, 2011 5:54 PM