alvaroval

Hi,
I have implemented some rules in my project, in order to catch some incorrect params changed by the user.
My problem is that i can't throw exceptions in my rules because they always reach the code, never display a messagebox like in the "dsl tools" model, so i display a custom messagebox instead.
How can i avoid this
Thanks.


Re: Visual Studio Extensibility [DSL Tools] Throwing exceptions in rules

alvaroval

Hi again,
For example, this is one of my rules (verifies if the name of a NamedElement is correct):

Code Block

[RuleOn(typeof(NamedElement), FireTime = TimeToFire.LocalCommit)]
internal sealed class NamedElementChangeRule : ChangeRule
{
public override void ElementPropertyChanged(ElementPropertyChangedEventArgs e)
{
NamedElement ne = e.ModelElement as NamedElement;
if (e.DomainProperty.DisplayName.Equals("Name"))
{
if (!correctName(e.NewValue.ToString()))
{
throw new InvalidOperationException();
}
base.ElementPropertyChanged(e);
}
}
}


When i change the name of a NamedElement and is incorrect, it throws and exception but it reach the class and display the exception in the code of the model project class, it doesn't display a messagebox with the exception in the debugging project.
Am i doing anything wrong or i have to configure something
Thanks




Re: Visual Studio Extensibility [DSL Tools] Throwing exceptions in rules

Edward Bakker

Hi,

Did you try to change the "Name" property from within the propertygrid If I am correct, it should popup a error form in that case. This form doesn't appear when you change the property (name in this case) in the shape itself.

Did you also have a look at validations This is another option to validate userinput. In some cases this is a bit more userfriendly (but that depends on the situation!). All validation errors appear in the Visual Studio Error window. If you are interested in validation you might want to have a look at this topic on MSDN.

Hope this helps in finding the right mix between using rules and validations.

Edward





Re: Visual Studio Extensibility [DSL Tools] Throwing exceptions in rules

alvaroval

Hi,

Thanks, but i have the same problem if i change the property from within the propertygrid. The box with the error appears sometimes, but the plenty of times the exception reach the code (in the same case).




Re: Visual Studio Extensibility [DSL Tools] Throwing exceptions in rules

DuncanP - MSFT

Does this still happen if you start the debugging project with Ctrl+F5 ("Start without Debugging")

If you do end up in the code for target designer, can you F5 past it and if so what do you see

Duncan