示例#1
0
        /// <inheritdoc/>
        public virtual Task <GetExtensionApiCall> PrepareGetExtensionAsync(ExtensionAlias alias, CancellationToken cancellationToken)
        {
            if (alias == null)
            {
                throw new ArgumentNullException("alias");
            }

            UriTemplate template = new UriTemplate("v2.0/extensions/{alias}");
            Dictionary <string, string> parameters = new Dictionary <string, string> {
                { "alias", alias.Value }
            };

            return(GetBaseUriAsync(cancellationToken)
                   .Then(PrepareRequestAsyncFunc(HttpMethod.Get, template, parameters, cancellationToken))
                   .Select(task => new GetExtensionApiCall(CreateJsonApiCall <ExtensionResponse>(task.Result))));
        }
        /// <summary>
        /// Prepare and send an HTTP API call to obtain details for a specific extension available for the current
        /// OpenStack Identity Service V2 endpoint.
        /// </summary>
        /// <param name="service">The <see cref="IIdentityService"/> instance.</param>
        /// <param name="alias">The unique alias identifying the extension.</param>
        /// <param name="cancellationToken">The <seealso cref="CancellationToken"/> that the task will observe.</param>
        /// <returns>
        /// A <seealso cref="Task"/> representing the asynchronous operation. When the task completes successfully, the
        /// <see cref="Task{TResult}.Result"/> property will contain an <see cref="Extension"/> instance describing the
        /// extension.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// <para>If <paramref name="service"/> is <see langword="null"/>.</para>
        /// <para>-or-</para>
        /// <para>If <paramref name="alias"/> is <see langword="null"/>.</para>
        /// </exception>
        /// <exception cref="HttpWebException">
        /// If an error occurs during an HTTP request as part of preparing or sending the API call.
        /// </exception>
        /// <seealso cref="IIdentityService.PrepareGetExtensionAsync"/>
        /// <seealso href="http://developer.openstack.org/api-ref-identity-v2.html#identity-api-extensions">Extensions (Identity API v2.0 - OpenStack Complete API Reference)</seealso>
        public static Task <Extension> GetExtensionAsync(this IIdentityService service, ExtensionAlias alias, CancellationToken cancellationToken)
        {
            if (service == null)
            {
                throw new ArgumentNullException("service");
            }
            if (alias == null)
            {
                throw new ArgumentNullException("alias");
            }

            return(TaskBlocks.Using(
                       () => service.PrepareGetExtensionAsync(alias, cancellationToken),
                       task => task.Result.SendAsync(cancellationToken).Select(innerTask => innerTask.Result.Item2.Extension)));
        }
        /// <summary>
        /// Sets (or removes) the <c>marker</c> query parameter for a <see cref="ListExtensionsApiCall"/> HTTP API call.
        /// </summary>
        /// <param name="apiCall">The prepared HTTP API call.</param>
        /// <param name="alias">
        /// <para>The alias of the last <see cref="Extension"/> in the previous page of results.</para>
        /// <para>-or-</para>
        /// <para><see langword="null"/> to remove the <c>marker</c> query parameter and have the resulting page start
        /// with the first item in the list.</para>
        /// </param>
        /// <returns>Returns the input argument <paramref name="apiCall"/>, which was modified according to the
        /// specified <paramref name="alias"/>.</returns>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="apiCall"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ObjectDisposedException">If the HTTP API call has been disposed.</exception>
        /// <exception cref="InvalidOperationException">If the HTTP API call has already been sent.</exception>
        /// <seealso href="http://docs.openstack.org/api/openstack-identity-service/2.0/content/Paginated_Collections-d1e325.html">Paginated collections (OpenStack Identity API v2.0 Reference)</seealso>
        public static ListExtensionsApiCall WithMarker(this ListExtensionsApiCall apiCall, ExtensionAlias alias)
        {
            if (apiCall == null)
            {
                throw new ArgumentNullException("apiCall");
            }
            if (alias == null)
            {
                throw new ArgumentNullException("alias");
            }

            Uri uri = apiCall.RequestMessage.RequestUri;

            if (alias == null)
            {
                apiCall.RequestMessage.RequestUri = UriUtility.RemoveQueryParameter(uri, "marker");
            }
            else
            {
                apiCall.RequestMessage.RequestUri = UriUtility.SetQueryParameter(uri, "marker", alias.Value);
            }

            return(apiCall);
        }
 /// <summary>
 /// Sets (or removes) the <c>marker</c> query parameter for a <see cref="ListExtensionsApiCall"/> HTTP API call.
 /// </summary>
 /// <remarks>
 /// <para>This method simplifies the use of <see cref="WithMarker(ListExtensionsApiCall, ExtensionAlias)"/> in
 /// scenarios where <see langword="async/await"/> are not used for the preparation of the HTTP API call.</para>
 /// </remarks>
 /// <param name="apiCall">A <see cref="Task"/> representing the asynchronous operation to prepare the HTTP API
 /// call.</param>
 /// <param name="alias">
 /// <para>The alias of the last <see cref="Extension"/> in the previous page of results.</para>
 /// <para>-or-</para>
 /// <para><see langword="null"/> to remove the <c>marker</c> query parameter and have the resulting page start
 /// with the first item in the list.</para>
 /// </param>
 /// <returns>A <see cref="Task"/> representing the asynchronous operation. When the task completes successfully,
 /// the <see cref="Task{TResult}.Result"/> property contains the result of the input task
 /// <paramref name="apiCall"/>, which was modified according to the specified
 /// <paramref name="alias"/>.</returns>
 /// <exception cref="ArgumentNullException">
 /// If <paramref name="apiCall"/> is <see langword="null"/>.
 /// </exception>
 /// <exception cref="ObjectDisposedException">If the HTTP API call has been disposed.</exception>
 /// <exception cref="InvalidOperationException">If the HTTP API call has already been sent.</exception>
 /// <seealso href="http://docs.openstack.org/api/openstack-identity-service/2.0/content/Paginated_Collections-d1e325.html">Paginated collections (OpenStack Identity API v2.0 Reference)</seealso>
 public static Task <ListExtensionsApiCall> WithMarker(this Task <ListExtensionsApiCall> apiCall, ExtensionAlias alias)
 {
     return(apiCall.Select(task => apiCall.Result.WithMarker(alias)));
 }