New Posts New Posts RSS Feed: How do we retrieve the VerifierResultCollection after automatic exection of Verifiers
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

How do we retrieve the VerifierResultCollection after automatic exection of Verifiers

 Post Reply Post Reply
Author
Sinnema View Drop Down
Groupie
Groupie
Avatar

Joined: 23-Mar-2009
Location: Muri AG, EU, CH
Posts: 54
Post Options Post Options   Quote Sinnema Quote  Post ReplyReply Direct Link To This Post Topic: How do we retrieve the VerifierResultCollection after automatic exection of Verifiers
    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;

}

 

Back to Top
eileenv View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 15-Jun-2007
Location: United States
Posts: 68
Post Options Post Options   Quote eileenv Quote  Post ReplyReply Direct Link To This Post 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.
 
Back to Top
Sinnema View Drop Down
Groupie
Groupie
Avatar

Joined: 23-Mar-2009
Location: Muri AG, EU, CH
Posts: 54
Post Options Post Options   Quote Sinnema Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
eileenv View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 15-Jun-2007
Location: United States
Posts: 68
Post Options Post Options   Quote eileenv Quote  Post ReplyReply Direct Link To This Post 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?

Back to Top
Sinnema View Drop Down
Groupie
Groupie
Avatar

Joined: 23-Mar-2009
Location: Muri AG, EU, CH
Posts: 54
Post Options Post Options   Quote Sinnema Quote  Post ReplyReply Direct Link To This Post 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
 


Edited by Sinnema - 10-Jul-2009 at 4:52am
Back to Top
eileenv View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 15-Jun-2007
Location: United States
Posts: 68
Post Options Post Options   Quote eileenv Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
Sinnema View Drop Down
Groupie
Groupie
Avatar

Joined: 23-Mar-2009
Location: Muri AG, EU, CH
Posts: 54
Post Options Post Options   Quote Sinnema Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down