Example #1
0
        /// <summary>
        /// Creates a new runtime policy evaluation.
        /// </summary>
        /// <param name="policy">The policy document.</param>
        public Policy(pol.PolicyElement policy)
        {
            if (policy == null)
            {
                throw new ArgumentNullException("policy");
            }
            _policy = policy;

            // Chechs the target for this policy.
            if (policy.Target != null)
            {
                _target = new Target((pol.TargetElement)policy.Target);

                // Load all the resources for this policy.
                foreach (ResourceElement resource in policy.Target.Resources.ItemsList)
                {
                    foreach (ResourceMatchElement rmatch in resource.Match)
                    {
                        if (!_allResources.Contains(rmatch.AttributeValue.Contents))
                        {
                            _allResources.Add(rmatch.AttributeValue.Contents);
                        }
                    }
                }
            }

            // Load all the Rules and creates a new runtime rule.
            foreach (pol.RuleElement rule in policy.Rules)
            {
                var ruleEv = new Rule(rule);
                _rules.Add(ruleEv);

                foreach (string rName in ruleEv.AllResources)
                {
                    if (!_allResources.Contains(rName))
                    {
                        _allResources.Add(rName);
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// Creates a new runtime policy evaluation.
        /// </summary>
        /// <param name="policy">The policy document.</param>
        public Policy(pol.PolicyElement policy)
        {
            if (policy == null) throw new ArgumentNullException("policy");
            _policy = policy;

            // Chechs the target for this policy.
            if (policy.Target != null)
            {
                _target = new Target((pol.TargetElement)policy.Target);

                // Load all the resources for this policy.
                foreach (ResourceElement resource in policy.Target.Resources.ItemsList)
                {
                    foreach (ResourceMatchElement rmatch in resource.Match)
                    {
                        if (!_allResources.Contains(rmatch.AttributeValue.Contents))
                        {
                            _allResources.Add(rmatch.AttributeValue.Contents);
                        }
                    }
                }
            }

            // Load all the Rules and creates a new runtime rule.
            foreach (pol.RuleElement rule in policy.Rules)
            {
                var ruleEv = new Rule(rule);
                _rules.Add(ruleEv);

                foreach (string rName in ruleEv.AllResources)
                {
                    if (!_allResources.Contains(rName))
                    {
                        _allResources.Add(rName);
                    }
                }
            }
        }