Esempio n. 1
0
        public object restoreObject(XmlReader xmlReader)
        {
            Object lastReadObject = null;

            try
            {
                while (xmlReader.Read())
                {
                    if (xmlReader.NodeType == XmlNodeType.Element)
                    {
                        if (xmlReader.Name.Equals(SAVEABLE_ELEMENT))
                        {
                            int    version    = 0;
                            String versionStr = xmlReader.GetAttribute(VERSION_ATTIBUTE);
                            if (versionStr != null)
                            {
                                version = NumberParser.ParseInt(versionStr);
                            }
                            ObjectIdentifier objectId = ObjectIdentifierFactory.CreateObjectIdentifier(NumberParser.ParseLong(xmlReader.GetAttribute(ID_ATTIBUTE)), xmlReader.GetAttribute(TYPE_ATTRIBUTE), typeFinder);
                            loadControl.startDefiningObject(objectId, version);
                            //If the element is empty do not bother to loop looking for elements.
                            if (!xmlReader.IsEmptyElement)
                            {
                                while (!(xmlReader.Name == SAVEABLE_ELEMENT && xmlReader.NodeType == XmlNodeType.EndElement) && xmlReader.Read())
                                {
                                    if (xmlReader.NodeType == XmlNodeType.Element)
                                    {
                                        valueReaders[xmlReader.Name].readValue(loadControl, xmlReader);
                                    }
                                }
                            }
                            lastReadObject = loadControl.createCurrentObject();
                        }
                    }
                }
            }
            finally
            {
                loadControl.reset();
            }
            return(lastReadObject);
        }
Esempio n. 2
0
        private Object readSaveable(JsonReader reader)
        {
            reader.Read();
            int version = 0;
            ObjectIdentifier objectId = ParseHeaderObject(reader, ref version);

            loadControl.startDefiningObject(objectId, version);
            bool keepReading = true;

            while (keepReading && reader.Read())
            {
                switch (reader.TokenType)
                {
                case JsonToken.PropertyName:
                    readProp(reader);
                    break;

                case JsonToken.EndObject:
                    keepReading = false;
                    break;
                }
            }
            return(loadControl.createCurrentObject());
        }