private void addGroupToolStripMenuItem_Click(object sender, EventArgs e) { AddGroupForm agf = new AddGroupForm(); for (;;) { if (agf.ShowDialog() != DialogResult.OK) { return; } bool NameExists = false; lock (Slaves) { lock (ComputerTree) { foreach (HostGroup Existing in Groups) { if (Existing.Name.ToLower() == agf.GroupName) { NameExists = true; break; } } if (!NameExists) { HostGroup NewGroup = new HostGroup(agf.GroupName); Groups.Add(NewGroup); TreeNode GroupNode = new TreeNode(NewGroup.GetDisplayText()); GroupNode.Tag = NewGroup; GroupNodes.Nodes.Add(GroupNode); Legend.Invalidate(); } } } if (NameExists) { if (MessageBox.Show("A group by that name already exists.") != DialogResult.OK) { return; } continue; } break; } SaveHostListToRegistry(); SaveGroupListToRegistry(); }
private void OnEditMembership_MenuItemClick(object sender, EventArgs e) { if (ContextNode == null) { return; } Slave ss = ContextNode.Tag as Slave; if (ss == null) { return; } List <HostGroup> Memberships = new List <HostGroup>(); lock (Slaves) { lock (ComputerTree) { foreach (TreeNode v in GroupNodes.Nodes) { HostGroup Group = v.Tag as HostGroup; if (Group.Slaves.Contains(ss)) { Memberships.Add(Group); } } } } AddHostForm ahf = new AddHostForm(Groups, Memberships); ahf.HostName = ss.HostName; if (ahf.ShowDialog() != DialogResult.OK) { return; } Memberships = ahf.Membership; lock (Slaves) { lock (ComputerTree) { List <TreeNode> ExistingInstances = FindAllInstancesOfSlave(ss.HostName); foreach (TreeNode tnGroup in GroupNodes.Nodes) { HostGroup Group = (HostGroup)tnGroup.Tag; if (Memberships.Contains(Group)) { if (!Group.Slaves.Contains(ss)) { // New membership added... Group.Slaves.Add(ss); TreeNode GNode = new TreeNode(ContextNode.Text); GNode.Tag = ss; tnGroup.Nodes.Add(GNode); tnGroup.Text = Group.GetDisplayText(); } } else { if (Group.Slaves.Contains(ss)) { // Existing membership revoked... Group.Slaves.Remove(ss); List <TreeNode> hits = new List <TreeNode>(); foreach (TreeNode tnHosts in tnGroup.Nodes) { if (((Slave)tnHosts.Tag).HostName == ss.HostName) { hits.Add(tnHosts); } } foreach (TreeNode tn in hits) { tnGroup.Nodes.Remove(tn); } tnGroup.Text = Group.GetDisplayText(); } } } Legend.Invalidate(); } } SaveHostListToRegistry(); SaveGroupListToRegistry(); }
private void MainForm_Load(object sender, EventArgs e) { try { RegistryKey key = Registry.CurrentUser.OpenSubKey(AppRegSubKey); Left = (int)key.GetValue("MainForm_Left", Left); Top = (int)key.GetValue("MainForm_Top", Top); Width = (int)key.GetValue("MainForm_Width", Width); Height = (int)key.GetValue("MainForm_Height", Height); MainSplitContainer.SplitterDistance = (int)key.GetValue("MainForm_SplitterDistance", MainSplitContainer.SplitterDistance); Terminal.TextFontSizeInPoints = (int)key.GetValue("Terminal_TextFontSize", (int)Terminal.TextFontSizeInPoints); } catch (Exception) { MainSplitContainer_Resize(null, null); } try { Show(); CredentialsDialog cd = new CredentialsDialog(this); cd.Caption = "Please provide the account to use upon connecting."; cd.Message = "Enter credentials."; if (cd.ShowDialog() != DialogResult.OK) { Close(); return; } UserCredentials = cd.Credentials; lock (Slaves) { lock (ComputerTree) { ComputerTree.Nodes.Add(HostNodes); ComputerTree.Nodes.Add(GroupNodes); // Add a LocalHost slave running in this process. Looks just like the service, but runs whenever parallel terminal is running- just in case // the user wants to run something to include localhost. LocalHostSlave = new SlaveCore(this, true); // Add all slaves and only start connecting them after they've all been added. This ensures proper semantics in the TerminalControl. Slaves.Add(new Slave("localhost", AcceptedCertificates)); // Find all other hosts that we've previously opened and use RegistryKey key = Registry.CurrentUser.OpenSubKey(HostRegSubKey, false); if (key != null) { foreach (var v in key.GetSubKeyNames()) { Slave NewSlave = new Slave(v, AcceptedCertificates); Slaves.Add(NewSlave); } } foreach (Slave ss in Slaves) { ss.Connection.OnMessage += Slave_Connection_OnMessage; ss.Connection.OnConnectionState += Slave_Connection_OnState; Terminal.AddSlave(ss); TreeNode SlaveNode = new TreeNode(ss.HostName + " (Disconnected)"); SlaveNode.Tag = ss; SlaveNode.Checked = false; HostNodes.Nodes.Add(SlaveNode); } // Find all groups we've previously had and restore them key = Registry.CurrentUser.OpenSubKey(GroupsRegSubKey, false); if (key != null) { foreach (var v in key.GetSubKeyNames()) { var group_key = key.OpenSubKey(v, false); HostGroup Group = new HostGroup(v); Groups.Add(Group); TreeNode GNode = new TreeNode(group_key + " (Disconnected)"); GNode.Tag = Group; object HostList = group_key.GetValue("Includes-Hosts"); if (HostList as string != null) { string[] HostNames = ((string)HostList).Split(new char[] { ';' }); foreach (string HostName in HostNames) { Slave Match = null; foreach (Slave ss in Slaves) { if (ss.HostName == HostName) { Match = ss; break; } } if (Match != null) { Group.Slaves.Add(Match); TreeNode HNode = new TreeNode(Match.HostName + " (Disconnected)"); HNode.Tag = Match; HNode.Checked = false; GNode.Nodes.Add(HNode); } } } GNode.Text = Group.GetDisplayText(); GroupNodes.Nodes.Add(GNode); } } GUITimer.Enabled = true; ComputerTree.ExpandAll(); Legend.Invalidate(); Terminal.Focus(); Terminal.Select(); } } ComputerTree_AfterCheck(null, null); if (!IsOnScreen(this)) { Top = 10; Left = 10; Width = 1000; Height = 1000; } Application.DoEvents(); // Clear out any keyboard events. Terminal.Enabled = true; // Enable keyboard input after dialog box. } catch (Exception ex) { MessageBox.Show(ex.ToString()); Close(); } }