New Posts New Posts RSS Feed: BatchInterceptor - Null Instance...
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

BatchInterceptor - Null Instance...

 Post Reply Post Reply
Author
as123 View Drop Down
Newbie
Newbie


Joined: 27-Apr-2010
Posts: 30
Post Options Post Options   Quote as123 Quote  Post ReplyReply Direct Link To This Post Topic: BatchInterceptor - Null Instance...
    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

Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post 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?
Back to Top
as123 View Drop Down
Newbie
Newbie


Joined: 27-Apr-2010
Posts: 30
Post Options Post Options   Quote as123 Quote  Post ReplyReply Direct Link To This Post Posted: 03-Jan-2011 at 6:20pm
             In the problem scenario, the verifiers were triggered by Setters (AfterSet). 
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post Posted: 03-Jan-2011 at 6:28pm
I couldn't repro this. What version are you using?
Back to Top
as123 View Drop Down
Newbie
Newbie


Joined: 27-Apr-2010
Posts: 30
Post Options Post Options   Quote as123 Quote  Post ReplyReply Direct Link To This Post 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;
            }
        }

Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post 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?
Back to Top
as123 View Drop Down
Newbie
Newbie


Joined: 27-Apr-2010
Posts: 30
Post Options Post Options   Quote as123 Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post 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;
}
Back to Top
as123 View Drop Down
Newbie
Newbie


Joined: 27-Apr-2010
Posts: 30
Post Options Post Options   Quote as123 Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down