コード例 #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
ファイル: PolicyContainer.cs プロジェクト: poke/monodevelop
        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
ファイル: PolicyContainer.cs プロジェクト: poke/monodevelop
        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);
        }