Print Page | Close Window

How do we retrieve the VerifierResultCollection after automatic exection of Verifiers

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2009
Forum Discription: For .NET 3.5
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=1346
Printed Date: 24-Jan-2026 at 2:15pm


Topic: How do we retrieve the VerifierResultCollection after automatic exection of Verifiers
Posted By: Sinnema
Subject: How do we retrieve the VerifierResultCollection after automatic exection of Verifiers
Date Posted: 24-Jun-2009 at 8:48am
Hi,
 
We've created a test Verifier on our Contact Entity. 2 Fields are evaluated by the code below. We do see the Verifiers being executed but we can't find the VerifierResultCollection anywhere. My guess was that it should be somewhere on the VerifierEngine related to the Entity.
 
Regards,
Paul Sinnema
Diartis AG
 

[VerifierProvider]

public static IEnumerable<Verifier> GetVerifiers(Object pVerifierProviderContext)

{

List<Verifier> verifiers = new List<Verifier>();

verifiers.Add(GetValidFromVerifier());

return verifiers;

}

private static Verifier GetValidFromVerifier()

{

DelegateVerifier<Person> v = new DelegateVerifier<Person>("ValidTo must be greater then ValidFrom", ValidFromSmallerValidToCondition);

v.ExecutionModes = VerifierExecutionModes.InstanceAndOnPostsetTriggers;

v.AddTrigger(Person.ValidFromEntityProperty.Name);

v.AddTrigger(Person.ValidToEntityProperty.Name);

return v;

}

private static VerifierResult ValidFromSmallerValidToCondition(Person person, TriggerContext pTriggerContext, VerifierContext pVerifierContext)

{

VerifierResult result = null;

if (person.ValidFrom <= person.ValidTo)

{

result = new VerifierResult(VerifierResultCode.Ok);

}

else

{

result = new VerifierResult(VerifierResultCode.OkWarning);

}

return result;

}

 




Replies:
Posted By: eileenv
Date Posted: 02-Jul-2009 at 6:39pm

The VerifierResultsCollection is returned from a call to someEntity.VerifierEngine.Execute(...). For a triggered verification, the call is made implicitly in the generated property setter code.

To explicitly make this call, you can create a property interceptor method that will get executed before any property set:
 
        [BeforeSet]
        public void BeforeSetAny(IPropertyInterceptorArgs args)
        {
            var entityPropertyArgs = args as IEntityPropertySetInterceptorArgs;
            var verificationResults = this.VerifierEngine.Execute(entityPropertyArgs.Instance, entityPropertyArgs.EntityProperty.Name, entityPropertyArgs.Value);
        }
 
This method can be implemented in a Base class, in which case, it will be called for any property set.
 
Or you can implement it such that it only applies to properties on a specific type:
 
        [BeforeSet]
        public void BeforeAnyEmployeeSet(PropertyInterceptorArgs<Employee, Object> args)
        {
            var entityPropertyArgs = args as IEntityPropertySetInterceptorArgs;
            var results = this.VerifierEngine.Execute(entityPropertyArgs.Instance, entityPropertyArgs.EntityProperty.Name, entityPropertyArgs.Value);
        }
 
You can also vary the above such that the Execute is called AfterSet, depending on how your verifier is configured.
 
Review the "Property Interceptor" chapter in the Developer's Guide for more details on how to implement property interceptors.
 


Posted By: Sinnema
Date Posted: 05-Jul-2009 at 5:41am
Hi Eileen,
 
Thanks for the reply.
 
I already read about the Excecute() method. I was just wondering if the ErrorCollection could be retrieved somewhere for the Verifiers that are executed automatically by DevForce. I guess that not the case then.
 
I don't see how we can benifit from automatcally executing Verifiers if we can't get the Verifiers Result afterwards. We don't want to throw Exceptions for errors. That would limit the Verifier to 1 check and above all it is a general rule of thumb not to use Exceptions for Functional Errors.
 
In the solution, you propose, a [BeforeSet] is used. Wouldn't this approach fire Verifiers excessively. Changes to fields also fire the (automatic) Verifiers.
 
The Execute() would, of course, be fine at the moment the data is being saved. We would get all the Verifiers executed and return their result(s).
 
If we would like to use the [BeforeSet] approach, is there a way to disable the automatic verifiers of IdeaBlade?
 
Regard,
Paul Sinnema
Diartis AG


Posted By: eileenv
Date Posted: 09-Jul-2009 at 11:31am

What exactly is the scenario you have in which you would like to inspect the VerifierResultCollection? On a per-property basis or before a save?



Posted By: Sinnema
Date Posted: 10-Jul-2009 at 4:51am
Eileen,
 
Thanks for sticking with me. We probably will need both. The verifiers are automatically fired on a per-property basis. Before save we will need to verify everything. The latter is no problem because we can use the Execute() which returns the ErrorCollection to us. On a per-property basis is the issue here. Each time a property is changed, attached Verifiers are fired. The errors that come from these Verifiers also need to be displayed (and adorned on the field). We know of the automatic WPF Adorners which are shown automatically when an exception is thrown. This would however limit the verifiers. Every time an exception is thrown the other Verifiers will no longer be fired. And as I said earlier. A rule of thumb is not to use Exceptions for functional errors.
 
Regards,
Paul Sinnema
Diartis AG
 


Posted By: eileenv
Date Posted: 15-Jul-2009 at 12:03pm
Have you looked at the WPF code sample found in "Learning Resources\060_Validation\Code Samples\200WC WPF"? It shows you how to set an attribute on the binding so that the UI can handle the errors thrown by the VerifierEngine.
 
The way it works is "attributed verifiers" are automatically generated by the Object Mapper (for String and required types) to enforce database constraints. You can see the attributed verifiers in the Designer file generated by the Object Mapper. Additional verifiers can be implemented in the Developer class.
 
You would then need to set an attribute on the binding in the XAML so that the result of a verification exception thrown by a property setter will display (by default) the control in which the data item was modified encircled by a red box with an asterisk placed next to it. Hovering the mouse cursor over the asterisk will display the verification error message.


Posted By: Sinnema
Date Posted: 04-Aug-2009 at 5:13am
In our next Sprint (starting tomorrow) we will be looking into the Business Rules solutions. So we will probably take a look at the example then. For now, thanks for all your input.



Print Page | Close Window