public BimlFile AddXml(string fileName, XmlDocument xmlDocument, XmlIRDocumentType docType, bool isReadOnly) { BimlFile bimlFile = AddXml(fileName, docType, isReadOnly); bimlFile.Text = xmlDocument.OuterXml; return(bimlFile); }
private void parseElement(XElement element, AstNode astNode, XmlIRDocumentType docType) { this._ScopeManager.Push(astNode); ParseAttributes(element, astNode, docType); ParseChildElements(element, astNode, docType); this._ScopeManager.Pop(); AstNamedNode astNamedNode = astNode as AstNamedNode; if (astNode is IPackageRootNode) { switch (docType) { case XmlIRDocumentType.SOURCE: ((IPackageRootNode)astNode).Emit = true; break; case XmlIRDocumentType.INCLUDE: ((IPackageRootNode)astNode).Emit = false; break; default: throw new NotImplementedException(String.Format(Properties.Resources.ErrorUnknownDocType, docType.ToString())); } } if (astNamedNode != null && astNamedNode.Name != null) { // Guaranteed to work since all sub-dictionaries were initialized in PreLoadPropertyMappingsAndGlobalDictionary() this._GlobalASTNamedNodeDictionary[astNamedNode.GetType()][_ScopeManager.GetScopedName(astNamedNode.Name)] = astNamedNode; } }
public void AddXml(XmlDocument xmlDocument, XmlIRDocumentType docType) { AddXml( XDocument.Load(XmlTextReader.Create(new System.IO.StringReader(xmlDocument.OuterXml))), docType ); }
public NewBindingItem(XmlIRDocumentType docType, XObject XObject, string XValue, AstNamedNode ParentASTNode, AstParserScopeManager scopeManager) { this.docType = docType; this.XObject = XObject; this.XValue = XValue; this.node = ParentASTNode; this.ScopeManager = scopeManager; }
private void ParseAttributes(XElement element, AstNode astNode, XmlIRDocumentType docType) { foreach (XAttribute xAttribute in element.Attributes()) { PropertyBindingAttributePair propertyBinding = GetPropertyBinding(astNode, xAttribute.Name, true); ParseChildXObject(astNode, xAttribute, xAttribute.Name, xAttribute.Value, propertyBinding == null ? null : propertyBinding.Property, docType); } }
private void ParseChildElements(XElement element, AstNode parentASTNode, XmlIRDocumentType docType) { foreach (XElement xElement in element.Elements()) { PropertyBindingAttributePair propertyBinding = GetPropertyBinding(parentASTNode, xElement.Name, false); AstXNameBindingAttribute BindingAttribute = propertyBinding == null ? null : propertyBinding.BindingAttribute; if (BindingAttribute != null && BindingAttribute.HasXPathQuery) { BindXPathQuery(parentASTNode, xElement, propertyBinding, BindingAttribute, docType); } ParseChildXObject(parentASTNode, xElement, xElement.Name, xElement.Value, propertyBinding == null ? null : propertyBinding.Property, docType); } PropertyBindingAttributePair textPropertyBinding = GetPropertyBinding(parentASTNode, XName.Get("__self", element.Name.NamespaceName)); AstXNameBindingAttribute textBindingAttribute = textPropertyBinding == null ? null : textPropertyBinding.BindingAttribute; if (textBindingAttribute != null && textBindingAttribute.HasXPathQuery) { BindXPathQuery(parentASTNode, element, textPropertyBinding, textBindingAttribute, docType); } }
public XDocument AddXml(string fileName, XmlIRDocumentType docType) { bool fileNameExpanded = false; string rootName = fileName.Split(new char[] { '.' })[0]; if (_documentRoots.ContainsKey(rootName)) { string fileNameTailing = fileName.Substring(rootName.Length + 1); fileName = Path.Combine(_documentRoots[rootName], fileNameTailing.Replace('.', '\\')) + ".xml"; fileNameExpanded = true; } if (Path.IsPathRooted(fileName)) { if (File.Exists(fileName)) { if (!_documentsLoaded.Contains(fileName)) { XDocument xDocument = XDocument.Load(fileName); AddXml(xDocument, docType); if (fileNameExpanded) { xDocument.Validate(SchemaSet, this.ValidationEventHandler, true); } _documentsLoaded.Add(fileName); return(xDocument); } } else { MessageEngine.Global.Trace(Severity.Warning, "<Using> file not found: {0}", fileName); } } return(null); }
public BimlFile(XmlIRDocumentType type, string path, bool bimlFileMember, XDocument document, bool isReadOnly) : base(path, isReadOnly) { IsInXmlIR = bimlFileMember; _emitType = type; FilePath = path; if (isReadOnly) { XDocument = XDocument.Load(FilePath, LoadOptions.SetLineInfo | LoadOptions.PreserveWhitespace); } else { if (document != null) { Load(document); } else { throw new NullReferenceException("Error: BimlFile: XDocument should not be null if isReadOnly is set to false."); } } }
private void ParseAttributes(XElement element, AstNode astNode, XmlIRDocumentType docType) { foreach (XAttribute xAttribute in element.Attributes()) { PropertyBindingAttributePair propertyBinding = GetPropertyBinding(astNode, xAttribute.Name, true); ParseChildXObject(astNode, xAttribute, xAttribute.Name, xAttribute.Value, propertyBinding == null ? null : propertyBinding.Property,docType); } }
private void parseElement(XElement element, AstNode astNode, XmlIRDocumentType docType) { this._ScopeManager.Push(astNode); ParseAttributes(element, astNode,docType); ParseChildElements(element, astNode,docType); this._ScopeManager.Pop(); AstNamedNode astNamedNode = astNode as AstNamedNode; if (astNode is IPackageRootNode) { switch(docType) { case XmlIRDocumentType.SOURCE: ((IPackageRootNode)astNode).Emit = true; break; case XmlIRDocumentType.INCLUDE: ((IPackageRootNode)astNode).Emit = false; break; default: throw new NotImplementedException(String.Format(Properties.Resources.ErrorUnknownDocType, docType.ToString())); } } if (astNamedNode != null && astNamedNode.Name != null) { // Guaranteed to work since all sub-dictionaries were initialized in PreLoadPropertyMappingsAndGlobalDictionary() this._GlobalASTNamedNodeDictionary[astNamedNode.GetType()][_ScopeManager.GetScopedName(astNamedNode.Name)] = astNamedNode; } }
public BimlFile(XmlIRDocumentType type, string path, bool bimlFileMember, XDocument document) : this(type, path, bimlFileMember, document, false) { }
public BimlFile(XmlIRDocumentType type) : this(type, null) { }
private void ParseChildXObject(AstNode parentASTNode, XObject xObject, XName xName, string xValue, PropertyInfo propertyToBind, XmlIRDocumentType docType) { bool mapped = false; if (propertyToBind != null) { // TODO: Do we need to check this cast or is it guaranteed safe? if (IsContainerOf(typeof(ICollection<AstNode>), propertyToBind.PropertyType) && xObject is XElement && !IsFlattenedListOf(propertyToBind.PropertyType, (XElement)xObject)) { // REVIEW: We ignore the child attributes of the ICollection-bound xObject and we process its children with the same parentASTNode and a binding preset to the ICollection mapped = true; foreach (XElement xElement in ((XElement)xObject).Elements()) { if (xElement.Name != XName.Get("Annotation", GetDefaultXMLNamespace(parentASTNode))) { mapped = mapped && ParseChildXObjectToElement(parentASTNode, xElement, xElement.Name, xElement.Value, propertyToBind, docType); } } } else { mapped = ParseChildXObjectToElement(parentASTNode, xObject, xName, xValue, propertyToBind,docType); } } // Property could not be found or ASTNode instance could not be created if (!mapped) { if (!this._UnmappedProperties.ContainsKey(xName)) { this._UnmappedProperties.Add(xName, new List<AstNode>()); } this._UnmappedProperties[xName].Add(parentASTNode); parentASTNode.UnmappedXObjects.Add(xObject); if (parentASTNode is AstNamedNode && xName == XName.Get("New", GetDefaultXMLNamespace(parentASTNode))) { NewBindingItem bindingItem = new NewBindingItem(docType, xObject, ((XElement)xObject).Attribute("Class").Value, (AstNamedNode)parentASTNode, _ScopeManager.Clone()); this._NewObjectItems.Add(bindingItem); } } }
public BimlFile AddXml(string fileName, XmlIRDocumentType docType, bool isReadOnly) { var bimlFile = new BimlFile(docType, fileName, isReadOnly); return(AddXml(bimlFile)); }
public BimlFile(XmlIRDocumentType type, string path) : this(type, path, true) { }
public BimlFile(XmlIRDocumentType type, string path, bool bimlFileMember, bool isReadOnly) : this(type, path, bimlFileMember, new XDocument(new XElement(XName.Get("Vulcan", "http://tempuri.org/vulcan2.xsd"))), isReadOnly) { }
private void ParseChildElements(XElement element, AstNode parentASTNode, XmlIRDocumentType docType) { foreach (XElement xElement in element.Elements()) { PropertyBindingAttributePair propertyBinding = GetPropertyBinding(parentASTNode, xElement.Name, false); AstXNameBindingAttribute BindingAttribute = propertyBinding == null ? null : propertyBinding.BindingAttribute; if (BindingAttribute != null && BindingAttribute.HasXPathQuery) { BindXPathQuery(parentASTNode, xElement, propertyBinding, BindingAttribute,docType); } ParseChildXObject(parentASTNode, xElement, xElement.Name, xElement.Value, propertyBinding == null ? null : propertyBinding.Property,docType); } PropertyBindingAttributePair textPropertyBinding = GetPropertyBinding(parentASTNode, XName.Get("__self", element.Name.NamespaceName)); AstXNameBindingAttribute textBindingAttribute = textPropertyBinding == null ? null : textPropertyBinding.BindingAttribute; if (textBindingAttribute != null && textBindingAttribute.HasXPathQuery) { BindXPathQuery(parentASTNode, element, textPropertyBinding, textBindingAttribute,docType); } }
public BimlFile AddXml(string fileName, XmlIRDocumentType docType, bool isReadOnly) { var bimlFile = new BimlFile(docType, fileName, isReadOnly); return AddXml(bimlFile); }
private void BindXPathQuery(AstNode parentASTNode, XElement xElement, PropertyBindingAttributePair propertyBinding, AstXNameBindingAttribute BindingAttribute, XmlIRDocumentType docType) { object EvaluationResult = xElement.XPathEvaluate(BindingAttribute.XPathQuery); if (IsContainerOf(typeof(IEnumerable<object>), EvaluationResult.GetType())) { foreach (object child in (IEnumerable<object>)EvaluationResult) { XAttribute childAttribute = child as XAttribute; XElement childElement = child as XElement; XText childText = child as XText; if (childAttribute != null) { ParseChildXObject(parentASTNode, childAttribute, childAttribute.Name, childAttribute.Value, propertyBinding.Property, docType); } else if (childElement != null) { ParseChildXObject(parentASTNode, childElement, childElement.Name, childElement.Value, propertyBinding.Property, docType); } else if (childText != null) { ParseChildXObject(parentASTNode, childText, null, childText.Value, propertyBinding.Property, docType); } } } else { XAttribute xResult = new XAttribute(XName.Get("XPathEvaluationResult", this._DefaultXmlNamespace), EvaluationResult); ParseChildXObject(parentASTNode, xResult, xResult.Name, xResult.Value, propertyBinding.Property, docType); } }
public BimlFile AddXml(string fileName, XmlDocument xmlDocument, XmlIRDocumentType docType, bool isReadOnly) { BimlFile bimlFile = AddXml(fileName, docType, isReadOnly); bimlFile.Text = xmlDocument.OuterXml; return bimlFile; }
// TODO: Should we add a global XObject dictionary keyed by object so that we can cross-refernce back to non-ASTNode literals? private bool ParseChildXObjectToElement(AstNode parentASTNode, XObject xObject, XName xName, string xValue, PropertyInfo propertyToBind, XmlIRDocumentType docType) { bool mapped = false; object convertedLiteralValue; if (IfLiteralTypeTryConvert(propertyToBind.PropertyType, xValue, out convertedLiteralValue)) // GOTO: Literal Type Handling Code { BindProperty(propertyToBind, parentASTNode, convertedLiteralValue, xObject, false); return true; } else if (IsXObjectValueTextOnly(xObject)) // GOTO: ASTNode Reference (Lookup) Handling Code { BindingItem bindingItem = new BindingItem(propertyToBind, xObject, xValue, parentASTNode, _ScopeManager.Clone()); if (!BindASTNodeReference(bindingItem)) { this._LateBindingItems.Add(bindingItem); } return true; } else // GOTO: ASTNode Child Element (recursive descent) Handling Code // xObject maps to a list of known IASTNode types { // TODO: Do we need to check this cast or is it guaranteed safe? AstNode astNode = CreateASTNodeInstance((XElement)xObject, parentASTNode); if (astNode != null) // xObject maps directly to a known IASTNode type { BindProperty(propertyToBind, parentASTNode, astNode, xObject, false); // TODO: Do we need to check this cast or is it guaranteed safe? parseElement((XElement)xObject, astNode, docType); return true; } } return mapped; }
private void BindXPathQuery(AstNode parentASTNode, XElement xElement, PropertyBindingAttributePair propertyBinding, AstXNameBindingAttribute BindingAttribute, XmlIRDocumentType docType) { object EvaluationResult = xElement.XPathEvaluate(BindingAttribute.XPathQuery); if (IsContainerOf(typeof(IEnumerable <object>), EvaluationResult.GetType())) { foreach (object child in (IEnumerable <object>)EvaluationResult) { XAttribute childAttribute = child as XAttribute; XElement childElement = child as XElement; XText childText = child as XText; if (childAttribute != null) { ParseChildXObject(parentASTNode, childAttribute, childAttribute.Name, childAttribute.Value, propertyBinding.Property, docType); } else if (childElement != null) { ParseChildXObject(parentASTNode, childElement, childElement.Name, childElement.Value, propertyBinding.Property, docType); } else if (childText != null) { ParseChildXObject(parentASTNode, childText, null, childText.Value, propertyBinding.Property, docType); } } } else { XAttribute xResult = new XAttribute(XName.Get("XPathEvaluationResult", this._DefaultXmlNamespace), EvaluationResult); ParseChildXObject(parentASTNode, xResult, xResult.Name, xResult.Value, propertyBinding.Property, docType); } }
public void AddXml(XDocument xDocument, XmlIRDocumentType docType) { _documents[docType].Add(xDocument); }
// TODO: Should we add a global XObject dictionary keyed by object so that we can cross-refernce back to non-ASTNode literals? private bool ParseChildXObjectToElement(AstNode parentASTNode, XObject xObject, XName xName, string xValue, PropertyInfo propertyToBind, XmlIRDocumentType docType) { bool mapped = false; object convertedLiteralValue; if (IfLiteralTypeTryConvert(propertyToBind.PropertyType, xValue, out convertedLiteralValue)) // GOTO: Literal Type Handling Code { BindProperty(propertyToBind, parentASTNode, convertedLiteralValue, xObject, false); return(true); } else if (IsXObjectValueTextOnly(xObject)) // GOTO: ASTNode Reference (Lookup) Handling Code { BindingItem bindingItem = new BindingItem(propertyToBind, xObject, xValue, parentASTNode, _ScopeManager.Clone()); if (!BindASTNodeReference(bindingItem)) { this._LateBindingItems.Add(bindingItem); } return(true); } else // GOTO: ASTNode Child Element (recursive descent) Handling Code // xObject maps to a list of known IASTNode types { // TODO: Do we need to check this cast or is it guaranteed safe? AstNode astNode = CreateASTNodeInstance((XElement)xObject, parentASTNode); if (astNode != null) // xObject maps directly to a known IASTNode type { BindProperty(propertyToBind, parentASTNode, astNode, xObject, false); // TODO: Do we need to check this cast or is it guaranteed safe? parseElement((XElement)xObject, astNode, docType); return(true); } } return(mapped); }
public XDocument AddXml(string fileName, XmlIRDocumentType docType) { bool fileNameExpanded = false; string rootName = fileName.Split(new char[] { '.' })[0]; if (_documentRoots.ContainsKey(rootName)) { string fileNameTailing = fileName.Substring(rootName.Length + 1); fileName = Path.Combine(_documentRoots[rootName], fileNameTailing.Replace('.', '\\')) + ".xml"; fileNameExpanded = true; } if (Path.IsPathRooted(fileName)) { if (File.Exists(fileName)) { if (!_documentsLoaded.Contains(fileName)) { XDocument xDocument = XDocument.Load(fileName); AddXml(xDocument, docType); if (fileNameExpanded) { xDocument.Validate(SchemaSet, this.ValidationEventHandler, true); } _documentsLoaded.Add(fileName); return xDocument; } } else { MessageEngine.Global.Trace(Severity.Warning, "<Using> file not found: {0}", fileName); } } return null; }
private void ParseChildXObject(AstNode parentASTNode, XObject xObject, XName xName, string xValue, PropertyInfo propertyToBind, XmlIRDocumentType docType) { bool mapped = false; if (propertyToBind != null) { // TODO: Do we need to check this cast or is it guaranteed safe? if (IsContainerOf(typeof(ICollection <AstNode>), propertyToBind.PropertyType) && xObject is XElement && !IsFlattenedListOf(propertyToBind.PropertyType, (XElement)xObject)) { // REVIEW: We ignore the child attributes of the ICollection-bound xObject and we process its children with the same parentASTNode and a binding preset to the ICollection mapped = true; foreach (XElement xElement in ((XElement)xObject).Elements()) { if (xElement.Name != XName.Get("Annotation", GetDefaultXMLNamespace(parentASTNode))) { mapped = mapped && ParseChildXObjectToElement(parentASTNode, xElement, xElement.Name, xElement.Value, propertyToBind, docType); } } } else { mapped = ParseChildXObjectToElement(parentASTNode, xObject, xName, xValue, propertyToBind, docType); } } // Property could not be found or ASTNode instance could not be created if (!mapped) { if (!this._UnmappedProperties.ContainsKey(xName)) { this._UnmappedProperties.Add(xName, new List <AstNode>()); } this._UnmappedProperties[xName].Add(parentASTNode); parentASTNode.UnmappedXObjects.Add(xObject); if (parentASTNode is AstNamedNode && xName == XName.Get("New", GetDefaultXMLNamespace(parentASTNode))) { NewBindingItem bindingItem = new NewBindingItem(docType, xObject, ((XElement)xObject).Attribute("Class").Value, (AstNamedNode)parentASTNode, _ScopeManager.Clone()); this._NewObjectItems.Add(bindingItem); } } }