Ejemplo n.º 1
0
        public BimlFile AddXml(string fileName, XmlDocument xmlDocument, XmlIRDocumentType docType, bool isReadOnly)
        {
            BimlFile bimlFile = AddXml(fileName, docType, isReadOnly);

            bimlFile.Text = xmlDocument.OuterXml;
            return(bimlFile);
        }
Ejemplo n.º 2
0
        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;
            }
        }
Ejemplo n.º 3
0
 public void AddXml(XmlDocument xmlDocument, XmlIRDocumentType docType)
 {
     AddXml(
         XDocument.Load(XmlTextReader.Create(new System.IO.StringReader(xmlDocument.OuterXml))),
         docType
         );
 }
Ejemplo n.º 4
0
 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;
 }
Ejemplo n.º 5
0
 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);
     }
 }
Ejemplo n.º 6
0
        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);
            }
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
        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.");
                }
            }
        }
Ejemplo n.º 9
0
        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.");
                }
            }
        }
Ejemplo n.º 10
0
 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);
     }
 }
Ejemplo n.º 11
0
        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;
            }
        }
Ejemplo n.º 12
0
 public BimlFile(XmlIRDocumentType type, string path, bool bimlFileMember, XDocument document)
     : this(type, path, bimlFileMember, document, false)
 {
 }
Ejemplo n.º 13
0
 public BimlFile(XmlIRDocumentType type)
     : this(type, null)
 {
 }
Ejemplo n.º 14
0
 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;
 }
Ejemplo n.º 15
0
        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);
                }
            }
        }
Ejemplo n.º 16
0
 public BimlFile(XmlIRDocumentType type)
     : this(type, null)
 {
 }
Ejemplo n.º 17
0
        public BimlFile AddXml(string fileName, XmlIRDocumentType docType, bool isReadOnly)
        {
            var bimlFile = new BimlFile(docType, fileName, isReadOnly);

            return(AddXml(bimlFile));
        }
Ejemplo n.º 18
0
 public BimlFile(XmlIRDocumentType type, string path)
     : this(type, path, true)
 {
 }
Ejemplo n.º 19
0
 public BimlFile(XmlIRDocumentType type, string path, bool bimlFileMember, XDocument document)
     : this(type, path, bimlFileMember, document, false)
 {
 }
Ejemplo n.º 20
0
 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)
 {
 }
Ejemplo n.º 21
0
        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);
            }
        }
Ejemplo n.º 22
0
Archivo: XmlIR.cs Proyecto: japj/vulcan
 public BimlFile AddXml(string fileName, XmlIRDocumentType docType, bool isReadOnly)
 {
     var bimlFile = new BimlFile(docType, fileName, isReadOnly);
     return AddXml(bimlFile);
 }
Ejemplo n.º 23
0
        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);
            }

        }
Ejemplo n.º 24
0
Archivo: XmlIR.cs Proyecto: japj/vulcan
 public BimlFile AddXml(string fileName, XmlDocument xmlDocument, XmlIRDocumentType docType, bool isReadOnly)
 {
     BimlFile bimlFile = AddXml(fileName, docType, isReadOnly);
     bimlFile.Text = xmlDocument.OuterXml;
     return bimlFile;
 }
Ejemplo n.º 25
0
        // 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;
        }
Ejemplo n.º 26
0
        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);
            }
        }
Ejemplo n.º 27
0
Archivo: XmlIR.cs Proyecto: japj/vulcan
 public void AddXml(XDocument xDocument, XmlIRDocumentType docType)
 {
     _documents[docType].Add(xDocument);
 }
Ejemplo n.º 28
0
        // 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);
        }
Ejemplo n.º 29
0
Archivo: XmlIR.cs Proyecto: japj/vulcan
        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;
        }
Ejemplo n.º 30
0
 public BimlFile(XmlIRDocumentType type, string path)
     : this(type, path, true)
 {
 }
Ejemplo n.º 31
0
        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);
                }
            }
        }
Ejemplo n.º 32
0
 public void AddXml(XDocument xDocument, XmlIRDocumentType docType)
 {
     _documents[docType].Add(xDocument);
 }
Ejemplo n.º 33
0
Archivo: XmlIR.cs Proyecto: japj/vulcan
 public void AddXml(XmlDocument xmlDocument, XmlIRDocumentType docType)
 {
     AddXml(
         XDocument.Load(XmlTextReader.Create(new System.IO.StringReader(xmlDocument.OuterXml))),
         docType
         );
 }
Ejemplo n.º 34
0
 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)
 {
 }