New Posts New Posts RSS Feed: Error count after a batch
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Error count after a batch

 Post Reply Post Reply
Author
stephenmcd1 View Drop Down
DevForce MVP
DevForce MVP


Joined: 27-Oct-2009
Location: Los Angeles, CA
Posts: 166
Post Options Post Options   Quote stephenmcd1 Quote  Post ReplyReply Direct Link To This Post Topic: Error count after a batch
    Posted: 20-May-2011 at 5:04pm
Our application tries to keep track of how many errors there are across all entities in the entity manager.  We do this via a BatchInterceptor and it seems to work well in most cases but there are a few times when the count is off.  I was able to reproduce the problem in the Silverlight Validation sample (http://drc.ideablade.com/xwiki/bin/view/Documentation/code-sample-validation-silverlight).

If I update the MainPage.xaml.cs file to add a simple batch interceptor, it demonstrates the problem.  Basically I attach a BatchInterceptor that waits until "EndOfBatch" and then loops through all the entities in the entity manager, gets all the errors for those entities and then writes the count to the message log.  Here is the code:

    void Page_Loaded(object sender, RoutedEventArgs e)
    {
        CreateEntityManager();
        PreloadVerifiers(_mgr.VerifierEngine);
        ConfigureDataForm();
        ConfigureDataGrid();
        Login();

        _mgr.VerifierEngine.BatchInterceptor = ValidationBatchCompleted;
    }

    private VerifierErrorContinuationMode ValidationBatchCompleted(object instance, TriggerContext triggercontext, VerifierContext verifiercontext)
    {
        //Skip processing if we aren't at the end of a batch
        if (!verifiercontext.EndOfBatch)
            return VerifierErrorContinuationMode.Inherit;

        //Get all errors for all entities in the enity manager
        var errors = _mgr
            //Find all entities
            .FindEntities<Entity>(EntityState.AllButDetached)
            //Grab all the errors on that entity
            .SelectMany(e => e.EntityAspect.ValidationErrors)
            //Only include ones that are errors
            .Where(vr => vr.IsError)
            .ToList();

        WriteMessage("Finished a validation batch.  There are " + errors.Count + " errors.");

        return VerifierErrorContinuationMode.Inherit;
    }

But when I run the application, clear out the first person's Last Name field and then tab off, I see an error in the UI but my batch interceptor doesn't see the error:


Then if I fix the problem by entering a last name, Dev Force notices the error (I print a message saying one error and then another batch seems to fire and the count goes back down to zero.)  But there are other cases where I've seen the count be off.

I've noticed that I can check the VerfierContext.VerifierResults that are passed to the batch interceptor and I'll have access to this error but it gets a bit awkward and annoying.  Is this a bug in DevForce that can be fixed?

Thanks,
-Stephen
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down