public override bool Read()
        {
            switch (this.State)
            {
                case ODataParameterReaderState.Start:
                    if (!this.inputContext.AvroReader.MoveNext())
                    {
                        this.state = ODataParameterReaderState.Completed;
                        return false;
                    }

                    this.avroRecord = this.inputContext.AvroReader.Current as AvroRecord;
                    if (this.avroRecord == null)
                    {
                        this.state = ODataParameterReaderState.Exception;
                        return false;
                    }

                    this.enumerator = this.avroRecord.Schema.Fields.GetEnumerator();
                    return this.UpdateState();
                case ODataParameterReaderState.Value:
                case ODataParameterReaderState.Entry:
                case ODataParameterReaderState.Feed:
                    return this.UpdateState();
                default:
                    throw new ApplicationException("Invalid state " + this.State);
            }
        }
        public ODataAvroParameterReader(ODataAvroInputContext inputContext, IEdmOperation operation)
        {
            Debug.Assert(inputContext != null, "inputContext != null");
            Debug.Assert(operation != null, "operation != null");

            this.inputContext = inputContext;
            this.operation = operation;
            this.state = ODataParameterReaderState.Start;
        }
Exemplo n.º 3
0
        private void RunParameterReaderErrorTest(
            ODataParameterReaderTestWrapper reader,
            ExpectedException expectedException,
            ODataParameterReaderState expectedState = ODataParameterReaderState.Exception)
        {
            if (reader == null)
            {
                // Reader creation failed and we verified the exception already
                return;
            }

            this.Assert.ExpectedException(() => reader.Read(), expectedException, this.ExceptionVerifier);
            this.Assert.AreEqual(expectedState, reader.State, "Reader should be in '" + expectedState.ToString() + "' state.");
        }
        private bool UpdateState()
        {
            if (!this.enumerator.MoveNext())
            {
                this.state = ODataParameterReaderState.Completed;
                return false;
            }

            var parameter = this.operation.Parameters.SingleOrDefault(para => para.Name == this.enumerator.Current.Name);
            if (parameter == null)
            {
                throw new ApplicationException("Given parameter name " + this.enumerator.Current.Name + " not found.");
            }

            this.name = parameter.Name;
            this.value = this.avroRecord[this.enumerator.Current.Position];
            if (this.value is AvroRecord)
            {
                if (parameter.Type.Definition is IEdmComplexType)
                {
                    this.value = ODataAvroConvert.ToODataComplexValue((AvroRecord)this.value);
                    this.state = ODataParameterReaderState.Value;
                }
                else if (parameter.Type.Definition is IEdmEntityType)
                {
                    this.state = ODataParameterReaderState.Entry;
                }
                else
                {
                    this.state = ODataParameterReaderState.Exception;
                    return false;
                }
            }
            else if (this.value is Array && !(this.value is byte[]))
            {
                this.state = ODataParameterReaderState.Feed;
            }
            else
            {
                this.state = ODataParameterReaderState.Value;
            }

            return true;
        }