예제 #1
0
        private void listView1_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Clicks == 1)
            {
                ServerListItem clickedItem = listView1.GetItemAt(e.X, e.Y) as ServerListItem;

                if (clickedItem != null && clickedItem.Index >= 0)
                {
                    if (e.Button == MouseButtons.Left)
                    {
                        // Check for the TestResult column and check if it's a "link".
                        if (clickedItem.TestConnectionResult != null)
                        {
                            // We're on a row that has a TestConnectionResult.  See if we're
                            // on the cell for the TestConnectionResult.

                            var subitem = clickedItem.GetSubItemAt(e.X, e.Y);

                            if (subitem == clickedItem.SubItems[colTestResult.Index])
                            {
                                clickedItem.TestConnectionResult.Show();
                            }
                        }
                    }
                    else if (e.Button == MouseButtons.Right && clickedItem.Selected && _waitingTests == 0)
                    {
                        editServerMenuItem.Enabled = listView1.SelectedItems.Count == 1;
                        contextMenuStrip1.Show(listView1, e.Location);
                    }
                }
            }
        }
예제 #2
0
        private void listView1_MouseMove(object sender, MouseEventArgs e)
        {
            // Change the cursor to the "hand" when the mouse is over a cell for a TestConnectionResult.

            ServerListItem mouseItem = listView1.GetItemAt(e.X, e.Y) as ServerListItem;

            if (mouseItem == null || mouseItem.TestConnectionResult == null)
            {
                Cursor = Cursors.Default;
            }
            else
            {
                // We're on a row that has a TestConnectionResult.  See if we're
                // on the cell for the TestConnectionResult.
                var subitem = mouseItem.GetSubItemAt(e.X, e.Y);

                if (subitem == mouseItem.SubItems[colTestResult.Index])
                {
                    Cursor = Cursors.Hand;
                }
                else
                {
                    Cursor = Cursors.Default;
                }
            }
        }
예제 #3
0
        private void AddServerItem(SavedServer newServer)
        {
            ServerListItem item = new ServerListItem(new string[] { newServer.HostName, newServer.HostAndPort, newServer.Domain, newServer.Category, newServer.UserId, "" });

            item.Server = newServer;
            item.UseItemStyleForSubItems = false; // So we can set the ForeColor of the test result.
            listView1.Items.Add(item);
        }
예제 #4
0
        // Returns a HashSet of all the server display names except the specified one.
        private HashSet <string> GetDisplayNames(ServerListItem exceptThisOne)
        {
            var result = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            foreach (ServerListItem item in listView1.Items)
            {
                result.Add(item.Server.HostName);
            }

            if (exceptThisOne != null)
            {
                result.Remove(exceptThisOne.Server.HostName);
            }

            return(result);
        }
예제 #5
0
        private void EditServerForItem(ServerListItem item)
        {
            var editDlg = new ServerConnEditor();

            editDlg.Init(GetUniqueCategories(), GetDisplayNames(item), item.Server);
            editDlg.ShowConnectButton = false;

            if (editDlg.ShowDialog() == DialogResult.OK)
            {
                item.SubItems[colDispName.Index].Text = item.Server.HostName;
                item.SubItems[colAddress.Index].Text  = item.Server.HostAndPort;
                item.SubItems[colCategory.Index].Text = item.Server.Category;
                item.SubItems[colUserID.Index].Text   = item.Server.UserId;

                btnOK.Enabled = true;
            }
        }
예제 #6
0
        // Called in the GUI thread.
        private void ShowTestResult(ServerListItem lvi)
        {
            ListViewItem.ListViewSubItem cell = lvi.SubItems[colTestResult.Index];
            cell.ForeColor = Color.Blue;

            if (lvi.TestConnectionResult.Exception == null)
            {
                cell.Text = "Succeeded";
            }
            else
            {
                //cell.Text = "Failed";
                cell.Text = lvi.TestConnectionResult.Exception.Message;
            }

            if (--_waitingTests == 0)
            {
                // We just processed the last result we were waiting for, so controls can be re-enabled.

                btnTest.Enabled = listView1.SelectedItems.Count > 0;
            }
        }
예제 #7
0
        private void TestConnection(ServerListItem item)
        {
            var remoteServer = new RemoteServer(item.Server);

            item.TestConnectionResult = remoteServer.TestConnection();

            if (this.IsHandleCreated)
            {
                try
                {
                    Invoke(new Action(() => ShowTestResult(item)));
                }
                catch (Exception ex)
                {
                    // User probably closed the form.
                    Debug.WriteLine("Exception: {0}", ex);
                }
            }
            else
            {
                // User probably closed the form.
                Debug.WriteLine("Form has no handle.");
            }
        }