Firing of calculation business rules

Firing of calculation business rules

Old forum URL: forums.lhotka.net/forums/t/11996.aspx


vikas_kumar82 posted on Monday, May 27, 2013

Hi,

I am using CSLA and silverlight in my project. I am using the calculation business rules. There is a situation that one calculation rule has to be applied on one or more properties (which is already been set by another calculation rule). In the UI, both are shown in Label and cannot be directly edited. Although, one of the Labels changes when the first rule fires, but this change doesn't fire the second rule (which is dependent on the value of first label) and the value of the second Label is not affected. However, when we save the page, and when the page reloads again, then the calculation fire and set the value of that property.

For example:

Rule1_ChangingLabel1(prop1, prop2, targetprop)

--> When there is a change in prop1 or prop2, this calculates the 'targetprop' (in Label).

When the value of 'targetprop' changes by the above rule, the second rule below should fire.

Rule2_ChangingLabel2(targetprop, prop3, prop4)



But the second rule doesn't fire when the 'targetprop' changes.


Could this be because it is in a Label? I would be thankful if anyone could let me know some solution.

Regards,

Vikas

JonnyBee replied on Monday, May 27, 2013

Hi,

No , this has nothing to with it being a label. 

Which version of CSLA do you use? 

vikas_kumar82 replied on Monday, May 27, 2013

Hi,

The CSLA version is:

Version - 4.3.10.0

Runtime Version - v4.0.30319

 

Regards,

Vikas

JonnyBee replied on Monday, May 27, 2013

Hi,

Look at these posts:

http://jonnybekkum.wordpress.com/2011/08/29/csla-4-2-rules-update/
http://jonnybekkum.wordpress.com/2012/04/29/unit-test-csla-4-businessrules/ 

They describe how the rule engine works internally. 

Basically 

  1. Rules will be executed for the PrimaryProperty that was changed.
  2. Then recheck rules for dependent properties (only first level and dependent properties is AffecteProperties from 1) and ProparyProperties from "type-rules" where InputProperties conatin PrimaryProperty in 1.) 

So you probably hit the barrier of "only 1 level down" on dependent properties. 

vikas_kumar82 replied on Monday, May 27, 2013

Hi,

I tried making primaryproperty of dependent rule as AffectedProperty in rule 1 but still doesn't work.

Could you please elaborate on the second point?

JonnyBee replied on Monday, May 27, 2013

Dependend properties is only checked for the first level. IE: It is not recursive. 

Which meand that when Property1 is changed:

  1. Rules where Property1 is PrimaryProperty is checked
  2. For (aggregated list of AffectedProperties + Properties where Prioperty1 is an InputProperty) check rules 

BUT - not in a recursive manner - so if Property3 is an AffectedProperty of 2) above it will not be revalidated.

Copyright (c) Marimer LLC