예제 #1
0
        // Delete selected role
        private void toolStripMenuItem6_Click(object sender, EventArgs e)
        {
            DscRoleNode roleNode = (treeLibrary.SelectedNode.Tag as DscRoleNode);

            if (roleNode == null)
            {
                return;
            }

            HashSet <string> roleUsages = roleNode.FindUsages(_repository.Servers);

            if (roleUsages.Count > 0)
            {
                MessageBoxWorker.CannotDeleteAreUsed(this, Strings.UI_Text_CannotDeleteServersGroups, roleUsages);
                return;
            }

            if (MessageBoxWorker.ConfirmDelete(this, Strings.UI_Text_RoleL) != DialogResult.Yes)
            {
                return;
            }

            _repositoryWorker.RemoveItem(roleNode);

            treeLibrary.Nodes.Remove(treeLibrary.SelectedNode);
        }
예제 #2
0
        // Add Role to Server Node
        private void tsbServerRoleAdd_Click(object sender, EventArgs e)
        {
            DscServerNode serverNode = (treeLibrary.SelectedNode.Tag as DscServerNode);

            if (serverNode == null)
            {
                return;
            }

            DialogTree treeDialog = new DialogTree(treeLibrary.Nodes["tviRoles"], imagesMain);

            if ((treeDialog.ShowDialog() != DialogResult.OK) || (treeDialog.SelectedTag == null))
            {
                return;
            }
            if (treeDialog.SelectedTag.GetType() != typeof(DscRoleNode))
            {
                return;
            }

            DscRoleNode roleNode = (treeDialog.SelectedTag as DscRoleNode);

            if (roleNode == null)
            {
                return;
            }

            serverNode.Node.Roles.Add(roleNode.BuildName());
            serverNode.Node.Save(serverNode.FilePath);

            listServerRoles.DataSource = null;
            listServerRoles.DataSource = serverNode.Node.Roles;
        }
예제 #3
0
        // Create new role
        private void createRoleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DscRoleGroup parent = (treeLibrary.SelectedNode.Tag as DscRoleGroup);

            DialogText nameDialog = new DialogText();

            if (nameDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            if (_repositoryWorker.Contains(nameDialog.InputResult, parent))
            {
                MessageBoxWorker.SameItemExists(this, Strings.UI_Text_RoleOrGroupC);
                return;
            }

            DscRoleNode roleNode = _repositoryWorker.NewRoleNode(nameDialog.InputResult, parent);

            if (roleNode == null)
            {
                return;
            }

            treeLibrary.SelectedNode = TreeViewWorker.TreeNodeAdd(roleNode.Name, roleNode, 1, menuRole,
                                                                  treeLibrary.SelectedNode);
        }
예제 #4
0
        // Add Configuration Item to Role
        private void tsbRoleAdd_Click(object sender, EventArgs e)
        {
            DscRoleNode roleNode = (treeLibrary.SelectedNode.Tag as DscRoleNode);

            if (roleNode == null)
            {
                return;
            }

            DialogTree treeDialog = new DialogTree(treeLibrary.Nodes["tviResources"], imagesMain);

            if ((treeDialog.ShowDialog() != DialogResult.OK) || (treeDialog.SelectedTag == null))
            {
                return;
            }
            if (treeDialog.SelectedTag.GetType() != typeof(DscConfigurationItemNode))
            {
                return;
            }

            DscConfigurationItemNode configurationItemNode = (treeDialog.SelectedTag as DscConfigurationItemNode);

            if (configurationItemNode == null)
            {
                return;
            }

            roleNode.Role.Resources.Add(configurationItemNode.GetFullName());
            roleNode.Role.Save(roleNode.FilePath);

            listRoleItems.DataSource = null;
            listRoleItems.DataSource = roleNode.Role.Resources;
        }
예제 #5
0
        // Show selected item specific controls
        private void tvLibrary_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (treeLibrary.SelectedNode.Tag == null)
            {
                return;
            }
            Type selectedType = treeLibrary.SelectedNode.Tag.GetType();

            HideControls();

            if (selectedType == typeof(DscConfigurationItemNode))
            {
                DscConfigurationItemNode configurationItemNode = (treeLibrary.SelectedNode.Tag as DscConfigurationItemNode);
                if (configurationItemNode == null)
                {
                    return;
                }

                panelConfigurationItem.Show();
                //gridConfigurationItem.SelectedObject = new DictionaryPropertyGridAdapter(configurationItemNode.ConfigurationItem.Properties, configurationItemNode.Parent);
                gridConfigurationItem.SelectedObject = new DscResourcePropertyGridAdapter(configurationItemNode);
                listDependsOn.DataSource             = configurationItemNode.ConfigurationItem.DependsOn;
            }

            if (selectedType == typeof(DscRoleNode))
            {
                DscRoleNode roleNode = (treeLibrary.SelectedNode.Tag as DscRoleNode);
                if (roleNode == null)
                {
                    return;
                }

                panelRole.Show();
                listRoleItems.DataSource = roleNode.Role.Resources;
            }

            if (selectedType == typeof(DscServerNode))
            {
                DscServerNode serverNode = (treeLibrary.SelectedNode.Tag as DscServerNode);
                if (serverNode == null)
                {
                    return;
                }

                panelServer.Show();
                listServerRoles.DataSource         = serverNode.Node.Roles;
                gridServerVariables.SelectedObject = new DictionaryPropertyGridAdapter(serverNode.Node.Variables);
            }
        }
예제 #6
0
        // Create new role
        public DscRoleNode NewRoleNode(string name, DscRoleGroup parent)
        {
            if (parent == null || string.IsNullOrWhiteSpace(name))
            {
                return(null);
            }

            string fileName = Path.Combine(parent.DirectoryPath, name + ".json");

            DscRole role = new DscRole();

            role.Save(fileName);
            DscRoleNode roleNode = new DscRoleNode(fileName, parent);

            parent.Nodes.Add(roleNode);

            return(roleNode);
        }
예제 #7
0
        public HashSet <string> GetUsedModules(DscRepository repository)
        {
            HashSet <string> modules         = new HashSet <string>();
            HashSet <string> resourceStrings = new HashSet <string>();

            foreach (string roleString in Roles)
            {
                DscRoleNode roleNode = repository.Roles.GetRoleNode(roleString);
                resourceStrings.UnionWith(roleNode.Role.Resources);
            }
            foreach (string resourceString in resourceStrings)
            {
                DscConfigurationItemNode configurationItemNode = repository.GetConfigurationItemNode(resourceString);
                if (configurationItemNode.Parent.Parent.Name != "PSDesiredStateConfiguration")
                {
                    modules.Add(configurationItemNode.Parent.Parent.Name);
                }
            }
            return(modules);
        }
예제 #8
0
        // Remove Configuration Item from Role
        private void tsbRoleRemove_Click(object sender, EventArgs e)
        {
            DscRoleNode roleNode = (treeLibrary.SelectedNode.Tag as DscRoleNode);

            if (roleNode == null)
            {
                return;
            }

            if (listRoleItems.SelectedItem == null)
            {
                return;
            }

            roleNode.Role.Resources.Remove(listRoleItems.SelectedItem.ToString());
            roleNode.Role.Save(roleNode.FilePath);

            listRoleItems.DataSource = null;
            listRoleItems.DataSource = roleNode.Role.Resources;
        }
예제 #9
0
        private static List <string> GetConfigText(PsConfiguration configuration, DscRepository repository)
        {
            List <string> configText = new List <string> {
                "Configuration Config_" + configuration.GetId(), "{", "Param", "("
            };

            for (int i = 0; i < configuration.Variables.Keys.Count; i++)
            {
                if (i == configuration.Variables.Keys.Count - 1)
                {
                    configText.Add("$" + configuration.Variables.Keys.ElementAt(i));
                }
                else
                {
                    configText.Add("$" + configuration.Variables.Keys.ElementAt(i) + ",");
                }
            }
            configText.Add(")");
            configText.AddRange(configuration.GetUsedModules(repository).Select(module => "Import-DscResource -Module " + module));
            configText.AddRange(new List <string> {
                "Node $AllNodes.Nodename", "{"
            });
            HashSet <string> resourceStrings = new HashSet <string>();

            foreach (string roleString in configuration.Roles)
            {
                DscRoleNode roleNode = repository.Roles.GetRoleNode(roleString);
                resourceStrings.UnionWith(roleNode.Role.Resources);
            }
            foreach (string resourceString in resourceStrings)
            {
                DscConfigurationItemNode configurationItemNode = repository.GetConfigurationItemNode(resourceString);
                configText.AddRange(GetConfigurationItemText(configurationItemNode, repository));
            }
            configText.AddRange(new List <string> {
                "}", "}"
            });
            return(configText);
        }
예제 #10
0
 // Remove role
 public void RemoveItem(DscRoleNode item)
 {
     item.Parent.Nodes.Remove(item);
     File.Delete(item.FilePath);
 }