/// <summary> /// Constructor. /// </summary> /// <param name="listener">Listener interface to be notified of operation changes.</param> internal ODataStream(IODataStreamListener listener, bool synchronous = true) { Debug.Assert(listener != null, "listener != null"); this.listener = listener; this.synchronous = synchronous; }
/// <summary> /// Constructor. Creates a request message for an operation of a batch request. /// </summary> /// <param name="contentStreamCreatorFunc">A function to create the content stream.</param> /// <param name="method">The HTTP method used for this request message.</param> /// <param name="requestUrl">The request Url for this request message.</param> /// <param name="headers">The headers for this request message.</param> /// <param name="operationListener">Listener interface to be notified of operation changes.</param> /// <param name="contentId">The content-ID for the operation request message.</param> /// <param name="payloadUriConverter">The optional URL converter to perform custom URL conversion for URLs written to the payload.</param> /// <param name="writing">true if the request message is being written; false when it is read.</param> /// <param name="container">The dependency injection container to get related services.</param> /// <param name="dependsOnIds"> /// Request or group Ids that current request has dependency on. Values are added to a new list. /// Empty list will be created if value is null. /// </param> /// <param name="groupId">Value for the group id that current request belongs to. Can be null.</param> internal ODataBatchOperationRequestMessage( Func <Stream> contentStreamCreatorFunc, string method, Uri requestUrl, ODataBatchOperationHeaders headers, IODataStreamListener operationListener, string contentId, IODataPayloadUriConverter payloadUriConverter, bool writing, IServiceProvider container, IEnumerable <string> dependsOnIds, string groupId) { Debug.Assert(contentStreamCreatorFunc != null, "contentStreamCreatorFunc != null"); Debug.Assert(operationListener != null, "operationListener != null"); Debug.Assert(payloadUriConverter != null, "payloadUriConverter != null"); this.Method = method; this.Url = requestUrl; this.ContentId = contentId; this.groupId = groupId; this.message = new ODataBatchOperationMessage(contentStreamCreatorFunc, headers, operationListener, payloadUriConverter, writing); this.Container = container; this.dependsOnIds = dependsOnIds == null ? new List <string>() : new List <string>(dependsOnIds); }
public ODataNotificationReaderTests() { this.stream = new MemoryStream(); this.reader = new StreamReader(this.stream, encoding: Encoding.UTF8, detectEncodingFromByteOrderMarks: true, bufferSize: 1024, leaveOpen: true); this.streamListenerWriter = new StreamWriter(this.stream, encoding: Encoding.UTF8, bufferSize: 1024, leaveOpen: true); this.streamListener = new MockODataStreamListener(this.streamListenerWriter); }
internal ODataNotificationReader(TextReader textReader, IODataStreamListener listener) { Debug.Assert(textReader != null, "Creating a notification reader for a null textReader."); Debug.Assert(listener != null, "Creating a notification reader with a null textReader."); this.textReader = textReader; this.listener = listener; }
/// <summary> /// Constructor. /// </summary> /// <param name="jsonBatchReader">The Json batch reader.</param> private ODataJsonLightBatchPayloadItemPropertiesCache(ODataJsonLightBatchReader jsonBatchReader) { Debug.Assert(jsonBatchReader != null, $"{nameof(jsonBatchReader)} != null"); this.jsonReader = jsonBatchReader.JsonLightInputContext.JsonReader; this.asynchronousJsonReader = jsonBatchReader.JsonLightInputContext.JsonReader; this.listener = jsonBatchReader; }
internal ODataNotificationStream(Stream underlyingStream, IODataStreamListener listener) { Debug.Assert(underlyingStream != null, "Creating a notification stream for a null stream."); Debug.Assert(listener != null, "Creating a notification stream with a null listener."); this.stream = underlyingStream; this.listener = listener; }
internal ODataNotificationWriter(TextWriter textWriter, IODataStreamListener listener) : base(System.Globalization.CultureInfo.InvariantCulture) { Debug.Assert(textWriter != null, "Creating a notification writer for a null textWriter."); Debug.Assert(listener != null, "Creating a notification writer with a null listener."); this.textWriter = textWriter; this.listener = listener; }
/// <summary> /// Creates a batch operation write stream over the specified output stream. /// </summary> /// <param name="outputStream">The output stream to create the operation write stream over.</param> /// <param name="operationListener">The operation listener to be passed to the newly created write stream.</param> /// <returns>A new <see cref="ODataWriteStream"/> instance.</returns> internal static ODataWriteStream CreateBatchOperationWriteStream( Stream outputStream, IODataStreamListener operationListener) { Debug.Assert(outputStream != null, "outputStream != null"); Debug.Assert(operationListener != null, "operationListener != null"); return(new ODataWriteStream(outputStream, operationListener)); }
/// <summary> /// Constructor. /// </summary> /// <param name="jsonBatchReader">The Json batch reader.</param> internal ODataJsonLightBatchPayloadItemPropertiesCache(ODataJsonLightBatchReader jsonBatchReader) { Debug.Assert(jsonBatchReader != null, "jsonBatchReader != null"); this.jsonReader = jsonBatchReader.JsonLightInputContext.JsonReader; this.listener = jsonBatchReader; ScanJsonProperties(); }
/// <summary> /// Encapsulates the common asynchronous cleanup operations. /// </summary> /// <returns>A task representing the asynchronous operation.</returns> protected virtual async ValueTask DisposeAsyncCore() { if (!this.disposed && this.listener != null) { await this.listener.StreamDisposedAsync() .ConfigureAwait(false); this.listener = null; } }
/// <summary> /// Disposes the object. /// </summary> /// <param name="disposing">True if called from Dispose; false if called from the finalizer.</param> protected override void Dispose(bool disposing) { if (disposing) { if (this.listener != null) { // Tell the listener that the stream is being disposed. this.listener.StreamDisposed(); this.listener = null; } } base.Dispose(disposing); }
/// <summary> /// Disposes the object. /// </summary> /// <param name="disposing">True if called from Dispose; false if called form the finalizer.</param> protected override void Dispose(bool disposing) { if (disposing) { if (this.listener != null) { // Tell the listener that the stream is being disposed; we expect // that no asynchronous action is triggered by doing so. this.listener.StreamDisposed(); this.listener = null; } } base.Dispose(disposing); }
public async ValueTask DisposeAsync() { if (!this.disposed && this.listener != null) { await this.listener.StreamDisposedAsync() .ConfigureAwait(false); this.listener = null; // NOTE: Do not dispose the stream since this instance does not own it. this.stream = null; } // Dispose unmanaged resources // Pass `false` to ensure functional equivalence with the synchronous dispose pattern this.Dispose(false); }
/// <summary> /// Constructor. Base class constructor to create a message for an operation of a batch request/response. /// </summary> /// <param name="contentStreamCreatorFunc">A function to retrieve the content stream for this batch operation message.</param> /// <param name="headers">The headers of the batch operation message.</param> /// <param name="operationListener">Listener interface to be notified of part changes.</param> /// <param name="payloadUriConverter">The URL resolver to perform custom URL resolution for URLs read or written from/to the payload.</param> /// <param name="writing">true if the request message is being written; false when it is read.</param> internal ODataBatchOperationMessage( Func <Stream> contentStreamCreatorFunc, ODataBatchOperationHeaders headers, IODataStreamListener operationListener, IODataPayloadUriConverter payloadUriConverter, bool writing) : base(writing, /*disableMessageStreamDisposal*/ false, /*maxMessageSize*/ -1) { Debug.Assert(contentStreamCreatorFunc != null, "contentStreamCreatorFunc != null"); Debug.Assert(operationListener != null, "operationListener != null"); this.contentStreamCreatorFunc = contentStreamCreatorFunc; this.operationListener = operationListener; this.headers = headers; this.payloadUriConverter = payloadUriConverter; }
/// <summary> /// Constructor. /// </summary> /// <param name="contentStreamCreatorFunc">A function to retrieve the content stream for this batch operation message.</param> /// <param name="headers">The headers of the batch operation message.</param> /// <param name="operationListener">Listener interface to be notified of part changes.</param> /// <param name="contentId">The content-ID for the operation response message.</param> /// <param name="payloadUriConverter">The optional URL converter to perform custom URL conversion for URLs written to the payload.</param> /// <param name="writing">true if the request message is being written; false when it is read.</param> /// <param name="container">The dependency injection container to get related services.</param> /// <param name="groupId">Value for the group id that corresponding request belongs to. Can be null.</param> internal ODataBatchOperationResponseMessage( Func <Stream> contentStreamCreatorFunc, ODataBatchOperationHeaders headers, IODataStreamListener operationListener, string contentId, IODataPayloadUriConverter payloadUriConverter, bool writing, IServiceProvider container, string groupId) { Debug.Assert(contentStreamCreatorFunc != null, "contentStreamCreatorFunc != null"); Debug.Assert(operationListener != null, "operationListener != null"); this.message = new ODataBatchOperationMessage(contentStreamCreatorFunc, headers, operationListener, payloadUriConverter, writing); this.ContentId = contentId; this.Container = container; this.GroupId = groupId; }
/// <summary> /// Disposes the object. /// </summary> /// <param name="disposing">True if called from Dispose; false if called form the finalizer.</param> protected override void Dispose(bool disposing) { if (!this.disposed && disposing) { // Tell the listener that the stream is being disposed; we expect // that no asynchronous action is triggered by doing so. if (this.synchronous) { this.listener?.StreamDisposed(); } else { this.listener?.StreamDisposedAsync().Wait(); } this.listener = null; } this.disposed = true; base.Dispose(disposing); }
/// <summary> /// Disposes the object. /// </summary> /// <param name="disposing">True if called from Dispose; false if called from the finalizer.</param> protected override void Dispose(bool disposing) { if (!this.disposed && disposing) { // Tell the listener that the stream is being disposed. if (synchronous) { this.listener?.StreamDisposed(); } else { this.listener?.StreamDisposedAsync().Wait(); } this.listener = null; // NOTE: Do not dispose the stream since this instance does not own it. this.stream = null; } this.disposed = true; base.Dispose(disposing); }
/// <summary> /// Creates a batch operation stream from the specified batch stream. /// </summary> /// <param name="batchReaderStream">The batch stream to create the operation read stream for.</param> /// <param name="headers">The headers of the current part; based on the header we create different, optimized stream implementations.</param> /// <param name="operationListener">The operation listener to be passed to the newly created read stream.</param> /// <returns>A new <see cref="ODataReadStream"/> instance.</returns> internal static ODataReadStream CreateBatchOperationReadStream( ODataBatchReaderStream batchReaderStream, ODataBatchOperationHeaders headers, IODataStreamListener operationListener) { Debug.Assert(batchReaderStream != null, "batchReaderStream != null"); Debug.Assert(operationListener != null, "operationListener != null"); // See whether we have a Content-Length header string contentLengthValue; if (headers.TryGetValue(ODataConstants.ContentLengthHeader, out contentLengthValue)) { int length = Int32.Parse(contentLengthValue, CultureInfo.InvariantCulture); if (length < 0) { throw new ODataException(Strings.ODataBatchReaderStream_InvalidContentLengthSpecified(contentLengthValue)); } return(ODataReadStream.Create(batchReaderStream, operationListener, length)); } return(ODataReadStream.Create(batchReaderStream, operationListener)); }
/// <summary> /// Create a batch operation read stream over the specified batch stream with a given content length. /// </summary> /// <param name="batchReaderStream">The batch stream underlying the operation stream to create.</param> /// <param name="listener">The batch operation listener.</param> /// <param name="length">The content length of the operation stream.</param> /// <returns>A <see cref="ODataReadStream"/> to read the content of a batch operation from.</returns> internal static ODataReadStream Create(ODataBatchReaderStream batchReaderStream, IODataStreamListener listener, int length) { return(new ODataBatchOperationReadStreamWithLength(batchReaderStream, listener, length)); }
/// <summary> /// Constructor. /// </summary> /// <param name="batchReaderStream">The underlying batch stream to write the message to.</param> /// <param name="listener">Listener interface to be notified of operation changes.</param> /// <param name="length">The total length of the stream.</param> internal ODataBatchOperationReadStreamWithLength(ODataBatchReaderStream batchReaderStream, IODataStreamListener listener, int length) : base(batchReaderStream, listener) { ExceptionUtils.CheckIntegerNotNegative(length, "length"); this.length = length; }
public ODataWriteStreamTests() { this.stream = new MemoryStream(); this.writer = new StreamWriter(this.stream); this.streamListener = new MockODataStreamListener(this.writer); }
/// <summary> /// Constructor. /// </summary> /// <param name="batchReaderStream">The underlying batch stream to write the message to.</param> /// <param name="listener">Listener interface to be notified of operation changes.</param> internal ODataBatchOperationReadStreamWithDelimiter(ODataBatchReaderStream batchReaderStream, IODataStreamListener listener) : base(batchReaderStream, listener) { }
/// <summary> /// Constructor. /// </summary> /// <param name="batchReaderStream">The underlying stream to read from.</param> /// <param name="listener">Listener interface to be notified of operation changes.</param> private ODataReadStream(ODataBatchReaderStream batchReaderStream, IODataStreamListener listener) : base(listener) { Debug.Assert(batchReaderStream != null, "batchReaderStream != null"); this.batchReaderStream = batchReaderStream; }
public ODataNotificationWriterTests() { this.stream = new MemoryStream(); this.writer = new StreamWriter(this.stream); this.streamListener = new MockODataStreamListener(this.writer); }
/// <summary> /// Constructor. /// </summary> /// <param name="stream">The underlying stream to write the message to.</param> /// <param name="listener">Listener interface to be notified of operation changes.</param> internal ODataWriteStream(Stream stream, IODataStreamListener listener, bool synchronous = true) : base(listener, synchronous) { Debug.Assert(stream != null, "stream != null"); this.stream = stream; }
/// <summary> /// Constructor. /// </summary> /// <param name="listener">Listener interface to be notified of operation changes.</param> internal ODataStream(IODataStreamListener listener) { Debug.Assert(listener != null, "listener != null"); this.listener = listener; }
/// <summary> /// Constructor. /// </summary> /// <param name="stream">The underlying stream to write the message to.</param> /// <param name="listener">Listener interface to be notified of operation changes.</param> internal ODataWriteStream(Stream stream, IODataStreamListener listener) : base(listener) { Debug.Assert(stream != null, "stream != null"); this.stream = stream; }
/// <summary> /// Constructor using default encoding (Base64Url without the BOM preamble). /// </summary> /// <param name="listener">The batch operation listener.</param> internal ODataJsonLightBatchBodyContentReaderStream(IODataStreamListener listener) { this.listener = listener; }
/// <summary> /// Create a batch operation read stream over the specified batch stream using the batch delimiter to detect the end of the stream. /// </summary> /// <param name="batchReaderStream">The batch stream underlying the operation stream to create.</param> /// <param name="listener">The batch operation listener.</param> /// <returns>A <see cref="ODataReadStream"/> to read the content of a batch operation from.</returns> internal static ODataReadStream Create(ODataBatchReaderStream batchReaderStream, IODataStreamListener listener) { return(new ODataBatchOperationReadStreamWithDelimiter(batchReaderStream, listener)); }