示例#1
0
        internal PolicyKey[] AddSerializedPolicies(StreamReader reader)
        {
            if (policies == null)
            {
                policies = new PolicyDictionary();
            }
            var keys = new List <PolicyKey> ();

            foreach (ScopedPolicy policyPair in PolicyService.RawDeserializeXml(reader))
            {
                PolicyKey key = new PolicyKey(policyPair.PolicyType, policyPair.Scope);
                if (policies.ContainsKey(key))
                {
                    throw new InvalidOperationException("Cannot add second policy of type '" +
                                                        key.ToString() + "' to policy set '" + Id + "'");
                }
                keys.Add(key);
                policies[key] = policyPair.Policy;
                if (!policyPair.SupportsDiffSerialize)
                {
                    externalPolicies.Add(key);
                }
            }
            return(keys.ToArray());
        }
示例#2
0
        internal void LoadFromFile(StreamReader reader)
        {
            if (policies == null)
            {
                policies = new PolicyDictionary();
            }
            else
            {
                policies.Clear();
            }

            //note: can't use AddSerializedPolicies as we want diff serialisation
            foreach (ScopedPolicy policyPair in PolicyService.DiffDeserializeXml(reader))
            {
                PolicyKey key = new PolicyKey(policyPair.PolicyType, policyPair.Scope);
                if (policies.ContainsKey(key))
                {
                    throw new InvalidOperationException("Cannot add second policy of type '" +
                                                        key.ToString() + "' to policy set '" + Id + "'");
                }
                policies[key] = policyPair.Policy;
            }
        }
示例#3
0
        internal void LoadFromXml(XmlReader reader)
        {
            if (policies == null)
            {
                policies = new PolicyDictionary();
            }
            else
            {
                policies.Clear();
            }

            reader.MoveToContent();
            string str = reader.GetAttribute("name");

            if (!string.IsNullOrEmpty(str))
            {
                Name = str;
            }
            str = reader.GetAttribute("id");
            if (!string.IsNullOrEmpty(str))
            {
                Id = str;
            }
            reader.MoveToElement();

            //note: can't use AddSerializedPolicies as we want diff serialisation
            foreach (ScopedPolicy policyPair in PolicyService.DiffDeserializeXml(reader))
            {
                PolicyKey key = new PolicyKey(policyPair.PolicyType, policyPair.Scope);
                if (policies.ContainsKey(key))
                {
                    throw new InvalidOperationException("Cannot add second policy of type '" +
                                                        key.ToString() + "' to policy set '" + Id + "'");
                }
                policies[key] = policyPair.Policy;
            }
        }