Esempio n. 1
0
 private bool ReadResourceFromRecord(object record)
 {
     this.item = ODataAvroConvert.ToODataEntry(record as AvroRecord);
     if (record == null)
     {
         this.state = ODataReaderState.Exception;
         return(false);
     }
     return(true);
 }
Esempio n. 2
0
        public override bool Read()
        {
            switch (this.state)
            {
            case ODataReaderState.Start:
                if (this.currentObject == null)
                {
                    if (!this.reader.MoveNext())
                    {
                        this.state = ODataReaderState.Exception;
                        return(false);
                    }

                    this.currentObject = this.reader.Current;
                }

                this.state = readingFeed
                        ? ODataReaderState.FeedStart
                        : ODataReaderState.EntryStart;
                break;

            case ODataReaderState.FeedStart:
                this.item = new ODataFeed();
                var objs = this.currentObject as object[];
                if (objs == null)
                {
                    this.state = ODataReaderState.Exception;
                    return(false);
                }

                this.recordEnumerator = objs.GetEnumerator();

                this.state = (this.recordEnumerator.MoveNext())
                        ? ODataReaderState.EntryStart
                        : ODataReaderState.FeedEnd;
                break;

            case ODataReaderState.FeedEnd:
                this.state = ODataReaderState.Completed;
                return(false);

            case ODataReaderState.EntryStart:
                var record = (this.readingFeed ? this.recordEnumerator.Current : this.currentObject) as AvroRecord;
                if (record == null)
                {
                    this.state = ODataReaderState.Exception;
                    return(false);
                }

                this.item  = ODataAvroConvert.ToODataEntry(record);
                this.state = ODataReaderState.EntryEnd;
                return(true);

            case ODataReaderState.EntryEnd:
                if (!readingFeed)
                {
                    this.state = ODataReaderState.Completed;
                    return(false);
                }

                this.state = this.recordEnumerator.MoveNext()
                        ? ODataReaderState.EntryStart
                        : ODataReaderState.FeedEnd;
                break;

            default:
                throw new ApplicationException("Invalid state");
            }

            return(true);
        }
Esempio n. 3
0
        public override bool Read()
        {
            switch (this.state)
            {
            case ODataReaderState.Start:
                if (this.currentObject == null)
                {
                    if (!this.reader.MoveNext())
                    {
                        this.state = ODataReaderState.Exception;
                        return(false);
                    }

                    this.currentObject = this.reader.Current;
                }

                if (readingFeed)
                {
                    this.state = ODataReaderState.ResourceSetStart;
                }
                else
                {
                    this.state = ODataReaderState.ResourceStart;
                    var record = this.currentObject as AvroRecord;

                    return(ReadResourceFromRecord(this.currentObject));
                }
                break;

            case ODataReaderState.ResourceSetStart:
            {
                this.item = new ODataResourceSet();
                scopes.Push(this.item);
                var objs = this.currentObject as object[];
                if (objs == null)
                {
                    this.state = ODataReaderState.Exception;
                    return(false);
                }

                this.recordEnumerator = objs.GetEnumerator();

                return(MoveToNextAndReadResource());
            }

            case ODataReaderState.ResourceSetEnd:
                this.state = ODataReaderState.Completed;
                return(false);

            case ODataReaderState.ResourceStart:
            {
                var nestedInfo = this.scopes.Count > 0 ? this.scopes.Peek() as ODataNestedResourceInfo : null;
                this.scopes.Push(this.item);
                if (nestedInfo != null)
                {
                    this.state = ODataReaderState.ResourceEnd;
                    return(true);
                }

                var record = (this.readingFeed ? this.recordEnumerator.Current : this.currentObject) as AvroRecord;

                nestedInfo = ODataAvroConvert.GetNestedResourceInfo(record);
                if (nestedInfo != null)
                {
                    this.item  = nestedInfo;
                    this.state = ODataReaderState.NestedResourceInfoStart;
                }
                else
                {
                    this.state = ODataReaderState.ResourceEnd;
                }
                return(true);
            }

            case ODataReaderState.ResourceEnd:
            {
                this.scopes.Pop();

                var nestedInfo = this.scopes.Count > 0 ? this.scopes.Peek() as ODataNestedResourceInfo : null;
                if (nestedInfo != null)
                {
                    this.item  = nestedInfo;
                    this.state = ODataReaderState.NestedResourceInfoEnd;
                    return(true);
                }

                if (!readingFeed)
                {
                    this.state = ODataReaderState.Completed;
                    return(false);
                }

                return(MoveToNextAndReadResource());
            }

            case ODataReaderState.NestedResourceInfoStart:
            {
                this.scopes.Push(this.item);
                var record     = (this.readingFeed ? this.recordEnumerator.Current : this.currentObject) as AvroRecord;
                var nestedInfo = this.item as ODataNestedResourceInfo;
                this.item  = ODataAvroConvert.ToODataEntry(record, nestedInfo.Name);
                this.state = ODataReaderState.ResourceStart;
            }
            break;

            case ODataReaderState.NestedResourceInfoEnd:
                this.scopes.Pop();
                this.item  = this.scopes.Peek();
                this.state = ODataReaderState.ResourceEnd;
                break;

            default:
                throw new ApplicationException("Invalid state");
            }

            return(true);
        }