// 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); }
// 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; }
// 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); }
// 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; }
// 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); } }
// 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); }
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); }
// 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; }
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); }
// Remove role public void RemoveItem(DscRoleNode item) { item.Parent.Nodes.Remove(item); File.Delete(item.FilePath); }