Visual Studio Development Bookmark and Share   
 index > Visual Studio Guidance Automation Toolkit > Declaratively determining if an action runs, or a item template unfolds
 

Declaratively determining if an action runs, or a item template unfolds

Is it possible to declaratively determine if an action runs, or a template unfolds?

 

I would like to be able to use a boolean argument (populated from a wizard) to decide if a common action is run or not, without resorting to code.
Is this possible?

 

Thanks

GJB  Wednesday, August 10, 2005 5:33 PM
We don't have such an attribute on any action, but you could fairly easily create your own "ConditionalAction" base class with this capability. The steps would be:

1 - Create an abstract IAction-implementing action, like "ConditionalAction".
2 - Implemement IConfigurable interface
3 - Receive and store an attribute of your choice with the condition, such as "Condition"
4 - Implementations of Execute and Undo should: a) evaluate the condition, and if true, b) call an OnExecute or OnUndo abstract method, to be implemented by derived classes.
5 - Evaluation of the condition can be achieved through a service implementation provided by the framework. The code would look like the following:

private bool ShouldExecute(string expression)
{
      ExpressionEvaluationService evaluator = new ExpressionEvaluationService();
      IDictionaryService dictservice = (IDictionaryService)
            ServiceHelper.GetService(this, typeof(IDictionaryService));
      return (bool) evaluator.Evaluate(expression, new ServiceAdapterDictionary(dictservice));
}

The evaluation service is the same one used by the ExpressionEvaluatorValueProvider, which is similar to the syntax of MSBuild properties: $(ArgumentName.APropertyMaybeOfTheArgumentValue)

If the argument is a boolean, the first segment of the expression is all you need: "$(BoolArgument)".

HTH
kzu  Tuesday, August 16, 2005 6:35 AM

If you mean to declare what to do when an action fails, then the answer is No. GAX executes all actions in a sequence and if any of them fails, it tries reversing the ones already executed.

 

I don't quite understand what you mean when you say "I would like to be able to use a boolean argument populated from a wizard". Can you describe the scenario in bit more detail? 

-- Wojtek  

WojtekKozaczynski  Monday, August 15, 2005 3:31 AM
Apols for not being clear.

For example: I have a boolean argument. It is populated by a wizard with a UI label like 'Would you like a help page generated?'.  I use common actions to generate the help page. Could i turn off my 'GenerateHelpPage' action without using code? ie is there a 'RunThisAction' parameter that takes a boolean arguement?

Thanks
GJB  Monday, August 15, 2005 7:35 AM
We don't have such an attribute on any action, but you could fairly easily create your own "ConditionalAction" base class with this capability. The steps would be:

1 - Create an abstract IAction-implementing action, like "ConditionalAction".
2 - Implemement IConfigurable interface
3 - Receive and store an attribute of your choice with the condition, such as "Condition"
4 - Implementations of Execute and Undo should: a) evaluate the condition, and if true, b) call an OnExecute or OnUndo abstract method, to be implemented by derived classes.
5 - Evaluation of the condition can be achieved through a service implementation provided by the framework. The code would look like the following:

private bool ShouldExecute(string expression)
{
      ExpressionEvaluationService evaluator = new ExpressionEvaluationService();
      IDictionaryService dictservice = (IDictionaryService)
            ServiceHelper.GetService(this, typeof(IDictionaryService));
      return (bool) evaluator.Evaluate(expression, new ServiceAdapterDictionary(dictservice));
}

The evaluation service is the same one used by the ExpressionEvaluatorValueProvider, which is similar to the syntax of MSBuild properties: $(ArgumentName.APropertyMaybeOfTheArgumentValue)

If the argument is a boolean, the first segment of the expression is all you need: "$(BoolArgument)".

HTH
kzu  Tuesday, August 16, 2005 6:35 AM

I couldn't resolve the interface IConfigurable to any library in the GAT/X, .NET, but would these two bases be an alternative?

  • Microsoft.Practices.Common.IAttributesConfigurable

  • Microsoft.Practices.RecipeFramework.ConfigurableAction

trent_m  Tuesday, December 18, 2007 6:19 PM

You can use google to search for other answers

Custom Search

More Threads

• unregister & register the guidance package
• How to store global variables/parameters?
• No "Guidance Package Manager" Link in VS-Menubar
• Slow loading Guidance Navigator
• System.TypeLoadException when starting a new project of type "Web Service Software Factory (WCF)"
• Keyref warning
• Web application Project Template
• Issue with DSL Tool
• SCSF
• How do I re-enable available guidance in a Guidance Automation solution?