New Posts New Posts RSS Feed: Bullets on Create Entity
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Bullets on Create Entity

 Post Reply Post Reply
Author
Markh View Drop Down
Newbie
Newbie
Avatar

Joined: 14-Jun-2007
Location: Australia
Posts: 14
Post Options Post Options   Quote Markh Quote  Post ReplyReply Direct Link To This Post Topic: Bullets on Create Entity
    Posted: 27-Nov-2007 at 2:16pm
Eileen
 
Thanks.
I Now understand what the VerifierResultCache is accomplishing.
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: 27-Nov-2007 at 12:56pm
Markh,
 
There is a bug in the reference Verification Tutorial app which is causing the "_Self" property to appear in the verifier result set.
 
The VerifierResultsCache attempts to cache only those results associated with the verified object. Because verifiers can be defined in both the DataRow and developer classes, when checking if the type associated with the verifier result matches the type of the object being verified, the Type.IsAssignableFrom should be used.
 
Here is the corrected method from the VerifierResultsCache.cs:
 

    private bool UpdateVerifierResultsWithTriggerLinkedResult(VerifierResult pResult, ICollection links) {

      bool addedResult = false;

      foreach ( TriggerLink link in links ) {

        TriggerItem ti = link.TriggerItem;

        //if ( ti.Type == mCachedType ) {

        if (ti.Type.IsAssignableFrom(mCachedType)) {

          UpdateVerifierResultsEntry(ti.MemberName, pResult);

          addedResult = true;

        }

      }

      return addedResult;

    }

 
The reason why FirstName appeared erroneously under "_Self" is because the associated verifier is defined in the EmployeeDataRow class and did not satisfy the condition: if ( ti.Type == mCachedType )
 
The other 3 properties are associated with verifiers defined in the Employee developer class.
 
The corrected method should fix the problem.


Edited by eileenv - 27-Nov-2007 at 2:23pm
Back to Top
Markh View Drop Down
Newbie
Newbie
Avatar

Joined: 14-Jun-2007
Location: Australia
Posts: 14
Post Options Post Options   Quote Markh Quote  Post ReplyReply Direct Link To This Post Posted: 25-Nov-2007 at 10:27pm

Hi Eileen

 

Changing the create method stops the Visual Studio  from handling he exception.  But the bullets do not appear next to the required fields.

The VerifierResultsChache.cs class separates  the results into IDictionary<string, VerifierResultCollection>

One based on "__Self" (No Triggers Result Set) (this result set show the First Name required……)

the others based on the Column Names ()

eg

+[0]        {[__Self, IdeaBlade.Verification.VerifierResultCollection]}                System.Collections.Generic.KeyValuePair<string,IdeaBlade.Verification.VerifierResultCollection>

+[1]        {[LastName, IdeaBlade.Verification.VerifierResultCollection]}                System.Collections.Generic.KeyValuePair<string,IdeaBlade.Verification.VerifierResultCollection>

+[2]        {[BirthDate, IdeaBlade.Verification.VerifierResultCollection]}                System.Collections.Generic.KeyValuePair<string,IdeaBlade.Verification.VerifierResultCollection>

+[3]        {[HireDate, IdeaBlade.Verification.VerifierResultCollection]}                System.Collections.Generic.KeyValuePair<string,IdeaBlade.Verification.VerifierResultCollection>

 

The IdataErrorInfo retrieves the errors from the VerifierResultsCache based on the column name (Property Name)

 

Is there a reason the original results are separated into  "__Self" result set?

 

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: 20-Nov-2007 at 5:15pm

Sorry for the confusion. I see what's happening now. Passing in the String.Empty values to the required fields is triggering verification from within the Create method, causing VisualStudio to handle the exception, when in fact, we want the exception to be handled from within the UI.

A better approach might be for you to implement a Create method that does not set the required fields. This will prevent verification from being triggered during the Create. Once the employee is created, you will then want to call instance verification on the employee. Finally, you will want to refresh the data binding, causing the error bullets to display on the required fields.

Here is a sample handler for adding a new employee:

    private void BindingNavigatorAddNewItemClickHandler(object sender, EventArgs e) {
      AddNewEmployee();
    }
    private void AddNewEmployee() {
      // Commit any pending edit operations
      mEmpBindingSource.EndEdit();

      // Create a new Employee object with default property values
      Employee aEmployee = Employee.Create(mPm);
     
      // Add the new employee to the list that's feeding the form.
      mEmployees.Add(aEmployee);
      mEmpBindingSource.MoveLast();
     
      // Perform instance verification on the employee.
      mPm.VerifierEngine.Execute(aEmployee);
     
      // Stimulate the data binding to refresh (causes error bullets to display, if applicable).
      mEmpBindingSource.ResetCurrentItem();     
    }

Hope this helps.



Edited by eileenv - 20-Nov-2007 at 6:23pm
Back to Top
Markh View Drop Down
Newbie
Newbie
Avatar

Joined: 14-Jun-2007
Location: Australia
Posts: 14
Post Options Post Options   Quote Markh Quote  Post ReplyReply Direct Link To This Post Posted: 19-Nov-2007 at 9:44pm
Hi Eileen
 

Sorry I must be missing something. I am using the Verification Tutorial program. I have change the binding navigator to allow an add to the employee class.

The add is as follows

 

    public static Employee Create(PersistenceManager pPersMgr,

      String pFirstName, String pLastName, DateTime? pBirthDate)

    {

 

      Employee aEmployee = (Employee)pPersMgr.CreateEntity(typeof(Employee));

      pPersMgr.GenerateId(aEmployee, Employee.IdEntityColumn);

      aEmployee.AddToManager();

 

      aEmployee.FirstName = pFirstName;

      aEmployee.LastName = pLastName;

      aEmployee.BirthDate = pBirthDate;

 

      return aEmployee;

    }

 

pFirstName = string.Empty

pLastName = string.Empty

pBirthDate = null

 

This caused an Verifier Exception (FirstName Required).

How do I get passed the Verifier Exception allowing the bullet to display next to the field?

 

When I override the FirstName with the following

 

      [StringLengthVerifier(MinValue = 0, MaxValue = 30,

        IsRequired = true,

        ExecutionModes = VerifierExecutionModes.InstanceAndOnPostsetTriggers)]

      public override string FirstName

      {

          get

          {

              return base.FirstName;

          }

          set

          {

              base.FirstName = value;

          }

      }

 

And remove the original automatically generated verification. The bullets display and no Verifier Exception occurs on the Create method.

 

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: 16-Nov-2007 at 10:42am

In your create method, initialize the fields that are required to empty or null. This will trigger verification and hence cause the bullets to appear next to the required fields.

Back to Top
Markh View Drop Down
Newbie
Newbie
Avatar

Joined: 14-Jun-2007
Location: Australia
Posts: 14
Post Options Post Options   Quote Markh Quote  Post ReplyReply Direct Link To This Post Posted: 15-Nov-2007 at 3:02pm

Hi

 

How do you get bullets to appear next to required fields without entering any data when you create a new entity?

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down