public static async Task<Transaction> SendAsync(this TestServer server, string uri, string cookieHeader = null) { var request = new HttpRequestMessage(HttpMethod.Get, uri); if (!string.IsNullOrEmpty(cookieHeader)) { request.Headers.Add("Cookie", cookieHeader); } var transaction = new Transaction { Request = request, Response = await server.CreateClient().SendAsync(request), }; if (transaction.Response.Headers.Contains("Set-Cookie")) { transaction.SetCookie = transaction.Response.Headers.GetValues("Set-Cookie").ToList(); } transaction.ResponseText = await transaction.Response.Content.ReadAsStringAsync(); if (transaction.Response.Content != null && transaction.Response.Content.Headers.ContentType != null && transaction.Response.Content.Headers.ContentType.MediaType == "text/xml") { transaction.ResponseElement = XElement.Parse(transaction.ResponseText); } return transaction; }
public static CloudStorageAccount GetCloudStorageAccount(this WindowsAzureSubscription subscription) { if (subscription == null || subscription.SubscriptionId == null) { return null; } if (subscription.currentCloudStorageAccount != null) { return subscription.currentCloudStorageAccount as CloudStorageAccount; } else { using (var storageClient = subscription.CreateClient<StorageManagementClient>()) { var storageServiceResponse = storageClient.StorageAccounts.Get(subscription.currentStorageAccountName); var storageKeysResponse = storageClient.StorageAccounts.GetKeys(subscription.currentStorageAccountName); subscription.currentCloudStorageAccount = new CloudStorageAccount( new StorageCredentials(storageServiceResponse.StorageAccount.Name, storageKeysResponse.PrimaryKey), GeneralUtilities.CreateHttpsEndpoint(storageServiceResponse.StorageAccount.Properties.Endpoints[0].ToString()), GeneralUtilities.CreateHttpsEndpoint(storageServiceResponse.StorageAccount.Properties.Endpoints[1].ToString()), GeneralUtilities.CreateHttpsEndpoint(storageServiceResponse.StorageAccount.Properties.Endpoints[2].ToString())); return subscription.currentCloudStorageAccount as CloudStorageAccount; } } }
public static async Task<DataServicePackageRepository> CreateV2FeedClient(this NuGetRepository self, CancellationToken cancellationToken) { // Get the V2Feed service definition var v2FeedClient = await self.CreateClient("v2feed"); cancellationToken.ThrowIfCancellationRequested(); // Use the URL to create a DataServicePackageRepository using an adaptor IHttpClient return new DataServicePackageRepository(v2FeedClient.Service.RootUrl); }
public static CloudStorageAccount GetCloudStorageAccount(this WindowsAzureSubscription subscription) { if (subscription == null || subscription.SubscriptionId == null) { return null; } if (subscription.currentCloudStorageAccount != null) { return subscription.currentCloudStorageAccount as CloudStorageAccount; } else { using (var storageClient = subscription.CreateClient<StorageManagementClient>()) { subscription.currentCloudStorageAccount = StorageUtilities.GenerateCloudStorageAccount( storageClient, subscription.currentStorageAccountName); return subscription.currentCloudStorageAccount as CloudStorageAccount; } } }
internal static SubscriptionDataExtended ToExtendedData(this WindowsAzureSubscription subscription) { using (var client = subscription.CreateClient<ManagementClient>()) { var response = client.Subscriptions.Get(); SubscriptionDataExtended result = new SubscriptionDataExtended { AccountAdminLiveEmailId = response.AccountAdminLiveEmailId, ActiveDirectoryUserId = subscription.ActiveDirectoryUserId, CurrentCoreCount = response.CurrentCoreCount, CurrentHostedServices = response.CurrentHostedServices, CurrentDnsServers = 0, // TODO: Add to spec CurrentLocalNetworkSites = 0, // TODO: Add to spec MaxCoreCount = response.MaximumCoreCount, MaxDnsServers = response.MaximumDnsServers, MaxHostedServices = response.MaximumHostedServices, MaxVirtualNetworkSites = response.MaximumVirtualNetworkSites, MaxStorageAccounts = response.MaximumStorageAccounts, ServiceAdminLiveEmailId = response.ServiceAdminLiveEmailId, SubscriptionRealName = response.SubscriptionName, SubscriptionStatus = response.SubscriptionStatus.ToString(), SubscriptionName = subscription.SubscriptionName, SubscriptionId = subscription.SubscriptionId, ServiceEndpoint = subscription.ServiceEndpoint, ResourceManagerEndpoint = subscription.ResourceManagerEndpoint, IsDefault = subscription.IsDefault, Certificate = subscription.Certificate, CurrentStorageAccountName = subscription.CurrentStorageAccountName }; return result; } }
public static IRestClient CreateClient(this IRequestFactory factory, Endpoint endpoint) { var client = factory.CreateClient(); client.BaseUrl = new Uri(endpoint.BaseUri); return client; }