Exemple #1
0
 internal IIfcFileHeader ReadHeader()
 {
     if (Api.TryMoveFirst(sesid, globalsTable))
     {
         byte[] hd = Api.RetrieveColumn(sesid, globalsTable, ifcHeaderColumn);
         if (hd == null)
         {
             return(null);           //there is nothing in at the moment
         }
         BinaryReader  br  = new BinaryReader(new MemoryStream(hd));
         IfcFileHeader hdr = new IfcFileHeader(IfcFileHeader.HeaderCreationMode.LeaveEmpty);
         hdr.Read(br);
         return(hdr);
     }
     else
     {
         return(null);
     }
 }
Exemple #2
0
        internal IfcFileHeader Read(IfcPersistedInstanceCache instanceCache, XbimEntityCursor entityTable, XmlReader input)
        {
            // Read until end of file
            idMap           = new Dictionary <string, int>();
            lastId          = 0;
            _entitiesParsed = 0;
            bool          foundHeader = false;
            IfcFileHeader header      = new IfcFileHeader(IfcFileHeader.HeaderCreationMode.LeaveEmpty);
            string        headerId    = "";

            while (_currentNode == null && input.Read()) //read through to UOS
            {
                switch (input.NodeType)
                {
                case XmlNodeType.Element:
                    if (string.Compare(input.LocalName, "uos", true) == 0)
                    {
                        _currentNode = new XmlUosCollection();
                    }
                    else if (string.Compare(input.LocalName, "iso_10303_28", true) == 0)
                    {
                        foundHeader = true;

                        if (!string.IsNullOrWhiteSpace(input.Prefix))
                        {
                            _expressNamespace  = input.Prefix;
                            _cTypeAttribute    = _expressNamespace + ":cType";
                            _posAttribute      = _expressNamespace + ":pos";
                            _expressNamespace += ":";
                        }
                        else
                        {
                            _cTypeAttribute = "cType";
                            _posAttribute   = "pos";
                        }     //correct the values if the namespace is defined correctly
                        while (input.MoveToNextAttribute())
                        {
                            if (input.Value == "urn:oid:1.0.10303.28.2.1.1" ||
                                input.Value == "urn:iso.org:standard:10303:part(28):version(2):xmlschema:common")
                            {
                                _expressNamespace  = input.LocalName;
                                _cTypeAttribute    = _expressNamespace + ":cType";
                                _posAttribute      = _expressNamespace + ":pos";
                                _expressNamespace += ":";
                                break;
                            }
                        }
                    }
                    else
                    {
                        headerId = input.LocalName.ToLower();
                    }
                    break;

                case XmlNodeType.Text:
                    switch (headerId)
                    {
                    case "name":
                        header.FileName.Name = input.Value;
                        break;

                    case "time_stamp":
                        header.FileName.TimeStamp = input.Value;
                        break;

                    case "author":
                        header.FileName.AuthorName.Add(input.Value);
                        break;

                    case "organization":
                        header.FileName.Organization.Add(input.Value);
                        break;

                    case "preprocessor_version":
                        header.FileName.PreprocessorVersion = input.Value;
                        break;

                    case "originating_system":
                        header.FileName.OriginatingSystem = input.Value;
                        break;

                    case "authorization":
                        header.FileName.AuthorizationName = input.Value;
                        break;

                    case "documentation":
                        header.FileDescription.Description.Add(input.Value);
                        break;

                    default:
                        break;
                    }
                    break;

                default:
                    break;
                }
            }
            if (!foundHeader)
            {
                throw new Exception("Invalid XML format, iso_10303_28 tag not found");
            }

            XmlNodeType prevInputType = XmlNodeType.None;
            string      prevInputName = "";

            // set counter for start of every element that is not empty, and reduce it on every end of that element



            try
            {
                using (var transaction = entityTable.BeginLazyTransaction())
                {
                    // this will create id of each element
                    Dictionary <string, int> ids = new Dictionary <string, int>();
                    while (input.Read())
                    {
                        switch (input.NodeType)
                        {
                        case XmlNodeType.Element:
                            StartElement(instanceCache, input, entityTable, transaction);
                            break;

                        case XmlNodeType.EndElement:
                            IPersistIfcEntity toWrite;
                            //if toWrite has a value we have completed an Ifc Entity
                            EndElement(input, prevInputType, prevInputName, out toWrite);
                            if (toWrite != null)
                            {
                                _entitiesParsed++;
                                //now write the entity to the database
                                entityTable.AddEntity(toWrite);
                                if (_entitiesParsed % _transactionBatchSize == (_transactionBatchSize - 1))
                                {
                                    transaction.Commit();
                                    transaction.Begin();
                                }
                            }
                            break;

                        case XmlNodeType.Whitespace:
                            SetValue(input, prevInputType, prevInputName);
                            break;

                        case XmlNodeType.Text:
                            SetValue(input, prevInputType, prevInputName);
                            break;

                        default:
                            break;
                        }
                        prevInputType = input.NodeType;
                        prevInputName = input.LocalName;
                    }
                    transaction.Commit();
                }
            }
            catch (Exception e)
            {
                throw new Exception(String.Format("Error reading XML, Line={0}, Position={1}, Tag='{2}'", ((IXmlLineInfo)input).LineNumber, ((IXmlLineInfo)input).LinePosition, input.LocalName), e);
            }
            return(header);
        }
Exemple #3
0
        internal IfcFileHeader Read(IfcPersistedInstanceCache instanceCache, XbimEntityCursor entityTable,  XmlReader input)
        {
           
            // Read until end of file
            idMap = new Dictionary<string, int>();
            lastId = 0;
            _entitiesParsed = 0;
            bool foundHeader = false;
            IfcFileHeader header = new IfcFileHeader(IfcFileHeader.HeaderCreationMode.LeaveEmpty);
            string headerId="";
            while (_currentNode == null && input.Read()) //read through to UOS
            {
                switch (input.NodeType)
                {
                    case XmlNodeType.Element:
                        if (string.Compare(input.LocalName, "uos", true) == 0)
                        {
                            _currentNode = new XmlUosCollection();
                           
                        }
                        else if (string.Compare(input.LocalName, "iso_10303_28", true) == 0)
                        {
                            foundHeader = true;
                            if (!string.IsNullOrWhiteSpace(input.Prefix))
                            {
                                _expressNamespace = input.Prefix;
                                _cTypeAttribute = _expressNamespace + ":cType";
                                _posAttribute = _expressNamespace + ":pos";
                                _expressNamespace += ":";
                            }
                            else
                            {
                                _cTypeAttribute = "cType";
                                _posAttribute = "pos";
                            }
                                
                        }
                        else
                        {
                            headerId = input.LocalName.ToLower();
                        }
                        break;
                    case XmlNodeType.Text:
                        switch (headerId)
                        {
                            case "name":
                                header.FileName.Name = input.Value;
                                break;
                            case "time_stamp":
                                header.FileName.TimeStamp= input.Value;
                                break;
                            case "author":
                                header.FileName.AuthorName.Add(input.Value);
                                break;
                            case "organization":
                                header.FileName.Organization.Add(input.Value);
                                break;
                            case "preprocessor_version":
                                header.FileName.PreprocessorVersion = input.Value;
                                break;
                            case "originating_system":
                                header.FileName.OriginatingSystem = input.Value;
                                break;
                            case "authorization":
                                header.FileName.AuthorizationName = input.Value;
                                break;
                            case "documentation":
                                header.FileDescription.Description.Add(input.Value);
                                break;
                            default:
                                break;
                        }
                        break;
                    default:
                        break;
                }
               
            }
            if (!foundHeader)
                throw new Exception("Invalid XML format, iso_10303_28 tag not found");
            XmlNodeType prevInputType = XmlNodeType.None;
            string prevInputName = "";

            // set counter for start of every element that is not empty, and reduce it on every end of that element


           
            try
            {
                using (var transaction = entityTable.BeginLazyTransaction())
                {


                    // this will create id of each element
                    Dictionary<string, int> ids = new Dictionary<string, int>();
                    while (input.Read())
                    {
                        switch (input.NodeType)
                        {
                            case XmlNodeType.Element:
                                StartElement(instanceCache, input, entityTable, transaction);
                                break;
                            case XmlNodeType.EndElement:
                                IPersistIfcEntity toWrite;
                                //if toWrite has a value we have completed an Ifc Entity
                                EndElement(input, prevInputType, prevInputName, out toWrite);
                                if (toWrite != null)
                                {
                                    _entitiesParsed++;
                                    //now write the entity to the database
                                    entityTable.AddEntity(toWrite);
                                    if (_entitiesParsed % _transactionBatchSize == (_transactionBatchSize - 1))
                                    {
                                        transaction.Commit();
                                        transaction.Begin();
                                    }
                                }
                                break;
                            case XmlNodeType.Whitespace:
                                SetValue(input, prevInputType, prevInputName);
                                break;
                            case XmlNodeType.Text:
                                SetValue(input, prevInputType, prevInputName);
                                break;
                            default:
                                break;
                        }
                        prevInputType = input.NodeType;
                        prevInputName = input.LocalName;
                    }
                    transaction.Commit();
                }
            }
            catch(Exception e)
            {
                throw new Exception(String.Format("Error reading XML, Line={0}, Position={1}, Tag='{2}'", ((IXmlLineInfo) input).LineNumber, ((IXmlLineInfo) input).LinePosition, input.LocalName), e);
            }
            return header;
        }