Print Page | Close Window

BatchInterceptor - Null Instance...

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=2415
Printed Date: 16-Apr-2024 at 2:25am


Topic: BatchInterceptor - Null Instance...
Posted By: as123
Subject: BatchInterceptor - Null Instance...
Date Posted: 03-Jan-2011 at 6:04pm
        The instance being passed to VerifierBatchInterceptor delegate is always null (found while debugging) even though the verifier is having the proper Instance passed.  Is there anything I need to do to populate it? 

        I am setting the BatchInterceptor delegate method to the corresponding property in VeriferEngine, and the BatchInteceptor method is called correctly,  but only the VerifierContext is set. 

        Any idea what might be going on here?

Thanks




Replies:
Posted By: DenisK
Date Posted: 03-Jan-2011 at 6:18pm
as123;

Are you calling the verifier with VerifierEngine.Execute method or are you triggering the verifier with the property set method?


Posted By: as123
Date Posted: 03-Jan-2011 at 6:20pm
             In the problem scenario, the verifiers were triggered by Setters (AfterSet). 


Posted By: DenisK
Date Posted: 03-Jan-2011 at 6:28pm
I couldn't repro this. What version are you using?


Posted By: as123
Date Posted: 03-Jan-2011 at 10:50pm
         I am using DevForce version 6.0.7. 

        The current instance is null when verifierContext.EndOfBatch is true.  In fact, I have logic to execute only when EndOfBatch is true (which I did not notice earlier), and the current instance is not available at that point.

        I duplicated this issue in the  sample application provided by DevForce earlier. Please let me know if you need additional information.

Thanks

Sample Code:

--------------
....
_mgr.VerifierEngine.BatchInterceptor = TestBatchInterceptor;
...
-----------
...
        public static VerifierErrorContinuationMode TestBatchInterceptor(object currInstance, TriggerContext triggerContext, VerifierContext verifierContext)
        {
            if (verifierContext.EndOfBatch)
            {
                verifierContext.VerifierResults.Add(new VerifierResult(VerifierResultCode.Error,
                                                                       String.Format(
                                                                           "Accumulated a total of {0} error(s)",
                                                                           verifierContext.VerifierResults.Errors.Count)));
                return VerifierErrorContinuationMode.Stop;
            }
            else
            {
                return VerifierErrorContinuationMode.Continue;
            }
        }



Posted By: DenisK
Date Posted: 04-Jan-2011 at 1:27am
as123;

This may or may not be set to null on purpose since it's the end of batch. Could you tell me the reason why you're trying to access the instance at the end of batch and not before it?


Posted By: as123
Date Posted: 04-Jan-2011 at 9:58am
             The purpose is to populate some kind of Error Summary at the end of the Batch with some Context Information from the instance being validated. Since the context is available until the last verifier returns, I expected it to be available as the context for the last batch. Is there a reason it is cleaned up at the end of the batch? 

Thanks


Posted By: DenisK
Date Posted: 04-Jan-2011 at 12:40pm
I see. Let me find out whether this was done on purpose or not. I will file a defect report and get back to you.


Posted By: DenisK
Date Posted: 06-Jan-2011 at 2:38pm
as123;

Yes, that was done on purpose because the triggerContext and instance are already available inside the verifierContext. Here's how you can get them.

if(verifierContext.EndOfBatch) {
var verifierResult = verifierContext.VerifierResults.Last();  //I'm just using last as an example.
triggerContext = verifierResult.TriggerContext;
instance = verifierResult.TargetInstance;
}


Posted By: as123
Date Posted: 06-Jan-2011 at 2:42pm
       It is good to know that it is available through the VerifierContext at the end of the batch.
 
Thanks



Print Page | Close Window