Exemple #1
0
        private static DOMElement       FromPageRendererXML(XmlElement _element)
        {
            DOMElement R = new DOMElement();

            if (_element.Name == "root")
            {
                R.m_type = ELEMENT_TYPE.ROOT;
            }
            else
            {
                R.m_path = _element.GetAttribute("path");
                string typeName = _element.GetAttribute("type");
                switch (typeName)
                {
                case "TEXT": R.m_type = ELEMENT_TYPE.TEXT; break;

                case "LINK": R.m_type = ELEMENT_TYPE.LINK; break;

                case "IMAGE": R.m_type = ELEMENT_TYPE.IMAGE; break;

                default: R.m_type = ELEMENT_TYPE.UNKNOWN; break;
                }

                float X, Y, W, H;
                if (float.TryParse(_element.GetAttribute("x"), out X) &&
                    float.TryParse(_element.GetAttribute("y"), out Y) &&
                    float.TryParse(_element.GetAttribute("w"), out W) &&
                    float.TryParse(_element.GetAttribute("h"), out H))
                {
                    R.m_rectangle = new RectangleF(X, Y, W, H);
                }

                if (R.m_type == ELEMENT_TYPE.LINK)
                {
                    R.m_URL = _element.GetAttribute("URL");
                }
            }

            List <DOMElement> tempChildren = new List <DOMElement>();

            foreach (XmlNode childNode in _element.ChildNodes)
            {
                if (childNode is XmlElement)
                {
                    tempChildren.Add(FromPageRendererXML(childNode as XmlElement));
                }
            }
            R.m_children = tempChildren.ToArray();

            return(R);
        }
Exemple #2
0
        public void     Read(BinaryReader _reader)
        {
            m_path      = _reader.ReadString();
            m_type      = (ELEMENT_TYPE)_reader.ReadInt32();
            m_rectangle = new RectangleF(_reader.ReadSingle(), _reader.ReadSingle(), _reader.ReadSingle(), _reader.ReadSingle());

            if (m_type == ELEMENT_TYPE.LINK)
            {
                m_URL = _reader.ReadString();
            }

            int childrenCount = _reader.ReadInt32();

            m_children = childrenCount > 0 ? new DOMElement[childrenCount] : null;
            for (int childIndex = 0; childIndex < childrenCount; childIndex++)
            {
                m_children[childIndex] = new DOMElement(_reader);
            }
        }
Exemple #3
0
        /// <summary>
        /// Reads the fiche's description and HTML content
        /// </summary>
        /// <param name="_reader"></param>
        /// <remarks>Heavy chunks are NOT read and will only be accessible asynchronously</remarks>
        public void             Read(BinaryReader _reader)
        {
            uint signature = _reader.ReadUInt32();

            if (signature != SIGNATURE)
            {
                throw new Exception("Unexpected signature!");
            }

            uint versionMajor, versionMinor;

            versionMajor = (uint)_reader.ReadUInt16();
            versionMinor = (uint)_reader.ReadUInt16();
            uint version = (versionMajor << 16) | versionMinor;

            // Read hierarchy
            string strGUID = _reader.ReadString();

            if (!Guid.TryParse(strGUID, out m_GUID))
            {
                throw new Exception("Failed to parse fiche GUID!");
            }

            string strCreationTime = _reader.ReadString();

            if (!DateTime.TryParse(strCreationTime, out m_creationTime))
            {
                throw new Exception("Failed to parse fiche creation time!");
            }

            // We only read the GUIDs while the actual fiches will be processed later
            uint parentsCount = _reader.ReadUInt32();

            while (m_tags.Count > 0)
            {
                RemoveTag(m_tags[0]);
            }
            m_tagGUIDs = new Guid[parentsCount];
            for (int parentIndex = 0; parentIndex < parentsCount; parentIndex++)
            {
                strGUID = _reader.ReadString();
                if (!Guid.TryParse(strGUID, out m_tagGUIDs[parentIndex]))
                {
                    throw new Exception("Failed to parse fiche's parent GUID!");
                }
            }

            // Read content
            string strType = _reader.ReadString();

            if (!Enum.TryParse(strType, out m_type))
            {
                throw new Exception("Failed to parse fiche's type!");
            }
            m_title = _reader.ReadString();
            if (_reader.ReadBoolean())
            {
                string strURL = _reader.ReadString();
                m_URL = WebHelpers.CreateCanonicalURL(strURL);
            }
            if (_reader.ReadBoolean())
            {
                m_HTMLContent = _reader.ReadString();
            }
            if (_reader.ReadBoolean())
            {
                m_rootElement = new Brain2.DOMElement(_reader);
            }

            // Read chunks
            while (m_chunks.Count > 0)
            {
                m_chunks[0].Dispose();
                m_chunks.RemoveAt(0);
            }
            uint chunksCount = _reader.ReadUInt32();

            for (uint chunkIndex = 0; chunkIndex < chunksCount; chunkIndex++)
            {
                string chunkType        = _reader.ReadString();
                uint   chunkLength      = _reader.ReadUInt32();
                ulong  chunkStartOffset = (ulong)_reader.BaseStream.Position;

                ChunkBase chunk = CreateChunkFromType(chunkType, chunkStartOffset, chunkLength);
                if (chunk != null)
                {
                    chunk.Read(_reader);                        // Only shallow data will be available, heavy data will be loaded asynchonously on demand
                }

                // Always jump to chunk's end, whether it read something or not...
                ulong chunkEndOffset = chunkStartOffset + chunkLength;
                _reader.BaseStream.Seek((long)chunkEndOffset, SeekOrigin.Begin);
            }

            // Fiche is now ready!
            m_status = STATUS.READY;
        }