예제 #1
0
        protected virtual void AddPagePropertiesToAudioNode(TreeNode audioWrapperNode, XmlNode pageTargetNode)
        {
            TextMedia textMedia = audioWrapperNode.Presentation.MediaFactory.CreateTextMedia();

            textMedia.Text = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(pageTargetNode, true, "text", pageTargetNode.NamespaceURI).InnerText;
            ChannelsProperty cProp = audioWrapperNode.Presentation.PropertyFactory.CreateChannelsProperty();

            cProp.SetMedia(audioWrapperNode.Presentation.ChannelsManager.GetOrCreateTextChannel(), textMedia);
            audioWrapperNode.AddProperty(cProp);
            System.Xml.XmlAttributeCollection pageAttributes = pageTargetNode.Attributes;
            if (pageAttributes != null)
            {
                XmlProperty xmlProp = audioWrapperNode.GetXmlProperty();
                xmlProp.SetQName("pagenum", "");
                string nsUri = audioWrapperNode.GetXmlNamespaceUri();
                foreach (System.Xml.XmlAttribute attr in pageAttributes)
                {
                    string uri = "";
                    if (!string.IsNullOrEmpty(attr.NamespaceURI))
                    {
                        if (attr.NamespaceURI != nsUri)
                        {
                            uri = attr.NamespaceURI;
                        }
                    }

                    xmlProp.SetAttribute(attr.Name, uri, attr.Value);
                }
            }
        }
예제 #2
0
        protected virtual TreeNode CheckAndAssignForHeadingAudio(TreeNode navPointTreeNode, TreeNode phraseTreeNode, XmlNode audioXmlNode)
        {
            XmlNode navLabelXmlNode = m_NavPointNode_NavLabelMap[navPointTreeNode];
            XmlNode headingAudio    = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(navLabelXmlNode, true, "audio", navLabelXmlNode.NamespaceURI);
            XmlNode textNode        = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(navLabelXmlNode, true, "text", navLabelXmlNode.NamespaceURI);

            double headingClipBegin = Math.Abs((new urakawa.media.timing.Time(headingAudio.Attributes.GetNamedItem("clipBegin").Value)).AsMilliseconds);
            double headingClipEnd   = Math.Abs((new urakawa.media.timing.Time(headingAudio.Attributes.GetNamedItem("clipEnd").Value)).AsMilliseconds);

            double audioClipBegin = Math.Abs((new urakawa.media.timing.Time(audioXmlNode.Attributes.GetNamedItem("clipBegin").Value)).AsMilliseconds);
            double audioClipEnd   = Math.Abs((new urakawa.media.timing.Time(audioXmlNode.Attributes.GetNamedItem("clipEnd").Value)).AsMilliseconds);

            if (headingAudio.Attributes.GetNamedItem("src").Value == audioXmlNode.Attributes.GetNamedItem("src").Value &&
                Math.Abs(headingClipBegin - audioClipBegin) <= 1 &&
                Math.Abs(headingClipEnd - audioClipEnd) <= 1)
            {
                TextMedia textMedia = navPointTreeNode.Presentation.MediaFactory.CreateTextMedia();
                textMedia.Text = textNode.InnerText;

                ChannelsProperty cProp = navPointTreeNode.Presentation.PropertyFactory.CreateChannelsProperty();
                cProp.SetMedia(navPointTreeNode.Presentation.ChannelsManager.GetOrCreateTextChannel(), textMedia);

                //TreeNode txtWrapperNode = parentNode.Presentation.TreeNodeFactory.Create();
                phraseTreeNode.AddProperty(cProp);
                //treeNode.AppendChild(txtWrapperNode);

                XmlProperty TextNodeXmlProp = navPointTreeNode.Presentation.PropertyFactory.CreateXmlProperty();
                phraseTreeNode.AddProperty(TextNodeXmlProp);
                TextNodeXmlProp.SetQName("hd", "");
            }

            return(phraseTreeNode);
        }
예제 #3
0
        public virtual bool PreVisit(TreeNode node)
        {
            if (mTotalNumberOfNodes == -1 && node.Parent == null)
            {
                countTotalNodes(node, mTotalNumberOfNodes, out mTotalNumberOfNodes);
            }

            mCurrentNodeIndex++;

            Inline      nodeRun = GetTextInline(node);
            XmlProperty xmlProp = node.GetProperty <XmlProperty>();

            if (xmlProp != null)
            {
                if (!HandleXmlElement(xmlProp, node, nodeRun))
                {
                    return(false);
                }
            }
            if (nodeRun != null)
            {
                HandleNodeRun(nodeRun);
            }
            return(true);
        }
예제 #4
0
        protected virtual TreeNode AddAnchorNode(TreeNode navPointTreeNode, XmlNode textPeerNode, string fullSmilPath)
        {
            TreeNode anchorNode = navPointTreeNode.Presentation.TreeNodeFactory.Create();

            navPointTreeNode.AppendChild(anchorNode);
            XmlNode xmlNodeAttr  = textPeerNode.Attributes.GetNamedItem("href");
            string  strReferedID = xmlNodeAttr.Value;
            XmlNode seqParent    = textPeerNode.ParentNode;

            while (seqParent != null)
            {
                if (seqParent.LocalName == "seq" && seqParent.Attributes.GetNamedItem("customTest") != null)
                {
                    break;
                }
                seqParent = seqParent.ParentNode;
            }
            string strClass = seqParent.Attributes.GetNamedItem("class").Value;

            if (strClass != null)
            {
                XmlProperty prop = anchorNode.GetOrCreateXmlProperty();
                prop.SetQName(strClass, "");

                prop.SetAttribute(xmlNodeAttr.Name, "", strReferedID);
            }
            return(anchorNode);
        }
        protected override bool HandleHtmlElement(XmlProperty xmlProp, TreeNode node, Inline nodeRun)
        {
            switch (xmlProp.LocalName)
            {
            case "ul":
                List uList = new List();
                uList.MarkerStyle = System.Windows.TextMarkerStyle.Disc;
                HandleListItems(uList.ListItems, node, nodeRun);
                ExtractedBlocks.Add(uList);
                return(false);

            case "ol":
                List oList = new List();
                oList.MarkerStyle = System.Windows.TextMarkerStyle.Decimal;
                HandleListItems(oList.ListItems, node, nodeRun);
                ExtractedBlocks.Add(oList);
                return(false);

            case "p":
                Paragraph newPara = new Paragraph();
                HandleInlines(newPara.Inlines, node, nodeRun);
                ExtractedBlocks.Add(newPara);
                return(false);

            default:
                break;
            }
            return(true);
        }
예제 #6
0
        public virtual void ParseNCXDocument(XmlDocument ncxDocument)
        {
            m_SmilRefToNavPointTreeNodeMap = new Dictionary <string, TreeNode>();
            m_NavPointNode_NavLabelMap     = new Dictionary <TreeNode, XmlNode>();
            //string ncxPath = Directory.GetFiles(Directory.GetParent(m_Book_FilePath).FullName, "*.ncx")[0];
            //ncxDocument = xuk.OpenXukAction.ParseXmlDocument(ncxPath, false);

            XmlNode      navMap       = ncxDocument.GetElementsByTagName("navMap")[0];
            Presentation presentation = m_Project.Presentations.Get(0);

            XmlProperty xmlProp = presentation.PropertyFactory.CreateXmlProperty();

            xmlProp.SetQName("book", navMap.NamespaceURI == null ? "" : navMap.NamespaceURI);

            presentation.PropertyFactory.DefaultXmlNamespaceUri = navMap.NamespaceURI;

            TreeNode treeNode = null;

            if (presentation.RootNode == null)
            {
                treeNode = presentation.TreeNodeFactory.Create();
                presentation.RootNode = treeNode;
            }
            else
            {
                treeNode = presentation.RootNode;
            }
            treeNode.AddProperty(xmlProp);

            m_DocTitleXmlNode   = XmlDocumentHelper.GetFirstChildElementOrSelfWithName(ncxDocument.DocumentElement, true, "docTitle", ncxDocument.DocumentElement.NamespaceURI);
            m_IsDocTitleCreated = false;

            ParseNCXNodes(presentation, navMap, treeNode);
            CollectPagesFromPageList(navMap);
        }
예제 #7
0
        public string GetXmlElementPrefixedLocalName()
        {
            if (!HasXmlProperty)
            {
                return(null);
            }
            XmlProperty xmlProp   = GetXmlProperty();
            string      localName = xmlProp.LocalName;

            if (NeedsXmlNamespacePrefix())
            {
                string nsUri  = GetXmlNamespaceUri();
                string prefix = GetXmlNamespacePrefix(nsUri);

#if DEBUG
                if (string.IsNullOrEmpty(prefix))
                {
                    Debugger.Break();
                }
#endif
                return(prefix + ":" + localName);
            }

            return(localName);
        }
예제 #8
0
 internal ClassStringBuilder AddPropertyWithBusinessRule(string modifier, XmlProperty xmlProperty)
 {
     SetIndent(Indent.Property);
     AddDescription(xmlProperty.Description);
     AddBusinessRule(xmlProperty);
     return(AddProperty(modifier, xmlProperty));
 }
예제 #9
0
        public static void ParseProperty(XmlProperty propertyToParse, XElement configElement, object createdObject, Dictionary<XmlProperty, bool> parsedPropertiesDict, IContext context)
        {
            var constarintProperties = propertyToParse.Constraints.Value;

            foreach (var constraintProperty in constarintProperties)
            {
                if (!parsedPropertiesDict[constraintProperty.Property])
                    ParseProperty(constraintProperty.Property, configElement, createdObject, parsedPropertiesDict, context);
            }

            if (!constarintProperties.All(c => c.Verify(createdObject)))
            {
                parsedPropertiesDict[propertyToParse] = true;
                return;
            }

            var xmlNode = propertyToParse.Location.Value.GetElement(configElement);
            if (xmlNode == null)
            {
                if (propertyToParse.IsRequired)
                    throw new TestLibsException($"There is no required element to parse. Property name: {propertyToParse.Info.Name}\nDescription: {propertyToParse.Description}\n{propertyToParse.Location}");

                parsedPropertiesDict[propertyToParse] = true;
                return;
            }

            var propertyValue = XmlParser.Parse(propertyToParse.PropertyType, xmlNode, propertyToParse.IsAssignableTypesAllowed, propertyToParse.ChildLocation?.Value, context);

            propertyToParse.SetValue(createdObject, propertyValue);
            parsedPropertiesDict[propertyToParse] = true;
        }
예제 #10
0
 internal ClassStringBuilder StartProperty(string modifier, XmlProperty xmlProperty)
 {
     SetIndent(Indent.Property);
     AddDescription(xmlProperty.Description);
     AppendLine($"{modifier} {xmlProperty.PropertyType.Name.GetDescription()} {xmlProperty.Name}");
     AppendLine("{");
     return(this);
 }
 /// <summary>
 /// Constructor setting the source <see cref="XmlProperty"/> of the event
 /// and the previous+new QName
 /// </summary>
 /// <param name="src">The source <see cref="XmlProperty"/> of the event</param>
 /// <param name="newLN">The local name part of the new QName</param>
 /// <param name="newNS">The namespace uri part of the new QName</param>
 /// <param name="prevLN">The local name part of the QName prior to the change</param>
 /// <param name="prevNS">The namespace uri part of the QName prior to the change</param>
 public QNameChangedEventArgs(XmlProperty src, string newLN, string newNS, string prevLN, string prevNS)
     : base(src)
 {
     NewLocalName         = newLN;
     NewNamespaceUri      = newNS;
     PreviousLocalName    = prevLN;
     PreviousNamespaceUri = prevNS;
 }
예제 #12
0
 /// <summary>
 /// Constructor setting the source <see cref="XmlProperty"/> of the event,
 /// the QName of the attribute and the previous+new value
 /// </summary>
 /// <param name="src">The source <see cref="XmlProperty"/> of the event</param>
 /// <param name="attrLN">The local name part of the OName of the attribute that was set</param>
 /// <param name="attrNS">The namespace uri part of the OName of the attribute that was set</param>
 /// <param name="newVal">The new value of the attribute</param>
 /// <param name="prevVal">The value of the attribute prior to being set</param>
 public XmlAttributeSetEventArgs(XmlProperty src, string attrLN, string attrNS, string newVal, string prevVal)
     : base(src)
 {
     AttributeLocalName    = attrLN;
     AttributeNamespaceUri = attrNS;
     NewValue      = newVal;
     PreviousValue = prevVal;
 }
 protected override bool HandleXmlElement(XmlProperty xmlProp, TreeNode node, Inline nodeRun)
 {
     if (xmlProp.NamespaceUri == HtmlNamespace)
     {
         return(HandleHtmlElement(xmlProp, node, nodeRun));
     }
     return(true);
 }
예제 #14
0
        private void parseContentDocuments(List <string> spineOfContentDocuments)
        {
            if (spineOfContentDocuments == null || spineOfContentDocuments.Count <= 0)
            {
                return;
            }

            //DirectoryInfo opfParentDir = Directory.GetParent(m_Book_FilePath);
            //string dirPath = opfParentDir.ToString();
            string dirPath = Path.GetDirectoryName(m_Book_FilePath);

            bool first = true;

            foreach (string docPath in spineOfContentDocuments)
            {
                string      fullDocPath = Path.Combine(dirPath, docPath);
                XmlDocument xmlDoc      = readXmlDocument(fullDocPath);

                parseMetadata(xmlDoc);

                //XmlNodeList listOfBodies = xmlDoc.GetElementsByTagName("body");
                //if (listOfBodies.Count == 0)
                //{
                //    listOfBodies = xmlDoc.GetElementsByTagName("book");
                //}
                XmlNode bodyElement = getFirstChildElementsWithName(xmlDoc, true, "body", null);

                if (bodyElement == null)
                {
                    bodyElement = getFirstChildElementsWithName(xmlDoc, true, "book", null);
                }

                if (bodyElement == null)
                {
                    continue;
                }

                if (first)
                {
                    Presentation presentation = m_Project.Presentations.Get(0);
                    XmlProperty  xmlProp      = presentation.PropertyFactory.CreateXmlProperty();
                    xmlProp.LocalName = "book";
                    presentation.PropertyFactory.DefaultXmlNamespaceUri = bodyElement.NamespaceURI;
                    xmlProp.NamespaceUri = presentation.PropertyFactory.DefaultXmlNamespaceUri;
                    TreeNode treeNode = presentation.TreeNodeFactory.Create();
                    treeNode.AddProperty(xmlProp);
                    presentation.RootNode = treeNode;

                    first = false;
                }

                foreach (XmlNode childOfBody in bodyElement.ChildNodes)
                {
                    parseContentDocument(childOfBody, m_Project.Presentations.Get(0).RootNode, fullDocPath);
                }
            }
        }
예제 #15
0
    public void XmlPropertyTest1()
    {
        const string XML_TEXT1 =
            "<Folker>Kinzel</Folker>";

        var xelement = XElement.Parse(XML_TEXT1);

        _ = new XmlProperty(xelement);
    }
예제 #16
0
    public void XmlPropertyTest2()
    {
        const string XML_TEXT1 =
            "<Folker xmlns=\"urn:ietf:params:xml:ns:vcard-4.0\">Kinzel</Folker>";

        var xelement = XElement.Parse(XML_TEXT1);

        _ = new XmlProperty(xelement);
    }
예제 #17
0
 public static PropertyModel ToViewModel(this XmlProperty entity)
 {
     return(new PropertyModel()
     {
         Id = entity.Id,
         Name = entity.Name,
         Enabled = entity.Enabled,
         ProductProperty = entity.ProductProperty,
     });
 }
예제 #18
0
        //private QualifiedName m_QualifiedName = null;
        //private QualifiedName GetXmlElementQName()
        //{
        //    XmlProperty xmlProp = GetXmlProperty();
        //    if (xmlProp != null)
        //    {
        //        //TODOx QualifiedName fields are unmutable,
        //        // so unless the underlying XmlProperty fields change, caching is okay
        //        // (here we assume that once a TreeNode as been XukedIn,
        //        // its XML definition does not change)
        //        if (m_QualifiedName == null || xmlProp.QNameIsInvalidated)
        //        {
        //            string nsUri = GetXmlNamespaceUri();

        //            m_QualifiedName = new QualifiedName(xmlProp.LocalName, nsUri);

        //            xmlProp.QNameIsInvalidated = false;
        //        }
        //    }
        //    else
        //    {
        //        m_QualifiedName = null;
        //    }

        //    return m_QualifiedName;
        //}


        public string GetXmlElementLang()
        {
            XmlProperty xmlProp = GetXmlProperty();

            if (xmlProp != null)
            {
                return(xmlProp.GetLangFromAttributes());
            }
            return(null);
        }
예제 #19
0
        public string GetXmlNamespacePrefix(string uri)
        {
            if (!HasXmlProperty)
            {
                return(null);
            }

            XmlProperty xmlProp = GetXmlProperty();

            return(xmlProp.GetXmlNamespacePrefix(uri));
        }
예제 #20
0
        public string GetXmlNamespaceUri(string prefix)
        {
            if (!HasXmlProperty)
            {
                return(null);
            }

            XmlProperty xmlProp = GetXmlProperty();

            return(xmlProp.GetNamespaceUri(prefix));
        }
예제 #21
0
        protected XmlProperty ObiNodeGetOrCreateXmlProperty()
        {
            XmlProperty xmlProp = this.GetProperty <urakawa.property.xml.XmlProperty>();

            if (xmlProp == null)
            {
                xmlProp = Presentation.PropertyFactory.CreateXmlProperty();
                this.AddProperty(xmlProp);
                xmlProp.SetQName(XmlPropertyString, GetXukNamespace());
            }
            return(xmlProp);
        }
예제 #22
0
        public IProperty DefineProperty(XElement element, string propertyName, Type type, object value, bool isReadOnly)
        {
            var propElem = new XElement("property");
            element.Add(propElem);

            var property = new XmlProperty(propElem);
            property.Name = propertyName;
            property.ReadOnly = isReadOnly;
            property.Type = type;
            property.SetValue(value);
            return property;
        }
예제 #23
0
        protected void UpdateAttributesInXmlProperty(XmlProperty xmlProp, string attributeLocalName, string attributeValue)
        {
            XmlAttribute attr = xmlProp.GetAttribute(attributeLocalName);

            if (attr == null)
            {
                xmlProp.SetAttribute(attributeLocalName, "", attributeValue);
            }
            else
            {
                attr.Value = attributeValue;
            }
        }
            protected override void SetValue(object target, XmlProperty property, object propertyValue)
            {
                var valueProxy = (ValueProxy)target;

                if (property.PropertyName.Length == 3)
                {
                    valueProxy.Key = (TKey)propertyValue;
                }
                else
                {
                    valueProxy.Value = (TValue)propertyValue;
                }
            }
예제 #25
0
        public string GetXmlElementLocalName()
        {
            //QualifiedName qName = GetXmlElementQName();
            //if (qName == null) return null;
            //return qName.LocalName;

            if (!HasXmlProperty)
            {
                return(null);
            }
            XmlProperty xmlProp = GetXmlProperty();

            return(xmlProp.LocalName);
        }
예제 #26
0
        private static readonly string USED_ATTR_NAME = "used";  // name of the used attribute

        /*
         * protected override void XukInChild(System.Xml.XmlReader source, IProgressHandler handler)
         * {
         *  base.XukInChild(source, handler);
         *  XukInNodeProperties();
         * }
         */

        protected virtual void XukInNodeProperties()
        {
            XmlProperty xmlProp = this.GetProperty <XmlProperty>();

            if (xmlProp != null)
            {
                XmlAttribute attrUsed = xmlProp.GetAttribute(USED_ATTR_NAME);
                string       used     = attrUsed != null?  attrUsed.Value: null;
                if (used != null && used == "False")
                {
                    mUsed = false;
                }
            }
        }
예제 #27
0
 public IEnumerable<IProperty> Parse(XElement element)
 {
     var properties = new List<IProperty>();
     var propertyElems = element.Elements("property").Where(x => x != null).ToList();
     if (propertyElems.Any())
     {
         foreach (var elem in propertyElems)
         {
             IProperty property = new XmlProperty(elem);
             properties.Add(property);
         }
     }
     return properties;
 }
예제 #28
0
        public bool FindProperty(Func <XmlProperty, bool> predicate,
                                 out XmlPropertyGroup propertyGroup, out XmlProperty property)
        {
            XmlProperty propertyForSearch = null;

            propertyGroup = Xml.PropertyGroups.FirstOrDefault(g =>
            {
                propertyForSearch = g.Properties.FirstOrDefault(predicate);
                return(propertyForSearch != null);
            });
            property = propertyForSearch;

            return(property != null);
        }
예제 #29
0
        private void AddBusinessRule(XmlProperty property)
        {
            var rules = BusinessRuleManager.GetRules(property.PropertyType.Name.GetDescription());

            if (property.Required)
            {
                AppendLine($"[Required(ErrorMessage = @\"{property.Name} is required\")]");
            }

            foreach (var rule in rules)
            {
                AppendLine(rule.GetRule(property));
            }
        }
예제 #30
0
        public bool NeedsXmlNamespacePrefix()
        {
            if (!HasXmlProperty)
            {
                return(false);
            }
            string nsUri_NearestXmlns = null;

            TreeNode node = this;

            while (node != null)
            {
                XmlProperty xmlProp = node.GetXmlProperty();

                foreach (XmlAttribute xmlAttr in xmlProp.Attributes.ContentsAs_Enumerable)
                {
                    string attrNSPrefix  = xmlAttr.Prefix;
                    string attrLocalName = xmlAttr.PrefixedLocalName != null
                                               ? xmlAttr.PrefixedLocalName
                                               : xmlAttr.LocalName;
                    if (String.IsNullOrEmpty(attrNSPrefix) &&
                        attrLocalName.Equals(XmlReaderWriterHelper.NS_PREFIX_XMLNS))
                    {
                        // xmlns="URI"
                        nsUri_NearestXmlns = xmlAttr.Value;
                        break;
                    }
                }
                if (!String.IsNullOrEmpty(nsUri_NearestXmlns))
                {
                    break;
                }

                node = node.Parent;
            }
            if (String.IsNullOrEmpty(nsUri_NearestXmlns))
            {
                nsUri_NearestXmlns = Presentation.PropertyFactory.DefaultXmlNamespaceUri;
            }

            string nsUri = GetXmlNamespaceUri();

            if (nsUri_NearestXmlns == nsUri)
            {
                return(false);
            }

            return(true);
        }
예제 #31
0
        public static XmlProperty ToEntity(this PropertyModel viewModel)
        {
            var entity = new XmlProperty()
            {
                Name            = viewModel.Name,
                ProductProperty = viewModel.ProductProperty,
                Enabled         = viewModel.Enabled
            };

            if (viewModel.Id.HasValue)
            {
                entity.Id = viewModel.Id.Value;
            }
            return(entity);
        }
예제 #32
0
    public void XmlPropertyTest3()
    {
        // null ist erlaubt - Der cast ist nur im Test nötig, da hier eine Verwechslungsgefahr
        // mit dem internal ctor besteht:
        _ = new XmlProperty((XElement?)null);

        const string XML_TEXT1 =
            "<Folker xmlns=\"https://www.folker-kinzel.de\">Kinzel</Folker>";

        const string GROUP = "group1";

        var xelement = XElement.Parse(XML_TEXT1);
        var prop     = new XmlProperty(xelement, GROUP);

        Assert.AreEqual(prop.Group, GROUP);
        Assert.AreEqual(prop.Value, XML_TEXT1);
    }
        public static string getTreeNodeLabel(TreeNode node)
        {
            string txt = "TXT";

            if (node.HasXmlProperty)
            {
                txt = node.GetXmlElementPrefixedLocalName();

                XmlProperty xmlProp = node.GetXmlProperty();

                XmlAttribute attrEpubType = xmlProp.GetAttribute("epub:type", DiagramContentModelHelper.NS_URL_EPUB);

                if (attrEpubType != null && !string.IsNullOrEmpty(attrEpubType.Value))
                {
                    txt += (" (" + attrEpubType.Value + ")");
                }
            }
            return(txt);
        }
예제 #34
0
 private void Write(XmlProperty xmlProperty)
 {
     xmlProperty.Write(_source, _writer);
 }
예제 #35
0
        private void StartElement(IfcPersistedInstanceCache cache, XmlReader input, XbimEntityCursor entityTable, XbimLazyDBTransaction transaction)
        {
            string elementName = input.LocalName;
            bool isRefType;
            int id = GetId(input, out isRefType);

            IfcType ifcType;
            
            IfcParserType parserType;
            IfcMetaProperty prop;
            int propIndex;


            if (id > -1 && IsIfcEntity(elementName, out ifcType)) //we have an element which is an Ifc Entity
            {
                IPersistIfcEntity ent;
                if (!cache.Contains(id))
                {
                    // not been declared in a ref yet
                    // model.New creates an instance uisng type and id
                    ent = cache.CreateNew(ifcType.Type, id);
                   
                }
                else
                {
                    ent = cache.GetInstance(id, false, true);
                }

                XmlEntity xmlEnt = new XmlEntity(_currentNode, ent);
               
                //if we have a completely empty element that is not a ref we need to make sure it is written to the database as EndElement will not be called
                if (input.IsEmptyElement && !isRefType)
                {
                    _entitiesParsed++;
                    //now write the entity to the database
                    entityTable.AddEntity(xmlEnt.Entity);
                    if (_entitiesParsed % _transactionBatchSize == (_transactionBatchSize - 1))
                    {
                        transaction.Commit();
                        transaction.Begin();
                    }
                    

                }


                string pos = input.GetAttribute(_posAttribute);
                if (string.IsNullOrEmpty(pos)) pos = input.GetAttribute("pos"); //try without namespace
                if (!string.IsNullOrEmpty(pos))
                    xmlEnt.Position = Convert.ToInt32(pos);
                if (!input.IsEmptyElement)
                {
                    // add the entity to its parent if its parent is a list
                    //if (!(_currentNode is XmlUosCollection) && _currentNode is XmlCollectionProperty && !(_currentNode.Parent is XmlUosCollection))
                    //    ((XmlCollectionProperty)_currentNode).Entities.Add(xmlEnt);

                    _currentNode = xmlEnt;
                }
                else if (_currentNode is XmlProperty)
                {
                    // if it is a ref then it will be empty element and wont have an end tag
                    // so nither SetValue nor EndElement will be called, so set the value of ref here e.g. #3
                    ((XmlProperty)(_currentNode)).SetValue(ent);
                }
                else if (!(_currentNode is XmlUosCollection) && _currentNode is XmlCollectionProperty && !(_currentNode.Parent is XmlUosCollection))
                {
                    ((XmlCollectionProperty)_currentNode).Entities.Add(xmlEnt);
                }
            }
            else if (input.IsEmptyElement)
            {
                if (IsIfcProperty(elementName, out propIndex, out prop))
                {
                    XmlProperty node = new XmlProperty(_currentNode, prop.PropertyInfo, propIndex); ;
                    PropertyValue propVal = new PropertyValue();
                    Type t = node.Property.PropertyType;

                    if (!typeof(ExpressEnumerable).IsAssignableFrom(t)) // if its a empty collection then dont do anything
                    {
                        if (t != null && t.IsGenericType && t.GetGenericTypeDefinition().Equals(typeof(Nullable<>)))
                            t = Nullable.GetUnderlyingType(t);
                        ExpressType et = null;
                        if (t != null && typeof(ExpressType).IsAssignableFrom(t))
                            et = (ExpressType)(Activator.CreateInstance(t));

                        IfcParserType pt;
                        if (et != null)
                            pt = primitives[et.UnderlyingSystemType.Name];
                        else
                        {
                            if (t.IsEnum)
                            {
                                pt = IfcParserType.Enum;
                            }
                            else
                                pt = primitives[t.Name];
                        }

                        if (pt.ToString().ToLower() == "string")
                            propVal.Init("'" + input.Value + "'", pt);
                        else
                        {
                            if (pt.ToString().ToLower() == "boolean")
                                propVal.Init(Convert.ToBoolean(input.Value) ? ".T." : ".F", pt);
                            else
                                propVal.Init(input.Value, pt);
                        }
                        ((XmlEntity)node.Parent).Entity.IfcParse(node.PropertyIndex - 1, propVal);
                    }

                }
                else if (IsIfcType(elementName, out ifcType))
                {
                    IPersistIfc ent;
                    object[] param = new object[1];
                    param[0] = ""; // empty element
                    ent = (IPersistIfc)Activator.CreateInstance(ifcType.Type, param);

                    ((XmlProperty)_currentNode).SetValue(ent);
                }

                return;
            }
            else if (id == -1 && IsIfcProperty(elementName, out propIndex, out prop)) //we have an element which is a property
            {

                string cType = input.GetAttribute(_cTypeAttribute);
                if (string.IsNullOrEmpty(cType)) cType = input.GetAttribute("cType"); //in case namespace omitted
                if (IsCollection(prop)) //the property is a collection
                {
                    XmlCollectionProperty xmlColl = new XmlCollectionProperty(_currentNode, prop.PropertyInfo, propIndex);
                    switch (cType)
                    {
                        case "list":
                            xmlColl.CType = CollectionType.List;
                            break;
                        case "list-unique":
                            xmlColl.CType = CollectionType.ListUnique;
                            break;
                        case "set":
                            xmlColl.CType = CollectionType.Set;
                            break;
                        default:
                            xmlColl.CType = CollectionType.List;
                            break;
                    }

                    _currentNode = xmlColl;
                }
                else //it is a simple value property;
                {


                    // its parent can be a collection, if yes then this property needs to be added to parent
                    XmlNode n = new XmlProperty(_currentNode, prop.PropertyInfo, propIndex);
                    if (_currentNode is XmlCollectionProperty && !(_currentNode.Parent is XmlUosCollection))
                        ((XmlCollectionProperty)_currentNode).Entities.Add(n);

                    if (!input.IsEmptyElement) _currentNode = n;
                }
            }
            else if (id == -1 && IsIfcType(elementName, out ifcType)) // we have an Ifc ExpressType
            {


                // its parent can be a collection, if yes then this property needs to be added to parent
                XmlNode n = new XmlExpressType(_currentNode, ifcType.Type);
                if (_currentNode is XmlCollectionProperty && !(_currentNode.Parent is XmlUosCollection))
                    ((XmlCollectionProperty)_currentNode).Entities.Add(n);

                if (!input.IsEmptyElement) _currentNode = n;
            }
            else if (id == -1 && IsPrimitiveType(elementName, out parserType)) // we have an basic type i.e. double, bool etc
            {
                // its parent can be a collection, if yes then this property needs to be added to parent
                XmlNode n = new XmlBasicType(_currentNode, parserType);
                if (_currentNode is XmlCollectionProperty && !(_currentNode.Parent is XmlUosCollection))
                    ((XmlCollectionProperty)_currentNode).Entities.Add(n);

                if (!input.IsEmptyElement) _currentNode = n;
            }
            else
                throw new Exception("Illegal XML element tag");
        }
예제 #36
0
 private void Read(XmlProperty xmlProperty)
 {
     xmlProperty.Read(_source, _reader);
 }