locked
How to get ActivityContext in CacheMetadata RRS feed

  • Question

  • Hi,

    I would like to validate data, which are in InArgument. I found sample (BasicValidation). This sample uses CacheMetadata method, but it checks public class data. I would like to check InArguments. I found method GetAgrumentsWithReflection. This method returns Collection of RuntimeArgument. Method RuntimeArgument.Get requires ActivityContext, but I don't know from where should I get this context.

    Is this scenario possible?

     

    Tuesday, August 17, 2010 7:21 AM

Answers

  • ActivityContext only exists during runtime, during the call to Activity.Execute().

    You can look at ActivityMetadata.GetArgumentsWithReflection(), however this gets RuntimeArguments. RuntimeArguments are different from the values being passed to your InArguments.

    To get your actual InArguments and validate them, you should just directly access your InArgument.

    e.g.

    your class is

    MyCustomActivity : CodeActivity

         public InArgument<string> Argument1 { get; set; }

        protected override CacheMetadata(CodeActivityMetadata m)
        {
             base.CacheMetadata(m); // if appropriate
             if (Argument1 != null)
             { //Get value or Argument1 and validate it here.
             }
        }
    }

    Is that the scenario you were looking for?

    Tim

    • Marked as answer by Divarius Wednesday, August 18, 2010 1:27 PM
    Tuesday, August 17, 2010 5:04 PM

All replies

  • ActivityContext only exists during runtime, during the call to Activity.Execute().

    You can look at ActivityMetadata.GetArgumentsWithReflection(), however this gets RuntimeArguments. RuntimeArguments are different from the values being passed to your InArguments.

    To get your actual InArguments and validate them, you should just directly access your InArgument.

    e.g.

    your class is

    MyCustomActivity : CodeActivity

         public InArgument<string> Argument1 { get; set; }

        protected override CacheMetadata(CodeActivityMetadata m)
        {
             base.CacheMetadata(m); // if appropriate
             if (Argument1 != null)
             { //Get value or Argument1 and validate it here.
             }
        }
    }

    Is that the scenario you were looking for?

    Tim

    • Marked as answer by Divarius Wednesday, August 18, 2010 1:27 PM
    Tuesday, August 17, 2010 5:04 PM
  • Yes, thank you. I also thought about checking InArgument if it sets as a variable, but is it also possible only during runtime.

    Mateusz

    Wednesday, August 18, 2010 1:27 PM
  • I think it is possible to inspect your InArgument and see what *expression* is set on it during CacheMetadata. (But you can't figure out the value of that expression.) Maybe you can decompile the expression, but I think you are on your own there...
    Tim
    Wednesday, August 18, 2010 6:53 PM