コード例 #1
0
ファイル: FormMain.cs プロジェクト: DmitryShaburov/EzDSC
        // 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;
        }
コード例 #2
0
ファイル: FormMain.cs プロジェクト: DmitryShaburov/EzDSC
        // Create new server
        private void miServersNewServer_Click(object sender, EventArgs e)
        {
            DscServerNode parent = (treeLibrary.SelectedNode.Tag as DscServerNode);

            if (parent == null)
            {
                return;
            }

            DialogText nameDialog = new DialogText();

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

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

            DscServerNode serverNode = _repositoryWorker.NewServerNode(nameDialog.InputResult,
                                                                       DscServerNode.ServerType.Server, parent);

            treeLibrary.SelectedNode = TreeViewWorker.TreeNodeAdd(serverNode.Name, serverNode, 2, menuServer,
                                                                  treeLibrary.SelectedNode);
        }
コード例 #3
0
ファイル: FormMain.cs プロジェクト: DmitryShaburov/EzDSC
        // Add variable to Server or Servers Groups
        private void tsbVariableAdd_Click(object sender, EventArgs e)
        {
            DscServerNode serverNode = (treeLibrary.SelectedNode.Tag as DscServerNode);

            if (serverNode == null)
            {
                return;
            }

            DialogText nameDialog = new DialogText();

            if ((nameDialog.ShowDialog() != DialogResult.OK) || string.IsNullOrWhiteSpace(nameDialog.InputResult))
            {
                return;
            }

            string variableName = nameDialog.InputResult.Replace("$", "");

            if (string.IsNullOrWhiteSpace(variableName))
            {
                return;
            }

            serverNode.Node.Variables.Add(variableName, "");
            serverNode.Node.Save(serverNode.FilePath);

            gridServerVariables.SelectedObject = new DictionaryPropertyGridAdapter(serverNode.Node.Variables);
        }
コード例 #4
0
ファイル: FormMain.cs プロジェクト: DmitryShaburov/EzDSC
        // Install DSC modules on selected server
        private void installModulesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DscServerNode serverNode = (treeLibrary.SelectedNode.Tag as DscServerNode);

            ModuleWorker.InstallModules(_repository, serverNode);

            MessageBoxWorker.Done(this, Strings.UI_Text_ModuleInstallComplete);
        }
コード例 #5
0
ファイル: DscRepository.cs プロジェクト: DmitryShaburov/EzDSC
 public DscRepository(string path)
 {
     Dir = new DscRepositoryFolders(path.TrimEnd('\\'));
     LoadModules(Environment.GetFolderPath(Environment.SpecialFolder.System) + "\\WindowsPowerShell\\v1.0\\Modules\\");
     LoadModules(Dir.Modules);
     LoadConfigurationItems();
     Roles   = new DscRoleGroup(Dir.Roles, null);
     Servers = new DscServerNode(DscServerNode.ServerType.Root, Dir.Servers + ".group", null);
 }
コード例 #6
0
        public static void InstallModules(DscRepository repository, DscServerNode serverNode)
        {
            if (serverNode == null)
            {
                return;
            }
            List <PsConfiguration> configurations = serverNode.GetConfigurations();

            foreach (PsConfiguration configuration in configurations)
            {
                InstallModules(repository, configuration.Servers, configuration.GetUsedModules(repository));
            }
        }
コード例 #7
0
        public HashSet <string> FindUsages(DscServerNode serverNode)
        {
            HashSet <string> usages = new HashSet <string>();

            foreach (DscRoleNode node in Nodes)
            {
                usages.UnionWith(node.FindUsages(serverNode));
            }
            foreach (DscRoleGroup group in Groups)
            {
                usages.UnionWith(group.FindUsages(serverNode));
            }
            return(usages);
        }
コード例 #8
0
ファイル: FormMain.cs プロジェクト: DmitryShaburov/EzDSC
        // Run DSC configuration on server node
        private void miRunConfiguration_Click(object sender, EventArgs e)
        {
            DscServerNode serverNode = (treeLibrary.SelectedNode.Tag as DscServerNode);

            if (serverNode == null)
            {
                return;
            }

            string filename = FileSystem.GetTempFile();

            File.WriteAllLines(filename, PsCodeBuilder.BuildScript(serverNode.GetConfigurations(), _repository));
            PsRunner.Start(filename);
        }
コード例 #9
0
ファイル: FormMain.cs プロジェクト: DmitryShaburov/EzDSC
        // 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);
            }
        }
コード例 #10
0
ファイル: DscRoleNode.cs プロジェクト: DmitryShaburov/EzDSC
        public HashSet <string> FindUsages(DscServerNode serverNode)
        {
            HashSet <string> usages   = new HashSet <string>();
            string           fullname = BuildName();

            if (serverNode.Node.Roles.Contains(fullname))
            {
                usages.Add(serverNode.Name);
            }
            foreach (DscServerNode childNode in serverNode.Nodes)
            {
                usages.UnionWith(FindUsages(childNode));
            }
            return(usages);
        }
コード例 #11
0
ファイル: FormMain.cs プロジェクト: DmitryShaburov/EzDSC
 // Fill TreeView recursively with servers from current repository
 private void FillServerTree(DscServerNode serverNode, TreeNode treeNode)
 {
     treeNode.Tag = serverNode;
     foreach (DscServerNode child in serverNode.Nodes)
     {
         if (child.Type != DscServerNode.ServerType.Group)
         {
             TreeViewWorker.TreeNodeAdd(child.Name, child, 2, menuServer, treeNode);
         }
         else
         {
             TreeNode childNode = TreeViewWorker.TreeNodeAdd(child.Name, child, 0, menuServerGroup, treeNode);
             FillServerTree(child, childNode);
         }
     }
 }
コード例 #12
0
 // Remove server or servers groups
 public void RemoveItem(DscServerNode item)
 {
     item.Parent.Nodes.Remove(item);
     if (item.Type != DscServerNode.ServerType.Server)
     {
         string folder = Path.GetDirectoryName(item.FilePath);
         if (folder != null)
         {
             Directory.Delete(folder, true);
         }
     }
     else
     {
         File.Delete(item.FilePath);
     }
 }
コード例 #13
0
ファイル: FormMain.cs プロジェクト: DmitryShaburov/EzDSC
        // Delete selected server
        private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DscServerNode serverNode = (treeLibrary.SelectedNode.Tag as DscServerNode);

            if (serverNode == null)
            {
                return;
            }

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

            _repositoryWorker.RemoveItem(serverNode);

            treeLibrary.Nodes.Remove(treeLibrary.SelectedNode);
        }
コード例 #14
0
ファイル: FormMain.cs プロジェクト: DmitryShaburov/EzDSC
        // Export DSC configuration for server node
        private void miBuildConfiguration_Click(object sender, EventArgs e)
        {
            DscServerNode serverNode = (treeLibrary.SelectedNode.Tag as DscServerNode);

            if (serverNode == null)
            {
                return;
            }

            if ((dialogSaveFile.ShowDialog() != DialogResult.OK) || string.IsNullOrWhiteSpace(dialogSaveFile.FileName))
            {
                return;
            }

            List <PsConfiguration> configurations = serverNode.GetConfigurations();

            File.WriteAllLines(dialogSaveFile.FileName, PsCodeBuilder.BuildScript(configurations, _repository));
        }
コード例 #15
0
ファイル: DscServerNode.cs プロジェクト: DmitryShaburov/EzDSC
        public DscServerNode(ServerType type, string path, DscServerNode parent)
        {
            Type     = type;
            FilePath = path;
            Parent   = parent;
            Nodes    = new List <DscServerNode>();
            Node     = DscServer.Load(FilePath);

            string folder = Path.GetDirectoryName(FilePath);

            if (folder == null)
            {
                return;
            }

            switch (type)
            {
            case ServerType.Root:
            case ServerType.Group:
                Name = Path.GetFileName(Path.GetDirectoryName(path));
                string[] servers = Directory.GetFiles(folder, "*.json");
                string[] groups  = Directory.GetDirectories(folder);
                foreach (string server in servers)
                {
                    Nodes.Add(new DscServerNode(ServerType.Server, server, this));
                }
                foreach (string group in groups)
                {
                    Nodes.Add(new DscServerNode(ServerType.Group, group + "\\.group", this));
                }
                break;

            case ServerType.Server:
                string fileName = Path.GetFileName(path);
                if (fileName != null)
                {
                    Name = fileName.Replace(".json", "");
                }
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }
        }
コード例 #16
0
ファイル: FormMain.cs プロジェクト: DmitryShaburov/EzDSC
        // Remove variable from server or servers group
        private void tsbVariableRemove_Click(object sender, EventArgs e)
        {
            DscServerNode serverNode = (treeLibrary.SelectedNode.Tag as DscServerNode);

            if (serverNode == null)
            {
                return;
            }

            if (gridServerVariables.SelectedGridItem.Label == null)
            {
                return;
            }

            serverNode.Node.Variables.Remove(gridServerVariables.SelectedGridItem.Label);
            serverNode.Node.Save(serverNode.FilePath);

            gridServerVariables.SelectedObject = new DictionaryPropertyGridAdapter(serverNode.Node.Variables);
        }
コード例 #17
0
ファイル: FormMain.cs プロジェクト: DmitryShaburov/EzDSC
        // Remove Role from Server Node
        private void tsbServerRoleRemove_Click(object sender, EventArgs e)
        {
            DscServerNode serverNode = (treeLibrary.SelectedNode.Tag as DscServerNode);

            if (serverNode == null)
            {
                return;
            }

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

            serverNode.Node.Roles.Remove(listServerRoles.SelectedItem.ToString());
            serverNode.Node.Save(serverNode.FilePath);

            listServerRoles.DataSource = null;
            listServerRoles.DataSource = serverNode.Node.Roles;
        }
コード例 #18
0
        // Create new server or server group
        public DscServerNode NewServerNode(string name, DscServerNode.ServerType type, DscServerNode parent)
        {
            if (parent == null || string.IsNullOrWhiteSpace(name))
            {
                return(null);
            }

            string fileFolder = Path.GetDirectoryName(parent.FilePath);

            if (fileFolder == null)
            {
                return(null);
            }

            string fileName;

            if (type == DscServerNode.ServerType.Server)
            {
                fileName = Path.Combine(fileFolder, name + @".json");
            }
            else
            {
                fileName = Path.Combine(fileFolder, name, @".group");
                FileSystem.DirectoryCreateIfNotExists(Path.GetDirectoryName(fileName));
            }

            DscServer server = new DscServer();

            server.Save(fileName);
            DscServerNode serverNode =
                new DscServerNode(type, fileName, parent);

            parent.Nodes.Add(serverNode);

            return(serverNode);
        }
コード例 #19
0
 // Check if server node already contains child with provided name
 public bool Contains(string name, DscServerNode parent)
 {
     return(parent != null && parent.Nodes.Any(x => x.Name == name));
 }
コード例 #20
0
ファイル: FormMain.cs プロジェクト: DmitryShaburov/EzDSC
        // Save changes in selected server node variables
        private void pgServerVariables_PropertyValueChanged(object s, PropertyValueChangedEventArgs e)
        {
            DscServerNode serverNode = (treeLibrary.SelectedNode.Tag as DscServerNode);

            serverNode?.Node.Save(serverNode.FilePath);
        }