/// <summary> /// Updates an add-on plan. /// </summary> /// <param name="name">The add-on name</param> /// <param name="plan">The add-on new plan id</param> /// <param name="promotionCode">The plan promotion code</param> public virtual void UpdateAddOn(string name, string plan, string promotionCode) { List <WindowsAzureAddOn> addons = GetAddOn(new AddOnSearchOptions(name)); if (addons.Count != 1) { throw new Exception(string.Format(Resources.AddOnNotFound, name)); } WindowsAzureAddOn addon = addons[0]; if (!string.IsNullOrEmpty(promotionCode) && addon.Plan.Equals(plan, StringComparison.OrdinalIgnoreCase)) { throw new Exception(Resources.PromotionCodeWithCurrentPlanMessage); } string type; string cloudServiceName; addon.AddOn = GetResourceInformation(addon.AddOn, addon.Location, out type, out cloudServiceName); AddOnUpdateParameters parameters = new AddOnUpdateParameters() { Plan = plan, Type = type, PromotionCode = promotionCode }; try { storeClient.AddOns.Update(cloudServiceName, addon.AddOn, name, parameters); } catch (Exception ex) { if (ex.Message.Equals(Resources.FirstPurchaseErrorMessage, StringComparison.OrdinalIgnoreCase)) { throw new Exception(Resources.FirstPurchaseMessage); } } }
/// <summary> /// The Update Store Item operation creates Windows Azure Store entries /// in a Windows Azure subscription. /// </summary> /// <param name='cloudServiceName'> /// The name of the cloud service to which this store item will be /// assigned. /// </param> /// <param name='resourceName'> /// The name of this resource. /// </param> /// <param name='addOnName'> /// The addon name. /// </param> /// <param name='parameters'> /// Parameters used to specify how the Create procedure will function. /// </param> /// <param name='cancellationToken'> /// Cancellation token. /// </param> /// <returns> /// The response body contains the status of the specified asynchronous /// operation, indicating whether it has succeeded, is inprogress, or /// has failed. Note that this status is distinct from the HTTP status /// code returned for the Get Operation Status operation itself. If /// the asynchronous operation succeeded, the response body includes /// the HTTP status code for the successful request. If the /// asynchronous operation failed, the response body includes the HTTP /// status code for the failed request, and also includes error /// information regarding the failure. /// </returns> public async Task <AddOnOperationStatusResponse> UpdateAsync(string cloudServiceName, string resourceName, string addOnName, AddOnUpdateParameters parameters, CancellationToken cancellationToken) { // Validate if (cloudServiceName == null) { throw new ArgumentNullException("cloudServiceName"); } if (resourceName == null) { throw new ArgumentNullException("resourceName"); } if (addOnName == null) { throw new ArgumentNullException("addOnName"); } if (parameters == null) { throw new ArgumentNullException("parameters"); } if (parameters.Plan == null) { throw new ArgumentNullException("parameters.Plan"); } if (parameters.Type == null) { throw new ArgumentNullException("parameters.Type"); } // 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("cloudServiceName", cloudServiceName); tracingParameters.Add("resourceName", resourceName); tracingParameters.Add("addOnName", addOnName); tracingParameters.Add("parameters", parameters); Tracing.Enter(invocationId, this, "UpdateAsync", tracingParameters); } // Construct URL string url = new Uri(this.Client.BaseUri, "/").ToString() + this.Client.Credentials.SubscriptionId + "/CloudServices/" + cloudServiceName + "/resources/" + parameters.Type + "/" + resourceName + "/" + addOnName; // Create HTTP transport objects HttpRequestMessage httpRequest = null; try { httpRequest = new HttpRequestMessage(); httpRequest.Method = HttpMethod.Put; httpRequest.RequestUri = new Uri(url); // Set Headers httpRequest.Headers.TryAddWithoutValidation("If-Match", "*"); httpRequest.Headers.Add("x-ms-version", "2013-06-01"); // Set Credentials cancellationToken.ThrowIfCancellationRequested(); await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false); // Serialize Request string requestContent = null; XDocument requestDoc = new XDocument(); XElement resourceElement = new XElement(XName.Get("Resource", "http://schemas.microsoft.com/windowsazure")); requestDoc.Add(resourceElement); XElement typeElement = new XElement(XName.Get("Type", "http://schemas.microsoft.com/windowsazure")); typeElement.Value = parameters.Type; resourceElement.Add(typeElement); XElement planElement = new XElement(XName.Get("Plan", "http://schemas.microsoft.com/windowsazure")); planElement.Value = parameters.Plan; resourceElement.Add(planElement); if (parameters.PromotionCode != null) { XElement promotionCodeElement = new XElement(XName.Get("PromotionCode", "http://schemas.microsoft.com/windowsazure")); promotionCodeElement.Value = parameters.PromotionCode; resourceElement.Add(promotionCodeElement); } requestContent = requestDoc.ToString(); httpRequest.Content = new StringContent(requestContent, Encoding.UTF8); httpRequest.Content.Headers.ContentType = new MediaTypeHeaderValue("application/xml"); // 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.Accepted) { cancellationToken.ThrowIfCancellationRequested(); CloudException ex = CloudException.Create(httpRequest, requestContent, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false), CloudExceptionType.Xml); if (shouldTrace) { Tracing.Error(invocationId, ex); } throw ex; } // Create Result AddOnOperationStatusResponse result = null; result = new AddOnOperationStatusResponse(); 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(); } } }
/// <summary> /// The Update Store Item operation creates Windows Azure Store entries /// in a Windows Azure subscription. /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.WindowsAzure.Management.Store.IAddOnOperations. /// </param> /// <param name='cloudServiceName'> /// Required. The name of the cloud service to which this store item /// will be assigned. /// </param> /// <param name='resourceName'> /// Required. The name of this resource. /// </param> /// <param name='addOnName'> /// Required. The addon name. /// </param> /// <param name='parameters'> /// Required. Parameters used to specify how the Create procedure will /// function. /// </param> /// <returns> /// The response body contains the status of the specified asynchronous /// operation, indicating whether it has succeeded, is inprogress, or /// has failed. Note that this status is distinct from the HTTP status /// code returned for the Get Operation Status operation itself. If /// the asynchronous operation succeeded, the response body includes /// the HTTP status code for the successful request. If the /// asynchronous operation failed, the response body includes the HTTP /// status code for the failed request, and also includes error /// information regarding the failure. /// </returns> public static OperationStatusResponse Update(this IAddOnOperations operations, string cloudServiceName, string resourceName, string addOnName, AddOnUpdateParameters parameters) { return(Task.Factory.StartNew((object s) => { return ((IAddOnOperations)s).UpdateAsync(cloudServiceName, resourceName, addOnName, parameters); } , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }
/// <summary> /// The Update Store Item operation creates Windows Azure Store entries /// in a Windows Azure subscription. /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.WindowsAzure.Management.Store.IAddOnOperations. /// </param> /// <param name='cloudServiceName'> /// Required. The name of the cloud service to which this store item /// will be assigned. /// </param> /// <param name='resourceName'> /// Required. The name of this resource. /// </param> /// <param name='addOnName'> /// Required. The addon name. /// </param> /// <param name='parameters'> /// Required. Parameters used to specify how the Create procedure will /// function. /// </param> /// <returns> /// The response body contains the status of the specified asynchronous /// operation, indicating whether it has succeeded, is inprogress, or /// has failed. Note that this status is distinct from the HTTP status /// code returned for the Get Operation Status operation itself. If /// the asynchronous operation succeeded, the response body includes /// the HTTP status code for the successful request. If the /// asynchronous operation failed, the response body includes the HTTP /// status code for the failed request, and also includes error /// information regarding the failure. /// </returns> public static Task <OperationStatusResponse> UpdateAsync(this IAddOnOperations operations, string cloudServiceName, string resourceName, string addOnName, AddOnUpdateParameters parameters) { return(operations.UpdateAsync(cloudServiceName, resourceName, addOnName, parameters, CancellationToken.None)); }
/// <summary> /// The Update Store Item operation creates Windows Azure Store entries /// in a Windows Azure subscription. /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.WindowsAzure.Management.Store.IAddOnOperations. /// </param> /// <param name='cloudServiceName'> /// The name of the cloud service to which this store item will be /// assigned. /// </param> /// <param name='resourceName'> /// The name of this resource. /// </param> /// <param name='addOnName'> /// The addon name. /// </param> /// <param name='parameters'> /// Parameters used to specify how the Create procedure will function. /// </param> /// <returns> /// The response body contains the status of the specified asynchronous /// operation, indicating whether it has succeeded, is inprogress, or /// has failed. Note that this status is distinct from the HTTP status /// code returned for the Get Operation Status operation itself. If /// the asynchronous operation succeeded, the response body includes /// the HTTP status code for the successful request. If the /// asynchronous operation failed, the response body includes the HTTP /// status code for the failed request, and also includes error /// information regarding the failure. /// </returns> public static AddOnOperationStatusResponse Update(this IAddOnOperations operations, string cloudServiceName, string resourceName, string addOnName, AddOnUpdateParameters parameters) { try { return(operations.UpdateAsync(cloudServiceName, resourceName, addOnName, parameters).Result); } catch (AggregateException ex) { if (ex.InnerExceptions.Count > 1) { throw; } else { throw ex.InnerException; } } }