/// <summary> /// Converts the specified URI into an absolute URI; if the URI is already absolute and the <paramref name="baseUri"/> /// is not null it also verifies that <paramref name="baseUri"/> is the base of <paramref name="uri"/>. /// </summary> /// <param name="uri">The uri to process.</param> /// <param name="baseUri">The base Uri to use.</param> /// <returns>An absolute URI which is either the specified <paramref name="uri"/> if it was absolute, /// or it's a combination of the <paramref name="baseUri"/> and the relative <paramref name="uri"/>.</returns> /// <remarks> /// This method will fail if the specified <paramref name="uri"/> is relative and there's no base URI available /// or if the <paramref name="baseUri"/> is not the base of <paramref name="uri"/>. /// </remarks> internal static Uri BuildAbsoluteUri(Uri uri, Uri baseUri) { DebugUtils.CheckNoExternalCallers(); Debug.Assert(uri != null, "uri != null"); Uri resultUri; if (uri.IsAbsoluteUri) { resultUri = uri; } else { if (baseUri == null) { throw new ODataException(Strings.ODataBatchWriterUtils_RelativeUriUsedWithoutBaseUriSpecified(UriUtils.UriToString(uri))); } resultUri = UriUtils.UriToAbsoluteUri(baseUri, uri); } return(resultUri); }
/// <summary> /// Creates an <see cref="ODataCollectionWriter"/> for the specified message and its stream. /// </summary> /// <param name="format">The serialization format to create the writer for.</param> /// <param name="encoding">The encoding to create the writer with.</param> /// <param name="stream">The response stream to write to.</param> /// <param name="settings">Writer settings to use.</param> /// <param name="metadataProvider">The metadata provider to use.</param> /// <param name="synchronous">True if the writer is created for synchronous operation; false for asynchronous.</param> /// <returns>The newly created <see cref="ODataCollectionWriter"/> instance.</returns> /// <remarks>This is used to create the collection writer once we've obtained the stream from the response.</remarks> private static ODataCollectionWriter CreateCollectionWriter( ODataFormat format, Encoding encoding, Stream stream, ODataWriterSettings settings, DataServiceMetadataProviderWrapper metadataProvider, bool synchronous) { if (settings.BaseUri != null && !settings.BaseUri.IsAbsoluteUri) { throw new ODataException(Strings.ODataWriter_BaseUriMustBeNullOrAbsolute(UriUtils.UriToString(settings.BaseUri))); } switch (format) { case ODataFormat.Json: return(new ODataJsonCollectionWriter(stream, settings, encoding, metadataProvider, synchronous)); case ODataFormat.Atom: return(new ODataAtomCollectionWriter(stream, settings, encoding, metadataProvider, synchronous)); case ODataFormat.Default: Debug.Assert(false, "Should never get here as content-type negotiation should not return Default format for collection."); throw new ODataException(Strings.ODataCollectionWriter_CannotCreateCollectionWriterForFormat(format.ToString())); default: throw new ODataException(Strings.General_InternalError(InternalErrorCodes.ODataCollectionWriter_CreateCollectionWriter_UnreachableCodePath)); } }