Esempio n. 1
0
        void IBaseTypeMembersReader.ReadMembers(object instance, INXmlElementReader nodeReader, IDataType type)
        {
            var dictionary = (IDictionary)instance;

            using (var itemNodesReader = nodeReader.GetNextChildNode("items"))
            {
                var numberOfItemPairs = itemNodesReader.Attributes.GetInteger("count");
                for (var itemIndex = 0; itemIndex < numberOfItemPairs; itemIndex++)
                {
                    object key;
                    object value;

                    using (var keyReader = itemNodesReader.GetNextChildNode())
                    {
                        key = objectReader.Get(keyReader);
                    }

                    using (var valueReader = itemNodesReader.GetNextChildNode())
                    {
                        value = objectReader.Get(valueReader);
                    }

                    dictionary.Add(key, value);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// A função correspondente à transição correspondente ao ponto interno aos delimitadores.
        /// </summary>
        /// <param name="reader">O leitor de símbolos.</param>
        /// <returns>O próximo estado.</returns>
        /// <exception cref="UtilitiesDataException">Se a leitura falhar no estado corrente.</exception>
        private IState <SymbValue, SymbType> InsideDelimitersTransition(IObjectReader <ISymbol <SymbValue, SymbType> > reader)
        {
            var symbolsStack = new Stack <SymbType>();
            var symbol       = reader.Get();

            symbolsStack.Push(symbol.SymbolType);
            this.currentSymbolValues.Add(symbol);
            while (symbolsStack.Count > 0)
            {
                var topValue = symbolsStack.Pop();
                if (reader.IsAtEOF())
                {
                    var dataParser = this.provider(
                        this.currentRowNumber,
                        this.currentColumnNumber);

                    var error  = new LogStatus <string, EParseErrorLevel>();
                    var parsed = dataParser.Parse(this.currentSymbolValues.ToArray(), error);
                    if (error.HasLogs(EParseErrorLevel.ERROR))
                    {
                        throw new UtilitiesDataException(string.Format(
                                                             "Can't parse value from cell with coords ({0},{1}) with the provided parser.",
                                                             this.currentRowNumber,
                                                             this.currentRowNumber));
                    }

                    this.currentRow.Add(parsed);
                    this.dataAdder.Add(this.currentTable, this.currentRow);
                    return(this.states[1]);
                }
                else
                {
                    symbol = reader.Get();
                    var close = this.delimiters[topValue];
                    if (close.Contains(symbol.SymbolType))
                    {
                        this.currentSymbolValues.Add(symbol);
                    }
                    else
                    {
                        if (!this.ignoreSymbolTypes.Contains(symbol.SymbolType))
                        {
                            this.currentSymbolValues.Add(symbol);
                        }

                        symbolsStack.Push(topValue);
                        if (this.delimiters.ContainsKey(symbol.SymbolType))
                        {
                            symbolsStack.Push(symbol.SymbolType);
                        }
                    }
                }
            }

            reader.UnGet();
            return(this.states[2]);
        }
Esempio n. 3
0
        public object Get(INXmlElementReader nodeReader)
        {
            var valuesList = new ArrayList();

            using (var itemNodes = nodeReader.GetNextChildNode("items"))
            {
                INXmlElementReader itemNode;
                while ((itemNode = itemNodes.GetNextChildNode()) != null)
                {
                    if (objectReader.CanRead(itemNode))
                    {
                        valuesList.Add(objectReader.Get(itemNode));
                    }

                    itemNode.Dispose();
                }
            }

            var elementType    = typeFinder.GetType(nodeReader.Attributes.Get("type")).GetElementType();
            var objectInstance = valuesList.ToArray(elementType.GetTargetType());

            readObjects.Add(nodeReader.Attributes.GetInteger("ID"), objectInstance);

            return(objectInstance);
        }
Esempio n. 4
0
        /// <summary>
        /// A função correspondente à transição inicial.
        /// </summary>
        /// <param name="reader">O leitor de símbolos.</param>
        /// <returns>O próximo estado.</returns>
        /// <exception cref="UtilitiesDataException">Se a leitura falhar no estado corrente.</exception>
        private IState <SymbValue, SymbType> StartTransition(IObjectReader <ISymbol <SymbValue, SymbType> > reader)
        {
            if (reader.IsAtEOF())
            {
                return(this.states[1]);
            }
            else
            {
                var symbol = reader.Get();
                if (symbol.SymbolType.Equals(this.lineSeparator))
                {
                    this.dataAdder.Add(this.currentTable, this.currentRow);
                    ++this.currentRowNumber;
                    return(this.states[2]);
                }
                else if (symbol.SymbolType.Equals(this.columnSeparator))
                {
                    var dataParser = this.provider(
                        this.currentRowNumber,
                        this.currentColumnNumber);

                    var error  = new LogStatus <string, EParseErrorLevel>();
                    var parsed = dataParser.Parse(
                        this.currentSymbolValues.ToArray(), error);
                    if (error.HasLogs(EParseErrorLevel.ERROR))
                    {
                        throw new UtilitiesDataException(string.Format(
                                                             "Can't parse value from cell with coords ({0},{1}) with the provided parser.",
                                                             this.currentRowNumber,
                                                             this.currentRowNumber));
                    }

                    this.currentRow.Add(parsed);
                    ++this.currentColumnNumber;
                    return(this.states[2]);
                }
                else if (this.delimiters.ContainsKey(symbol.SymbolType))
                {
                    reader.UnGet();
                    return(this.states[3]);
                }
                else
                {
                    if (!this.ignoreSymbolTypes.Contains(symbol.SymbolType))
                    {
                        this.currentSymbolValues.Add(symbol);
                    }

                    return(this.states[2]);
                }
            }
        }
Esempio n. 5
0
        void IBaseTypeMembersReader.ReadMembers(object instance, INXmlElementReader nodeReader, IDataType type)
        {
            var list = (IList)instance;

            using (var itemNodes = nodeReader.GetNextChildNode("items"))
            {
                var numberOfItems = itemNodes.Attributes.GetInteger("count");

                while (numberOfItems-- > 0)
                {
                    INXmlElementReader itemNode;
                    using (itemNode = itemNodes.GetNextChildNode())
                    {
                        list.Add(objectReader.Get(itemNode));
                    }
                }
            }
        }
Esempio n. 6
0
        public MetaData Read(XmlStreamReader inputStream)
        {
            MetaData metaData;

            if (inputStream.SeekFromEnd(string.Format("<c type=\"{0}\"", typeof(MetaData).FullName)))
            {
                using (var nodeReader = new XmlElementReaderFactory(inputStream).Create())
                {
                    metaData = (MetaData)objectReader.Get(nodeReader);
                }
            }
            else
            {
                throw new UnableToReadXMLTextException("Missing metadata.");
            }

            return(metaData);
        }
Esempio n. 7
0
        public Payload Read(XmlStreamReader inputStream)
        {
            Payload payload;

            inputStream.Seek(0, SeekOrigin.Begin);
            if (inputStream.Seek("<c type=\"!0\""))
            {
                using (var nodeReader = new XmlElementReaderFactory(inputStream).Create())
                {
                    payload = (Payload)objectReader.Get(nodeReader);
                }
            }
            else
            {
                throw new UnableToReadXMLTextException("Missing payload.");
            }

            return(payload);
        }
Esempio n. 8
0
        public IMemberValue Read(INXmlElementReader nodeReader, IDataType type)
        {
            var fieldName = nodeReader.Attributes.Get("name");

            var field = type.GetField(fieldName);

            if (field == null)
            {
                throw new UnableToReadXMLTextException(
                          string.Format("Unable to find field '{0}'.", fieldName));
            }

            IMemberValue value;

            using (var valueNode = nodeReader.GetNextChildNode())
            {
                value = new FieldValue(field, objectReader.Get(valueNode));
            }

            return(value);
        }