コード例 #1
0
        /// <summary>
        /// Asynchronous implementation of the reader logic when in state 'Operation'.
        /// </summary>
        /// <returns>
        /// A task that represents the asynchronous read operation.
        /// The value of the TResult parameter contains the batch reader state after the read.
        /// </returns>
        protected override async Task <ODataBatchReaderState> ReadAtOperationImplementationAsync()
        {
            if (this.JsonLightInputContext.JsonReader.NodeType != JsonNodeType.StartObject)
            {
                // No more requests in the batch.
                return(await HandleMessagesEndAsync()
                       .ConfigureAwait(false));
            }

            // Load the message properties if there is no cached item for processing.
            if (this.messagePropertiesCache == null)
            {
                // Load the message details since operation is detected.
                this.messagePropertiesCache = await ODataJsonLightBatchPayloadItemPropertiesCache.CreateAsync(this)
                                              .ConfigureAwait(false);
            }

            // Calculate and return next state with changeset state detection.
            return(DetectChangesetStates(this.messagePropertiesCache));
        }
コード例 #2
0
        /// <summary>
        /// Asynchronous implementation of the reader logic when in state 'Start'.
        /// </summary>
        /// <returns>
        /// A task that represents the asynchronous read operation.
        /// The value of the TResult parameter contains the batch reader state after the read.
        /// </returns>
        protected override async Task <ODataBatchReaderState> ReadAtStartImplementationAsync()
        {
            Debug.Assert(this.State == ODataBatchReaderState.Initial, $"{nameof(this.State)} == {nameof(ODataBatchReaderState.Initial)}");

            if (mode == ReaderMode.NotDetected)
            {
                // The stream should be positioned at the beginning of the batch envelope.
                // Need to detect whether we are reading request or response. Stay in Initial state upon return.
                await DetectReaderModeAsync()
                .ConfigureAwait(false);

                return(ODataBatchReaderState.Initial);
            }
            else
            {
                // The stream should be positioned at the beginning of requests array.
                await this.StartReadingBatchArrayAsync()
                .ConfigureAwait(false);

                Debug.Assert(this.messagePropertiesCache == null, $"{nameof(this.messagePropertiesCache)} == null");
                this.messagePropertiesCache = await ODataJsonLightBatchPayloadItemPropertiesCache.CreateAsync(this)
                                              .ConfigureAwait(false);

                string currentGroup = (string)this.messagePropertiesCache.GetPropertyValue(
                    ODataJsonLightBatchPayloadItemPropertiesCache.PropertyNameAtomicityGroup);

                if (currentGroup == null)
                {
                    return(ODataBatchReaderState.Operation);
                }
                else
                {
                    HandleNewAtomicGroupStart(
                        (string)this.messagePropertiesCache.GetPropertyValue(
                            ODataJsonLightBatchPayloadItemPropertiesCache.PropertyNameId),
                        currentGroup);
                    return(ODataBatchReaderState.ChangesetStart);
                }
            }
        }