/// <summary>
        /// Displays a set of hostnames in the control.
        /// </summary>
        public void Initialize(string defaultHost, IList <string> hostnames)
        {
            HostsCB.Items.Clear();

            // add option to browse for hosts.
            HostsCB.Items.Add("<Browse...>");

            // add any existing hosts.
            if (hostnames != null)
            {
                foreach (string hostname in hostnames)
                {
                    HostsCB.Items.Add(hostname);
                }
            }

            // set a suitable default hostname.
            if (String.IsNullOrEmpty(defaultHost))
            {
                if (!m_selectDomains)
                {
                    defaultHost = Utils.GetHostName();
                }
                else
                {
                    defaultHost = CredentialCache.DefaultNetworkCredentials.Domain;
                }

                if (hostnames != null && hostnames.Count > 0)
                {
                    defaultHost = hostnames[0];
                }
            }

            // set the current selection.
            m_selectedIndex = HostsCB.Items.IndexOf(HostsCB.FindName(defaultHost));

            if (m_selectedIndex == -1)
            {
                HostsCB.Items.Add(defaultHost);
                m_selectedIndex = HostsCB.SelectedIndex;
            }

            HostsCB.SelectedIndex = m_selectedIndex;
        }
Пример #2
0
        /// <summary>
        /// Displays a set of hostnames in the control.
        /// </summary>
        public void Initialize(string defaultHost, IList <string> hostnames)
        {
            HostsCB.Items.Clear();

            // add option to browse for hosts.
            HostsCB.Items.Add("<Browse...>");

            // add any existing hosts.
            if (hostnames != null)
            {
                foreach (string hostname in hostnames)
                {
                    HostsCB.Items.Add(hostname);
                }
            }

            // set a suitable default hostname.
            if (String.IsNullOrEmpty(defaultHost))
            {
                if (!m_selectDomains)
                {
                    defaultHost = System.Net.Dns.GetHostName();
                }
                else
                {
                    defaultHost = ConfigUtils.GetComputerWorkgroupOrDomain();
                }

                if (hostnames != null && hostnames.Count > 0)
                {
                    defaultHost = hostnames[0];
                }
            }

            // set the current selection.
            m_selectedIndex = HostsCB.FindString(defaultHost);

            if (m_selectedIndex == -1)
            {
                m_selectedIndex = HostsCB.Items.Add(defaultHost);
            }

            HostsCB.SelectedIndex = m_selectedIndex;
        }
Пример #3
0
        private void HostsCB_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                if (HostsCB.SelectedIndex != 0)
                {
                    if (m_HostSelected != null)
                    {
                        m_HostSelected(this, new SelectHostCtrlEventArgs((string)HostsCB.SelectedItem));
                    }

                    m_selectedIndex = HostsCB.SelectedIndex;
                    return;
                }

                if (!m_selectDomains)
                {
                    // prompt user to select a host.
                    string hostname = new HostListDlg().ShowDialog(null);

                    if (hostname == null)
                    {
                        HostsCB.SelectedIndex = m_selectedIndex;
                        return;
                    }

                    // set the current selection.
                    m_selectedIndex = HostsCB.FindString(hostname);

                    if (m_selectedIndex == -1)
                    {
                        m_selectedIndex = HostsCB.Items.Add(hostname);
                    }
                }

                HostsCB.SelectedIndex = m_selectedIndex;
            }
            catch (Exception exception)
            {
                GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
            }
        }
Пример #4
0
        private void ConnectBTN_Click(object sender, EventArgs e)
        {
            try
            { int index = HostsCB.SelectedIndex;

              if (index == 0)
              {
                  return;
              }

              if (m_HostConnected != null)
              {
                  if (index == -1)
                  {
                      if (!String.IsNullOrEmpty(HostsCB.Text))
                      {
                          m_HostConnected(this, new SelectHostCtrlEventArgs(HostsCB.Text));
                      }

                      // add host to list.
                      m_selectedIndex = HostsCB.FindString(HostsCB.Text);

                      if (m_selectedIndex == -1)
                      {
                          m_selectedIndex = HostsCB.Items.Add(HostsCB.Text);
                      }

                      return;
                  }

                  m_HostConnected(this, new SelectHostCtrlEventArgs((string)HostsCB.SelectedItem));
              }
            }
            catch (Exception exception)
            {
                GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
            }
        }