locked
can u get ExpressionText from a RuntimeArgument? RRS feed

  • Question

  • I'm wondering if it's possible to somehow retrieve the ExpressionText of a RuntimeArgument object.  I'm retrieving a collection of RuntimeArguments and then attempting to get the ExpressionText in order to set a ValidationError.

    Any ideas?  (the commented code does not work, it only works with regular Arguments, not RuntimeArguments):

        [RequiredArgument]
        public OutArgument<Patient> Patient { get; set; }
    
        protected override void CacheMetadata(NativeActivityMetadata metadata)
        {
          base.CacheMetadata(metadata);
    
          Collection<RuntimeArgument> arguments = metadata.GetArgumentsWithReflection();
          Collection<Variable> variables = metadata.GetVariablesWithReflection();
    
          foreach (RuntimeArgument arg in arguments)
          {
            if (arg.IsRequired)
            {
              string name = arg.Name;
              
              //if (arg.Expression is VisualBasicValue<T>)
              //{
              //  VisualBasicValue<T> val = arg.Expression as VisualBasicValue<T>;
    
              //  if (val != null)
              //    return val.ExpressionText;
              //}
            }
          }      
        }
    

     

    Thursday, August 12, 2010 8:46 PM

Answers

  • So you have a container activity, and within it you have child activities with required arguments that are not bound, and you want to put a different message on the parent activity other than "one or more children have errors".?

    One thing you can do, if you do not want to use RequiredArgument attribute is to check to see if the argument is bound (!= null) in your CacheMetadata override and then add the desired validation error. That answers the question of how to check required arguments inside your activity, but doesn't seem to solve the problem of the validation message that appears in the parent activity's designer though. I may be misunderstanding your question. Does any of this info help?

    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 Andrew_Zhu Friday, August 20, 2010 7:06 AM
    Thursday, August 19, 2010 2:38 PM
  • Marking some argument with [RequiredArgument] already provides such functionality, you don't need to override CachedMetadata and check it again anymore. You can reference here for more information http://msdn.microsoft.com/en-us/library/ee358733.aspx

    • Marked as answer by Andrew_Zhu Friday, August 20, 2010 7:06 AM
    Tuesday, August 17, 2010 1:40 AM

All replies

  • You need to work against the argument bound to each RuntimeArgument for such information rather than the RuntimeArgument itself. But it's you who bind the RuntimeArgument and the argument from the beginning, why don't you work against the arguments directly but with RuntimeArguments? Can I know more about your scenarios?

    Monday, August 16, 2010 8:10 AM
  • Yes, I could be missing something very obvious - I'm a little new to WF.

    If you look at my code snippet above, I'm getting the RuntimeArguments from a method called GetArgumentsWithReflection from within the CacheMetadata override.  I'm not sure of any other way to get arguments/variables from within that override for the activity. 

    Is there a more obvious or better way to get a list of context items I can iterate through in the CacheMetadata override?

    Monday, August 16, 2010 4:19 PM
  • Basically what I'm trying to do is really just check if the Required Arguments for my custom activity have been set ... from within my custom activity.  I want to check if a particular Required argument has been set with a value, and if NOT, then I want to add a ValidationError.

    Apparently the best way to add Validation errors is from the CacheMetadata override ... that's why I'm doing it that way.

    Any ideas?

    Monday, August 16, 2010 6:25 PM
  • Marking some argument with [RequiredArgument] already provides such functionality, you don't need to override CachedMetadata and check it again anymore. You can reference here for more information http://msdn.microsoft.com/en-us/library/ee358733.aspx

    • Marked as answer by Andrew_Zhu Friday, August 20, 2010 7:06 AM
    Tuesday, August 17, 2010 1:40 AM
  • I'm trying to change the validation tooltip that appears on the activity in a rehosted designer: "one or more children have errors".   That message is too generic and I want it to be more specific ... I found I can adjust the tooltip message through the CacheMetadata override.

    So - how do I check my required arguments (or can I?) from inside my activity?

    Tuesday, August 17, 2010 1:16 PM
  • So you have a container activity, and within it you have child activities with required arguments that are not bound, and you want to put a different message on the parent activity other than "one or more children have errors".?

    One thing you can do, if you do not want to use RequiredArgument attribute is to check to see if the argument is bound (!= null) in your CacheMetadata override and then add the desired validation error. That answers the question of how to check required arguments inside your activity, but doesn't seem to solve the problem of the validation message that appears in the parent activity's designer though. I may be misunderstanding your question. Does any of this info help?

    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 Andrew_Zhu Friday, August 20, 2010 7:06 AM
    Thursday, August 19, 2010 2:38 PM
  • RuntimeArgument won't work, but I think you can do this:

    protected override void CacheMetadata(NativeActivityMetadata metadata)
        {
          base.CacheMetadata(metadata);
          if (Patient != null && Patient.Expression as VisualBasicReference<Patient> != null){

    //validate  ((VisualBasicReference<Patient>)(VisualBasicReference.Expression).ExpressionText) ..

    i.e. you were on the right track with VisualBasicValue<>, except as it is an OutArgument, you should expect a VisualBasicReference<> instead.

    Tim

    Friday, August 20, 2010 7:09 AM