FirstMatchCodeGroup.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // System.Security.Policy.FirstMatchCodeGroup
  2. //
  3. // Author(s):
  4. // Jackson Harper ([email protected])
  5. //
  6. // (C) 2002 Jackson Harper, All rights reserved.
  7. using System;
  8. namespace System.Security.Policy {
  9. public sealed class FirstMatchCodeGroup : CodeGroup {
  10. public FirstMatchCodeGroup(IMembershipCondition membershipCondition, PolicyStatement policy) :
  11. base (membershipCondition, policy)
  12. {
  13. }
  14. //
  15. // Public Properties
  16. //
  17. public override string MergeLogic
  18. {
  19. get { return "First Match"; }
  20. }
  21. //
  22. // Public Methods
  23. //
  24. public override CodeGroup Copy()
  25. {
  26. FirstMatchCodeGroup copy = CopyNoChildren ();
  27. foreach (CodeGroup group in Children) {
  28. copy.AddChild ( group );
  29. }
  30. return copy;
  31. }
  32. public override PolicyStatement Resolve(Evidence evidence)
  33. {
  34. PolicyStatement policy = null;
  35. PolicyStatement child_policy;
  36. if (null == evidence)
  37. throw new ArgumentNullException ();
  38. if (MembershipCondition.Check (evidence)) {
  39. if (null != PolicyStatement) {
  40. policy = PolicyStatement;
  41. } else {
  42. // Loop through all children breaking on the first one that resolves
  43. foreach (CodeGroup child in Children) {
  44. if (null == (child_policy = child.Resolve (evidence)))
  45. continue;
  46. policy = child_policy;
  47. break;
  48. }
  49. }
  50. }
  51. return policy;
  52. }
  53. public override CodeGroup ResolveMatchingCodeGroups(Evidence evidence)
  54. {
  55. CodeGroup group = null;
  56. if (null == evidence)
  57. throw new ArgumentNullException ();
  58. if (MembershipCondition.Check (evidence)) {
  59. group = CopyNoChildren ();
  60. // Add the first child that resolves
  61. foreach (CodeGroup child in Children) {
  62. if ( null == child.Resolve (evidence))
  63. continue;
  64. group.AddChild (child);
  65. break;
  66. }
  67. }
  68. return group;
  69. }
  70. //
  71. // Private Methods
  72. //
  73. private FirstMatchCodeGroup CopyNoChildren()
  74. {
  75. FirstMatchCodeGroup copy = new FirstMatchCodeGroup (MembershipCondition, PolicyStatement);
  76. copy.Name = Name;
  77. copy.Description = Description;
  78. return copy;
  79. }
  80. }
  81. }