/// <summary> /// Convert from the resource provider endpoint. /// </summary> /// <param name="resourceProviderEndpoint">The resource provider endpoint.</param> public static EndpointModel FromResourceProviderEndpoint(ResourceProviderEndpoint resourceProviderEndpoint) { return new EndpointModel() { EndpointAddress = resourceProviderEndpoint.ForwardingAddress.AbsoluteUri, Username = resourceProviderEndpoint.AuthenticationUsername, Password = resourceProviderEndpoint.AuthenticationPassword }; }
/// <summary> /// Convert from the resource provider endpoint. /// </summary> /// <param name="resourceProviderEndpoint">The resource provider endpoint.</param> public static EndpointModel FromResourceProviderEndpoint(ResourceProviderEndpoint resourceProviderEndpoint) { return(new EndpointModel() { EndpointAddress = resourceProviderEndpoint.ForwardingAddress.AbsoluteUri, Username = resourceProviderEndpoint.AuthenticationUsername, Password = resourceProviderEndpoint.AuthenticationPassword }); }
/// <summary> /// Create or update delegated provider configuration. (see /// http://msdn.microsoft.com/en-us/library/windowsazure/XXXXX.aspx /// for more information) /// </summary> /// <param name='parameters'> /// Required. The create or update result of delegated provider /// configuration operation. /// </param> /// <param name='cancellationToken'> /// Cancellation token. /// </param> /// <returns> /// The create or update result of delegated provider configuration /// operation. /// </returns> public async Task <DelegatedProviderConfigurationOperationsCreateOrUpdateResult> CreateOrUpdateAsync(DelegatedProviderConfigurationOperationsCreateOrUpdateParameters parameters, CancellationToken cancellationToken) { // Validate if (parameters == null) { throw new ArgumentNullException("parameters"); } if (parameters.DelegatedProviderConfiguration == null) { throw new ArgumentNullException("parameters.DelegatedProviderConfiguration"); } // Tracing bool shouldTrace = TracingAdapter.IsEnabled; string invocationId = null; if (shouldTrace) { invocationId = TracingAdapter.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("parameters", parameters); TracingAdapter.Enter(invocationId, this, "CreateOrUpdateAsync", tracingParameters); } // Construct URL string url = ""; url = url + "/subscriptions/"; if (this.Client.Credentials.SubscriptionId != null) { url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId); } url = url + "/providers/Microsoft.Subscriptions/configurations/default"; List <string> queryParameters = new List <string>(); queryParameters.Add("api-version=" + Uri.EscapeDataString(this.Client.ApiVersion)); if (queryParameters.Count > 0) { url = url + "?" + string.Join("&", queryParameters); } 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.Put; httpRequest.RequestUri = new Uri(url); // Set Headers // Set Credentials cancellationToken.ThrowIfCancellationRequested(); await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false); // Serialize Request string requestContent = null; JToken requestDoc = null; JObject delegatedProviderConfigurationOperationsCreateOrUpdateParametersValue = new JObject(); requestDoc = delegatedProviderConfigurationOperationsCreateOrUpdateParametersValue; if (parameters.DelegatedProviderConfiguration.Name != null) { delegatedProviderConfigurationOperationsCreateOrUpdateParametersValue["name"] = parameters.DelegatedProviderConfiguration.Name; } if (parameters.DelegatedProviderConfiguration.ProviderIdentifier != null) { delegatedProviderConfigurationOperationsCreateOrUpdateParametersValue["providerIdentifier"] = parameters.DelegatedProviderConfiguration.ProviderIdentifier; } if (parameters.DelegatedProviderConfiguration.DisplayName != null) { delegatedProviderConfigurationOperationsCreateOrUpdateParametersValue["displayName"] = parameters.DelegatedProviderConfiguration.DisplayName; } if (parameters.DelegatedProviderConfiguration.ExternalReferenceId != null) { delegatedProviderConfigurationOperationsCreateOrUpdateParametersValue["externalReferenceId"] = parameters.DelegatedProviderConfiguration.ExternalReferenceId; } if (parameters.DelegatedProviderConfiguration.SubscriptionApprovalEndpoint != null) { JObject subscriptionApprovalEndpointValue = new JObject(); delegatedProviderConfigurationOperationsCreateOrUpdateParametersValue["subscriptionApprovalEndpoint"] = subscriptionApprovalEndpointValue; if (parameters.DelegatedProviderConfiguration.SubscriptionApprovalEndpoint.ApiVersion != null) { subscriptionApprovalEndpointValue["apiVersion"] = parameters.DelegatedProviderConfiguration.SubscriptionApprovalEndpoint.ApiVersion; } if (parameters.DelegatedProviderConfiguration.SubscriptionApprovalEndpoint.Enabled != null) { subscriptionApprovalEndpointValue["enabled"] = parameters.DelegatedProviderConfiguration.SubscriptionApprovalEndpoint.Enabled.Value; } if (parameters.DelegatedProviderConfiguration.SubscriptionApprovalEndpoint.EndpointUri != null) { subscriptionApprovalEndpointValue["endpointUri"] = parameters.DelegatedProviderConfiguration.SubscriptionApprovalEndpoint.EndpointUri; } subscriptionApprovalEndpointValue["timeout"] = XmlConvert.ToString(parameters.DelegatedProviderConfiguration.SubscriptionApprovalEndpoint.Timeout); if (parameters.DelegatedProviderConfiguration.SubscriptionApprovalEndpoint.AuthenticationUsername != null) { subscriptionApprovalEndpointValue["authenticationUsername"] = parameters.DelegatedProviderConfiguration.SubscriptionApprovalEndpoint.AuthenticationUsername; } if (parameters.DelegatedProviderConfiguration.SubscriptionApprovalEndpoint.AuthenticationPassword != null) { subscriptionApprovalEndpointValue["authenticationPassword"] = parameters.DelegatedProviderConfiguration.SubscriptionApprovalEndpoint.AuthenticationPassword; } } if (parameters.DelegatedProviderConfiguration.PricingEndpoint != null) { JObject pricingEndpointValue = new JObject(); delegatedProviderConfigurationOperationsCreateOrUpdateParametersValue["pricingEndpoint"] = pricingEndpointValue; if (parameters.DelegatedProviderConfiguration.PricingEndpoint.ApiVersion != null) { pricingEndpointValue["apiVersion"] = parameters.DelegatedProviderConfiguration.PricingEndpoint.ApiVersion; } if (parameters.DelegatedProviderConfiguration.PricingEndpoint.Enabled != null) { pricingEndpointValue["enabled"] = parameters.DelegatedProviderConfiguration.PricingEndpoint.Enabled.Value; } if (parameters.DelegatedProviderConfiguration.PricingEndpoint.EndpointUri != null) { pricingEndpointValue["endpointUri"] = parameters.DelegatedProviderConfiguration.PricingEndpoint.EndpointUri; } pricingEndpointValue["timeout"] = XmlConvert.ToString(parameters.DelegatedProviderConfiguration.PricingEndpoint.Timeout); if (parameters.DelegatedProviderConfiguration.PricingEndpoint.AuthenticationUsername != null) { pricingEndpointValue["authenticationUsername"] = parameters.DelegatedProviderConfiguration.PricingEndpoint.AuthenticationUsername; } if (parameters.DelegatedProviderConfiguration.PricingEndpoint.AuthenticationPassword != null) { pricingEndpointValue["authenticationPassword"] = parameters.DelegatedProviderConfiguration.PricingEndpoint.AuthenticationPassword; } } requestContent = requestDoc.ToString(Newtonsoft.Json.Formatting.Indented); httpRequest.Content = new StringContent(requestContent, Encoding.UTF8); httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8"); // 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.OK && statusCode != HttpStatusCode.Created) { cancellationToken.ThrowIfCancellationRequested(); CloudException ex = CloudException.Create(httpRequest, requestContent, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false)); if (shouldTrace) { TracingAdapter.Error(invocationId, ex); } throw ex; } // Create Result DelegatedProviderConfigurationOperationsCreateOrUpdateResult result = null; // Deserialize Response if (statusCode == HttpStatusCode.OK || statusCode == HttpStatusCode.Created) { cancellationToken.ThrowIfCancellationRequested(); string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); result = new DelegatedProviderConfigurationOperationsCreateOrUpdateResult(); JToken responseDoc = null; if (string.IsNullOrEmpty(responseContent) == false) { responseDoc = JToken.Parse(responseContent); } if (responseDoc != null && responseDoc.Type != JTokenType.Null) { DelegatedProviderConfigurationDefinition delegatedProviderConfigurationInstance = new DelegatedProviderConfigurationDefinition(); result.DelegatedProviderConfiguration = delegatedProviderConfigurationInstance; JToken nameValue = responseDoc["name"]; if (nameValue != null && nameValue.Type != JTokenType.Null) { string nameInstance = ((string)nameValue); delegatedProviderConfigurationInstance.Name = nameInstance; } JToken providerIdentifierValue = responseDoc["providerIdentifier"]; if (providerIdentifierValue != null && providerIdentifierValue.Type != JTokenType.Null) { string providerIdentifierInstance = ((string)providerIdentifierValue); delegatedProviderConfigurationInstance.ProviderIdentifier = providerIdentifierInstance; } JToken displayNameValue = responseDoc["displayName"]; if (displayNameValue != null && displayNameValue.Type != JTokenType.Null) { string displayNameInstance = ((string)displayNameValue); delegatedProviderConfigurationInstance.DisplayName = displayNameInstance; } JToken externalReferenceIdValue = responseDoc["externalReferenceId"]; if (externalReferenceIdValue != null && externalReferenceIdValue.Type != JTokenType.Null) { string externalReferenceIdInstance = ((string)externalReferenceIdValue); delegatedProviderConfigurationInstance.ExternalReferenceId = externalReferenceIdInstance; } JToken subscriptionApprovalEndpointValue2 = responseDoc["subscriptionApprovalEndpoint"]; if (subscriptionApprovalEndpointValue2 != null && subscriptionApprovalEndpointValue2.Type != JTokenType.Null) { ResourceProviderEndpoint subscriptionApprovalEndpointInstance = new ResourceProviderEndpoint(); delegatedProviderConfigurationInstance.SubscriptionApprovalEndpoint = subscriptionApprovalEndpointInstance; JToken apiVersionValue = subscriptionApprovalEndpointValue2["apiVersion"]; if (apiVersionValue != null && apiVersionValue.Type != JTokenType.Null) { string apiVersionInstance = ((string)apiVersionValue); subscriptionApprovalEndpointInstance.ApiVersion = apiVersionInstance; } JToken enabledValue = subscriptionApprovalEndpointValue2["enabled"]; if (enabledValue != null && enabledValue.Type != JTokenType.Null) { bool enabledInstance = ((bool)enabledValue); subscriptionApprovalEndpointInstance.Enabled = enabledInstance; } JToken endpointUriValue = subscriptionApprovalEndpointValue2["endpointUri"]; if (endpointUriValue != null && endpointUriValue.Type != JTokenType.Null) { string endpointUriInstance = ((string)endpointUriValue); subscriptionApprovalEndpointInstance.EndpointUri = endpointUriInstance; } JToken timeoutValue = subscriptionApprovalEndpointValue2["timeout"]; if (timeoutValue != null && timeoutValue.Type != JTokenType.Null) { TimeSpan timeoutInstance = XmlConvert.ToTimeSpan(((string)timeoutValue)); subscriptionApprovalEndpointInstance.Timeout = timeoutInstance; } JToken authenticationUsernameValue = subscriptionApprovalEndpointValue2["authenticationUsername"]; if (authenticationUsernameValue != null && authenticationUsernameValue.Type != JTokenType.Null) { string authenticationUsernameInstance = ((string)authenticationUsernameValue); subscriptionApprovalEndpointInstance.AuthenticationUsername = authenticationUsernameInstance; } JToken authenticationPasswordValue = subscriptionApprovalEndpointValue2["authenticationPassword"]; if (authenticationPasswordValue != null && authenticationPasswordValue.Type != JTokenType.Null) { string authenticationPasswordInstance = ((string)authenticationPasswordValue); subscriptionApprovalEndpointInstance.AuthenticationPassword = authenticationPasswordInstance; } } JToken pricingEndpointValue2 = responseDoc["pricingEndpoint"]; if (pricingEndpointValue2 != null && pricingEndpointValue2.Type != JTokenType.Null) { ResourceProviderEndpoint pricingEndpointInstance = new ResourceProviderEndpoint(); delegatedProviderConfigurationInstance.PricingEndpoint = pricingEndpointInstance; JToken apiVersionValue2 = pricingEndpointValue2["apiVersion"]; if (apiVersionValue2 != null && apiVersionValue2.Type != JTokenType.Null) { string apiVersionInstance2 = ((string)apiVersionValue2); pricingEndpointInstance.ApiVersion = apiVersionInstance2; } JToken enabledValue2 = pricingEndpointValue2["enabled"]; if (enabledValue2 != null && enabledValue2.Type != JTokenType.Null) { bool enabledInstance2 = ((bool)enabledValue2); pricingEndpointInstance.Enabled = enabledInstance2; } JToken endpointUriValue2 = pricingEndpointValue2["endpointUri"]; if (endpointUriValue2 != null && endpointUriValue2.Type != JTokenType.Null) { string endpointUriInstance2 = ((string)endpointUriValue2); pricingEndpointInstance.EndpointUri = endpointUriInstance2; } JToken timeoutValue2 = pricingEndpointValue2["timeout"]; if (timeoutValue2 != null && timeoutValue2.Type != JTokenType.Null) { TimeSpan timeoutInstance2 = XmlConvert.ToTimeSpan(((string)timeoutValue2)); pricingEndpointInstance.Timeout = timeoutInstance2; } JToken authenticationUsernameValue2 = pricingEndpointValue2["authenticationUsername"]; if (authenticationUsernameValue2 != null && authenticationUsernameValue2.Type != JTokenType.Null) { string authenticationUsernameInstance2 = ((string)authenticationUsernameValue2); pricingEndpointInstance.AuthenticationUsername = authenticationUsernameInstance2; } JToken authenticationPasswordValue2 = pricingEndpointValue2["authenticationPassword"]; if (authenticationPasswordValue2 != null && authenticationPasswordValue2.Type != JTokenType.Null) { string authenticationPasswordInstance2 = ((string)authenticationPasswordValue2); pricingEndpointInstance.AuthenticationPassword = authenticationPasswordInstance2; } } } } result.StatusCode = statusCode; if (shouldTrace) { TracingAdapter.Exit(invocationId, result); } return(result); } finally { if (httpResponse != null) { httpResponse.Dispose(); } } } finally { if (httpRequest != null) { httpRequest.Dispose(); } } }