/// <summary> /// Creates a new runtime policy set evaluation. /// </summary> /// <param name="engine">The evaluation engine.</param> /// <param name="policySet">The policy set defined in the policy document.</param> public PolicySet( EvaluationEngine engine, pol.PolicySetElement policySet ) { if (engine == null) throw new ArgumentNullException("engine"); if (policySet == null) throw new ArgumentNullException("policySet"); _policySet = policySet; // Create a runtime target of this policy set. if( policySet.Target != null ) { _target = new Target( (pol.TargetElement)policySet.Target ); foreach( pol.ResourceElement resource in policySet.Target.Resources.ItemsList ) { foreach( pol.ResourceMatchElement rmatch in resource.Match ) { if( !_allResources.Contains( rmatch.AttributeValue.Contents ) ) { _allResources.Add( rmatch.AttributeValue.Contents ); } } } } // Add all the policies (or policy set) inside this policy set. foreach( object child in policySet.Policies ) { pol.PolicySetElement childPolicySet = child as pol.PolicySetElement; pol.PolicyElement childPolicyElement = child as pol.PolicyElement; pol.PolicySetIdReferenceElement childPolicySetIdReference = child as pol.PolicySetIdReferenceElement; pol.PolicyIdReferenceElement childPolicyIdReferenceElement = child as pol.PolicyIdReferenceElement; if (childPolicySet != null) { PolicySet policySetEv = new PolicySet(engine, childPolicySet); foreach( string rName in policySetEv.AllResources ) { if( !_allResources.Contains( rName ) ) { _allResources.Add( rName ); } } _policies.Add( policySetEv ); } else if (childPolicyElement!=null) { Policy policyEv = new Policy(childPolicyElement); foreach( string rName in policyEv.AllResources ) { if( !_allResources.Contains( rName ) ) { _allResources.Add( rName ); } } _policies.Add( policyEv ); } else if (childPolicySetIdReference!=null) { pol.PolicySetElement policySetDefinition = EvaluationEngine.Resolve(childPolicySetIdReference); if( policySetDefinition != null ) { PolicySet policySetEv = new PolicySet( engine, policySetDefinition ); foreach( string rName in policySetEv.AllResources ) { if( !_allResources.Contains( rName ) ) { _allResources.Add( rName ); } } _policies.Add( policySetEv ); } else { throw new EvaluationException( Resource.ResourceManager[ Resource.MessageKey.exc_policyset_reference_not_resolved, ((pol.PolicySetIdReferenceElement)child).PolicySetId ] ); } } else if (childPolicyIdReferenceElement!=null) { pol.PolicyElement policyDefinition = EvaluationEngine.Resolve(childPolicyIdReferenceElement); if( policyDefinition != null ) { Policy policyEv = new Policy( policyDefinition ); foreach( string rName in policyEv.AllResources ) { if( !_allResources.Contains( rName ) ) { _allResources.Add( rName ); } } _policies.Add( policyEv ); } else { throw new EvaluationException( Resource.ResourceManager[ Resource.MessageKey.exc_policy_reference_not_resolved, ((pol.PolicyIdReferenceElement)child).PolicyId ] ); } } } }
/// <summary> /// Creates a new runtime policy set evaluation. /// </summary> /// <param name="engine">The evaluation engine.</param> /// <param name="policySet">The policy set defined in the policy document.</param> public PolicySet(EvaluationEngine engine, pol.PolicySetElement policySet) { if (engine == null) { throw new ArgumentNullException("engine"); } if (policySet == null) { throw new ArgumentNullException("policySet"); } _policySet = policySet; // Create a runtime target of this policy set. if (policySet.Target != null) { _target = new Target((pol.TargetElement)policySet.Target); foreach (pol.ResourceElement resource in policySet.Target.Resources.ItemsList) { foreach (pol.ResourceMatchElement rmatch in resource.Match) { if (!_allResources.Contains(rmatch.AttributeValue.Contents)) { _allResources.Add(rmatch.AttributeValue.Contents); } } } } // Add all the policies (or policy set) inside this policy set. foreach (object child in policySet.Policies) { pol.PolicySetElement childPolicySet = child as pol.PolicySetElement; pol.PolicyElement childPolicyElement = child as pol.PolicyElement; pol.PolicySetIdReferenceElement childPolicySetIdReference = child as pol.PolicySetIdReferenceElement; pol.PolicyIdReferenceElement childPolicyIdReferenceElement = child as pol.PolicyIdReferenceElement; if (childPolicySet != null) { PolicySet policySetEv = new PolicySet(engine, childPolicySet); foreach (string rName in policySetEv.AllResources) { if (!_allResources.Contains(rName)) { _allResources.Add(rName); } } _policies.Add(policySetEv); } else if (childPolicyElement != null) { Policy policyEv = new Policy(childPolicyElement); foreach (string rName in policyEv.AllResources) { if (!_allResources.Contains(rName)) { _allResources.Add(rName); } } _policies.Add(policyEv); } else if (childPolicySetIdReference != null) { pol.PolicySetElement policySetDefinition = EvaluationEngine.Resolve(childPolicySetIdReference); if (policySetDefinition != null) { PolicySet policySetEv = new PolicySet(engine, policySetDefinition); foreach (string rName in policySetEv.AllResources) { if (!_allResources.Contains(rName)) { _allResources.Add(rName); } } _policies.Add(policySetEv); } else { throw new EvaluationException(Resource.ResourceManager[Resource.MessageKey.exc_policyset_reference_not_resolved, ((pol.PolicySetIdReferenceElement)child).PolicySetId]); } } else if (childPolicyIdReferenceElement != null) { pol.PolicyElement policyDefinition = EvaluationEngine.Resolve(childPolicyIdReferenceElement); if (policyDefinition != null) { Policy policyEv = new Policy(policyDefinition); foreach (string rName in policyEv.AllResources) { if (!_allResources.Contains(rName)) { _allResources.Add(rName); } } _policies.Add(policyEv); } else { throw new EvaluationException(Resource.ResourceManager[Resource.MessageKey.exc_policy_reference_not_resolved, ((pol.PolicyIdReferenceElement)child).PolicyId]); } } } }