/// <summary>
        /// Creates firewall rule for given server name and IP address range. Throws exception if operation fails
        /// </summary>
        public async Task <FirewallRuleResponse> CreateFirewallRuleAsync(string serverName, IPAddress startIpAddress, IPAddress endIpAddress)
        {
            try
            {
                FirewallRuleResponse firewallRuleResponse = new FirewallRuleResponse()
                {
                    Created = false
                };
                CommonUtil.CheckStringForNullOrEmpty(serverName, "serverName");
                CommonUtil.CheckForNull(startIpAddress, "startIpAddress");
                CommonUtil.CheckForNull(endIpAddress, "endIpAddress");

                IAzureAuthenticationManager authenticationManager = AuthenticationManager;

                if (authenticationManager != null && !await authenticationManager.GetUserNeedsReauthenticationAsync())
                {
                    FirewallRuleResource firewallRuleResource = await FindAzureResourceAsync(serverName);

                    firewallRuleResponse = await CreateFirewallRule(firewallRuleResource, startIpAddress, endIpAddress);
                }
                if (firewallRuleResponse == null || !firewallRuleResponse.Created)
                {
                    throw new FirewallRuleException(SR.FirewallRuleCreationFailed);
                }
                return(firewallRuleResponse);
            }
            catch (ServiceExceptionBase)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new FirewallRuleException(string.Format(CultureInfo.CurrentCulture, SR.FirewallRuleCreationFailedWithError, ex.Message), ex);
            }
        }
Пример #2
0
        public async Task GetSubscriptionShouldThrowIfFailed()
        {
            var currentUserAccount = CreateAccount();
            IAzureAuthenticationManager accountManager = await CreateAccountManager(currentUserAccount, null, true);

            await Assert.ThrowsAsync <ServiceFailedException>(() => accountManager.GetSelectedSubscriptionsAsync());
        }
        private async void UpdateSettings()
        {
            Account account = (Account)_accountPicker.SelectedAccount;
            IReadOnlyList <IAzureRMUserAccountSubscriptionContext> subscriptions;

            if (account != null)
            {
                IAzureAuthenticationManager manager = AzureAuthenticationManager;

                if (manager != null)
                {
                    await manager.SetCurrentVSAccountAsync(account);
                }

                Dispatcher.Invoke(() => { IsLoadingSubscriptions = true; });

                subscriptions = (await AzureRMAuthenticationManager.GetSubscriptionsAsync()).ToList();

                Dispatcher.Invoke(() => { IsLoadingSubscriptions = false; });
            }
            else
            {
                subscriptions = NoSubscriptions;
            }

            Dispatcher.Invoke(() =>
            {
                Account       = account;
                Subscriptions = subscriptions.ToList();
            });
        }
        public AccountPickerViewModel(IServiceProvider serviceProvider, string hostId)
        {
            this.hostId = hostId;

            this.authenticationManager = (IAzureAuthenticationManager)serviceProvider.GetService(typeof(IAzureAuthenticationManager));
            this.authenticationManager.SubscriptionsChanged += this.OnSubscriptionsChanged;

            this.accountManager = (IAccountManager)serviceProvider.GetService(typeof(SVsAccountManager));
        }
Пример #5
0
        public async Task GetSubscriptionShouldThrowWhenUserNeedsAuthentication()
        {
            var currentUserAccount = CreateAccount();

            currentUserAccount.Account.IsStale = true;
            IAzureAuthenticationManager accountManager = await CreateAccountManager(currentUserAccount, null);

            await Assert.ThrowsAsync <ExpiredTokenException>(() => accountManager.GetSelectedSubscriptionsAsync());
        }
Пример #6
0
        public async Task GetSubscriptionShouldReturnEmptyWhenUserIsNotSignedIn()
        {
            IAzureAuthenticationManager accountManager = await CreateAccountManager(null, null);

            IEnumerable <IAzureUserAccountSubscriptionContext> result =
                await accountManager.GetSelectedSubscriptionsAsync();

            Assert.False(result.Any());
        }
        public AccountPickerViewModel(IServiceProvider serviceProvider, string hostId)
        {
            this.hostId = hostId;

            this.authenticationManager = (IAzureAuthenticationManager)serviceProvider.GetService(typeof(IAzureAuthenticationManager));
            this.authenticationManager.SubscriptionsChanged += this.OnSubscriptionsChanged;

            this.accountManager = (IAccountManager)serviceProvider.GetService(typeof(SVsAccountManager));
        }
Пример #8
0
        public async Task GetSubscriptionShouldReturnTheListSuccessfully()
        {
            List <IAzureUserAccountSubscriptionContext> subscriptions = new List <IAzureUserAccountSubscriptionContext> {
                new Mock <IAzureUserAccountSubscriptionContext>().Object
            };
            var currentUserAccount = CreateAccount();
            IAzureAuthenticationManager accountManager = await CreateAccountManager(currentUserAccount, subscriptions, false);

            IEnumerable <IAzureUserAccountSubscriptionContext> result =
                await accountManager.GetSelectedSubscriptionsAsync();

            Assert.True(result.Any());
        }
Пример #9
0
        public async Task CurrentUserShouldBeNullWhenUserIsNotSignedIn()
        {
            IAzureAuthenticationManager accountManager = await CreateAccountManager(null, null);

            Assert.Null(await accountManager.GetCurrentAccountAsync());
        }