示例#1
0
        /// <summary>
        /// Handles the SelectionChanged event of the SubscriptionList control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="SelectionChangedEventArgs"/> instance containing the event data.</param>
        private void SubscriptionList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            this.btnDone.IsEnabled = false;

            this.progressBar.Visibility = Visibility.Visible;
            RM.Models.SubscriptionInner selectedSubscription = (sender as ComboBox).SelectedItem as RM.Models.SubscriptionInner;

            Thread relayThread = new Thread(new ThreadStart(() =>
            {
                try
                {
                    List <RelayNamespaceInner> relayList = this.relayResourceManager.GetRelayNamespacesAsync(selectedSubscription).ConfigureAwait(false).GetAwaiter().GetResult();

                    this.Dispatcher.Invoke(() =>
                    {
                        this.relays.Clear();

                        // Add a fake relay. This guides people to create a new one.
                        this.relays.Add(newRelay);
                        relayList.ForEach(sub => this.relays.Add(sub));
                        this.comboAzureRelayList.IsEnabled = true;
                        this.progressBar.Visibility        = Visibility.Hidden;

                        this.listBoxSubscriptionLocations.Items.Clear();

                        foreach (RM.Models.Location location in this.userAuthenticator.GetSubscriptionLocations(selectedSubscription))
                        {
                            this.listBoxSubscriptionLocations.Items.Add(location.DisplayName);
                        }

                        this.listBoxSubscriptionLocations.SelectedIndex = 0;
                    });
                }
                catch (Exception ex)
                {
                    this.logger.LogError(ex, "Failed to get list of Azure Relay namespaces");

                    this.Dispatcher.Invoke(() => MessageBox.Show("Failed to get list of Azure Relay namespaces!!. Exiting", "Azure Error", MessageBoxButton.OKCancel, MessageBoxImage.Error));
                    Application.Current.Shutdown();
                }
            }));

            relayThread.Start();
        }
示例#2
0
        /// <summary>
        /// Handles the Click event of the Done control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RoutedEventArgs" /> instance containing the event data.</param>
        private void Done_Click(object sender, RoutedEventArgs e)
        {
            this.progressBar.Visibility = Visibility.Visible;
            this.btnDone.IsEnabled      = false;
            RM.Models.SubscriptionInner selectedSubscription = (this.comboSubscriptionList as ComboBox).SelectedItem as RM.Models.SubscriptionInner;
            RelayNamespaceInner         selectedAzureRelay   = (this.comboAzureRelayList as ComboBox).SelectedItem as RelayNamespaceInner;
            string selectedLocation = this.listBoxSubscriptionLocations.SelectedItem.ToString();

            string newRelayName = this.txtAzureRelayName.Text;

            // Case 1. When user used existing Relay.
            Thread existingAzureRelayThread = new Thread(new ThreadStart(() =>
            {
                try
                {
                    HybridConnectionDetails hybridConnectionDetails = this.relayResourceManager.GetHybridConnectionAsync(selectedSubscription, selectedAzureRelay, Environment.MachineName).ConfigureAwait(false).GetAwaiter().GetResult();

                    this.SetApplicationData(hybridConnectionDetails);
                }
                catch (Exception ex)
                {
                    this.logger.LogError(ex, "Failed to connect to relay namespace");

                    this.Dispatcher.Invoke(() => MessageBox.Show("Failed to connect to Azure Relay namespace!!", "Azure Error", MessageBoxButton.OKCancel, MessageBoxImage.Error));
                }
            }));

            // Case 2. When user created a new Relay.
            Thread newAzureRelayThread = new Thread(new ThreadStart(() =>
            {
                try
                {
                    if (string.IsNullOrEmpty(newRelayName))
                    {
                        MessageBox.Show("Please enter the name for Azure Relay.");
                        this.Dispatcher.Invoke(() =>
                        {
                            this.progressBar.Visibility = Visibility.Hidden;
                            this.btnDone.IsEnabled      = true;
                        });
                        return;
                    }

                    if (newRelayName.Length < 6)
                    {
                        MessageBox.Show("Name of Azure Relay must be at least 6 characters.");
                        this.Dispatcher.Invoke(() =>
                        {
                            this.progressBar.Visibility = Visibility.Hidden;
                            this.btnDone.IsEnabled      = true;
                        });
                        return;
                    }

                    HybridConnectionDetails hybridConnectionDetails = this.relayResourceManager.CreateHybridConnectionAsync(
                        selectedSubscription,
                        newRelayName,
                        Environment.MachineName,
                        selectedLocation).ConfigureAwait(false).GetAwaiter().GetResult();

                    this.SetApplicationData(hybridConnectionDetails);
                }
                catch (CloudException cloudEx)
                {
                    this.logger.LogError(cloudEx, "Cloud exception while creating Azure Relay namespace.");

                    this.Dispatcher.Invoke(() =>
                    {
                        MessageBox.Show(cloudEx.Message, "Azure Error", MessageBoxButton.OKCancel, MessageBoxImage.Error);
                        this.progressBar.Visibility = Visibility.Hidden;
                        this.btnDone.IsEnabled      = true;
                    });
                }
                catch (Exception ex)
                {
                    this.logger.LogError(ex, "Failed to create new Azure Relay namespace");

                    this.Dispatcher.Invoke(() =>
                    {
                        MessageBox.Show("Failed to create new Azure Relay namespace!!", "Azure Error", MessageBoxButton.OKCancel, MessageBoxImage.Error);
                        this.progressBar.Visibility = Visibility.Hidden;
                        this.btnDone.IsEnabled      = true;
                    });
                }
            }));

            // If the user selected to new Relay entry we added.
            if (selectedAzureRelay.Id == null)
            {
                newAzureRelayThread.Start();
            }
            else
            {
                existingAzureRelayThread.Start();
            }
        }