public void TestCustomMediaTypeGetFormatFromContentType() { var resolver = new MyMediaTypeResolver(); foreach (var payloadKind in Enum.GetValues(typeof(ODataPayloadKind)).Cast <ODataPayloadKind>()) { if (payloadKind == ODataPayloadKind.Unsupported) { continue; } string contentType = "text/x-A"; string expectedBoundary = null; ODataMediaType expectedMediaType = MyFormat.MediaTypeWithFormatA.MediaType; if (payloadKind == ODataPayloadKind.Batch) { expectedBoundary = "ba_" + Guid.NewGuid(); contentType += ";boundary=" + expectedBoundary; expectedMediaType = new ODataMediaType("text", "x-A", new KeyValuePair <string, string>("boundary", expectedBoundary)); } ODataMediaType mediaType; Encoding encoding; ODataPayloadKind selectedPayloadKind; ODataFormat actual = MediaTypeUtils.GetFormatFromContentType(contentType, new[] { payloadKind }, resolver, out mediaType, out encoding, out selectedPayloadKind); Console.WriteLine(payloadKind); actual.ShouldBeEquivalentTo(MyFormat.Instance); mediaType.ShouldBeEquivalentTo(expectedMediaType); encoding.ShouldBeEquivalentTo(payloadKind == ODataPayloadKind.BinaryValue ? null : Encoding.UTF8); selectedPayloadKind.ShouldBeEquivalentTo(payloadKind); } }
public IGroup AddAudioGroup(string name, double fps) { OnBeforeGroupAdded(); AMMediaType mediaType = null; try { mediaType = MediaTypeUtils.GetAudioMediaType(); IGroup group = new Group(this, GroupType.Audio, mediaType, name, fps); _groups.Add(group); AttachHandlers(group); OnAfterGroupAdded(group); return(group); } finally { if (mediaType != null) { DsUtils.FreeAMMediaType(mediaType); } } }
public void AlterContentTypeForJsonPaddingIfNeededShouldKeepParametersWhenReplacing() { const string original = "application/json;p1=v1;P2=v2"; var result = MediaTypeUtils.AlterContentTypeForJsonPadding(original); Assert.Equal("text/javascript;p1=v1;P2=v2", result); }
public void AlterContentTypeForJsonPaddingIfNeededShouldThrowIfAtom() { const string original = "application/atom+xml"; Action target = () => MediaTypeUtils.AlterContentTypeForJsonPadding(original); target.Throws <ODataException>(Strings.ODataMessageWriter_JsonPaddingOnInvalidContentType("application/atom+xml")); }
public void AlterContentTypeForJsonPaddingIfNeededShouldReplaceWithJavaScriptIfTextPlain() { const string original = "text/plain"; var result = MediaTypeUtils.AlterContentTypeForJsonPadding(original); Assert.Equal("text/javascript", result); }
public void AlterContentTypeForJsonPaddingIfNeededShouldReplaceWithJavaScriptIfAppJson() { const string original = "application/json"; var result = MediaTypeUtils.AlterContentTypeForJsonPadding(original); result.Should().Be("text/javascript"); }
public IGroup AddVideoGroup(string name, double fps, short bitCount, int width, int height) { OnBeforeGroupAdded(); AMMediaType mediaType = null; try { mediaType = MediaTypeUtils.GetVideoMediaType(bitCount, width, height); IGroup group = new Group(this, GroupType.Video, mediaType, name, fps); _groups.Add(group); AttachHandlers(group); OnAfterGroupAdded(group); return(group); } finally { if (mediaType != null) { DsUtils.FreeAMMediaType(mediaType); } } }
public void GetVideoMediaType() { AMMediaType mediaType = null; try { mediaType = MediaTypeUtils.GetVideoMediaType(16, 320, 200); } finally { DsUtils.FreeAMMediaType(mediaType); } try { mediaType = MediaTypeUtils.GetVideoMediaType(24, 172, 160); } finally { DsUtils.FreeAMMediaType(mediaType); } try { mediaType = MediaTypeUtils.GetVideoMediaType(32, 172, 160); } finally { DsUtils.FreeAMMediaType(mediaType); } }
public bool UpdateMediaAttribute(MediaType mediaType, MediaAttr attribute, ActionConfig config) { bool ret = this.mSession.update(MediaTypeUtils.ConvertToNative(mediaType), (int)attribute, config); config.Dispose(); return(ret); }
public void AlterContentTypeForJsonPaddingIfNeededShouldFailIfAppJsonIsNotAtStart() { const string original = "tricky/application/json"; Action target = () => MediaTypeUtils.AlterContentTypeForJsonPadding(original); target.Throws <ODataException>(Strings.ODataMessageWriter_JsonPaddingOnInvalidContentType("tricky/application/json")); }
public void AlterContentTypeForJsonPaddingIfNeededShouldBeCaseInsensitive() { const string original = "aPplIcAtiOn/JsOn"; var result = MediaTypeUtils.AlterContentTypeForJsonPadding(original); Assert.Equal("text/javascript", result); }
public bool Update(MediaType newMediaType) { if (mSession != null) { return(mSession.call(base.ToUri, MediaTypeUtils.ConvertToNative(newMediaType))); } return(false); }
public bool MakeVideoSharingCall(string remoteUri) { this.outgoing = true; ActionConfig config = new ActionConfig(); bool ret = this.mSession.call(remoteUri, MediaTypeUtils.ConvertToNative(MediaType.Video), 0, config); config.Dispose(); return(ret); }
public bool MakeCall(string remoteUri, MediaAttr mediaAttr, ActionConfig config) { this.outgoing = true; base.ToUri = remoteUri; bool ret = this.mSession.call(remoteUri, MediaTypeUtils.ConvertToNative(this.mMediaType), (int)mediaAttr, config); config.Dispose(); return(ret); }
public void MultipartBoundariesShouldNotGrowCache() { for (int i = 1; i < 100; i++) { ODataMediaType mediaType; Encoding encoding; ODataPayloadKind payloadKind; MediaTypeUtils.GetFormatFromContentType(string.Format("multipart/mixed;boundary={0}", Guid.NewGuid()), new ODataPayloadKind[] { ODataPayloadKind.Batch }, ODataMediaTypeResolver.GetMediaTypeResolver(null), out mediaType, out encoding, out payloadKind); } Assert.True(MediaTypeUtils.GetCacheKeys().Count(k => k.StartsWith("multipart/mixed")) == 1, "Multiple multipart/mixed keys in cache"); }
internal static TestMediaTypeWithFormat ParseContentType(string contentType, ODataVersion version, ODataMediaTypeResolver resolver = null) { ODataMediaType mediaType; Encoding encoding; ODataPayloadKind payloadKind; var format = MediaTypeUtils.GetFormatFromContentType(contentType, new[] { ODataPayloadKind.Resource }, resolver ?? ODataMediaTypeResolver.GetMediaTypeResolver(null), out mediaType, out encoding, out payloadKind); Assert.NotNull(mediaType); Assert.NotNull(format); return(new TestMediaTypeWithFormat { MediaType = mediaType, Format = format }); }
public void GetAudioMediaType() { AMMediaType mediaType = null; try { mediaType = MediaTypeUtils.GetAudioMediaType(); Assert.IsNotNull(mediaType); } finally { DsUtils.FreeAMMediaType(mediaType); } }
internal static TestMediaTypeWithFormat ParseContentType(string contentType, ODataVersion version, ODataMediaTypeResolver resolver = null) { ODataMediaType mediaType; Encoding encoding; ODataPayloadKind payloadKind; string batchBoundary; var format = MediaTypeUtils.GetFormatFromContentType(contentType, new[] { ODataPayloadKind.Entry }, resolver ?? ODataMediaTypeResolver.DefaultMediaTypeResolver, out mediaType, out encoding, out payloadKind, out batchBoundary); mediaType.Should().NotBeNull(); format.Should().NotBeNull(); return(new TestMediaTypeWithFormat { MediaType = mediaType, Format = format }); }
public static bool HandleMediaUpdate(long id, twrap_media_type_t newMediaType) { MyAVSession avSession = MyAVSession.GetSession(id); if (avSession != null) { if ((newMediaType & twrap_media_type_t.twrap_media_msrp) == twrap_media_type_t.twrap_media_msrp) { return(false); // For now MSRP update is not suportted } avSession.mMediaType = MediaTypeUtils.ConvertFromNative(newMediaType); return(true); } return(false); }
public static MyAVSession TakeOutgoingTranferSession(MySipStack sipStack, CallSession session, twrap_media_type_t mediaType, SipMessage sipMessage) { MediaType media = MediaTypeUtils.ConvertFromNative(mediaType); if (media == MediaType.None) { return(null); } MyAVSession avSession = MyAVSession.CreateOutgoingSession(sipStack, session, media); if (sipMessage != null) { avSession.RemotePartyUri = sipMessage.getSipHeaderValue("refer-to"); } return(avSession); }
public bool MakeVideoSharingCall(String remoteUri) { bool ret; base.outgoing = true; ActionConfig config = #if WINDOWS_PHONE org.doubango.WindowsPhone.BackgroundProcessController.Instance.rtActionConfigNew(); #else new ActionConfig(); #endif ret = mSession.call(remoteUri, MediaTypeUtils.ConvertToNative(MediaType.Video), config); config.Dispose(); return(ret); }
/// <summary> /// Validates the headers that have been read for a part. /// </summary> /// <param name="headers">The set of headers to validate.</param> /// <param name="isChangeSetPart">true if the headers indicate a changeset part; otherwise false.</param> /// <returns>The set of validated headers.</returns> /// <remarks> /// An operation part is required to have content type 'application/http' and content transfer /// encoding 'binary'. A changeset is required to have content type 'multipart/mixed'. /// Note that we allow additional headers for batch parts; clients of the library can choose /// to be more strict. /// </remarks> private ODataBatchOperationHeaders ValidatePartHeaders(ODataBatchOperationHeaders headers, out bool isChangeSetPart) { string contentType; if (!headers.TryGetValue(ODataConstants.ContentTypeHeader, out contentType)) { throw new ODataException(Strings.ODataBatchReaderStream_MissingContentTypeHeader); } if (MediaTypeUtils.MediaTypeAndSubtypeAreEqual(contentType, MimeConstants.MimeApplicationHttp)) { isChangeSetPart = false; // An operation part is required to have application/http content type and // binary content transfer encoding. string transferEncoding; if (!headers.TryGetValue(ODataConstants.ContentTransferEncoding, out transferEncoding) || string.Compare(transferEncoding, ODataConstants.BatchContentTransferEncoding, StringComparison.OrdinalIgnoreCase) != 0) { throw new ODataException(Strings.ODataBatchReaderStream_MissingOrInvalidContentEncodingHeader( ODataConstants.ContentTransferEncoding, ODataConstants.BatchContentTransferEncoding)); } } else if (MediaTypeUtils.MediaTypeStartsWithTypeAndSubtype(contentType, MimeConstants.MimeMultipartMixed)) { isChangeSetPart = true; if (this.changesetBoundary != null) { // Nested changesets are not supported throw new ODataException(Strings.ODataBatchReaderStream_NestedChangesetsAreNotSupported); } } else { throw new ODataException(Strings.ODataBatchReaderStream_InvalidContentTypeSpecified( ODataConstants.ContentTypeHeader, contentType, MimeConstants.MimeMultipartMixed, MimeConstants.MimeApplicationHttp)); } return(headers); }
private static TestMediaTypeWithFormat GetResponseType(ODataVersion version, Action <ODataMessageWriterSettings> configureSettings) { var settings = new ODataMessageWriterSettings { Version = version }; configureSettings(settings); ODataMediaType mediaType; Encoding encoding; var format = MediaTypeUtils.GetContentTypeFromSettings(settings, ODataPayloadKind.Entry, ODataMediaTypeResolver.DefaultMediaTypeResolver, out mediaType, out encoding); mediaType.Should().NotBeNull(); format.Should().NotBeNull(); return(new TestMediaTypeWithFormat { MediaType = mediaType, Format = format }); }
private static TestMediaTypeWithFormat GetResponseType(ODataVersion version, Action <ODataMessageWriterSettings> configureSettings) { var settings = new ODataMessageWriterSettings { Version = version }; configureSettings(settings); ODataMediaType mediaType; Encoding encoding; var format = MediaTypeUtils.GetContentTypeFromSettings(settings, ODataPayloadKind.Resource, ODataMediaTypeResolver.GetMediaTypeResolver(null), out mediaType, out encoding); Assert.NotNull(mediaType); Assert.NotNull(format); return(new TestMediaTypeWithFormat { MediaType = mediaType, Format = format }); }
/// <summary> /// Parse the content type header value to retrieve the boundary and encoding of a changeset. /// </summary> /// <param name="contentType">The content type to parse.</param> private void DetermineChangesetBoundaryAndEncoding(string contentType) { Debug.Assert(!string.IsNullOrEmpty(contentType), "Should have validated that non-null, non-empty content type header exists."); ODataMediaType mediaType; ODataPayloadKind readerPayloadKind; MediaTypeUtils.GetFormatFromContentType( contentType, new ODataPayloadKind[] { ODataPayloadKind.Batch }, this.mediaTypeResolver, out mediaType, out this.changesetEncoding, out readerPayloadKind); Debug.Assert(readerPayloadKind == ODataPayloadKind.Batch, "Must find batch payload kind."); Debug.Assert(HttpUtils.CompareMediaTypeNames(MimeConstants.MimeMultipartMixed, mediaType.FullTypeName), "Must be multipart/mixed media type."); this.changesetBoundary = ODataMultipartMixedBatchWriterUtils.GetBatchBoundaryFromMediaType(mediaType); Debug.Assert(this.changesetBoundary != null && this.changesetBoundary.Length > 0, "Boundary string should have been validated by now."); }
public static MyAVSession TakeIncomingSession(MySipStack sipStack, CallSession session, twrap_media_type_t mediaType, SipMessage sipMessage) { MediaType media = MediaTypeUtils.ConvertFromNative(mediaType); if (media == MediaType.None) { return(null); } lock (MyAVSession.sessions) { MyAVSession avSession = new MyAVSession(sipStack, session, media, InviteState.INCOMING); if (sipMessage != null) { avSession.RemotePartyUri = sipMessage.getSipHeaderValue("f"); } MyAVSession.sessions.Add(avSession.Id, avSession); return(avSession); } }
/// <summary>Reads a Content-Type header and extracts the media type's name (type/subtype) and parameters.</summary> /// <param name="contentType">The Content-Type header.</param> /// <param name="mediaTypeName">The media type in standard type/subtype form, without parameters.</param> /// <param name="mediaTypeCharset">The (optional) charset parameter of the media type.</param> /// <returns>The parameters of the media type not including the 'charset' parameter.</returns> internal static IList <KeyValuePair <string, string> > ReadMimeType(string contentType, out string mediaTypeName, out string mediaTypeCharset) { if (String.IsNullOrEmpty(contentType)) { throw new ODataContentTypeException(Strings.HttpUtils_ContentTypeMissing); } IList <KeyValuePair <MediaType, string> > mediaTypes = ReadMediaTypes(contentType); if (mediaTypes.Count != 1) { throw new ODataContentTypeException(Strings.HttpUtils_NoOrMoreThanOneContentTypeSpecified(contentType)); } MediaType mediaType = mediaTypes[0].Key; MediaTypeUtils.CheckMediaTypeForWildCards(mediaType); mediaTypeName = mediaType.FullTypeName; mediaTypeCharset = mediaTypes[0].Value; return(mediaType.Parameters); }
public void MediaTypeResolutionForJsonBatchShouldWork() { string[] contentTypes = new string[] { "application/json", "application/json;odata.metadata=minimal", "application/json;odata.metadata=minimal;odata.streaming=true", "application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false" }; foreach (string contentType in contentTypes) { ODataMediaType mediaType; Encoding encoding; ODataPayloadKind payloadKind; ODataFormat format = MediaTypeUtils.GetFormatFromContentType(contentType, new[] { ODataPayloadKind.Batch }, ODataMediaTypeResolver.GetMediaTypeResolver(null), out mediaType, out encoding, out payloadKind); Assert.NotNull(mediaType); Assert.NotNull(encoding); Assert.Equal(ODataPayloadKind.Batch, payloadKind); Assert.Equal(ODataFormat.Json, format); } }
public bool Update(MediaType newMediaType, MediaAttr mediaAttr, ActionConfig config) { return(this.mSession != null && this.mSession.call(base.ToUri, MediaTypeUtils.ConvertToNative(newMediaType), (int)mediaAttr)); }
public bool MakeVideoPollCall(string remoteUri, ActionConfig config) { this.outgoing = true; base.ToUri = remoteUri; return(this.mSession.call(remoteUri, MediaTypeUtils.ConvertToNative(this.mMediaType), 0, config)); }