|
Hi katit
I can't be sure of all of your needs. I confess to be leery of async validations and I am not as familiar with DevForce validation as I once was.
If I understand, you want to run an async validation for an entity only in a certain environment (e.g., a particular data entry screen). You don't want to do so whenever the property changes; just when the property changes in that environment.
You also want to leverage the entity's implementation of INotifyDataErrorInfo to project validation error conditions into the UI.
I think you can achieve this in a more simple way than you are proposing. In particular, I would avoid interacting with the VerifierEngine and would instead manipulate the entity's ValidationErrors collection
Following your plan, you will run your validation logic asynchronously at the ViewModel level. When the validation returns, you can update the entity's ValidationErrors collection directly. DevForce will raise OnErrorsChanged which should cause the View to update its display of the bound property.
For example - user enters serial number - you run async validation method - that method returns, indicating that the entered serial number is a duplicate - you construct a suitable DevForce VerifierResult with the message and error status - add this to the entity's ValidationErrors - that raises OnErrorsChanged - the UI displays the error - the user enters a different serial number - you run async validation method again - that method returns, indicating that the entered serial number is available - you remove the "Duplicate Serial Number" VerifierResult that you previously created from the collection [alternatively, if you don't want to remember it, you can search the collection for the custom VerifierResult of this type] - remove this VerifierResult from the entity's ValidationErrors - that raises OnErrorsChanged - the UI clears the error display
When the user leaves the screen, you have to decide manually what to do about VerifierResults that you have added. You'll also have to figure out what to do about async validation methods that have not yet returned ... both before you let the user hit save and before letting them abandon the screen (cancel).
I assume you've already worked out those details for yourself.
Here's an obvious code snippet to add/remove VRs to an entity's ValidationErrors
using IbEm = IdeaBlade.EntityModel;
using IbVal = IdeaBlade.Validation; public static void AddErrorToEntity(IbEm.IEntity entity , IbVal.VerifierResult error)
{
entity.EntityAspect.ValidationErrors.Add(error);
}
public static void RemoveErrorFromEntity(IbEm.IEntity entity, IbVal.VerifierResult error)
{
entity.EntityAspect.ValidationErrors.Remove(error);
}
I haven't tested this. I'm merely suggesting a direction for you to pursue.
Let us know how this works out.
|