Пример #1
0
        private void WriteEntryImplementation(ODataResource entry)
        {
            if (this.schema == null)
            {
                this.schema = this.outputContext.AvroWriter.UpdateSchema(entry, null, this.writingFeed);
            }

            if (this.scopes.Count > 0)
            {
                var parent = this.scopes.Pop() as ODataNestedResourceInfo;
                var obj    = this.currentEntityObject;
                ODataAvroConvert.UpdateNestedInfoFromODataObject(obj, entry, parent, schema);
            }
            else
            {
                var obj = (AvroRecord)ODataAvroConvert.FromODataObject(entry, this.schema);

                if (this.writingFeed)
                {
                    this.entityObjectList.Add(obj);
                    this.currentEntityObject = obj;
                }
                else
                {
                    this.currentEntityObject = obj;
                }
            }
        }
Пример #2
0
        public override void WriteError(ODataError error, bool includeDebugInformation)
        {
            var schema = this.AvroWriter.UpdateSchema(error, null);
            var obj    = ODataAvroConvert.FromODataObject(error, schema);

            this.AvroWriter.Write(obj);
            this.Flush();
        }
Пример #3
0
        public override void WriteProperty(ODataProperty property)
        {
            var schema = this.AvroWriter.UpdateSchema(property.Value, null);
            var obj    = ODataAvroConvert.FromODataObject(property.Value, schema);

            this.AvroWriter.Write(obj);
            this.Flush();
        }
Пример #4
0
 private bool ReadResourceFromRecord(object record)
 {
     this.item = ODataAvroConvert.ToODataEntry(record as AvroRecord);
     if (record == null)
     {
         this.state = ODataReaderState.Exception;
         return(false);
     }
     return(true);
 }
Пример #5
0
        public override ODataProperty ReadProperty(IEdmStructuralProperty property, IEdmTypeReference expectedPropertyTypeReference)
        {
            if (!this.AvroReader.MoveNext())
            {
                throw new ApplicationException("Error Reader state");
            }

            return(new ODataProperty {
                Value = ODataAvroConvert.ToODataValue(this.AvroReader.Current)
            });
        }
Пример #6
0
        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);
        }
Пример #7
0
        private void WriteEntryImplementation(ODataEntry entry)
        {
            if (this.schema == null)
            {
                this.schema = this.outputContext.AvroWriter.UpdateSchema(entry, null, this.writingFeed);
            }

            var obj = (AvroRecord)ODataAvroConvert.FromODataObject(entry, this.schema);

            if (this.writingFeed)
            {
                this.entityObjectList.Add(obj);
            }
            else
            {
                this.currentEntityObject = obj;
            }
        }
Пример #8
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);
        }
 public override void WriteValue(string parameterName, object parameterValue)
 {
     this.record[parameterName] = ODataAvroConvert.FromODataObject(parameterValue, this.GetSubSchema(parameterName));
 }
Пример #10
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);
        }