/// <summary>Returns an <see cref="ODataBatchOperationResponseMessage" /> for reading the content of a batch operation.</summary> /// <returns>A response message for reading the content of a batch operation.</returns> public ODataBatchOperationResponseMessage CreateOperationResponseMessage() { this.VerifyCanCreateOperationResponseMessage(synchronousCall: true); ODataBatchOperationResponseMessage result = this.InterceptException((thisParam) => thisParam.CreateOperationResponseMessageImplementation()); this.ReaderOperationState = OperationState.MessageCreated; return(result); }
/// <summary>Returns an <see cref="Microsoft.OData.ODataBatchOperationResponseMessage" /> for reading the content of a batch operation.</summary> /// <returns>A response message for reading the content of a batch operation.</returns> public ODataBatchOperationResponseMessage CreateOperationResponseMessage() { this.VerifyCanCreateOperationResponseMessage(/*synchronousCall*/ true); ODataBatchOperationResponseMessage result = this.InterceptException((Func <ODataBatchOperationResponseMessage>) this.CreateOperationResponseMessageImplementation); this.ReaderOperationState = OperationState.MessageCreated; return(result); }
/// <summary>Asynchronously returns an <see cref="ODataBatchOperationResponseMessage" /> for reading the content of a batch operation.</summary> /// <returns>A task that when completed returns a response message for reading the content of a batch operation.</returns> public async Task <ODataBatchOperationResponseMessage> CreateOperationResponseMessageAsync() { this.VerifyCanCreateOperationResponseMessage(synchronousCall: false); ODataBatchOperationResponseMessage result = await this.InterceptExceptionAsync( (thisParam) => thisParam.CreateOperationResponseMessageImplementationAsync()).ConfigureAwait(false); this.ReaderOperationState = OperationState.MessageCreated; return(result); }
/// <summary> /// Instantiate an <see cref="ODataBatchOperationResponseMessage"/> instance and set the status code. /// </summary> /// <param name="streamCreatorFunc">The function for stream creation.</param> /// <param name="statusCode">The status code for the response.</param> /// <param name="headers">The headers for this response message.</param> /// <param name="contentId">The contentId of this request message.</param> /// <param name="groupId">The groupId of this request message.</param> /// <returns>The <see cref="ODataBatchOperationResponseMessage"/> instance.</returns> protected ODataBatchOperationResponseMessage BuildOperationResponseMessage( Func <Stream> streamCreatorFunc, int statusCode, ODataBatchOperationHeaders headers, string contentId, string groupId) { ODataBatchOperationResponseMessage responseMessage = new ODataBatchOperationResponseMessage( streamCreatorFunc, headers, this, contentId, this.PayloadUriConverter.BatchMessagePayloadUriConverter, /*writing*/ false, this.container, groupId) { StatusCode = statusCode }; return(responseMessage); }
/// <summary> /// Returns the cached <see cref="ODataBatchOperationRequestMessage"/> for reading the content of an operation /// in a batch request. /// </summary> /// <returns>The message that can be used to read the content of the batch request operation from.</returns> private ODataBatchOperationResponseMessage CreateOperationResponseMessageImplementation() { this.operationState = OperationState.MessageCreated; string responseLine = this.batchStream.ReadFirstNonEmptyLine(); int statusCode = this.ParseResponseLine(responseLine); // Read all headers and create the response message ODataBatchOperationHeaders headers = this.batchStream.ReadHeaders(); if (this.batchStream.ChangeSetBoundary != null) { if (this.allowLegacyContentIdBehaviour) { // Add a potential Content-ID header to the URL resolver so that it will be available // to subsequent operations. string contentId; if (this.contentIdToAddOnNextRead == null && headers.TryGetValue(ODataConstants.ContentIdHeader, out contentId)) { if (contentId != null && this.payloadUriConverter.ContainsContentId(contentId)) { throw new ODataException(Strings.ODataBatchReader_DuplicateContentIDsNotAllowed(contentId)); } this.contentIdToAddOnNextRead = contentId; } } } // In responses we don't need to use our batch URL resolver, since there are no cross referencing URLs // so use the URL resolver from the batch message instead. ODataBatchOperationResponseMessage responseMessage = ODataBatchOperationResponseMessage.CreateReadMessage( this.batchStream, statusCode, headers, this.contentIdToAddOnNextRead, /*operationListener*/ this, this.payloadUriConverter.BatchMessagePayloadUriConverter, this.container); //// NOTE: Content-IDs for cross referencing are only supported in request messages; in responses //// we allow a Content-ID header but don't process it (i.e., don't add the content ID to the URL resolver). return(responseMessage); }
/// <summary> /// Creates an operation response message that can be used to read the operation content from. /// </summary> /// <param name="batchReaderStream">The batch stream underyling the operation response message.</param> /// <param name="statusCode">The status code to use for the operation response message.</param> /// <param name="headers">The headers to use for the operation response message.</param> /// <param name="contentId">The content-ID for the operation response message.</param> /// <param name="operationListener">The operation listener.</param> /// <param name="payloadUriConverter">The (optional) URL converter for the message to create.</param> /// <param name="container">The dependency injection container to get related services.</param> /// <returns>An <see cref="ODataBatchOperationResponseMessage"/> that can be used to read the operation content.</returns> internal static ODataBatchOperationResponseMessage CreateReadMessage( ODataBatchReaderStream batchReaderStream, int statusCode, ODataBatchOperationHeaders headers, string contentId, IODataBatchOperationListener operationListener, IODataPayloadUriConverter payloadUriConverter, IServiceProvider container) { Debug.Assert(batchReaderStream != null, "batchReaderStream != null"); Debug.Assert(operationListener != null, "operationListener != null"); Func <Stream> streamCreatorFunc = () => ODataBatchUtils.CreateBatchOperationReadStream(batchReaderStream, headers, operationListener); ODataBatchOperationResponseMessage responseMessage = new ODataBatchOperationResponseMessage(streamCreatorFunc, headers, operationListener, contentId, payloadUriConverter, /*writing*/ false, container); responseMessage.statusCode = statusCode; return(responseMessage); }