Print Page | Close Window

Instance Verification

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce Classic
Forum Discription: For .NET 2.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=249
Printed Date: 11-Jun-2026 at 12:23pm


Topic: Instance Verification
Posted By: Darren
Subject: Instance Verification
Date Posted: 16-Jul-2007 at 9:07am

Just now i have implemeted custom property verfication into my developer classes.

For example i have implemented custom verifiers on the Username and Password, Forename , Surname and Age.
 
This works fine when the user tries to leave the field blank and they get the error icon appearing to the right of the textbox.
 
But when they add a new user, the fields are all blank at this point and they can save a blank record without verification firing.
 
I know i have to add something into the save event to trigger the verification. The question is what do i add into that event.
 
I have looked at the code from the tutorial , but i got lost in c# code.
 
Any pointers would much appreciated.
 
Thanks
 
 



Replies:
Posted By: eileenv
Date Posted: 17-Jul-2007 at 12:19pm
In your Saving event handler, you can iterate through the list of entities and call instance verification on each entity. If errors are found you may want want to collect the error descriptions and throw an exception.
 
For example:
 
    protected virtual void SavingHandler(object sender, EntitySavingEventArgs e) {
      VerifyEntities(e.Entities);
    }
 
     private void VerifyEntities(IList<Entity> pEntities) {
      foreach ( Entity anEntity in pEntities ) {
        VerifierResultCollection results;
        results = aPm.VerifierEngine.Execute(pEntity);
        if ( !results.AreOk ) {
          // do something, e.g. get error descriptions and throw exception
        }
      }
    }
 
 


Posted By: Darren
Date Posted: 18-Jul-2007 at 3:07am

Thank you eileenv,

got it working before you posted , but thanks anyway.
My code is very similar to your snippet you posted.
 
Cheers


Posted By: owais,zahid
Date Posted: 22-Aug-2007 at 7:33am

Yes, the above snippet works well. But we can do one more thing here. Suppose in a situation where you have many verifiers and you don't want all of them to be invoke. We can selectively invoke the verifiers that we need. By:

result = persistenceManager.VerifierEngine.Execute(code, EntityPropertyDescriptors.APBankCode.Code.PropertyPath);
 
 



Print Page | Close Window