internal static Localization Load(BuildingBlocks buildingBlocks, string path, ObjectIndex references) { var xmlNode = buildingBlocks.XmlNode.Element(PolicyItem.ns + "Localization"); if (xmlNode == null) { return(null); } Localization item = new Localization(path, xmlNode, references, buildingBlocks); // fill data item.SupportedLanguage = new List <string>(); foreach (var lang in item.XmlNode.Element(PolicyItem.ns + "SupportedLanguages").Elements(PolicyItem.ns + "SupportedLanguage")) { item.SupportedLanguage.Add(lang.Value); } item.LocalizedResources = new List <LocalizedResources>(); foreach (var locRes in item.XmlNode.Element(PolicyItem.ns + "SupportedLanguages").Elements(PolicyItem.ns + "LocalizedResources")) { item.LocalizedResources.Add(PolicyItem.Load <LocalizedResources>(item, path, locRes, references)); } return(item); }
public object GetReference(Type type, string id, Policy startPolicy) { if (id == null) { return(null); } var allReference = index.Where(i => i.GetType() == type && i.Id == id).Cast <PolicyItem>(); // return policy item if (allReference.Count() == 1) { PolicyItem reference = (PolicyItem)allReference.First(); if (startPolicy.Inheritances().Contains(reference.Policy)) { return(allReference.First()); } else { return(null); // reference is not in any policy } } else if (allReference.Count() == 0) { return(null); } else { var pi = startPolicy.Inheritances(); // filter all references in the inheritance chain var refFiltered = allReference.Where(r => pi.Contains(r.Policy)); return(refFiltered.OrderBy(r => pi.IndexOf(r.Policy)).First()); } }
public T GetItemReference <T>(string id, Policy startPolicy) where T : PolicyItem, new() { if (id == null) { return(Helper.CreateNullReference <T>()); } var allReference = index.Where(i => i.GetType() == typeof(T) && i.Id == id).Cast <PolicyItem>(); // return policy item if (allReference.Count() == 1) { PolicyItem reference = (PolicyItem)allReference.First(); if (startPolicy.Inheritances().Contains(reference.Policy)) { return((T)allReference.First()); } else { return(Helper.CreateUnkReference <T>(id)); // reference is not in any policy } } else if (allReference.Count() == 0) { return(Helper.CreateUnkReference <T>(id)); } else { var pi = startPolicy.Inheritances(); // filter all references in the inheritance chain var refFiltered = allReference.Where(r => pi.Contains(r.Policy)); return((T)refFiltered.OrderBy(r => pi.IndexOf(r.Policy)).First()); } }
internal static BuildingBlocks Load(Policy policy, string path, ObjectIndex references) { var xmlNode = policy.XmlNode.Element(PolicyItem.ns + "BuildingBlocks"); if (xmlNode == null) { return(null); } BuildingBlocks item = new BuildingBlocks(path, xmlNode, references, policy); // fill data // claims schema item.ClaimsSchema = new List <ClaimType>(); if (xmlNode.Element(PolicyItem.ns + "ClaimsSchema") != null) { foreach (var node in xmlNode.Element(PolicyItem.ns + "ClaimsSchema").Elements(PolicyItem.ns + "ClaimType")) { item.ClaimsSchema.Add(PolicyItem.Load <ClaimType>(item, path, node, references)); } } // Predicates item.Predicates = new List <Predicate>(); if (xmlNode.Element(PolicyItem.ns + "Predicates") != null) { // Predicate foreach (var node in xmlNode.Element(PolicyItem.ns + "Predicates").Elements(PolicyItem.ns + "Predicate")) { item.Predicates.Add(PolicyItem.Load <Predicate>(item, path, node, references)); } } // PredicateValidations item.PredicateValidations = new List <PredicateValidation>(); if (xmlNode.Element(PolicyItem.ns + "PredicateValidations") != null) { foreach (var node in xmlNode.Element(PolicyItem.ns + "PredicateValidations").Elements(PolicyItem.ns + "PredicateValidation")) { item.PredicateValidations.Add(PolicyItem.Load <PredicateValidation>(item, path, node, references)); } } // ContentDefinitions item.ContentDefinitions = new List <ContentDefinition>(); if (xmlNode.Element(PolicyItem.ns + "ContentDefinitions") != null) { foreach (var node in xmlNode.Element(PolicyItem.ns + "ContentDefinitions").Elements(PolicyItem.ns + "ContentDefinition")) { item.ContentDefinitions.Add(PolicyItem.Load <ContentDefinition>(item, path, node, references)); } } // ContentDefinitions item.Localization = Localization.Load(item, path, references); return(item); }
internal static TechnicalProfile Load(PolicyItem parent, string path, XElement node, ObjectIndex references) { TechnicalProfile item = new TechnicalProfile(path, node, node.Attribute("Id").Value, references, parent); // fill data item.OutputClaims = new List <Claim>(); if (item.XmlNode.Element(PolicyItem.ns + "OutputClaims") != null) { foreach (var claim in item.XmlNode.Element(PolicyItem.ns + "OutputClaims").Elements(PolicyItem.ns + "OutputClaim")) { item.OutputClaims.Add(PolicyItem.Load <Claim>(item, path, claim, references)); } } item.InputClaims = new List <Claim>(); if (item.XmlNode.Element(PolicyItem.ns + "InputClaims") != null) { foreach (var claim in item.XmlNode.Element(PolicyItem.ns + "InputClaims").Elements(PolicyItem.ns + "InputClaim")) { item.InputClaims.Add(PolicyItem.Load <Claim>(item, path, claim, references)); } } return(item); }
internal static T Load <T>(PolicyItem parent, string path, XElement node, ObjectIndex references) where T : PolicyItem { string id = node.Attribute("Id")?.Value; return((T)Activator.CreateInstance(typeof(T), path, node, id, references, parent)); }