本文整理汇总了C#中ProfileClient.GetEnvironmentOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# ProfileClient.GetEnvironmentOrDefault方法的具体用法?C# ProfileClient.GetEnvironmentOrDefault怎么用?C# ProfileClient.GetEnvironmentOrDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProfileClient
的用法示例。
在下文中一共展示了ProfileClient.GetEnvironmentOrDefault方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetClient
internal IJobSubmissionClient GetClient(string cluster)
{
cluster.ArgumentNotNull("ClusterEndpoint");
IJobSubmissionClient client = null;
ProfileClient profileClient = new ProfileClient(new AzureProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile)));
string currentEnvironmentName = this.CurrentSubscription == null ? null : this.CurrentSubscription.Environment;
var clientCredential = this.GetJobSubmissionClientCredentials(
this.CurrentSubscription,
profileClient.GetEnvironmentOrDefault(currentEnvironmentName),
cluster,
profileClient.Profile);
if (clientCredential != null)
{
client = ServiceLocator.Instance.Locate<IAzureHDInsightJobSubmissionClientFactory>().Create(clientCredential);
client.SetCancellationSource(this.tokenSource);
if (this.Logger.IsNotNull())
{
client.AddLogWriter(this.Logger);
}
return client;
}
throw new InvalidOperationException("Expected either a Subscription or Credential parameter.");
}
示例2: GetClient
internal IHDInsightClient GetClient()
{
this.CurrentSubscription.ArgumentNotNull("CurrentSubscription");
ProfileClient client = new ProfileClient();
var subscriptionCredentials = this.GetSubscriptionCredentials(
this.CurrentSubscription,
client.GetEnvironmentOrDefault(this.CurrentSubscription.Environment),
client.Profile);
if (this.Endpoint.IsNotNull())
{
subscriptionCredentials.Endpoint = this.Endpoint;
}
var clientInstance = ServiceLocator.Instance.Locate<IAzureHDInsightClusterManagementClientFactory>().Create(subscriptionCredentials);
clientInstance.SetCancellationSource(this.tokenSource);
if (this.Logger.IsNotNull())
{
clientInstance.AddLogWriter(this.Logger);
}
return clientInstance;
}
示例3: GetClient
internal IHDInsightClient GetClient(bool ignoreSslErrors = false)
{
this.CurrentSubscription.ArgumentNotNull("CurrentSubscription");
ProfileClient client = new ProfileClient(new AzureSMProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile)));
var subscriptionCredentials = this.GetSubscriptionCredentials(
this.CurrentSubscription,
client.GetEnvironmentOrDefault(this.CurrentSubscription.Environment),
client.Profile);
if (this.Endpoint.IsNotNull())
{
subscriptionCredentials.Endpoint = this.Endpoint;
}
var clientInstance = ServiceLocator.Instance.Locate<IAzureHDInsightClusterManagementClientFactory>().Create(subscriptionCredentials, ignoreSslErrors);
clientInstance.SetCancellationSource(this.tokenSource);
if (this.Logger.IsNotNull())
{
clientInstance.AddLogWriter(this.Logger);
}
return clientInstance;
}
示例4: AddsAzureEnvironment
public void AddsAzureEnvironment()
{
var profile = new AzureProfile();
Mock<ICommandRuntime> commandRuntimeMock = new Mock<ICommandRuntime>();
AddAzureEnvironmentCommand cmdlet = new AddAzureEnvironmentCommand()
{
CommandRuntime = commandRuntimeMock.Object,
Name = "Katal",
PublishSettingsFileUrl = "http://microsoft.com",
ServiceEndpoint = "endpoint.net",
ManagementPortalUrl = "management portal url",
StorageEndpoint = "endpoint.net",
GalleryEndpoint = "http://galleryendpoint.com",
Profile = profile
};
cmdlet.InvokeBeginProcessing();
cmdlet.ExecuteCmdlet();
cmdlet.InvokeEndProcessing();
commandRuntimeMock.Verify(f => f.WriteObject(It.IsAny<PSAzureEnvironment>()), Times.Once());
ProfileClient client = new ProfileClient(profile);
AzureEnvironment env = client.GetEnvironmentOrDefault("KaTaL");
Assert.Equal(env.Name, cmdlet.Name);
Assert.Equal(env.Endpoints[AzureEnvironment.Endpoint.PublishSettingsFileUrl], cmdlet.PublishSettingsFileUrl);
Assert.Equal(env.Endpoints[AzureEnvironment.Endpoint.ServiceManagement], cmdlet.ServiceEndpoint);
Assert.Equal(env.Endpoints[AzureEnvironment.Endpoint.ManagementPortalUrl], cmdlet.ManagementPortalUrl);
Assert.Equal(env.Endpoints[AzureEnvironment.Endpoint.Gallery], "http://galleryendpoint.com");
}
示例5: Subscription
internal Subscription(AzureSubscription azureSubscription)
{
if (azureSubscription == null)
{
throw new ArgumentNullException();
}
ProfileClient client = new ProfileClient(new AzureSMProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile)));
var environment = client.GetEnvironmentOrDefault(azureSubscription.Environment);
this.SubscriptionName = azureSubscription.Name;
this.SubscriptionId = azureSubscription.Id.ToString();
this.ServiceEndpoint = new Uri(String.Format("{0}/{1}/services/systemcenter/vmm", environment.GetEndpoint(AzureEnvironment.Endpoint.ServiceManagement).TrimEnd(new[] { '/' }), SubscriptionId));
this.Certificate = FileUtilities.DataStore.GetCertificate(azureSubscription.Account);
this.CredentialType = CredentialType.UseCertificate;
}
示例6: AzurePSCmdlet
public AzurePSCmdlet()
{
DefaultProfileClient = new ProfileClient();
if (AzureSession.CurrentContext.Subscription == null &&
DefaultProfileClient.Profile.DefaultSubscription != null)
{
try
{
AzureSession.SetCurrentContext(
DefaultProfileClient.Profile.DefaultSubscription,
DefaultProfileClient.GetEnvironmentOrDefault(
DefaultProfileClient.Profile.DefaultSubscription.Environment),
DefaultProfileClient.GetAccountOrNull(DefaultProfileClient.Profile.DefaultSubscription.Account));
}
catch
{
// Ignore anything at this point
}
}
}
示例7: GetCurrentEnvironmentReturnsCorrectValue
public void GetCurrentEnvironmentReturnsCorrectValue()
{
MockDataStore dataStore = new MockDataStore();
ProfileClient.DataStore = dataStore;
ProfileClient client = new ProfileClient();
AzureSession.SetCurrentContext(azureSubscription1, azureEnvironment, azureAccount);
var newEnv = client.GetEnvironmentOrDefault(azureEnvironment.Name);
Assert.Equal(azureEnvironment.Name, newEnv.Name);
}
示例8: GetAzureEnvironmentReturnsCorrectValue
public void GetAzureEnvironmentReturnsCorrectValue()
{
MockDataStore dataStore = new MockDataStore();
ProfileClient.DataStore = dataStore;
ProfileClient client = new ProfileClient();
client.AddOrSetEnvironment(azureEnvironment);
Assert.Equal(EnvironmentName.AzureCloud, AzureSession.CurrentContext.Environment.Name);
var defaultEnv = client.GetEnvironmentOrDefault(null);
Assert.Equal(EnvironmentName.AzureCloud, defaultEnv.Name);
var newEnv = client.GetEnvironmentOrDefault(azureEnvironment.Name);
Assert.Equal(azureEnvironment.Name, newEnv.Name);
Assert.Throws<ArgumentException>(() => client.GetEnvironmentOrDefault("bad"));
}
示例9: GetStorageAccountWithAzureEnvironment
/// <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 = "")
{
AzureEnvironment azureEnvironment = null;
if (null != SMProfile)
{
if (DefaultContext != null && string.IsNullOrEmpty(azureEnvironmentName))
{
azureEnvironment = DefaultContext.Environment;
if (null == azureEnvironment)
{
azureEnvironmentName = EnvironmentName.AzureCloud;
}
}
if(null == azureEnvironment)
{
try
{
var profileClient = new ProfileClient(SMProfile);
azureEnvironment = profileClient.GetEnvironmentOrDefault(azureEnvironmentName);
}
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);
}
示例10: GetCurrentEnvironmentReturnsCorrectValue
public void GetCurrentEnvironmentReturnsCorrectValue()
{
MemoryDataStore dataStore = new MemoryDataStore();
AzureSession.DataStore = dataStore;
ProfileClient client = new ProfileClient(currentProfile);
client.AddOrSetEnvironment(azureEnvironment);
client.AddOrSetAccount(azureAccount);
client.AddOrSetSubscription(azureSubscription1);
currentProfile.DefaultSubscription = azureSubscription1;
var newEnv = client.GetEnvironmentOrDefault(azureEnvironment.Name);
Assert.Equal(azureEnvironment.Name, newEnv.Name);
}
示例11: GetStorageAccountWithAzureEnvironment
/// <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 = "")
{
AzureEnvironment azureEnvironment = null;
if (string.IsNullOrEmpty(azureEnvironmentName))
{
azureEnvironment = Profile.Context.Environment;
}
else
{
try
{
var profileClient = new ProfileClient(Profile);
azureEnvironment = profileClient.GetEnvironmentOrDefault(azureEnvironmentName);
}
catch (ArgumentException e)
{
throw new ArgumentException(e.Message + " " + string.Format(CultureInfo.CurrentCulture, Resources.ValidEnvironmentName, EnvironmentName.AzureCloud, EnvironmentName.AzureChinaCloud));
}
}
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);
}