public AzureAccount AddAccountAndLoadSubscriptions(AzureAccount account, AzureEnvironment environment, SecureString password)
{
if (environment == null)
{
throw new ArgumentNullException("environment");
}
if (account == null)
{
throw new ArgumentNullException("account");
}
var subscriptionsFromServer = ListSubscriptionsFromServer(
account,
environment,
password,
password == null ? ShowDialog.Always : ShowDialog.Never).ToList();
if (subscriptionsFromServer == null ||
subscriptionsFromServer.Count ==0 )
{
throw new ArgumentException(Resources.NoSubscriptionFoundForTenant);
}
// If account id is null the login failed
if (account.Id != null)
{
// Update back Profile.Subscriptions
foreach (var subscription in subscriptionsFromServer)
{
AddOrSetSubscription(subscription);
}
if (Profile.DefaultSubscription == null)
{
var firstSubscription = Profile.Subscriptions.Values.FirstOrDefault();
if (firstSubscription != null)
{
SetSubscriptionAsDefault(firstSubscription.Name, firstSubscription.Account);
}
}
return Profile.Accounts[account.Id];
}
else
{
return null;
}
}