CodeSmith Community
Your Code. Your Way. Faster!

Processors and Terminating Execution

Latest post 02-22-2007 9:45 AM by skbach. 2 replies.
  • 02-21-2007 3:47 PM

    • skbach
    • Top 75 Contributor
    • Joined on 01-18-2007
    • Vancouver, British Columbia
    • Posts 58
    • Points 1,470

    Processors and Terminating Execution

    Out of curiosity,

    What's the best approach for having the 2nd or 3rd Processor in an Execution list terminate or not execute, based on the results of the first processor?

    for example:

    ProcessorList.Add((new ShipmentInventoryValidator(iItem)));
    ProcessorList.Add((new ShipmentInventoryAccountAdjustment(iItem)));

    ServiceResult result = this.Execute();

    if(result.HasErrors) doSomething; 

    Now, I don't want the 2nd processor to execute in the list if the first processor (validator) failed?  But I'm not sure how to accomplish this in a best practice manner within the framework...

    Thanks.

     

    Scott Klarenbach PointyHat Software www.pointyhat.ca _______________________________________ To iterate is human; to recurse, divine
    • Post Points: 35
  • 02-22-2007 2:36 AM In reply to

    • swin
    • Top 10 Contributor
    • Joined on 06-14-2006
    • London, UK
    • Posts 922
    • Points 34,710

    Re: Processors and Terminating Execution

    Hi Scott,

    This is quite simple to do - just use the Execute overload that takes a boolean to decide whether to "abortIfFailure" i.e.

    ServiceResult result = this.Execute( true );


    This causes the execute method to check the ProcessorResult "Result" property to see if it is false i.e there is no result (this can be set manually otherwise it will be determined by whether your process has any broken rules).  If the "Result" is false and you specified "abortIfFailure = true" then the loop that processes the ProcessorList will exit - thus any further processors will not be executed.

    For the actual code that does this see the ServiceBaseCore.generated.cs for the Execute method and the GenericProcessorResult.cs for the"Result" property.

    hth

    swin 

    ------------------------------------------------- Member of the .NetTiers team -------------------------------------------------
    • Post Points: 35
  • 02-22-2007 9:45 AM In reply to

    • skbach
    • Top 75 Contributor
    • Joined on 01-18-2007
    • Vancouver, British Columbia
    • Posts 58
    • Points 1,470

    Re: Processors and Terminating Execution

    Thanks Swin!
    Scott Klarenbach PointyHat Software www.pointyhat.ca _______________________________________ To iterate is human; to recurse, divine
    • Post Points: 5
Page 1 of 1 (3 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems