Exemplo n.º 1
0
        public void initialize_sub_groups_combobox(ComboBox combobox, EventHandler combobox_SelectedIndexChanged,
                                                   EventHandler sub_groups_combobox_PKGroupChanged)
        {
            if (File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                                         "PuTTYStorm", "groups.xml")))
            {
                SavedGroupInfo groups = saved_groups.get_Groups();

                combobox.Items.Add("");

                foreach (string name in groups.names)
                {
                    combobox.Items.Add(name);
                }

                combobox.DropDownWidth = DropDownWidth(combobox);
            }
            combobox.Font                  = new Font("Calibri", 10);
            combobox.Location              = DPIAwareScaling.ScalePoint(147, 182);
            combobox.Size                  = DPIAwareScaling.ScaleSize(120, 32);
            combobox.Name                  = "sub_groups_combobox";
            combobox.DropDownStyle         = ComboBoxStyle.DropDownList;
            combobox.SelectedIndexChanged += new EventHandler(combobox_SelectedIndexChanged);
            combobox.SelectedIndexChanged += new EventHandler(sub_groups_combobox_PKGroupChanged);
        }
Exemplo n.º 2
0
        private void UpdateComboBox(ComboBox combobox, SavedGroupInfo groups)
        {
            List <string> ItemsToDelete = new List <string>();

            ItemsToDelete.AddRange(combobox.Items.Cast <String>().ToList());

            if (!combobox.Items.Contains(""))
            {
                combobox.Items.Add("");
            }

            foreach (string name in groups.names)
            {
                if (combobox.Items.Contains(name))
                {
                    ItemsToDelete.Remove(name);
                    continue;
                }
                else
                {
                    combobox.Items.Add(name);
                }
            }

            foreach (string name in ItemsToDelete)
            {
                if (name == "")
                {
                    continue;
                }

                combobox.Items.Remove(name);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Get saved groups from groups.xml configuration file.
        /// </summary>
        /// <returns>Class with List of groups</returns>
        public SavedGroupInfo get_Groups()
        {
            SavedGroupInfo xml_group_info = new SavedGroupInfo();

            String filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                                           "PuTTYStorm", "groups.xml");

            try
            {
                using (XmlReader reader = XmlReader.Create(filePath))
                {
                    while (reader.Read())
                    {
                        if (reader.IsStartElement())
                        {
                            switch (reader.Name)
                            {
                            case "name":
                                if (reader.Read())
                                {
                                    xml_group_info.names.Add(reader.Value);
                                }
                                break;
                            }
                        }
                    }
                }
            } catch (Exception e)
            {
                MessageBox.Show(e.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
            return(xml_group_info);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Refresh dropdown menus in advanced form Panel2 when adding new groups
 /// </summary>
 public void set_passwords_combobox_groups(SplitContainer splitcontainer, SavedGroupInfo groups)
 {
     if (File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                                  "PuTTYStorm", "groups.xml")))
     {
         foreach (ComboBox combobox in splitcontainer.Panel2.Controls.OfType <ComboBox>())
         {
             UpdateComboBox(combobox, groups);
             combobox.DropDownWidth = DropDownWidth(combobox);
         }
     }
 }
Exemplo n.º 5
0
        private bool FindNodeGroupBetweenGroups(SavedGroupInfo groups, string node_group)
        {
            bool find = false;

            foreach (string group in groups.names)
            {
                if (group == node_group)
                {
                    find = true;
                }
            }

            return(find);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Refresh all sessions dropdown menus when adding new groups
 /// </summary>
 public void set_combobox_groups(List <GroupBox> containers_list, SavedGroupInfo groups)
 {
     if (File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                                  "PuTTYStorm", "groups.xml")))
     {
         foreach (GroupBox groupbox in containers_list)
         {
             foreach (ComboBox combobox in groupbox.Controls.OfType <ComboBox>())
             {
                 UpdateComboBox(combobox, groups);
                 combobox.DropDownWidth = DropDownWidth(combobox);
             }
         }
     }
 }
Exemplo n.º 7
0
        /// <summary>
        /// Remove empty group and sub-group nodes
        /// </summary>
        private void RemoveEmptryTreeViewGroups(TreeView ServerPane, SavedGroupInfo groups, List <GroupBox> containers_list)
        {
            foreach (string name in groups.names)
            {
                TreeNode[] remove_empty_group_nodes = ServerPane.Nodes.Find(name, true);

                if (remove_empty_group_nodes.Length > 0)
                {
                    foreach (TreeNode remove_group in remove_empty_group_nodes)
                    {
                        // If group or sub-group doesn't contain any other nodes remove it
                        if (remove_group.Nodes.Count == 0)
                        {
                            ServerPane.Nodes.Remove(remove_group);
                        }
                        else
                        {
                            foreach (TreeNode node in remove_group.Nodes)
                            {
                                // If group or sub-group is not empty then:
                                // 1) Skip sub-group if we are checking a group.
                                //    - sub-group will be removed in the next iteration
                                if (node != null && FindNodeGroupBetweenGroups(groups, node.Text))
                                {
                                    continue;
                                }

                                // 2) If the node is hostname and it is not between sessions anymore,
                                //    remove it.
                                if (node != null && !FindHostnameInContainers(containers_list, node.Text))
                                {
                                    ServerPane.Nodes.Remove(node);
                                }
                            }

                            // Check again if now group or sub-group is empty.
                            // If yes remove it, if not go to the next group or sub-group or
                            // to the next iteration.
                            if (remove_group.Nodes.Count == 0)
                            {
                                ServerPane.Nodes.Remove(remove_group);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Initialize controls in Kotarak Plugin
        /// </summary>
        public void initialize_kotarak_group_subgroup_combobox(ComboBox combobox)
        {
            if (File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                                         "PuTTYStorm", "groups.xml")))
            {
                SavedGroupInfo groups = saved_groups.get_Groups();

                combobox.Items.Add("");

                foreach (string name in groups.names)
                {
                    combobox.Items.Add(name);
                }

                combobox.DropDownWidth = DropDownWidth(combobox);
            }
            combobox.Font          = new Font("Calibri", 11);
            combobox.DropDownStyle = ComboBoxStyle.DropDownList;
        }
Exemplo n.º 9
0
        /// <summary>
        /// Load TreeView Panel with grouped servers placed on the right side of Sessions Form.
        /// </summary>
        public void LoadTreeViewPane(TreeView ServerPane, List <GroupBox> containers_list,
                                     TreeNodeMouseClickEventHandler ServerPane_NodeMouseDoubleClick)
        {
            try
            {
                // Image list for ServerPane TreeView
                ImageList ServerPaneImageList = new ImageList();
                ServerPaneImageList.ImageSize = DPIAwareScaling.ScaleSize(16, 16);
                ServerPaneImageList.Images.Add(PuTTY_Storm.Properties.Resources.VSO_Folder_hoverblue_32x);
                ServerPaneImageList.Images.Add(PuTTY_Storm.Properties.Resources.ComputerSystem_32x);
                ServerPane.ImageList = ServerPaneImageList;

                // Disable redrawing of ServerPane to prevent flickering while changes are made.
                ServerPane.BeginUpdate();

                foreach (GroupBox container in containers_list)
                {
                    Control[] group            = container.Controls.Find("combobox", true);
                    Control[] sub_group        = container.Controls.Find("sub_groups_combobox", true);
                    Control[] hostname_textbox = container.Controls.Find("hostname_textbox", true);

                    Console.WriteLine(group[0].Text);
                    Console.WriteLine(hostname_textbox[0].Text);

                    if ((!(group[0].Text == null || group[0].Text == "")))
                    {
                        // If group doesn't exists - add it
                        if (!ServerPane.Nodes.ContainsKey(group[0].Text))
                        {
                            ServerPane.Nodes.Add(new TreeNode(group[0].Text)
                            {
                                Name       = group[0].Text,
                                ImageIndex = 0, SelectedImageIndex = 0
                            });
                            Console.WriteLine("Group " + group[0].Text + " doesnt exists adding");
                        }

                        // If sub-group doesn't exists - add it
                        if (!ServerPane.Nodes[group[0].Text].Nodes.ContainsKey(sub_group[0].Text))
                        {
                            if (!(sub_group[0].Text == null || sub_group[0].Text == ""))
                            {
                                ServerPane.Nodes[group[0].Text].Nodes.Add(new TreeNode(sub_group[0].Text)
                                {
                                    Name       = sub_group[0].Text,
                                    ImageIndex = 0, SelectedImageIndex = 0
                                });
                                Console.WriteLine("##### SUBGROUP " + sub_group[0].Text + " doesnt exists adding");
                            }
                        }

                        // If server has a group only defined - add it under that group
                        if ((!(group[0].Text == null || group[0].Text == "") && (sub_group[0].Text == null || sub_group[0].Text == "")))
                        {
                            // If server doesn't exists in current group first check if it's part of another group.
                            // If that's the case remove it from that group! Server can be part only of one group!
                            // And then add it to the current group.
                            if (!ServerPane.Nodes[group[0].Text].Nodes.ContainsKey(hostname_textbox[0].Text))
                            {
                                TreeNode[] node = ServerPane.Nodes.Find(hostname_textbox[0].Text, true);
                                if (node.Length > 0)
                                {
                                    ServerPane.Nodes.Remove(node[0]);
                                }
                                ServerPane.Nodes[group[0].Text].Nodes.Add(new TreeNode(hostname_textbox[0].Text)
                                {
                                    Name = hostname_textbox[0].Text, ImageIndex = 1, SelectedImageIndex = 1
                                });
                            }
                        }

                        // If server has group and also sub-group defined - add it under that group -> sub-group
                        if ((!(group[0].Text == null || group[0].Text == "") && !(sub_group[0].Text == null || sub_group[0].Text == "")))
                        {
                            // If server doesn't exists in current sub-group first check if it's part of another sub-group.
                            // If that's the case remove it from that sub-group! Server can be part only of one sub-group!
                            // And then add it to the current sub-group.
                            if (!ServerPane.Nodes[group[0].Text].Nodes[sub_group[0].Text].Nodes.ContainsKey(hostname_textbox[0].Text))
                            {
                                TreeNode[] node = ServerPane.Nodes.Find(hostname_textbox[0].Text, true);
                                if (node.Length > 0)
                                {
                                    ServerPane.Nodes.Remove(node[0]);
                                }
                                ServerPane.Nodes[group[0].Text].Nodes[sub_group[0].Text].Nodes.Add(new TreeNode(hostname_textbox[0].Text)
                                {
                                    Name = hostname_textbox[0].Text, ImageIndex = 1, SelectedImageIndex = 1
                                });
                            }
                        }
                    }
                }

                // Remove empty group and sub-group nodes
                SavedGroupInfo groups = null;

                if (File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                                             "PuTTYStorm", "groups.xml")))
                {
                    groups = saved_groups.get_Groups();
                }
                // Check both layers in case we are removing group which have also empty sub-group
                // inside. Can be done also using recursion.
                for (int i = 0; i < 2; i++)
                {
                    if (groups != null)
                    {
                        RemoveEmptryTreeViewGroups(ServerPane, groups, containers_list);
                    }
                }

                // Sort Nodes in TreeView
                ServerPane.TreeViewNodeSorter = new NodeSorter();
                // Enable redrawing of ServerPane.
                ServerPane.EndUpdate();
            } catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }