예제 #1
0
        static void HandleInvariantPolicySetChanged(object sender, PolicyChangedEventArgs e)
        {
            PolicySet pset = GetPolicySet("Invariant");
            object    p    = pset.Get(e.PolicyType, e.Scope);

            if (p != null)
            {
                invariantPolicies.InternalSet(e.PolicyType, e.Scope, p);
            }
            else
            {
                invariantPolicies.InternalSet(e.PolicyType, e.Scope, Activator.CreateInstance(e.PolicyType));
            }
        }
예제 #2
0
        internal static ScopedPolicy DiffDeserialize(DataNode data)
        {
            DataItem item = (DataItem)data;

            DataValue inheritVal = item.ItemData ["inheritsSet"] as DataValue;

            if (inheritVal == null || inheritVal.Value == "null")
            {
                return(RawDeserialize(data));
            }

            Type t = GetRegisteredType(data.Name);

            if (t == null)
            {
                UnknownPolicy up = new UnknownPolicy(data);
                return(new ScopedPolicy(typeof(UnknownPolicy), up, up.Scope));
            }

            item.ItemData.Remove(inheritVal);

            PolicySet set = GetSet(inheritVal.Value);

            if (set == null)
            {
                throw new InvalidOperationException("No policy set found for id '" + inheritVal.Value + "'");
            }

            DataValue inheritScope = item.ItemData.Extract("inheritsScope") as DataValue;

            object baseItem = set.Get(t, inheritScope != null ? inheritScope.Value : null);

            if (baseItem == null)
            {
                string msg = "Policy set '" + set.Id + "' does not contain a policy for '" + data.Name + "'";
                if (inheritScope != null)
                {
                    msg += ", scope '" + inheritScope.Value + "'";
                }
                msg += ". This policy is likely provided by an addin that is not currently installed.";
                throw new InvalidOperationException(msg);
            }

            DataValue    scopeVal = item.ItemData.Extract("scope") as DataValue;
            DataNode     baseline = RawSerialize(t, baseItem);
            ScopedPolicy p        = RawDeserialize(ApplyOverlay(baseline, data));

            return(new ScopedPolicy(t, p.Policy, scopeVal != null ? scopeVal.Value : null));
        }
예제 #3
0
 public static T GetDefaultPolicy <T> () where T : class, IEquatable <T>, new ()
 {
     return(defaultPolicies.Get <T> () ?? new T());
 }