Пример #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 bool SupportsDiffSerialize(ScopedPolicy pol)
        {
            if (!AllowDiffSerialize)
            {
                return(false);
            }
            PolicyKey pk = new PolicyKey(pol.PolicyType, pol.Scope);

            return(!externalPolicies.Contains(pk));
        }
Пример #3
0
        internal void InternalSet(Type t, string scope, object ob)
        {
            PolicyKey key = new PolicyKey(t, scope);

            if (policies == null)
            {
                policies = new PolicyDictionary();
            }
            policies[key] = ob;
            OnPolicyChanged(key.PolicyType, key.Scope);
        }
Пример #4
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 + "' to policy set '" + Id + "'"
                              );
                }
                policies[key] = policyPair.Policy;
            }
        }
Пример #5
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;
            }
        }
Пример #6
0
        public void Set <T> (T value, string scope) where T : class, IEquatable <T>, new ()
        {
            CheckReadOnly();
            PolicyKey key = new PolicyKey(typeof(T), scope);

            System.Diagnostics.Debug.Assert(key.Scope == scope);

            if (policies == null)
            {
                policies = new PolicyDictionary();
            }
            else if (value != null)
            {
                object oldVal = null;
                policies.TryGetValue(key, out oldVal);
                if (oldVal != null && ((IEquatable <T>)oldVal).Equals(value))
                {
                    return;
                }
            }

            policies[key] = value;
            OnPolicyChanged(key.PolicyType, key.Scope);
        }