Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class WhenRule<T> : WhenCondition<T> where T : RuleContext
- {
- private ID rulesId;
- public WhenRule()
- {
- this.rulesId = ID.Null;
- }
- protected override bool Execute(T ruleContext)
- {
- Assert.ArgumentNotNull(ruleContext, "ruleContext");
- Item item = ruleContext.Item;
- if (item != null)
- {
- Item item2 = item.Database.GetItem(this.RulesId);
- if (item2 == null)
- {
- return true;
- }
- foreach (Rule<T> rule in RuleFactory.GetRules<T>(new Item[] { item2 }, "Rule").Rules)
- {
- if (rule.Condition != null)
- {
- RuleStack stack = new RuleStack();
- rule.Condition.Evaluate(ruleContext, stack);
- if (ruleContext.IsAborted)
- {
- return false;
- }
- if ((stack.Count != 0) && ((bool)stack.Pop()))
- {
- //customization
- rule.Execute(ruleContext);
- return true;
- }
- }
- }
- }
- return false;
- }
- public ID RulesId
- {
- get
- {
- return this.rulesId;
- }
- set
- {
- Assert.ArgumentNotNull(value, "value");
- this.rulesId = value;
- }
- }
- }
Add Comment
Please, Sign In to add comment