Ejemplo n.º 1
0
        internal static ScopedPolicy RawDeserialize(DataNode data)
        {
            string scope = null;
            Type   t     = GetRegisteredType(data.Name);

            if (t == null)
            {
                UnknownPolicy up = new UnknownPolicy(data);
                return(new ScopedPolicy(typeof(UnknownPolicy), up, up.Scope));
            }
            bool     allowDiff = false;
            DataItem di        = data as DataItem;

            if (di != null)
            {
                DataValue allowDiffData = di ["allowDiffSerialize"] as DataValue;
                allowDiff = allowDiffData != null && allowDiffData.Value == "True";
                DataValue val = di ["scope"] as DataValue;
                if (val != null)
                {
                    scope = val.Value;
                }
                DataValue inh = di ["inheritsSet"] as DataValue;
                if (inh != null && inh.Value == "null")
                {
                    return(new ScopedPolicy(t, null, scope, allowDiff));
                }
            }
            object o = Serializer.Deserialize(t, data);

            return(new ScopedPolicy(t, o, scope, allowDiff));
        }
Ejemplo n.º 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));
        }