/// <summary> /// Validates a stream reference property info to ensure it's not null and its name if correct. /// </summary> /// <param name="streamInfo">The stream reference info to validate.</param> /// <param name="edmProperty">Property metadata to validate against.</param> /// <param name="propertyName">The name of the property being validated.</param> internal static void ValidateStreamPropertyInfo(IODataStreamReferenceInfo streamInfo, IEdmProperty edmProperty, string propertyName) { Debug.Assert(streamInfo != null, "streamInfo != null"); if (edmProperty != null && !edmProperty.Type.IsStream()) { throw new ODataException(Strings.ValidationUtils_MismatchPropertyKindForStreamProperty(propertyName)); } }
/// <summary> /// Validates a stream reference property. /// </summary> /// <param name="streamInfo">The stream property to check.</param> /// <param name="propertyName">The name of the property being checked.</param> /// <param name="structuredType">The owning type of the stream property or null if no metadata is available.</param> /// <param name="streamEdmProperty">The stream property defined by the model.</param> public void ValidateStreamReferenceProperty(IODataStreamReferenceInfo streamInfo, string propertyName, IEdmStructuredType structuredType, IEdmProperty streamEdmProperty) { ReaderValidationUtils.ValidateStreamReferenceProperty( streamInfo, propertyName, structuredType, streamEdmProperty, settings.ThrowOnUndeclaredPropertyForNonOpenType); }
private void WriteStreamValue(IODataStreamReferenceInfo streamInfo, string propertyName, ODataResourceMetadataBuilder metadataBuilder) { WriterValidationUtils.ValidateStreamPropertyInfo(streamInfo, currentPropertyInfo.MetadataType.EdmProperty, propertyName, this.WritingResponse); this.WriteStreamInfo(propertyName, streamInfo); if (metadataBuilder != null) { metadataBuilder.MarkStreamPropertyProcessed(propertyName); } }
/// <summary> /// Validates a named stream property to ensure it's not null and it's name if correct. /// </summary> /// <param name="streamPropertyInfo">The stream reference property to validate.</param> /// <param name="edmProperty">Property metadata to validate against.</param> /// <param name="propertyName">The name of the property being validated.</param> /// <param name="writingResponse">true when writing a response; otherwise false.</param> /// <remarks>This does NOT validate the value of the stream property, just the property itself.</remarks> internal static void ValidateStreamPropertyInfo(IODataStreamReferenceInfo streamPropertyInfo, IEdmProperty edmProperty, string propertyName, bool writingResponse) { Debug.Assert(streamPropertyInfo != null, "streamProperty != null"); ValidationUtils.ValidateStreamPropertyInfo(streamPropertyInfo, edmProperty, propertyName); if (!writingResponse) { // Read/Write links and ETags on Stream properties are only valid in responses; writers fail if they encounter them in requests. if (streamPropertyInfo != null && streamPropertyInfo.EditLink != null || streamPropertyInfo.ReadLink != null || streamPropertyInfo.ETag != null) { throw new ODataException(Strings.WriterValidationUtils_StreamPropertyInRequest(propertyName)); } } }
/// <summary> /// Writes stream property information. /// </summary> /// <param name="propertyName">The name of the stream property to write.</param> /// <param name="streamInfo">The stream reference value to be written</param> private void WriteStreamInfo(string propertyName, IODataStreamReferenceInfo streamInfo) { Debug.Assert(!string.IsNullOrEmpty(propertyName), "!string.IsNullOrEmpty(propertyName)"); Debug.Assert(streamInfo != null, "streamReferenceValue != null"); Uri mediaEditLink = streamInfo.EditLink; if (mediaEditLink != null) { this.ODataAnnotationWriter.WritePropertyAnnotationName(propertyName, ODataAnnotationNames.ODataMediaEditLink); this.JsonWriter.WriteValue(this.UriToString(mediaEditLink)); } Uri mediaReadLink = streamInfo.ReadLink; if (mediaReadLink != null) { this.ODataAnnotationWriter.WritePropertyAnnotationName(propertyName, ODataAnnotationNames.ODataMediaReadLink); this.JsonWriter.WriteValue(this.UriToString(mediaReadLink)); } string mediaContentType = streamInfo.ContentType; if (mediaContentType != null) { this.ODataAnnotationWriter.WritePropertyAnnotationName(propertyName, ODataAnnotationNames.ODataMediaContentType); this.JsonWriter.WriteValue(mediaContentType); } string mediaETag = streamInfo.ETag; if (mediaETag != null) { this.ODataAnnotationWriter.WritePropertyAnnotationName(propertyName, ODataAnnotationNames.ODataMediaETag); this.JsonWriter.WriteValue(mediaETag); } }