/// <summary> /// Asynchronously creates an <see cref="ODataBatchWriter" /> to write a batch of requests or responses. /// </summary> /// <param name="batchBoundary">The boundary string for the batch structure itself.</param> /// <returns>A running task for the created batch writer.</returns> /// <remarks>We don't plan to make this public!</remarks> /// <remarks>The write must flush the output when it's finished (inside the last Write call).</remarks> internal override Task <ODataBatchWriter> CreateODataBatchWriterAsync(string batchBoundary) { DebugUtils.CheckNoExternalCallers(); this.AssertAsynchronous(); return(TaskUtils.GetTaskForSynchronousOperation(() => this.CreateODataBatchWriterImplementation(batchBoundary))); }
/// <summary> /// Asynchronously create a <see cref="ODataBatchReader"/>. /// </summary> /// <param name="batchBoundary">The batch boundary to use.</param> /// <returns>Task which when completed returns the newly created <see cref="ODataCollectionReader"/>.</returns> internal override Task <ODataBatchReader> CreateBatchReaderAsync(string batchBoundary) { DebugUtils.CheckNoExternalCallers(); // Note that the reading is actually synchronous since we buffer the entire input when getting the stream from the message. return(TaskUtils.GetTaskForSynchronousOperation(() => this.CreateBatchReaderImplementation(batchBoundary, /*synchronous*/ false))); }
/// <summary> /// Asynchronously read a top-level value. /// </summary> /// <param name="expectedPrimitiveTypeReference">The expected type reference for the value to be read; null if no expected type is available.</param> /// <returns>Task which when completed returns an <see cref="object"/> representing the read value.</returns> internal override Task <object> ReadValueAsync(IEdmPrimitiveTypeReference expectedPrimitiveTypeReference) { DebugUtils.CheckNoExternalCallers(); // Note that the reading is actually synchronous since we buffer the entire input when getting the stream from the message. return(TaskUtils.GetTaskForSynchronousOperation(() => this.ReadValueImplementation(expectedPrimitiveTypeReference))); }
public sealed override Task WriteStartAsync(ODataNavigationLink navigationLink) { this.VerifyCanWriteStartNavigationLink(false, navigationLink); return(TaskUtils.GetTaskForSynchronousOperation(delegate { this.WriteStartNavigationLinkImplementation(navigationLink); })); }
public sealed override Task WriteStartAsync(ODataFeed feed) { this.VerifyCanWriteStartFeed(false, feed); return(TaskUtils.GetTaskForSynchronousOperation(delegate { this.WriteStartFeedImplementation(feed); })); }
public sealed override Task WriteStartAsync(ODataEntry entry) { this.VerifyCanWriteStartEntry(false, entry); return(TaskUtils.GetTaskForSynchronousOperation(delegate { this.WriteStartEntryImplementation(entry); })); }
/// <summary> /// Asynchronously start writing a value parameter. /// </summary> /// <param name="parameterName">The name of the parameter to write.</param> /// <param name="parameterValue">The value of the parameter to write.</param> /// <returns>A task instance that represents the asynchronous write operation.</returns> public sealed override Task WriteValueAsync(string parameterName, object parameterValue) { ExceptionUtils.CheckArgumentStringNotNullOrEmpty(parameterName, "parameterName"); IEdmTypeReference expectedTypeReference = this.VerifyCanWriteValueParameter(false /*synchronousCall*/, parameterName, parameterValue); return(TaskUtils.GetTaskForSynchronousOperation(() => this.InterceptException(() => this.WriteValueImplementation(parameterName, parameterValue, expectedTypeReference)))); }
public Task <ODataBatchOperationResponseMessage> CreateOperationResponseMessageAsync() { this.VerifyCanCreateOperationResponseMessage(false); return(TaskUtils.GetTaskForSynchronousOperation <ODataBatchOperationResponseMessage>(new Func <ODataBatchOperationResponseMessage>(this.CreateOperationResponseMessageImplementation)).FollowOnFaultWith <ODataBatchOperationResponseMessage>(delegate(Task <ODataBatchOperationResponseMessage> t) { this.State = ODataBatchReaderState.Exception; })); }
protected virtual Task <bool> ReadAsynchronously() { // We are reading from the fully buffered read stream here; thus it is ok // to use synchronous reads and then return a completed task // NOTE: once we switch to fully async reading this will have to change return(TaskUtils.GetTaskForSynchronousOperation <bool>(this.ReadImplementation)); }
public sealed override Task WriteStartAsync(ODataCollectionStart collection) { this.VerifyCanWriteStart(false, collection); return(TaskUtils.GetTaskForSynchronousOperation(delegate { this.WriteStartImplementation(collection); })); }
public sealed override Task WriteEntityReferenceLinkAsync(ODataEntityReferenceLink entityReferenceLink) { this.VerifyCanWriteEntityReferenceLink(entityReferenceLink, false); return(TaskUtils.GetTaskForSynchronousOperation(delegate { this.WriteEntityReferenceLinkImplementation(entityReferenceLink); })); }
/// <summary>Asynchronously returns an <see cref="T:Microsoft.Data.OData.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 Task <ODataBatchOperationResponseMessage> CreateOperationResponseMessageAsync() { this.VerifyCanCreateOperationResponseMessage(/*synchronousCall*/ false); return(TaskUtils.GetTaskForSynchronousOperation <ODataBatchOperationResponseMessage>( this.CreateOperationResponseMessageImplementation) .FollowOnFaultWith(t => this.State = ODataBatchReaderState.Exception)); }
public sealed override Task WriteItemAsync(object item) { this.VerifyCanWriteItem(false); return(TaskUtils.GetTaskForSynchronousOperation(delegate { this.WriteItemImplementation(item); })); }
/// <summary> /// Asynchronously creates an <see cref="ODataCollectionWriter"/> to write the value of a collection parameter. /// </summary> /// <param name="parameterName">The name of the collection parameter to write.</param> /// <returns>A running task for the created writer.</returns> public sealed override Task <ODataCollectionWriter> CreateCollectionWriterAsync(string parameterName) { ExceptionUtils.CheckArgumentStringNotNullOrEmpty(parameterName, "parameterName"); IEdmTypeReference itemTypeReference = this.VerifyCanCreateCollectionWriter(false /*synchronousCall*/, parameterName); return(TaskUtils.GetTaskForSynchronousOperation( () => this.InterceptException(() => this.CreateCollectionWriterImplementation(parameterName, itemTypeReference)))); }
/// <summary> /// Asynchronously detects the payload kinds supported by this format for the specified message payload. /// </summary> /// <param name="requestMessage">The request message with the payload stream.</param> /// <param name="detectionInfo">Additional information available for the payload kind detection.</param> /// <returns>A task that when completed returns the set of <see cref="ODataPayloadKind"/>s /// that are supported with the specified payload.</returns> internal override Task <IEnumerable <ODataPayloadKind> > DetectPayloadKindAsync( IODataRequestMessageAsync requestMessage, ODataPayloadKindDetectionInfo detectionInfo) { DebugUtils.CheckNoExternalCallers(); ExceptionUtils.CheckArgumentNotNull(requestMessage, "requestMessage"); ExceptionUtils.CheckArgumentNotNull(detectionInfo, "detectionInfo"); return(TaskUtils.GetTaskForSynchronousOperation(() => DetectPayloadKindImplementation(detectionInfo.ContentType))); }
public sealed override Task WriteEndAsync() { this.VerifyCanWriteEnd(false); return(TaskUtils.GetTaskForSynchronousOperation(new Action(this.WriteEndImplementation)).FollowOnSuccessWithTask(delegate(Task task) { if (this.scopes.Peek().State == CollectionWriterState.Completed) { return this.FlushAsync(); } return TaskUtils.CompletedTask; })); }
public sealed override Task WriteEndAsync() { this.VerifyCanWriteEnd(false); return(TaskUtils.GetTaskForSynchronousOperation(delegate { this.InterceptException(() => this.WriteEndImplementation()); }).FollowOnSuccessWithTask(delegate(Task task) { if (this.State == ParameterWriterState.Completed) { return this.FlushAsync(); } return TaskUtils.CompletedTask; })); }
/// <summary> /// Asynchronously finish writing a collection. /// </summary> /// <returns>A task instance that represents the asynchronous write operation.</returns> public sealed override Task WriteEndAsync() { this.VerifyCanWriteEnd(false); return(TaskUtils.GetTaskForSynchronousOperation(this.WriteEndImplementation) .FollowOnSuccessWithTask( task => { if (this.scopes.Peek().State == CollectionWriterState.Completed) { // Note that we intentionally go through the public API so that if the Flush fails the writer moves to the Error state. return this.FlushAsync(); } else { return TaskUtils.CompletedTask; } })); }
/// <summary> /// Asynchronously finish writing a parameter payload. /// </summary> /// <returns>A task instance that represents the asynchronous write operation.</returns> public sealed override Task WriteEndAsync() { this.VerifyCanWriteEnd(false /*synchronousCall*/); return(TaskUtils.GetTaskForSynchronousOperation(() => this.InterceptException(() => this.WriteEndImplementation())) .FollowOnSuccessWithTask( task => { if (this.State == ParameterWriterState.Completed) { // Note that we intentionally go through the public API so that if the Flush fails the writer moves to the Error state. return this.FlushAsync(); } else { return TaskUtils.CompletedTask; } })); }
protected override Task <bool> ReadAsynchronously() { Task <bool> result; switch (this.State) { case ODataReaderState.Start: result = this.ReadAtStartImplementationAsync(); break; case ODataReaderState.FeedStart: result = this.ReadAtFeedStartImplementationAsync(); break; case ODataReaderState.FeedEnd: result = this.ReadAtFeedEndImplementationAsync(); break; case ODataReaderState.EntryStart: result = TaskUtils.GetTaskForSynchronousOperation(() => this.IncreaseEntryDepth()) .FollowOnSuccessWithTask(t => this.ReadAtEntryStartImplementationAsync()); break; case ODataReaderState.EntryEnd: result = TaskUtils.GetTaskForSynchronousOperation(() => this.DecreaseEntryDepth()) .FollowOnSuccessWithTask(t => this.ReadAtEntryEndImplementationAsync()); break; case ODataReaderState.NavigationLinkStart: result = this.ReadAtNavigationLinkStartImplementationAsync(); break; case ODataReaderState.NavigationLinkEnd: result = this.ReadAtNavigationLinkEndImplementationAsync(); break; case ODataReaderState.EntityReferenceLink: result = this.ReadAtEntityReferenceLinkAsync(); break; case ODataReaderState.Exception: // fall through case ODataReaderState.Completed: result = TaskUtils.GetFaultedTask <bool>(new ODataException(Strings.ODataReaderCore_NoReadCallsAllowed(this.State))); break; default: Debug.Assert(false, "Unsupported reader state " + this.State + " detected."); result = TaskUtils.GetFaultedTask <bool>(new ODataException(Strings.General_InternalError(InternalErrorCodes.ODataReaderCoreAsync_ReadAsynchronously))); break; } return(result.FollowOnSuccessWith(t => { if ((this.State == ODataReaderState.EntryStart || this.State == ODataReaderState.EntryEnd) && this.Item != null) { ReaderValidationUtils.ValidateEntry(this.CurrentEntry); } return t.Result; })); }
internal override Task <object> ReadValueAsync(IEdmPrimitiveTypeReference expectedPrimitiveTypeReference) { return(TaskUtils.GetTaskForSynchronousOperation <object>(() => this.ReadValueImplementation(expectedPrimitiveTypeReference))); }
internal override Task <IEnumerable <ODataPayloadKind> > DetectPayloadKindAsync(IODataResponseMessageAsync responseMessage, ODataPayloadKindDetectionInfo detectionInfo) { ExceptionUtils.CheckArgumentNotNull <IODataResponseMessageAsync>(responseMessage, "responseMessage"); ExceptionUtils.CheckArgumentNotNull <ODataPayloadKindDetectionInfo>(detectionInfo, "detectionInfo"); return(TaskUtils.GetTaskForSynchronousOperation <IEnumerable <ODataPayloadKind> >(() => DetectPayloadKindImplementation(detectionInfo.ContentType))); }
public Task <ODataBatchOperationResponseMessage> CreateOperationResponseMessageAsync() { this.VerifyCanCreateOperationResponseMessage(false); return(TaskUtils.GetTaskForSynchronousOperation <ODataBatchOperationResponseMessage>(new Func <ODataBatchOperationResponseMessage>(this.CreateOperationResponseMessageImplementation))); }
public Task WriteStartChangesetAsync() { this.VerifyCanWriteStartChangeset(false); return(TaskUtils.GetTaskForSynchronousOperation(new Action(this.WriteStartChangesetImplementation))); }
public Task WriteEndBatchAsync() { this.VerifyCanWriteEndBatch(false); return(TaskUtils.GetTaskForSynchronousOperation(new Action(this.WriteEndBatchImplementation)).FollowOnSuccessWithTask(task => this.FlushAsync())); }
public Task <ODataBatchOperationRequestMessage> CreateOperationRequestMessageAsync(string method, Uri uri) { this.VerifyCanCreateOperationRequestMessage(false, method, uri); return(TaskUtils.GetTaskForSynchronousOperation <ODataBatchOperationRequestMessage>(() => this.CreateOperationRequestMessageImplementation(method, uri))); }
internal override Task <ODataBatchWriter> CreateODataBatchWriterAsync(string batchBoundary) { return(TaskUtils.GetTaskForSynchronousOperation <ODataBatchWriter>(() => this.CreateODataBatchWriterImplementation(batchBoundary))); }
private Task <bool> ReadAsynchronously() { return(TaskUtils.GetTaskForSynchronousOperation <bool>(new Func <bool>(this.ReadImplementation))); }
/// <summary> /// Asynchronously start writing a parameter payload. /// </summary> /// <returns>A task instance that represents the asynchronous write operation.</returns> public sealed override Task WriteStartAsync() { this.VerifyCanWriteStart(false /*synchronousCall*/); return(TaskUtils.GetTaskForSynchronousOperation(() => this.InterceptException(() => this.WriteStartImplementation()))); }