private XElement CreateDefinitions(CircuitDocument document, WriterContext context) { var componentSources = new XElement(Ns.Document + "definitions"); var componentTypes = document.Elements.Where(x => x is Component) .Cast <Component>() .Select(c => c.Type) .Distinct(); foreach (var source in componentTypes.GroupBy(x => x.Collection)) { var sourceXml = new XElement(Ns.Document + "src"); if (source.Key != ComponentTypeCollection.Unknown) { sourceXml.SetAttributeValue("col", source.Key.Value); } foreach (var type in source) { var typeXml = new XElement(Ns.Document + "add"); typeXml.SetAttributeValue("id", context.AssignId(type)); if (type.CollectionItem != null) { typeXml.SetAttributeValue("item", type.CollectionItem); } typeXml.SetAttributeValue(Ns.DocumentComponentDescriptions + "name", type.Name); if (type.Id.HasValue) { typeXml.SetAttributeValue(Ns.DocumentComponentDescriptions + "guid", type.Id); } // Only write configurations that are actually used in this document foreach (var configuration in type.Configurations.Where(cf => document.Components.Any(cp => cp.Configuration == cf))) { typeXml.Add(new XElement(Ns.Document + "configuration", new XAttribute("name", configuration.Name), new XAttribute("implements", configuration.Implements))); } sourceXml.Add(typeXml); } componentSources.Add(sourceXml); } return(componentSources); }
private XElement CreateDefinitions(CircuitDocument document, WriterContext context) { var componentSources = new XElement(Ns.Document + "definitions"); var componentTypes = document.Elements.Where(x => x is Component) .Cast <Component>() .Select(c => c.Type) .Distinct(); foreach (var source in componentTypes.GroupBy(x => x.Collection)) { var sourceXml = new XElement(Ns.Document + "src"); if (source.Key != null && source.Key != ComponentType.UnknownCollection) { sourceXml.SetAttributeValue("col", source.Key); } foreach (var type in source) { var typeXml = new XElement(Ns.Document + "add"); typeXml.SetAttributeValue("id", context.AssignId(type)); if (type.CollectionItem != null) { typeXml.SetAttributeValue("item", type.CollectionItem); } var tdComponentType = type as TypeDescriptionComponentType; if (tdComponentType != null) { typeXml.SetAttributeValue(Ns.DocumentComponentDescriptions + "guid", tdComponentType.Id); } sourceXml.Add(typeXml); } componentSources.Add(sourceXml); } return(componentSources); }