Пример #1
0
        public AzureAccount RemoveAccount(string accountId)
        {
            if (string.IsNullOrEmpty(accountId))
            {
                throw new ArgumentNullException("User name needs to be specified.", "userName");
            }

            if (!Profile.Accounts.ContainsKey(accountId))
            {
                throw new ArgumentException("User name is not valid.", "userName");
            }

            AzureAccount account = Profile.Accounts[accountId];

            Profile.Accounts.Remove(account.Id);

            foreach (AzureSubscription subscription in account.GetSubscriptions(Profile).ToArray())
            {
                if (subscription.Account == accountId)
                {
                    AzureAccount remainingAccount = GetSubscriptionAccount(subscription.Id);
                    // There's no default account to use, remove the subscription.
                    if (remainingAccount == null)
                    {
                        // Warn the user if the removed subscription is the default one.
                        if (subscription.IsPropertySet(AzureSubscription.Property.Default))
                        {
                            WriteWarningMessage(Resources.RemoveDefaultSubscription);
                        }

                        // Warn the user if the removed subscription is the current one.
                        if (subscription.Equals(AzureSession.CurrentContext.Subscription))
                        {
                            WriteWarningMessage(Resources.RemoveCurrentSubscription);
                            AzureSession.SetCurrentContext(null, null, null);
                        }

                        Profile.Subscriptions.Remove(subscription.Id);
                    }
                    else
                    {
                        subscription.Account = remainingAccount.Id;
                        AddOrSetSubscription(subscription);
                    }
                }
            }

            return(account);
        }
Пример #2
0
        public AzureAccount RemoveAccount(string accountId)
        {
            if (string.IsNullOrEmpty(accountId))
            {
                throw new ArgumentNullException("accountId", Resources.UserNameNeedsToBeSpecified);
            }

            if (!Profile.Accounts.ContainsKey(accountId))
            {
                throw new ArgumentException(Resources.UserNameIsNotValid, "accountId");
            }

            AzureAccount account = Profile.Accounts[accountId];

            Profile.Accounts.Remove(account.Id);

            foreach (AzureSubscription subscription in account.GetSubscriptions(Profile).ToArray())
            {
                if (subscription.Account == accountId)
                {
                    AzureAccount remainingAccount = GetSubscriptionAccount(subscription.Id);
                    // There's no default account to use, remove the subscription.
                    if (remainingAccount == null)
                    {
                        // Warn the user if the removed subscription is the default one.
                        if (subscription.IsPropertySet(AzureSubscription.Property.Default))
                        {
                            Debug.Assert(subscription.Equals(Profile.DefaultSubscription));
                            WriteWarningMessage(Resources.RemoveDefaultSubscription);
                        }

                        Profile.Subscriptions.Remove(subscription.Id);
                    }
                    else
                    {
                        subscription.Account = remainingAccount.Id;
                        AddOrSetSubscription(subscription);
                    }
                }
            }

            return(account);
        }