Ejemplo n.º 1
0
        protected bool ReadImplementation()
        {
            bool flag = false;

            switch (this.State)
            {
            case ODataParameterReaderState.Start:
                flag = this.ReadAtStartImplementation();
                break;

            case ODataParameterReaderState.Value:
            case ODataParameterReaderState.Collection:
                this.subReaderState = SubReaderState.None;
                flag = this.ReadNextParameterImplementation();
                break;

            case ODataParameterReaderState.Exception:
            case ODataParameterReaderState.Completed:
                throw new ODataException(Microsoft.Data.OData.Strings.General_InternalError(InternalErrorCodes.ODataParameterReader_ReadImplementation));

            default:
                throw new ODataException(Microsoft.Data.OData.Strings.General_InternalError(InternalErrorCodes.ODataParameterReader_ReadImplementation));
            }
            if (this.State != ODataParameterReaderState.Completed)
            {
                if (this.parametersRead.Contains(this.Name))
                {
                    throw new ODataException(Microsoft.Data.OData.Strings.ODataParameterReaderCore_DuplicateParametersInPayload(this.Name));
                }
                this.parametersRead.Add(this.Name);
            }
            return(flag);
        }
Ejemplo n.º 2
0
        public override ODataCollectionReader CreateCollectionReader()
        {
            this.VerifyCanCreateSubReader(ODataParameterReaderState.Collection);
            this.subReaderState = SubReaderState.Active;
            IEdmTypeReference elementType = ((IEdmCollectionType)this.GetParameterTypeReference(this.Name).Definition).ElementType;

            return(this.CreateCollectionReader(elementType));
        }
        /// <summary>
        /// This method creates an <see cref="ODataCollectionReader"/> to read the collection value when the state is ODataParameterReaderState.Collection.
        /// </summary>
        /// <remarks>
        /// When the state is ODataParameterReaderState.Collection, the Name property of the <see cref="ODataParameterReader"/> returns the name of the parameter
        /// and the Value property of the <see cref="ODataParameterReader"/> returns null. Calling this method in any other state will cause an ODataException to be thrown.
        /// </remarks>
        /// <returns>Returns an <see cref="ODataCollectionReader"/> to read the collection value when the state is ODataParameterReaderState.Collection.</returns>
        public override ODataCollectionReader CreateCollectionReader()
        {
            this.VerifyCanCreateSubReader(ODataParameterReaderState.Collection);
            this.subReaderState = SubReaderState.Active;
            Debug.Assert(this.Name != null, "this.Name != null");
            Debug.Assert(this.Value == null, "this.Value == null");
            IEdmTypeReference expectedItemTypeReference = ((IEdmCollectionType)this.GetParameterTypeReference(this.Name).Definition).ElementType;

            return(this.CreateCollectionReader(expectedItemTypeReference));
        }
        /// <summary>
        /// This method creates an <see cref="ODataReader"/> to read the feed value when the state is ODataParameterReaderState.Feed.
        /// </summary>
        /// <remarks>
        /// When the state is ODataParameterReaderState.Feed, the Name property of the <see cref="ODataParameterReader"/> returns the name of the parameter
        /// and the Value property of the <see cref="ODataParameterReader"/> returns null. Calling this method in any other state will cause an ODataException to be thrown.
        /// </remarks>
        /// <returns>Returns an <see cref="ODataReader"/> to read the feed value when the state is ODataParameterReaderState.Feed.</returns>
        public override ODataReader CreateFeedReader()
        {
            this.VerifyCanCreateSubReader(ODataParameterReaderState.Feed);
            this.subReaderState = SubReaderState.Active;
            Debug.Assert(this.Name != null, "this.Name != null");
            Debug.Assert(this.Value == null, "this.Value == null");
            IEdmEntityType expectedEntityType = (IEdmEntityType)((IEdmCollectionType)this.GetParameterTypeReference(this.Name).Definition).ElementType.Definition;

            return(this.CreateFeedReader(expectedEntityType));
        }
Ejemplo n.º 5
0
 /// <summary>
 /// This method notifies the implementer of this interface that the created reader is in Completed state.
 /// </summary>
 void IODataReaderWriterListener.OnCompleted()
 {
     Debug.Assert(
         this.State == ODataParameterReaderState.Resource ||
         this.State == ODataParameterReaderState.ResourceSet ||
         this.State == ODataParameterReaderState.Collection,
         "OnCompleted called in unexpected state: " + this.State);
     Debug.Assert(this.State == ODataParameterReaderState.Exception || this.subReaderState == SubReaderState.Active, "OnCompleted called in unexpected subReaderState: " + this.subReaderState);
     this.subReaderState = SubReaderState.Completed;
 }
Ejemplo n.º 6
0
        /// <summary>
        /// This method creates an <see cref="ODataReader"/> to read the resource value when the state is ODataParameterReaderState.Resource.
        /// </summary>
        /// <remarks>
        /// When the state is ODataParameterReaderState.Resource, the Name property of the <see cref="ODataParameterReader"/> returns the name of the parameter
        /// and the Value property of the <see cref="ODataParameterReader"/> returns null. Calling this method in any other state will cause an ODataException to be thrown.
        /// </remarks>
        /// <returns>Returns an <see cref="ODataReader"/> to read the resource value when the state is ODataParameterReaderState.Resource.</returns>
        public override ODataReader CreateResourceReader()
        {
            this.VerifyCanCreateSubReader(ODataParameterReaderState.Resource);
            this.subReaderState = SubReaderState.Active;
            Debug.Assert(this.Name != null, "this.Name != null");
            Debug.Assert(this.Value == null, "this.Value == null");
            IEdmStructuredType expectedResourceType = (IEdmStructuredType)this.GetParameterTypeReference(this.Name).Definition;

            return(this.CreateResourceReader(expectedResourceType));
        }
        /// <summary>
        /// This method notifies the implementer of this interface that the created reader is in Completed state.
        /// </summary>
        void IODataReaderWriterListener.OnCompleted()
        {
            Debug.Assert(
#if SUPPORT_ENTITY_PARAMETER
                this.State == ODataParameterReaderState.Entry ||
                this.State == ODataParameterReaderState.Feed ||
#endif
                this.State == ODataParameterReaderState.Collection,
                "OnCompleted called in unexpected state: " + this.State);
            Debug.Assert(this.State == ODataParameterReaderState.Exception || this.subReaderState == SubReaderState.Active, "OnCompleted called in unexpected subReaderState: " + this.subReaderState);
            this.subReaderState = SubReaderState.Completed;
        }
 /// <summary>
 /// Called when the a parameter was completed.
 /// </summary>
 protected void OnParameterCompleted()
 {
     Debug.Assert(this.State == ODataParameterReaderState.Value || this.subReaderState == SubReaderState.Completed, "this.State == ODataParameterReaderState.Value || this.subReaderState == SubReaderState.Completed");
     this.subReaderState = SubReaderState.None;
 }
Ejemplo n.º 9
0
 void IODataReaderWriterListener.OnCompleted()
 {
     this.subReaderState = SubReaderState.Completed;
 }
        /// <summary>
        /// Reads the next <see cref="ODataItem"/> from the message payload.
        /// </summary>
        /// <returns>true if more items were read; otherwise false.</returns>
        protected bool ReadImplementation()
        {
            bool result = false;

            switch (this.State)
            {
            case ODataParameterReaderState.Start:
                result = this.ReadAtStartImplementation();
                Debug.Assert(
                    this.State == ODataParameterReaderState.Value ||
#if SUPPORT_ENTITY_PARAMETER
                    this.State == ODataParameterReaderState.Entry ||
                    this.State == ODataParameterReaderState.Feed ||
#endif
                    this.State == ODataParameterReaderState.Collection ||
                    this.State == ODataParameterReaderState.Completed,
                    "ReadAtParameterStartImplementation should transition the state to ODataParameterReaderState.Value, ODataParameterReaderState.Entry, ODataParameterReaderState.Feed, ODataParameterReaderState.Collection or ODataParameterReaderState.Completed. The current state is: " + this.State);
                break;

            case ODataParameterReaderState.Value:
#if SUPPORT_ENTITY_PARAMETER
            case ODataParameterReaderState.Entry:
            case ODataParameterReaderState.Feed:
#endif
            case ODataParameterReaderState.Collection:
                Debug.Assert(this.State == ODataParameterReaderState.Value || this.subReaderState == SubReaderState.Completed, "this.State == ODataParameterReaderState.Value || this.subReaderState == SubReaderState.Completed");
                this.subReaderState = SubReaderState.None;
                result = this.ReadNextParameterImplementation();
                Debug.Assert(
                    this.State == ODataParameterReaderState.Value ||
#if SUPPORT_ENTITY_PARAMETER
                    this.State == ODataParameterReaderState.Entry ||
                    this.State == ODataParameterReaderState.Feed ||
#endif
                    this.State == ODataParameterReaderState.Collection ||
                    this.State == ODataParameterReaderState.Completed,
                    "ReadAtParameterStartImplementation should transition the state to ODataParameterReaderState.Value, ODataParameterReaderState.Entry, ODataParameterReaderState.Feed, ODataParameterReaderState.Collection or ODataParameterReaderState.Completed. The current state is: " + this.State);
                break;

            case ODataParameterReaderState.Exception:        // fall through
            case ODataParameterReaderState.Completed:
                Debug.Assert(false, "This case should have been caught earlier.");
                throw new ODataException(Strings.General_InternalError(InternalErrorCodes.ODataParameterReader_ReadImplementation));

            default:
                Debug.Assert(false, "Unsupported parameter reader state " + this.State + " detected.");
                throw new ODataException(Strings.General_InternalError(InternalErrorCodes.ODataParameterReader_ReadImplementation));
            }

            if (this.State != ODataParameterReaderState.Completed)
            {
                Debug.Assert(!string.IsNullOrEmpty(this.Name), "!string.IsNullOrEmpty(this.Name)");
                if (this.parametersRead.Contains(this.Name))
                {
                    throw new ODataException(Strings.ODataParameterReaderCore_DuplicateParametersInPayload(this.Name));
                }

                this.parametersRead.Add(this.Name);
            }

            return(result);
        }