public static AzureTenant ToAzureTenant(this TenantIdDescription other, IAccessToken accessToken) { var tenant = new AzureTenant() { Id = other.TenantId }; tenant.SetProperty(AzureTenant.Property.Directory, accessToken?.GetDomain()); if (!string.IsNullOrEmpty(other.DisplayName)) { tenant.SetOrAppendProperty(AzureTenant.Property.DisplayName, other.DisplayName); } if (other.TenantCategory != null) { tenant.SetOrAppendProperty(AzureTenant.Property.TenantCategory, other.TenantCategory?.ToSerializedValue()); } if (other.Domains != null && other.Domains.Any()) { tenant.SetOrAppendProperty(AzureTenant.Property.Domains, other.Domains.ToArray()); } if (!string.IsNullOrEmpty(other.CountryCode)) { tenant.SetOrAppendProperty(AzureTenant.Property.CountryCode, other.CountryCode); } return(tenant); }
public static AzureTenant ToAzureTenant(this TenantIdDescription other, IAccessToken accessToken) { var tenant = new AzureTenant() { Id = other.TenantId }; tenant.SetProperty(AzureTenant.Property.Directory, accessToken?.GetDomain()); return(tenant); }
/// <summary> /// Gets a list of the tenantIds. /// </summary> /// <param name='cancellationToken'> /// Cancellation token. /// </param> /// <returns> /// Tenant Ids information. /// </returns> public async Task <TenantListResult> ListAsync(CancellationToken cancellationToken) { // Validate // Tracing bool shouldTrace = TracingAdapter.IsEnabled; string invocationId = null; if (shouldTrace) { invocationId = TracingAdapter.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); TracingAdapter.Enter(invocationId, this, "ListAsync", tracingParameters); } // Construct URL string url = "/tenants?"; url = url + "api-version=2014-04-01-preview"; 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.Get; httpRequest.RequestUri = new Uri(url); // Set Headers // 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.OK) { 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 TenantListResult result = null; // Deserialize Response if (statusCode == HttpStatusCode.OK) { cancellationToken.ThrowIfCancellationRequested(); string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); result = new TenantListResult(); JToken responseDoc = null; if (string.IsNullOrEmpty(responseContent) == false) { responseDoc = JToken.Parse(responseContent); } if (responseDoc != null && responseDoc.Type != JTokenType.Null) { JToken valueArray = responseDoc["value"]; if (valueArray != null && valueArray.Type != JTokenType.Null) { foreach (JToken valueValue in ((JArray)valueArray)) { TenantIdDescription tenantIdDescriptionInstance = new TenantIdDescription(); result.TenantIds.Add(tenantIdDescriptionInstance); JToken idValue = valueValue["id"]; if (idValue != null && idValue.Type != JTokenType.Null) { string idInstance = ((string)idValue); tenantIdDescriptionInstance.Id = idInstance; } JToken tenantIdValue = valueValue["tenantId"]; if (tenantIdValue != null && tenantIdValue.Type != JTokenType.Null) { string tenantIdInstance = ((string)tenantIdValue); tenantIdDescriptionInstance.TenantId = tenantIdInstance; } } } } } 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(); } } }
private ITenant WrapModel(TenantIdDescription inner) { return(new TenantImpl(inner)); }