Print Page | Close Window

VerifierEngine.Execute

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=1772
Printed Date: 21-Apr-2026 at 8:53am


Topic: VerifierEngine.Execute
Posted By: orcities
Subject: VerifierEngine.Execute
Date Posted: 29-Apr-2010 at 8:22am

When I run VerifierEngine.Execute(Entity x) the verifier collection returned doesn't include my custom verifiers. I can step through and watch them run but the are not in the collection returned. It only includes the foreign key constraint verifiers. Why is that? I have tried using the generic EntityModel.Entity and the specific Contact when running execute.

Implementation on DXGrid Row or Column Verification:
 
VerifierEngine engine = new VerifierEngine();

engine.DiscoverVerifiers(e.Row.GetType());

VerifierResultCollection verifiers = engine.Execute((EntityModel.Entity)e.Row);

 

public partial class Contact : BaseEntity

  {

      #region Verification

 

      /// <summary>

      /// Implement IVerifierProvider interface to give DevForce the verifiers in use at run time.

      /// </summary>

      public class VerifierProvider : IVerifierProvider

      {

 

          #region IVerifierProvider Members

 

          public IEnumerable<Verifier> GetVerifiers(object verifierProviderContext)

          {

 

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

              verifiers.Add(FirstNameRequiredVerifier());

              verifiers.Add(LastNameRequiredVerifier());

              return verifiers;

          }

 

          #endregion

      }

 

      private static Verifier FirstNameRequiredVerifier()

      {

          Verifier v = new DelegateVerifier<Contact>("First Name is required", MinLengthCondition);

          v.VerifierOptions.ExecutionModes = VerifierExecutionModes.OnBeforeSetTriggers;

          v.AddTrigger(new TriggerItem(typeof(Contact), Contact.PropertyMetadata.FirstName.Name));

          return v;

      }

 

      private static Verifier LastNameRequiredVerifier()

      {

          Verifier v = new DelegateVerifier<Contact>("Last Name is required", MinLengthCondition);

          v.VerifierOptions.ExecutionModes = VerifierExecutionModes.OnBeforeSetTriggers;

          v.AddTrigger(new TriggerItem(typeof(Contact), Contact.PropertyMetadata.LastName.Name));

          return v;

      }

 

      private static VerifierResult MinLengthCondition(Contact pContact, TriggerContext triggerContext, VerifierContext verifierContext)

      {

          bool pass = (triggerContext.ProposedValue != null && triggerContext.ProposedValue.ToString().Length > 0);

          return new VerifierResult(pass);

      }

      #endregion

 

  }

 

 




Replies:
Posted By: orcities
Date Posted: 29-Apr-2010 at 8:45am
One thing of note:
I am testing the same thing ont he LiteHausWPF app with Verification and I get the same result. I check the verifiers after the ValidateEmployee method is ran. If I add my verifier that basically just checks that firstname has some value in it, it does not show up in the collection. The other verifiers defined by IdeaBlade are present. If I comment your verifiers out, like:
 

//verifiers.Add(GetHireDateRangeVerifier());

//verifiers.Add(new BirthDateRangeVerifier());

//verifiers.Add(GetBornBeforeHiredVerifier());

//verifiers.Add(GetPhoneNumberVerifier(Employee.PropertyMetadata.HomePhone));

 
The collection changes and removes thos but still doesn't show mine.

public class VerifierProvider : IVerifierProvider {

 

      #region IVerifierProvider Members

 

      public IEnumerable<Verifier> GetVerifiers(object verifierProviderContext) {

 

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

 

        //verifiers.Add(GetHireDateRangeVerifier());

        //verifiers.Add(new BirthDateRangeVerifier());

        //verifiers.Add(GetBornBeforeHiredVerifier());

        //verifiers.Add(GetPhoneNumberVerifier(Employee.PropertyMetadata.HomePhone));

        verifiers.Add(NameRequiredVerifier());

        return verifiers;

      }

 

      #endregion

    }

 

    private static Verifier NameRequiredVerifier()

    {

        Verifier v  = new DelegateVerifier<Employee>("First Name is required", MinLengthCondition);

        v.AddTrigger(new TriggerItem(typeof(Employee), Employee.PropertyMetadata.FirstName.Name));

        v.VerifierOptions.ExecutionModes = VerifierExecutionModes.OnBeforeSetTriggers;

        return v;

    }

 

    private static VerifierResult MinLengthCondition(Employee address, TriggerContext triggerContext, VerifierContext verifierContext)

    {

        return new VerifierResult(triggerContext.ProposedValue.ToString().Length > 0);

    }…..}

 



Posted By: orcities
Date Posted: 29-Apr-2010 at 8:59am
I have also tried:

[DataAnnot.MetadataType(typeof(EmployeeMetaData))]

  public partial class Employee {

….}

 

public class EmployeeMetaData

{

      [IdeaBlade.Validation.StringLengthVerifier(MinValue=1, ErrorMessage="First Name is required.", IncludeMaxEndpoint=true)]

      public static string FirstName;

}

 
 
And the verifier shows up in the list but has an error and when the data is invalid it still says ok. 
 
[14] = Ok; '((IdeaBlade.Validation.VerifierResult)((new System.Collections.Generic.Mscorlib_CollectionDebugView<IdeaBlade.Validation.VerifierResult>(verifiers)).Items[14])).Message' threw an exception of type 'System.InvalidOperationException'; {DomainModel.Employee}
 
I do atleast get something when the validation should throw an error. It throws an error at the Employee.FirstName property but doesn't propogate up to the UI. It stops execution.


Posted By: orcities
Date Posted: 29-Apr-2010 at 9:58am
I can now get it to show in the list. If I use the MetaData I have to include all values available if I use the the Verifier approach I had create a new StringLenthVerifier class.
 
The problem now is that when the value fails it fails at the assignment of the new value in the property and never sets the object or propogates to the UI. The other validates propogate to the UI. What is the difference.
 
To duplcate add the following Employee.cs or add the above MetaData (they both have the same result):
...

verifiers.Add(new MinLenghtStringVerifier());

private class MinLenghtStringVerifier : StringLengthVerifier

    {

        public MinLenghtStringVerifier()

            : base(typeof(Employee), Employee.PropertyMetadata.FirstName.Name, true, 1, 30)

        {

            this.VerifierArgs.ErrorMessageInfo.ErrorMessage = "First Name can not be blank!";

        }

    }
 
After adding run the UI and remove the value from the FirstName field of the Employee.


Posted By: ting
Date Posted: 29-Apr-2010 at 5:59pm
You can set the VerifierOptions to control the behavior of the validation (e.g. how to raise errors and whether to set the value on an validation failure).  Specifically, take a look at:
VerifierOptions.ErrorNotificationMode
VerifierOptions.ShouldExitOnBeforeSetError
 
You can set these globally using EntityManager.VerifierEngine.DefaultVerifierOptions or on the verifier directly.
 
The Litehaus application was a straight port and still needs to have its verification updated for DevForce 2010.  Sorry about the confusion.
 


Posted By: orcities
Date Posted: 03-May-2010 at 7:26am
I tried settings:

MinLenghtStringVerifier min = new MinLenghtStringVerifier();
min.VerifierOptions.ShouldExitOnBeforeSetError = true;

and

min.VerifierOptions.ErrorNotificationMode = VerifierErrorNotificationMode.Notify;

And the result is the same the error is not caught and is thrown at the property. The other property verifiers for you Employee verification example do not do this. What am I doing wrong or missing?


Posted By: ting
Date Posted: 03-May-2010 at 6:09pm

Hi - sorry, I don't quite understand what behavior you're looking for.  Do you want an exception thrown?  If so, you should set VerifierOptions.ErrorNotificationMode to VerifierErrorNotificationMode.ThrowException or VerifierErrorNotificationMode.NotifyAndThrowException.

 


Posted By: orcities
Date Posted: 03-May-2010 at 6:21pm
No it is throwing an error at the property. I want it to go to the ui.


Posted By: WardBell
Date Posted: 04-May-2010 at 4:30pm
Hang in there, orcities. Cavalry is coming. Suspect some misunderstandings. Will get to you as soon as I slay current dragon.


Posted By: orcities
Date Posted: 04-May-2010 at 4:37pm
I am using DevEx. I ended up Implement their IDXDataErrorInfo in my BaseEntity and hooking it to the Verifiers to get the appropriate error when needed.
 
The problem I am having now is when I do entity.EntityAspect.Delete() it throws an error:
http://www.ideablade.com/forum/forum_posts.asp?TID=1780 - http://www.ideablade.com/forum/forum_posts.asp?TID=1780


Posted By: WardBell
Date Posted: 04-May-2010 at 7:38pm
Ah ... you got ahead of me. That was what I was going to recommend that you do.
 
I remain convinced that we need to give a far better tutorial on this process ... so that others don't have to suffer as you have. We'll do it.
 
Following you to the post on Delete.


Posted By: orcities
Date Posted: 05-May-2010 at 1:24pm

One last question, I hope. If I want to execute the verifiers for an entity and its child entities how would I set that up.

 
Example.
 
I am displaying a list of ContactAddresses which displays editable date for the contactinfo and the address info. When I execute the verifiers it only shows the contactaddress verifiers not the address verifiers. The address verifiers don't run until the entity is being saved.


Posted By: WardBell
Date Posted: 05-May-2010 at 2:13pm
You are correct that, when you initiate validation of an entity, DevForce does not propagate valdations to the related entities.
 
If we did that automatically, we could not ensure that the cascade of validations completed in reasonable time or were even appropriate.
 
At save, we validate the entities that are in the save list; that's why you see validation of address at that time. Note that we'll validate only the addresses in the save list; other unchanged addresses might have become invalid as a consequence of other changes to the graph. We can't know.
 
Accordingly, you ... the developer ... are responsible for instigating validations across a graph.
 
You can add cross-object verification rules to your list of parent entity verifiers. For example, you can write an object verifier that itself validates its child entities. You can also write child verifiers that look to or provoke validations of the parent.
 
This may satisfy your need to automatically validate addresses when you validate the parent ContactAddresses (or something upstream of that).
 
I believe we discuss cross-object validation in the documentation; it's been a feature since at least 2005.



Print Page | Close Window