Пример #1
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;
        }
Пример #2
0
        // Delete selected configuration item
        private void toolStripMenuItem7_Click(object sender, EventArgs e)
        {
            DscConfigurationItemNode configurationItemNode = (treeLibrary.SelectedNode.Tag as DscConfigurationItemNode);

            if (configurationItemNode == null)
            {
                return;
            }

            HashSet <string> configurationItemUsages = configurationItemNode.FindUsages(_repository.Roles);

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

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

            _repositoryWorker.RemoveItem(configurationItemNode);

            treeLibrary.Nodes.Remove(treeLibrary.SelectedNode);
        }
Пример #3
0
        // Add dependency to configuration item
        private void tsbCIAddDepends_Click(object sender, EventArgs e)
        {
            DscConfigurationItemNode currentConfigurationItemNode = (treeLibrary.SelectedNode.Tag as DscConfigurationItemNode);

            if (currentConfigurationItemNode == 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 selectedConfigurationItemNode = (treeDialog.SelectedTag as DscConfigurationItemNode);

            if (selectedConfigurationItemNode == null)
            {
                return;
            }

            currentConfigurationItemNode.ConfigurationItem.DependsOn.Add(selectedConfigurationItemNode.GetFullName());
            currentConfigurationItemNode.ConfigurationItem.Save(currentConfigurationItemNode.FilePath);

            listDependsOn.DataSource = null;
            listDependsOn.DataSource = currentConfigurationItemNode.ConfigurationItem.DependsOn;
        }
Пример #4
0
        // Create new configuration item
        private void miResourceTypeNewConfigurationItem_Click(object sender, EventArgs e)
        {
            DscResource parent = (treeLibrary.SelectedNode.Tag as DscResource);

            DialogText nameDialog = new DialogText();

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

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

            DscConfigurationItemNode configurationItemNode =
                _repositoryWorker.NewConfigurationItemNode(nameDialog.InputResult, parent);

            if (configurationItemNode == null)
            {
                return;
            }

            treeLibrary.SelectedNode = TreeViewWorker.TreeNodeAdd(configurationItemNode.Name, configurationItemNode, 1,
                                                                  menuConfigurationItem, treeLibrary.SelectedNode);
        }
Пример #5
0
        private static List <string> GetConfigurationItemText(DscConfigurationItemNode node, DscRepository repository)
        {
            List <string> itemText = new List <string> {
                node.Parent.FriendlyName + " \"" + node.Name + "\"", "{"
            };

            foreach (DictionaryEntry entry in node.ConfigurationItem.Properties)
            {
                if (((entry.Value == null) || (entry.Value.ToString() == "")) && !node.Parent.GetRequiredOf(entry.Key.ToString()))
                {
                    continue;
                }
                switch (node.Parent.GetVariableTypeOf(entry.Key.ToString()))
                {
                case DscResource.VariableType.String:
                    if ((entry.Value != null) && (entry.Value.ToString().StartsWith("$") || entry.Value.ToString().StartsWith("\"")))
                    {
                        itemText.Add(entry.Key + " = " + entry.Value);
                    }
                    else
                    {
                        itemText.Add(entry.Key + " = \"" + entry.Value + "\"");
                    }
                    break;

                case DscResource.VariableType.Boolean:
                    itemText.Add(entry.Key + " = $" + entry.Value);
                    break;

                case DscResource.VariableType.Uint16:
                case DscResource.VariableType.Sint16:
                case DscResource.VariableType.Uint32:
                case DscResource.VariableType.Sint32:
                case DscResource.VariableType.Uint64:
                case DscResource.VariableType.Sint64:
                    itemText.Add(entry.Key + " = " + entry.Value);
                    break;

                default:
                    itemText.Add(entry.Key + " = \"" + entry.Value + "\"");
                    break;
                }
            }
            if (node.ConfigurationItem.DependsOn.Count > 0)
            {
                List <string> dependsOn = new List <string>();
                foreach (string dependency in node.ConfigurationItem.DependsOn)
                {
                    DscConfigurationItemNode dependencyNode = repository.GetConfigurationItemNode(dependency);
                    dependsOn.Add("'[" + dependencyNode.Parent.FriendlyName + "]" + dependencyNode.Name + "'");
                }
                itemText.Add("DependsOn = " + string.Join(",", dependsOn));
            }
            itemText.Add("}");

            return(itemText);
        }
Пример #6
0
        // Save changes in selected configuration item properties
        private void pgEditor_PropertyValueChanged(object s, PropertyValueChangedEventArgs e)
        {
            DscConfigurationItemNode configurationItemNode = (treeLibrary.SelectedNode.Tag as DscConfigurationItemNode);

            if (configurationItemNode == null)
            {
                return;
            }

            configurationItemNode.Validate();
            configurationItemNode.ConfigurationItem.Save(configurationItemNode.FilePath);
        }
Пример #7
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);
            }
        }
Пример #8
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);
        }
Пример #9
0
        // Remove dependency from configuration item
        private void tsbCIRemoveDepends_Click(object sender, EventArgs e)
        {
            DscConfigurationItemNode configurationItemNode = (treeLibrary.SelectedNode.Tag as DscConfigurationItemNode);

            if (configurationItemNode == null)
            {
                return;
            }

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

            configurationItemNode.ConfigurationItem.DependsOn.Remove(listDependsOn.SelectedItem.ToString());
            configurationItemNode.ConfigurationItem.Save(configurationItemNode.FilePath);

            listDependsOn.DataSource = null;
            listDependsOn.DataSource = configurationItemNode.ConfigurationItem.DependsOn;
        }
Пример #10
0
        // Create new configuration item
        public DscConfigurationItemNode NewConfigurationItemNode(string name, DscResource parent)
        {
            if (parent == null || string.IsNullOrWhiteSpace(name))
            {
                return(null);
            }

            string fileName = Path.Combine(_repository.Dir.Resources, parent.Parent.Name, parent.FriendlyName,
                                           name + @".json");

            DscConfigurationItem configurationItem = new DscConfigurationItem(parent);

            configurationItem.Save(fileName);
            DscConfigurationItemNode configurationItemNode = new DscConfigurationItemNode(fileName, parent);

            configurationItemNode.Validate();
            parent.Nodes.Add(configurationItemNode);

            return(configurationItemNode);
        }
Пример #11
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);
        }
Пример #12
0
 internal DscResourcePropertyDescriptor(DscConfigurationItemNode item, object key)
     : base(key.ToString(), null)
 {
     _item = item;
     _key  = key;
 }
Пример #13
0
 public DscResourcePropertyGridAdapter(DscConfigurationItemNode item)
 {
     _item = item;
 }
Пример #14
0
 // Remove configuration item
 public void RemoveItem(DscConfigurationItemNode item)
 {
     item.Parent.Nodes.Remove(item);
     File.Delete(item.FilePath);
 }