/// <summary> /// Get storage account and use specific azure environment /// </summary> /// <param name="credential">Storage credential</param> /// <param name="storageAccountName">Storage account name, it's used for build end point</param> /// <param name="useHttps">Use secure Http protocol</param> /// <param name="azureEnvironmentName">Environment name</param> /// <returns>A storage account</returns> internal CloudStorageAccount GetStorageAccountWithAzureEnvironment(StorageCredentials credential, string storageAccountName, bool useHttps, string azureEnvironmentName = "") { IAzureEnvironment azureEnvironment = null; var profile = SMProfile ?? RMProfile; if (null != profile) { if (profile.DefaultContext != null && profile.DefaultContext.Environment != null && string.IsNullOrEmpty(azureEnvironmentName)) { azureEnvironment = profile.DefaultContext.Environment; if (null == azureEnvironment) { azureEnvironmentName = EnvironmentName.AzureCloud; } } if (null == azureEnvironment) { try { azureEnvironment = profile.Environments.FirstOrDefault((s) => string.Equals(s.Name, azureEnvironmentName, StringComparison.OrdinalIgnoreCase)); if (azureEnvironment == null) { azureEnvironment = AzureEnvironment.PublicEnvironments[EnvironmentName.AzureCloud]; } } catch (ArgumentException e) { throw new ArgumentException(e.Message + " " + string.Format(CultureInfo.CurrentCulture, Resources.ValidEnvironmentName, EnvironmentName.AzureCloud, EnvironmentName.AzureChinaCloud)); } } } if (null != azureEnvironment) { try { Uri blobEndPoint = azureEnvironment.GetStorageBlobEndpoint(storageAccountName, useHttps); Uri queueEndPoint = azureEnvironment.GetStorageQueueEndpoint(storageAccountName, useHttps); Uri tableEndPoint = azureEnvironment.GetStorageTableEndpoint(storageAccountName, useHttps); Uri fileEndPoint = azureEnvironment.GetStorageFileEndpoint(storageAccountName, useHttps); return(new CloudStorageAccount(credential, blobEndPoint, queueEndPoint, tableEndPoint, fileEndPoint)); } catch (ArgumentNullException) { // the environment may not have value for StorageEndpointSuffix, in this case, we'll still use the default domain of "core.windows.net" } } return(GetStorageAccountWithEndPoint(credential, storageAccountName, useHttps, Resources.DefaultDomain)); }
public CloudStorageService(string accountName, string[] authenticationKeys, IAzureEnvironment environment) { _name = accountName; foreach (var key in authenticationKeys) { _authenticationKeys.Add(key); } _environment = environment; _blobEndpoint = environment.GetStorageBlobEndpoint(accountName, true); _queueEndpoint = environment.GetStorageQueueEndpoint(accountName, true); _tableEndpoint = environment.GetStorageTableEndpoint(accountName, true); _fileEndpoint = environment.GetStorageFileEndpoint(accountName, true); }