void ICustomDataItem.Deserialize(ITypeSerializer handler, DataCollection data) { if (data.Count == 0) { return; } policies = new PolicyDictionary(); foreach (DataNode node in data) { try { if (!(node is DataItem)) { continue; } ScopedPolicy val = PolicyService.DiffDeserialize((DataItem)node); policies.Add(val); } catch (Exception ex) { if (handler.SerializationContext.ProgressMonitor != null) { handler.SerializationContext.ProgressMonitor.ReportError(ex.Message, ex); } else { LoggingService.LogError(ex.Message, ex); } } } }
internal bool SupportsDiffSerialize(ScopedPolicy pol) { if (!AllowDiffSerialize) { return(false); } PolicyKey pk = new PolicyKey(pol.PolicyType, pol.Scope); return(!externalPolicies.Contains(pk)); }
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)); }
public void Add(ScopedPolicy scopedPolicy) { Add(new PolicyKey(scopedPolicy.PolicyType, scopedPolicy.Scope), scopedPolicy.Policy); }
public void Add(ScopedPolicy scopedPolicy) { this[new PolicyKey(scopedPolicy.PolicyType, scopedPolicy.Scope)] = scopedPolicy.Policy; }