Exemple #1
0
 public TableEntityReader(string json)
 {
     if (string.IsNullOrEmpty(json))
     {
         throw new ArgumentException("json");
     }
     scanner = new JsonScanner(json);
     state   = TableEntityReaderState.Initial;
 }
Exemple #2
0
        public bool MoveNext()
        {
            ThrowIfDisposed();
            if (state == TableEntityReaderState.Done)
            {
                return(false);
            }
            JsonToken jsonToken = PopToken();

            if (jsonToken.Type == JsonTokenType.EndObject)
            {
                state = TableEntityReaderState.Done;
                return(false);
            }
            if (jsonToken.Type == JsonTokenType.String)
            {
                currentName = jsonToken.GetStringValue();
            }
            else
            {
                ThrowFormatException("Expecting a name but found '{0}'", jsonToken.Lexeme);
            }
            Expect(JsonTokenType.Colon);
            JsonToken jsonToken2 = PopToken();

            if (EdmSchemaMapping.IsDocumentDBProperty(currentName) || currentName == "$pk" || currentName == "$id")
            {
                switch (jsonToken2.Type)
                {
                case JsonTokenType.String:
                    currentEdmType = DataType.String;
                    currentValue   = jsonToken2;
                    break;

                case JsonTokenType.Number:
                    currentEdmType = DataType.Double;
                    currentValue   = jsonToken2;
                    break;

                default:
                    ThrowFormatException("Unexpected value type '{0}' for DocumentDB property.", jsonToken2.Type);
                    break;
                }
            }
            else
            {
                if (jsonToken2.Type != JsonTokenType.BeginObject)
                {
                    ThrowFormatException("Value is expected to be an object instead it was '{0}'.", jsonToken2.Type);
                }
                currentEdmType = ParseEdmType();
            }
            TryReadComma();
            state = TableEntityReaderState.HasValue;
            return(true);
        }
Exemple #3
0
        public bool MoveNext()
        {
            this.ThrowIfDisposed();
            if (this.state == TableEntityReaderState.Done)
            {
                return(false);
            }

            JsonToken nameToken = this.PopToken();

            if (nameToken.Type == JsonTokenType.EndObject)
            {
                this.state = TableEntityReaderState.Done;
                return(false);
            }

            if (nameToken.Type == JsonTokenType.String)
            {
                string name = nameToken.GetStringValue();
                if (this.IsDocumentDBProperty(name))
                {
                    // just skip it
                    this.Expect(JsonTokenType.Colon);
                    this.PopToken();
                    this.TryReadComma();
                    return(this.MoveNext());
                }

                this.currentName = nameToken.GetStringValue();
            }
            else
            {
                this.ThrowFormatException("Expecting a name but found '{0}'", nameToken.Lexeme);
            }

            this.Expect(JsonTokenType.Colon);
            JsonToken valueToken = this.PopToken();

            if (valueToken.Type != JsonTokenType.BeginObject)
            {
                this.ThrowFormatException("Value is expected to be an object instead it was '{0}'.", valueToken.Type);
            }

            this.currentEdmType = this.ParseEdmType();
            this.TryReadComma();
            this.state = TableEntityReaderState.HasValue;

            return(true);
        }