Beispiel #1
0
        private void addHostStripMenuItem_Click(object sender, EventArgs e)
        {
            AddHostForm ahf = new AddHostForm(Groups, LastAdditions);

            if (ahf.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            LastAdditions = ahf.Membership;

            Slave NewSlave = new Slave(ahf.HostName, AcceptedCertificates);

            lock (Slaves)
            {
                NewSlave.Connection.OnMessage         += Slave_Connection_OnMessage;
                NewSlave.Connection.OnConnectionState += Slave_Connection_OnState;
                Slaves.Add(NewSlave);

                lock (ComputerTree)
                {
                    Terminal.AddSlave(NewSlave);
                    string   Display   = NewSlave.HostName + " (Disconnected)";
                    TreeNode SlaveNode = new TreeNode(Display);
                    SlaveNode.Tag = NewSlave;
                    HostNodes.Nodes.Add(SlaveNode);

                    foreach (HostGroup Group in LastAdditions)
                    {
                        Group.Slaves.Add(NewSlave);
                        List <TreeNode> Instances = FindAllInstancesOfGroup(Group.Name);
                        foreach (TreeNode tn in Instances)
                        {
                            TreeNode GNode = new TreeNode(Display);
                            GNode.Tag = NewSlave;
                            tn.Nodes.Add(GNode);
                            tn.Text = Group.GetDisplayText();
                        }
                    }

                    Legend.Invalidate();
                }
            }

            SaveHostListToRegistry();
            SaveGroupListToRegistry();
        }
Beispiel #2
0
        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();
            }
        }