/// <summary>
 /// The Regenerate Media Services Account Key operation regenerates an
 /// account key for the given Media Services account in Windows Azure.
 /// (see
 /// http://msdn.microsoft.com/en-us/library/windowsazure/dn167010.aspx
 /// for more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.MediaServices.IAccountOperations.
 /// </param>
 /// <param name='accountName'>
 /// The name of the Media Services Account.
 /// </param>
 /// <param name='keyType'>
 /// The type of key to regenerate (primary or secondary)
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static OperationResponse RegenerateKey(this IAccountOperations operations, string accountName, MediaServicesKeyType keyType)
 {
     try
     {
         return operations.RegenerateKeyAsync(accountName, keyType).Result;
     }
     catch (AggregateException ex)
     {
         if (ex.InnerExceptions.Count > 1)
         {
             throw;
         }
         else
         {
             throw ex.InnerException;
         }
     }
 }
 /// <summary>
 /// The Regenerate Media Services Account Key operation regenerates an
 /// account key for the given Media Services account in Windows Azure.
 /// (see
 /// http://msdn.microsoft.com/en-us/library/windowsazure/dn167010.aspx
 /// for more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.MediaServices.IAccountOperations.
 /// </param>
 /// <param name='accountName'>
 /// The name of the Media Services Account.
 /// </param>
 /// <param name='keyType'>
 /// The type of key to regenerate (primary or secondary)
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static Task<OperationResponse> RegenerateKeyAsync(this IAccountOperations operations, string accountName, MediaServicesKeyType keyType)
 {
     return operations.RegenerateKeyAsync(accountName, keyType, CancellationToken.None);
 }
        /// <summary>
        /// The Regenerate Media Services Account Key operation regenerates an
        /// account key for the given Media Services account in Windows Azure.
        /// (see
        /// http://msdn.microsoft.com/en-us/library/windowsazure/dn167010.aspx
        /// for more information)
        /// </summary>
        /// <param name='accountName'>
        /// The name of the Media Services Account.
        /// </param>
        /// <param name='keyType'>
        /// The type of key to regenerate (primary or secondary)
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// A standard service response including an HTTP status code and
        /// request ID.
        /// </returns>
        public async System.Threading.Tasks.Task <OperationResponse> RegenerateKeyAsync(string accountName, MediaServicesKeyType keyType, CancellationToken cancellationToken)
        {
            // Validate
            if (accountName == null)
            {
                throw new ArgumentNullException("accountName");
            }

            // Tracing
            bool   shouldTrace  = CloudContext.Configuration.Tracing.IsEnabled;
            string invocationId = null;

            if (shouldTrace)
            {
                invocationId = Tracing.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                tracingParameters.Add("accountName", accountName);
                tracingParameters.Add("keyType", keyType);
                Tracing.Enter(invocationId, this, "RegenerateKeyAsync", tracingParameters);
            }

            // Construct URL
            string url = new Uri(this.Client.BaseUri, "/").ToString() + this.Client.Credentials.SubscriptionId + "/services/mediaservices/Accounts/" + accountName + "/AccountKeys/" + keyType + "/Regenerate";

            // Create HTTP transport objects
            HttpRequestMessage httpRequest = null;

            try
            {
                httpRequest            = new HttpRequestMessage();
                httpRequest.Method     = HttpMethod.Post;
                httpRequest.RequestUri = new Uri(url);

                // Set Headers
                httpRequest.Headers.Add("x-ms-version", "2011-10-01");

                // Set Credentials
                cancellationToken.ThrowIfCancellationRequested();
                await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                // Send Request
                HttpResponseMessage httpResponse = null;
                try
                {
                    if (shouldTrace)
                    {
                        Tracing.SendRequest(invocationId, httpRequest);
                    }
                    cancellationToken.ThrowIfCancellationRequested();
                    httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                    if (shouldTrace)
                    {
                        Tracing.ReceiveResponse(invocationId, httpResponse);
                    }
                    HttpStatusCode statusCode = httpResponse.StatusCode;
                    if (statusCode != HttpStatusCode.NoContent)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false), CloudExceptionType.Xml);
                        if (shouldTrace)
                        {
                            Tracing.Error(invocationId, ex);
                        }
                        throw ex;
                    }

                    // Create Result
                    OperationResponse result = null;
                    result            = new OperationResponse();
                    result.StatusCode = statusCode;
                    if (httpResponse.Headers.Contains("x-ms-request-id"))
                    {
                        result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
                    }

                    if (shouldTrace)
                    {
                        Tracing.Exit(invocationId, result);
                    }
                    return(result);
                }
                finally
                {
                    if (httpResponse != null)
                    {
                        httpResponse.Dispose();
                    }
                }
            }
            finally
            {
                if (httpRequest != null)
                {
                    httpRequest.Dispose();
                }
            }
        }
Пример #4
0
 /// <summary>
 ///     Deletes azure media service account async.
 /// </summary>
 public Task <OperationResponse> RegenerateMediaServicesAccountAsync(string name, MediaServicesKeyType keyType)
 {
     return(_mediaServicesManagementClient.Accounts.RegenerateKeyAsync(name, keyType));
 }
 /// <summary>
 /// The Regenerate Media Services Account Key operation regenerates an
 /// account key for the given Media Services account in Windows Azure.
 /// (see
 /// http://msdn.microsoft.com/en-us/library/windowsazure/dn167010.aspx
 /// for more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.MediaServices.IAccountOperations.
 /// </param>
 /// <param name='accountName'>
 /// Required. The name of the Media Services Account.
 /// </param>
 /// <param name='keyType'>
 /// Required. The type of key to regenerate (primary or secondary)
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static Task <AzureOperationResponse> RegenerateKeyAsync(this IAccountOperations operations, string accountName, MediaServicesKeyType keyType)
 {
     return(operations.RegenerateKeyAsync(accountName, keyType, CancellationToken.None));
 }
 /// <summary>
 /// The Regenerate Media Services Account Key operation regenerates an
 /// account key for the given Media Services account in Windows Azure.
 /// (see
 /// http://msdn.microsoft.com/en-us/library/windowsazure/dn167010.aspx
 /// for more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.MediaServices.IAccountOperations.
 /// </param>
 /// <param name='accountName'>
 /// Required. The name of the Media Services Account.
 /// </param>
 /// <param name='keyType'>
 /// Required. The type of key to regenerate (primary or secondary)
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static AzureOperationResponse RegenerateKey(this IAccountOperations operations, string accountName, MediaServicesKeyType keyType)
 {
     return(Task.Factory.StartNew((object s) =>
     {
         return ((IAccountOperations)s).RegenerateKeyAsync(accountName, keyType);
     }
                                  , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
 /// <summary>
 /// The Regenerate Media Services Account Key operation regenerates an
 /// account key for the given Media Services account in Windows Azure.
 /// (see
 /// http://msdn.microsoft.com/en-us/library/windowsazure/dn167010.aspx
 /// for more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.MediaServices.IAccountOperations.
 /// </param>
 /// <param name='accountName'>
 /// Required. The name of the Media Services Account.
 /// </param>
 /// <param name='keyType'>
 /// Required. The type of key to regenerate (primary or secondary)
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static AzureOperationResponse RegenerateKey(this IAccountOperations operations, string accountName, MediaServicesKeyType keyType)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IAccountOperations)s).RegenerateKeyAsync(accountName, keyType);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
Пример #8
0
        /// <summary>
        /// The Regenerate Media Services Account Key operation regenerates an
        /// account key for the given Media Services account in Windows Azure.
        /// (see
        /// http://msdn.microsoft.com/en-us/library/windowsazure/dn167010.aspx
        /// for more information)
        /// </summary>
        /// <param name='accountName'>
        /// Required. The name of the Media Services Account.
        /// </param>
        /// <param name='keyType'>
        /// Required. The type of key to regenerate (primary or secondary)
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// A standard service response including an HTTP status code and
        /// request ID.
        /// </returns>
        public async Task <AzureOperationResponse> RegenerateKeyAsync(string accountName, MediaServicesKeyType keyType, CancellationToken cancellationToken)
        {
            // Validate
            if (accountName == null)
            {
                throw new ArgumentNullException("accountName");
            }

            // Tracing
            bool   shouldTrace  = TracingAdapter.IsEnabled;
            string invocationId = null;

            if (shouldTrace)
            {
                invocationId = TracingAdapter.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                tracingParameters.Add("accountName", accountName);
                tracingParameters.Add("keyType", keyType);
                TracingAdapter.Enter(invocationId, this, "RegenerateKeyAsync", tracingParameters);
            }

            // Construct URL
            string url = "";

            url = url + "/";
            if (this.Client.Credentials.SubscriptionId != null)
            {
                url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
            }
            url = url + "/services/mediaservices/Accounts/";
            url = url + Uri.EscapeDataString(accountName);
            url = url + "/AccountKeys/";
            url = url + Uri.EscapeDataString(keyType.ToString());
            url = url + "/Regenerate";
            string baseUrl = this.Client.BaseUri.AbsoluteUri;

            // Trim '/' character from the end of baseUrl and beginning of url.
            if (baseUrl[baseUrl.Length - 1] == '/')
            {
                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
            }
            if (url[0] == '/')
            {
                url = url.Substring(1);
            }
            url = baseUrl + "/" + url;
            url = url.Replace(" ", "%20");

            // Create HTTP transport objects
            HttpRequestMessage httpRequest = null;

            try
            {
                httpRequest            = new HttpRequestMessage();
                httpRequest.Method     = HttpMethod.Post;
                httpRequest.RequestUri = new Uri(url);

                // Set Headers
                httpRequest.Headers.Add("x-ms-version", "2011-10-01");

                // Set Credentials
                cancellationToken.ThrowIfCancellationRequested();
                await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                // Send Request
                HttpResponseMessage httpResponse = null;
                try
                {
                    if (shouldTrace)
                    {
                        TracingAdapter.SendRequest(invocationId, httpRequest);
                    }
                    cancellationToken.ThrowIfCancellationRequested();
                    httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                    if (shouldTrace)
                    {
                        TracingAdapter.ReceiveResponse(invocationId, httpResponse);
                    }
                    HttpStatusCode statusCode = httpResponse.StatusCode;
                    if (statusCode != HttpStatusCode.NoContent)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
                        if (shouldTrace)
                        {
                            TracingAdapter.Error(invocationId, ex);
                        }
                        throw ex;
                    }

                    // Create Result
                    AzureOperationResponse result = null;
                    // Deserialize Response
                    result            = new AzureOperationResponse();
                    result.StatusCode = statusCode;
                    if (httpResponse.Headers.Contains("x-ms-request-id"))
                    {
                        result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
                    }

                    if (shouldTrace)
                    {
                        TracingAdapter.Exit(invocationId, result);
                    }
                    return(result);
                }
                finally
                {
                    if (httpResponse != null)
                    {
                        httpResponse.Dispose();
                    }
                }
            }
            finally
            {
                if (httpRequest != null)
                {
                    httpRequest.Dispose();
                }
            }
        }
 /// <summary>
 /// The Regenerate Media Services Account Key operation regenerates an
 /// account key for the given Media Services account in Windows Azure.
 /// (see
 /// http://msdn.microsoft.com/en-us/library/windowsazure/dn167010.aspx
 /// for more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.MediaServices.IAccountOperations.
 /// </param>
 /// <param name='accountName'>
 /// The name of the Media Services Account.
 /// </param>
 /// <param name='keyType'>
 /// The type of key to regenerate (primary or secondary)
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static OperationResponse RegenerateKey(this IAccountOperations operations, string accountName, MediaServicesKeyType keyType)
 {
     try
     {
         return(operations.RegenerateKeyAsync(accountName, keyType).Result);
     }
     catch (AggregateException ex)
     {
         if (ex.InnerExceptions.Count > 1)
         {
             throw;
         }
         else
         {
             throw ex.InnerException;
         }
     }
 }