/// <summary>Constructor.</summary> /// <param name="messageInfo">The context information for the message.</param> /// <param name="messageReaderSettings">Configuration settings of the OData reader.</param> public ODataJsonLightInputContext( ODataMessageInfo messageInfo, ODataMessageReaderSettings messageReaderSettings) : this(CreateTextReader(messageInfo.MessageStream, messageInfo.Encoding), messageInfo, messageReaderSettings) { Debug.Assert(messageInfo.MessageStream != null, "messageInfo.MessageStream != null"); this.stream = messageInfo.MessageStream; }
internal VCardOutputContext( ODataFormat format, ODataMessageInfo messageInfo, ODataMessageWriterSettings messageWriterSettings) : base(format, messageInfo, messageWriterSettings) { this.writer = new VCardWriter(new StreamWriter(messageInfo.MessageStream, messageInfo.Encoding)); this.outputStream = messageInfo.MessageStream; }
/// <summary> /// Creates an instance of the output context for this format. /// </summary> /// <param name="messageInfo">The context information for the message.</param> /// <param name="messageWriterSettings">Configuration settings of the OData writer.</param> /// <returns>The newly created output context.</returns> public override ODataOutputContext CreateOutputContext( ODataMessageInfo messageInfo, ODataMessageWriterSettings messageWriterSettings) { ExceptionUtils.CheckArgumentNotNull(messageInfo, "messageInfo"); ExceptionUtils.CheckArgumentNotNull(messageWriterSettings, "messageWriterSettings"); return(new ODataMultipartMixedBatchOutputContext(this, messageInfo, messageWriterSettings)); }
internal ODataAvroOutputContext( ODataFormat format, ODataMessageInfo messageInfo, ODataMessageWriterSettings messageWriterSettings) : base(format, messageInfo, messageWriterSettings) { this.outputStream = messageInfo.MessageStream; this.AvroWriter = new AvroWriter(new StreamWrapper(outputStream)); }
/// <summary> /// Creates an instance of the output context for this format. /// </summary> /// <param name="messageInfo">The context information for the message.</param> /// <param name="messageWriterSettings">Configuration settings of the OData writer.</param> /// <returns>The newly created output context.</returns> public override ODataOutputContext CreateOutputContext( ODataMessageInfo messageInfo, ODataMessageWriterSettings messageWriterSettings) { ExceptionUtils.CheckArgumentNotNull(messageInfo, "messageInfo"); ExceptionUtils.CheckArgumentNotNull(messageWriterSettings, "messageWriterSettings"); return(new ODataJsonLightOutputContext(messageInfo, messageWriterSettings)); }
public CsvOutputContext( ODataFormat format, ODataMessageWriterSettings settings, ODataMessageInfo messageInfo, bool synchronous) : base(format, settings, messageInfo.IsResponse, synchronous, messageInfo.Model, messageInfo.UrlResolver) { this.stream = messageInfo.GetMessageStream(); this.Writer = new StreamWriter(this.stream); }
/// <summary> /// Asynchronously creates an instance of the input context for this format. /// </summary> /// <param name="messageInfo">The context information for the message.</param> /// <param name="messageReaderSettings">Configuration settings of the OData reader.</param> /// <returns>Task which when completed returned the newly created input context.</returns> public override Task <ODataInputContext> CreateInputContextAsync( ODataMessageInfo messageInfo, ODataMessageReaderSettings messageReaderSettings) { ExceptionUtils.CheckArgumentNotNull(messageInfo, "messageInfo"); ExceptionUtils.CheckArgumentNotNull(messageReaderSettings, "messageReaderSettings"); return(Task.FromResult <ODataInputContext>( new ODataJsonLightInputContext(messageInfo, messageReaderSettings))); }
public VCardInputContext( ODataFormat format, ODataMessageInfo messageInfo, ODataMessageReaderSettings messageReaderSettings) : base(format, messageInfo, messageReaderSettings) { this.stream = messageInfo.MessageStream; this.reader = new VCardReader(new StreamReader(messageInfo.MessageStream, messageInfo.Encoding)); this.throwExceptionOnDuplicatedPropertyNames = false; }
/// <summary> /// Constructor. /// </summary> /// <param name="format">The format for this output context.</param> /// <param name="messageInfo">The context information for the message.</param> /// <param name="messageWriterSettings">Configuration settings of the OData writer.</param> internal ODataMultipartMixedBatchOutputContext( ODataFormat format, ODataMessageInfo messageInfo, ODataMessageWriterSettings messageWriterSettings) : base(format, messageInfo, messageWriterSettings) { Debug.Assert(messageInfo.MessageStream != null, "messageInfo.MessageStream != null"); Debug.Assert(messageInfo.MediaType != null, "Media type should have been set in messageInfo prior to creating Raw Input Context for Batch"); this.batchBoundary = ODataMultipartMixedBatchWriterUtils.GetBatchBoundaryFromMediaType(messageInfo.MediaType); }
/// <summary> /// Detects the payload kind(s) from the message stream. /// </summary> /// <param name="messageInfo">The context information for the message.</param> /// <param name="settings">Configuration settings of the OData reader.</param> /// <returns>An enumerable of zero, one or more payload kinds that were detected from looking at the payload in the message stream.</returns> private static IEnumerable <ODataPayloadKind> DetectPayloadKindImplementation( ODataMessageInfo messageInfo, ODataMessageReaderSettings settings) { var detectionInfo = new ODataPayloadKindDetectionInfo(messageInfo, settings); messageInfo.Encoding = detectionInfo.GetEncoding(); using (var jsonLightInputContext = new ODataJsonLightInputContext(messageInfo, settings)) { return(jsonLightInputContext.DetectPayloadKind(detectionInfo)); } }
private ODataJsonLightInputContext CreateJsonLightInputContext(string payload, bool isAsync = false) { var messageInfo = new ODataMessageInfo { Encoding = Encoding.UTF8, IsResponse = true, MediaType = new ODataMediaType("application", "json"), IsAsync = isAsync, Model = new EdmModel(), }; return(new ODataJsonLightInputContext(new StringReader(payload), messageInfo, this.messageReaderSettings)); }
/// <summary>Constructor.</summary> /// <param name="textReader">The text reader to use.</param> /// <param name="messageInfo">The context information for the message.</param> /// <param name="messageReaderSettings">Configuration settings of the OData reader.</param> internal ODataJsonLightInputContext( TextReader textReader, ODataMessageInfo messageInfo, ODataMessageReaderSettings messageReaderSettings) : base(ODataFormat.Json, messageInfo, messageReaderSettings) { Debug.Assert(messageInfo.MediaType != null, "messageInfo.MediaType != null"); try { this.textReader = textReader; var innerReader = CreateJsonReader(this.Container, this.textReader, messageInfo.MediaType.HasIeee754CompatibleSetToTrue()); if (messageReaderSettings.ArrayPool != null) { // make sure customer also can use reading setting if without DI. JsonReader jsonReader = innerReader as JsonReader; if (jsonReader != null && jsonReader.ArrayPool == null) { jsonReader.ArrayPool = messageReaderSettings.ArrayPool; } } if (messageInfo.MediaType.HasStreamingSetToTrue()) { this.jsonReader = new BufferingJsonReader( innerReader, JsonLightConstants.ODataErrorPropertyName, messageReaderSettings.MessageQuotas.MaxNestingDepth); } else { // If we have a non-streaming Json Light content type we need to use the re-ordering Json reader this.jsonReader = new ReorderingJsonReader(innerReader, messageReaderSettings.MessageQuotas.MaxNestingDepth); } } catch (Exception e) { // Dispose the message stream if we failed to create the input context. if (ExceptionUtils.IsCatchableExceptionType(e) && this.textReader != null) { this.textReader.Dispose(); } throw; } // don't know how to get MetadataDocumentUri uri here, messageReaderSettings do not have one // Uri metadataDocumentUri = messageReaderSettings..MetadataDocumentUri == null ? null : messageReaderSettings.MetadataDocumentUri.BaseUri; // the uri here is used here to create the FullMetadataLevel can pass null in this.metadataLevel = JsonLightMetadataLevel.Create(messageInfo.MediaType, null, this.Model, this.ReadingResponse); }
/// <summary> /// Detects the payload kinds supported by this format for the specified message payload. /// </summary> /// <param name="messageInfo">The context information for the message.</param> /// <param name="settings">Configuration settings of the OData reader.</param> /// <returns>The set of <see cref="ODataPayloadKind"/>s that are supported with the specified payload.</returns> public override IEnumerable<ODataPayloadKind> DetectPayloadKind( ODataMessageInfo messageInfo, ODataMessageReaderSettings settings) { ExceptionUtils.CheckArgumentNotNull(messageInfo, "messageInfo"); return this.DetectPayloadKindImplementation( messageInfo.GetMessageStream(), messageInfo.IsResponse, new ODataPayloadKindDetectionInfo( messageInfo.MediaType, messageInfo.Encoding, settings, messageInfo.Model)); }
private ODataMultipartMixedBatchOutputContext CreateMultipartMixedBatchOutputContext(bool writingRequest = true, bool asynchronous = false) { var messageInfo = new ODataMessageInfo { MessageStream = this.stream, MediaType = this.mediaType, // Async writer needs the default encoding to not use the preamble. Encoding = MediaTypeUtils.EncodingUtf8NoPreamble, IsResponse = !writingRequest, IsAsync = asynchronous }; return(new ODataMultipartMixedBatchOutputContext(ODataFormat.Batch, messageInfo, this.settings)); }
private ODataJsonLightOutputContext CreateJsonLightOutputContext(bool isAsync = true) { var messageInfo = new ODataMessageInfo { MessageStream = new NonDisposingStream(this.stream), MediaType = new ODataMediaType("application", "json"), Encoding = Encoding.UTF8, IsResponse = true, IsAsync = isAsync, Model = this.model }; return(new ODataJsonLightOutputContext(messageInfo, this.messageWriterSettings)); }
/// <summary> /// Detects the payload kinds supported by this format for the specified message payload. /// </summary> /// <param name="messageInfo">The context information for the message.</param> /// <param name="settings">Configuration settings of the OData reader.</param> /// <returns>The set of <see cref="ODataPayloadKind"/>s that are supported with the specified payload.</returns> public override IEnumerable <ODataPayloadKind> DetectPayloadKind( ODataMessageInfo messageInfo, ODataMessageReaderSettings settings) { ExceptionUtils.CheckArgumentNotNull(messageInfo, "messageInfo"); return(this.DetectPayloadKindImplementation( messageInfo.GetMessageStream(), messageInfo.IsResponse, new ODataPayloadKindDetectionInfo( messageInfo.MediaType, messageInfo.Encoding, settings, messageInfo.Model))); }
private ODataJsonLightOutputContext CreateJsonLightOutputContext(bool writingRequest = true, bool asynchronous = false) { var messageInfo = new ODataMessageInfo { MessageStream = this.stream, MediaType = this.mediaType, Encoding = this.encoding, IsResponse = !writingRequest, IsAsync = asynchronous, Model = this.model }; return(new ODataJsonLightOutputContext(messageInfo, this.settings)); }
public async Task ExecuteChangeSet_Throws_IfRequestIsNull() { // Arrange ODataMessageInfo messageInfo = new ODataMessageInfo(); ODataMessageReaderSettings settings = new ODataMessageReaderSettings(); Mock <ODataInputContext> inputContext = new Mock <ODataInputContext>(ODataFormat.Batch, messageInfo, settings); Mock <ODataBatchReader> batchReader = new Mock <ODataBatchReader>(inputContext.Object, false); UnbufferedODataBatchHandler batchHandler = new UnbufferedODataBatchHandler(); // Act & Assert await ExceptionAssert.ThrowsArgumentNullAsync( () => batchHandler.ExecuteChangeSetAsync(batchReader.Object, Guid.NewGuid(), null, null), "originalRequest"); }
public ODataAvroInputContext( ODataFormat format, ODataMessageInfo messageInfo, ODataMessageReaderSettings messageReaderSettings) : base(format, messageInfo, messageReaderSettings) { this.stream = messageInfo.MessageStream; MemoryStream st = new MemoryStream(); stream.CopyTo(st); st.Seek(0, SeekOrigin.Begin); this.AvroReader = new AvroReader(AvroContainer.CreateGenericReader(st)); }
/// <summary> /// Detects the payload kind(s) from the message stream. /// </summary> /// <param name="messageInfo">The context information for the message.</param> /// <param name="settings">Configuration settings of the OData reader.</param> /// <returns>An enumerable of zero, one or more payload kinds that were detected from looking at the payload in the message stream.</returns> private static Task <IEnumerable <ODataPayloadKind> > DetectPayloadKindImplementationAsync( ODataMessageInfo messageInfo, ODataMessageReaderSettings settings) { var detectionInfo = new ODataPayloadKindDetectionInfo(messageInfo, settings); messageInfo.Encoding = detectionInfo.GetEncoding(); var jsonLightInputContext = new ODataJsonLightInputContext(messageInfo, settings); return(jsonLightInputContext.DetectPayloadKindAsync(detectionInfo) .FollowAlwaysWith(t => { jsonLightInputContext.Dispose(); })); }
/// <summary> /// Asynchronously detects the payload kinds supported by this format for the specified message payload. /// </summary> /// <param name="messageInfo">The context information for the message.</param> /// <param name="settings">Configuration settings of the OData reader.</param> /// <returns>A task that when completed returns the set of <see cref="ODataPayloadKind"/>s /// that are supported with the specified payload.</returns> public override Task <IEnumerable <ODataPayloadKind> > DetectPayloadKindAsync( ODataMessageInfo messageInfo, ODataMessageReaderSettings settings) { ExceptionUtils.CheckArgumentNotNull(messageInfo, "messageInfo"); return(messageInfo.GetMessageStreamAsync() .FollowOnSuccessWithTask(streamTask => this.DetectPayloadKindImplementationAsync( streamTask.Result, /*readingResponse*/ messageInfo.IsResponse, new ODataPayloadKindDetectionInfo( messageInfo.MediaType, messageInfo.Encoding, settings, messageInfo.Model)))); }
private ODataJsonLightInputContext GetInputContext(string payload, IEdmModel model = null) { var messageInfo = new ODataMessageInfo { IsResponse = true, MediaType = JsonLightUtils.JsonLightStreamingMediaType, IsAsync = false, Model = model ?? new EdmModel(), }; return(new ODataJsonLightInputContext( new StringReader(payload), messageInfo, new ODataMessageReaderSettings())); }
private ODataJsonLightInputContext CreateJsonLightInputContext(string payload, IEdmModel model = null, bool isAsync = false) { var messageInfo = new ODataMessageInfo { IsResponse = true, MediaType = JsonLightUtils.JsonLightStreamingMediaType, IsAsync = isAsync, Model = model ?? EdmCoreModel.Instance, }; return(new ODataJsonLightInputContext( new StringReader(payload), messageInfo, new ODataMessageReaderSettings())); }
/// <summary> /// Constructor. /// </summary> /// <param name="textWriter">The text writer to write to.</param> /// <param name="messageInfo">The context information for the message.</param> /// <param name="messageWriterSettings">Configuration settings of the OData writer.</param> internal ODataJsonLightOutputContext( TextWriter textWriter, ODataMessageInfo messageInfo, ODataMessageWriterSettings messageWriterSettings) : base(ODataFormat.Json, messageInfo, messageWriterSettings) { Debug.Assert(!this.WritingResponse, "Expecting WritingResponse to always be false for this constructor, so no need to validate the MetadataDocumentUri on the writer settings."); Debug.Assert(textWriter != null, "textWriter != null"); Debug.Assert(messageWriterSettings != null, "messageWriterSettings != null"); this.textWriter = textWriter; this.jsonWriter = CreateJsonWriter(messageInfo.Container, textWriter, true /*isIeee754Compatible*/); this.metadataLevel = new JsonMinimalMetadataLevel(); this.propertyCacheHandler = new PropertyCacheHandler(); }
private ODataAvroOutputContext CreateOutputContext(Stream stream) { var messageInfo = new ODataMessageInfo { MessageStream = stream, Encoding = Encoding.UTF8, IsAsync = false, IsResponse = true, }; return(new ODataAvroOutputContext( AvroFormat.Avro, messageInfo, new ODataMessageWriterSettings())); }
private ODataAvroInputContext CreateODataInputContext(Stream stream) { var messageInfo = new ODataMessageInfo { MessageStream = stream, MediaType = new ODataMediaType("avro", "binary"), Encoding = Encoding.UTF8, IsAsync = false, IsResponse = true, }; return(new ODataAvroInputContext( AvroFormat.Avro, messageInfo, new ODataMessageReaderSettings())); }
/// <summary> /// Creates an instance of the input context for this format. /// </summary> /// <param name="messageInfo">The context information for the message.</param> /// <param name="messageReaderSettings">Configuration settings of the OData reader.</param> /// <returns>The newly created input context.</returns> public override ODataInputContext CreateInputContext( ODataMessageInfo messageInfo, ODataMessageReaderSettings messageReaderSettings) { ExceptionUtils.CheckArgumentNotNull(messageInfo, "messageInfo"); ExceptionUtils.CheckArgumentNotNull(messageReaderSettings, "messageReaderSettings"); return new ODataAtomInputContext( this, messageInfo.GetMessageStream(), messageInfo.Encoding, messageReaderSettings, messageInfo.IsResponse, /*synchronous*/ true, messageInfo.Model, messageInfo.UrlResolver); }
/// <summary> /// Creates an instance of the output context for this format. /// </summary> /// <param name="messageInfo">The context information for the message.</param> /// <param name="messageWriterSettings">Configuration settings of the OData writer.</param> /// <returns>The newly created output context.</returns> public override ODataOutputContext CreateOutputContext( ODataMessageInfo messageInfo, ODataMessageWriterSettings messageWriterSettings) { ExceptionUtils.CheckArgumentNotNull(messageInfo, "messageInfo"); ExceptionUtils.CheckArgumentNotNull(messageWriterSettings, "messageWriterSettings"); return(new ODataAtomOutputContext( this, messageInfo.GetMessageStream(), messageInfo.Encoding, messageWriterSettings, messageInfo.IsResponse, /*synchronous*/ true, messageInfo.Model, messageInfo.UrlResolver)); }
private ODataJsonLightInputContext CreateJsonLightInputContext(string payload, bool isAsync = false, bool isResponse = true) { var messageInfo = new ODataMessageInfo { MediaType = new ODataMediaType("application", "json"), #if NETCOREAPP1_1 Encoding = Encoding.GetEncoding(0), #else Encoding = Encoding.Default, #endif IsResponse = isResponse, IsAsync = isAsync, Model = this.model }; return(new ODataJsonLightInputContext(new StringReader(payload), messageInfo, this.messageReaderSettings)); }
private ODataJsonLightServiceDocumentDeserializer CreateODataJsonServiceDocumentDeserializer(MemoryStream stream, IODataPayloadUriConverter urlResolver = null) { var messageInfo = new ODataMessageInfo { Encoding = Encoding.UTF8, IsResponse = true, MediaType = new ODataMediaType("application", "json"), IsAsync = false, Model = new EdmModel(), PayloadUriConverter = urlResolver, MessageStream = stream }; var inputContext = new ODataJsonLightInputContext(messageInfo, new ODataMessageReaderSettings()); return(new ODataJsonLightServiceDocumentDeserializer(inputContext)); }
/// <summary> /// Constructor. /// </summary> /// <param name="messageInfo">The context information for the message.</param> /// <param name="messageWriterSettings">Configuration settings of the OData writer.</param> public ODataJsonLightOutputContext( ODataMessageInfo messageInfo, ODataMessageWriterSettings messageWriterSettings) : base(ODataFormat.Json, messageInfo, messageWriterSettings) { Debug.Assert(messageInfo.MessageStream != null, "messageInfo.MessageStream != null"); Debug.Assert(messageInfo.MediaType != null, "messageInfo.MediaType != null"); try { this.messageOutputStream = messageInfo.MessageStream; Stream outputStream; if (this.Synchronous) { outputStream = this.messageOutputStream; } else { this.asynchronousOutputStream = new AsyncBufferedStream(this.messageOutputStream); outputStream = this.asynchronousOutputStream; } this.textWriter = new StreamWriter(outputStream, messageInfo.Encoding); // COMPAT 2: JSON indentation - WCFDS indents only partially, it inserts newlines but doesn't actually insert spaces for indentation // in here we allow the user to specify if true indentation should be used or if the limited functionality is enough. this.jsonWriter = CreateJsonWriter(this.Container, this.textWriter, messageInfo.MediaType.HasIeee754CompatibleSetToTrue(), messageWriterSettings); } catch (Exception e) { // Dispose the message stream if we failed to create the input context. if (ExceptionUtils.IsCatchableExceptionType(e)) { this.messageOutputStream.Dispose(); } throw; } Uri metadataDocumentUri = messageWriterSettings.MetadataDocumentUri; bool alwaysAddTypeAnnotationsForDerivedTypes = messageWriterSettings.AlwaysAddTypeAnnotationsForDerivedTypes; this.metadataLevel = JsonLightMetadataLevel.Create(messageInfo.MediaType, metadataDocumentUri, alwaysAddTypeAnnotationsForDerivedTypes, this.Model, this.WritingResponse); this.propertyCacheHandler = new PropertyCacheHandler(); }
private static ODataBatchReaderStream CreateBatchReaderStream(string inputString) { var messageInfo = new ODataMessageInfo { Encoding = Encoding.UTF8, IsResponse = false, IsAsync = false, PayloadKind = ODataPayloadKind.Batch, MessageStream = new MemoryStream(Encoding.UTF8.GetBytes(inputString)) }; var inputContext = new ODataRawInputContext( ODataFormat.Batch, messageInfo, new ODataMessageReaderSettings()); var batchStream = new ODataBatchReaderStream(inputContext, "batch_862fb28e-dc50-4af1-aad5-9608647761d1", Encoding.UTF8); return(batchStream); }
public override System.Threading.Tasks.Task<ODataOutputContext> CreateOutputContextAsync(ODataMessageInfo messageInfo, ODataMessageWriterSettings messageWriterSettings) { throw new NotImplementedException(); }
/// <summary> /// Creates an instance of the output context for this format. /// </summary> /// <param name="messageInfo">The context information for the message.</param> /// <param name="messageWriterSettings">Configuration settings of the OData writer.</param> /// <returns>Task which represents the pending create operation.</returns> public override Task<ODataOutputContext> CreateOutputContextAsync( ODataMessageInfo messageInfo, ODataMessageWriterSettings messageWriterSettings) { ExceptionUtils.CheckArgumentNotNull(messageInfo, "messageInfo"); ExceptionUtils.CheckArgumentNotNull(messageWriterSettings, "messageWriterSettings"); return messageInfo.GetMessageStreamAsync() .FollowOnSuccessWith( (streamTask) => (ODataOutputContext)new ODataAtomOutputContext( this, streamTask.Result, messageInfo.Encoding, messageWriterSettings, messageInfo.IsResponse, /*synchronous*/ false, messageInfo.Model, messageInfo.UrlResolver)); }
/// <summary> /// Asynchronously detects the payload kinds supported by this format for the specified message payload. /// </summary> /// <param name="messageInfo">The context information for the message.</param> /// <param name="settings">Configuration settings of the OData reader.</param> /// <returns>A task that when completed returns the set of <see cref="ODataPayloadKind"/>s /// that are supported with the specified payload.</returns> public override Task<IEnumerable<ODataPayloadKind>> DetectPayloadKindAsync( ODataMessageInfo messageInfo, ODataMessageReaderSettings settings) { ExceptionUtils.CheckArgumentNotNull(messageInfo, "messageInfo"); return messageInfo.GetMessageStreamAsync() .FollowOnSuccessWith( streamTask => this.DetectPayloadKindImplementation( streamTask.Result, /*readingResponse*/ messageInfo.IsResponse, /*synchronous*/ false, new ODataPayloadKindDetectionInfo( messageInfo.MediaType, messageInfo.Encoding, settings, messageInfo.Model))); }
public override IEnumerable<ODataPayloadKind> DetectPayloadKind(ODataMessageInfo messageInfo, ODataMessageReaderSettings settings) { throw new System.NotImplementedException(); }
public override ODataOutputContext CreateOutputContext(ODataMessageInfo messageInfo, ODataMessageWriterSettings messageWriterSettings) { throw new NotImplementedException(); }
public override System.Threading.Tasks.Task<IEnumerable<ODataPayloadKind>> DetectPayloadKindAsync(ODataMessageInfo messageInfo, ODataMessageReaderSettings settings) { throw new NotImplementedException(); }