Esempio n. 1
0
        internal protected override bool TryCreate(MetaElementType elementType, out ReadElement element)
        {
            switch (elementType)
            {
            case MetaElementType.Field:
                FieldReadElement fieldReadElement = new FieldReadElement();
                fieldList.Add(fieldReadElement);
                element = fieldReadElement;
                return(true);

            case MetaElementType.Sequence:
                SequenceReadElement sequenceReadElement = new SequenceReadElement();
                sequenceList.Add(sequenceReadElement);
                element = sequenceReadElement;
                return(true);

            case MetaElementType.Substitution:
                SubstitutionReadElement substitutionReadElement = new SubstitutionReadElement();
                substitutionList.Add(substitutionReadElement);
                element = substitutionReadElement;
                return(true);

            default:
                element = null;
                return(false);
            }
        }
Esempio n. 2
0
        private void TryAddOrIgnoreAttribute(ReadElement readElement, string name, string value)
        {
            string errorDescription;

            if (!readElement.TryAddOrIgnoreAttribute(name, value, out errorDescription))
            {
                throw new FtMetaSerializationException(string.Format(Properties.Resources.XmlMetaSerializationReader_Read_AttributeError,
                                                                     name, value, errorDescription));
            }
        }
Esempio n. 3
0
        private void ReadAttributes(XmlReader reader, ReadElement readElement)
        {
            if (reader.MoveToFirstAttribute())
            {
                TryAddOrIgnoreAttribute(readElement, reader.Name, reader.Value);

                while (reader.MoveToNextAttribute())
                {
                    TryAddOrIgnoreAttribute(readElement, reader.Name, reader.Value);
                }
            }
        }
Esempio n. 4
0
        internal protected override bool TryCreate(MetaElementType elementType, out ReadElement element)
        {
            switch (elementType)
            {
            case MetaElementType.SequenceItem:
                SequenceItemReadElement itemReadElement = new SequenceItemReadElement();
                itemList.Add(itemReadElement);
                element = itemReadElement;
                return(true);

            default:
                element = null;
                return(false);
            }
        }
Esempio n. 5
0
        internal protected override bool TryCreate(MetaElementType elementType, out ReadElement element)
        {
            switch (elementType)
            {
            case MetaElementType.SequenceRedirect:
                SequenceRedirectReadElement redirectReadElement = new SequenceRedirectReadElement();
                redirectList.Add(redirectReadElement);
                element = redirectReadElement;
                return(true);

            default:
                element = null;
                return(false);
            }
        }
Esempio n. 6
0
 internal protected override bool TryCreate(MetaElementType elementType, out ReadElement element)
 {
     element = null;
     return(false);
 }
Esempio n. 7
0
        internal protected virtual FtMeta Read(XmlReader reader)
        {
            if (!reader.ReadToFollowing(MetaElementTypeFormatter.ToElementName(MetaElementType.FieldedText)))
            {
                return(null);
            }
            else
            {
                bool emptyElement = reader.IsEmptyElement;
                FieldedTextReadElement rootElement = ReadElement.CreateFieldedTextXmlReadElement();
                ReadAttributes(reader, rootElement);

                if (!emptyElement)
                {
                    ReadElement activeElement       = rootElement;
                    Stack       parentStack         = new Stack();
                    int         foreignElementDepth = 0;

                    while (activeElement != null)
                    {
                        if (!reader.Read())
                        {
                            throw new FtMetaSerializationException(Properties.Resources.XmlMetaSerializationReader_Read_IncompleteXmlStream);
                        }

                        switch (reader.NodeType)
                        {
                        case XmlNodeType.Element:
                            emptyElement = reader.IsEmptyElement;

                            if (foreignElementDepth > 0)
                            {
                                if (!emptyElement)
                                {
                                    foreignElementDepth++;
                                }
                            }
                            else
                            {
                                MetaElementType elementType;
                                if (!MetaElementTypeFormatter.TryParseElementName(reader.Name, out elementType))
                                {
                                    if (!emptyElement)
                                    {
                                        foreignElementDepth++;
                                    }
                                }
                                else
                                {
                                    ReadElement newActiveElement;
                                    if (activeElement.TryCreate(elementType, out newActiveElement))
                                    {
                                        parentStack.Push(activeElement);
                                        activeElement = newActiveElement;

                                        ReadAttributes(reader, activeElement);

                                        if (emptyElement)
                                        {
                                            if (parentStack.Count > 0)
                                            {
                                                activeElement = parentStack.Pop();
                                            }
                                            else
                                            {
                                                activeElement = null;
                                            }
                                        }
                                    }
                                }
                            }
                            break;

                        case XmlNodeType.EndElement:
                            if (foreignElementDepth > 0)
                            {
                                foreignElementDepth--;
                            }
                            else
                            {
                                if (parentStack.Count > 0)
                                {
                                    activeElement = parentStack.Pop();
                                }
                                else
                                {
                                    activeElement = null;
                                }
                            }
                            break;
                        }
                    }
                }

                string errorDescription;
                FtMeta result = MetaFactory.CreateMeta();
                if (!rootElement.ResolveTo(result, out errorDescription))
                {
                    throw new FtMetaSerializationException(errorDescription);
                }
                return(result);
            }
        }