Guest User

Untitled

a guest
Jun 25th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. public class WhenRule<T> : WhenCondition<T> where T : RuleContext
  2. {
  3. private ID rulesId;
  4.  
  5. public WhenRule()
  6. {
  7. this.rulesId = ID.Null;
  8. }
  9.  
  10. protected override bool Execute(T ruleContext)
  11. {
  12. Assert.ArgumentNotNull(ruleContext, "ruleContext");
  13. Item item = ruleContext.Item;
  14. if (item != null)
  15. {
  16. Item item2 = item.Database.GetItem(this.RulesId);
  17. if (item2 == null)
  18. {
  19. return true;
  20. }
  21. foreach (Rule<T> rule in RuleFactory.GetRules<T>(new Item[] { item2 }, "Rule").Rules)
  22. {
  23. if (rule.Condition != null)
  24. {
  25. RuleStack stack = new RuleStack();
  26. rule.Condition.Evaluate(ruleContext, stack);
  27. if (ruleContext.IsAborted)
  28. {
  29. return false;
  30. }
  31. if ((stack.Count != 0) && ((bool)stack.Pop()))
  32. {
  33. //customization
  34. rule.Execute(ruleContext);
  35. return true;
  36. }
  37. }
  38. }
  39. }
  40. return false;
  41. }
  42.  
  43. public ID RulesId
  44. {
  45. get
  46. {
  47. return this.rulesId;
  48. }
  49. set
  50. {
  51. Assert.ArgumentNotNull(value, "value");
  52. this.rulesId = value;
  53. }
  54. }
  55. }
Add Comment
Please, Sign In to add comment