Exemplo n.º 1
0
        // Create new roles group
        private void miRolesNewGroup_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;
            }

            DscRoleGroup roleGroup = _repositoryWorker.NewRoleGroup(nameDialog.InputResult, parent);

            if (roleGroup == null)
            {
                return;
            }

            treeLibrary.SelectedNode = TreeViewWorker.TreeNodeAdd(roleGroup.Name, roleGroup, 0, menuRoleGroup,
                                                                  treeLibrary.SelectedNode);
        }
Exemplo n.º 2
0
        // Delete selected roles group
        private void deleteToolStripMenuItem2_Click(object sender, EventArgs e)
        {
            DscRoleGroup roleGroup = (treeLibrary.SelectedNode.Tag as DscRoleGroup);

            if (roleGroup?.Parent == null)
            {
                return;
            }

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

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

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

            _repositoryWorker.RemoveItem(roleGroup);

            treeLibrary.Nodes.Remove(treeLibrary.SelectedNode);
        }
Exemplo n.º 3
0
 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);
 }
Exemplo n.º 4
0
        public DscRoleNode GetRoleNode(string fullname)
        {
            string[] path = fullname.Split(':');
            if (path.Length == 2)
            {
                return(Nodes.Find(x => x.Name == path[1]));
            }
            DscRoleGroup nextGroup = Groups.Find(x => x.Name == path[1]);

            return(nextGroup.GetRoleNode(string.Join(":", path.Skip(1).ToArray())));
        }
Exemplo n.º 5
0
        public DscRoleNode(string path, DscRoleGroup parent)
        {
            Parent   = parent;
            FilePath = path;
            string fileName = Path.GetFileName(path);

            if (fileName != null)
            {
                Name = fileName.Replace(".json", "");
            }
            Role = DscRole.Load(path);
        }
Exemplo n.º 6
0
 // Fill TreeView recursively with roles from current repository
 private void FillRoleTree(DscRoleGroup group, TreeNode treeNode)
 {
     treeNode.Tag = group;
     foreach (DscRoleNode childRole in group.Nodes)
     {
         TreeViewWorker.TreeNodeAdd(childRole.Name, childRole, 1, menuRole, treeNode);
     }
     foreach (DscRoleGroup childGroup in group.Groups)
     {
         TreeNode groupNode = TreeViewWorker.TreeNodeAdd(childGroup.Name, childGroup, 0, menuRoleGroup, treeNode);
         FillRoleTree(childGroup, groupNode);
     }
 }
Exemplo n.º 7
0
 public DscRoleGroup(string path, DscRoleGroup parent)
 {
     DirectoryPath = path.EndsWith("\\") ? path : path + "\\";
     Name          = Path.GetFileName(Path.GetDirectoryName(DirectoryPath));
     Parent        = parent;
     string[] roles  = Directory.GetFiles(path, "*.json");
     string[] groups = Directory.GetDirectories(path);
     foreach (string role in roles)
     {
         Nodes.Add(new DscRoleNode(role, this));
     }
     foreach (string group in groups)
     {
         Groups.Add(new DscRoleGroup(group, this));
     }
 }
Exemplo n.º 8
0
        // Create new roles group
        public DscRoleGroup NewRoleGroup(string name, DscRoleGroup parent)
        {
            if (parent == null || string.IsNullOrWhiteSpace(name))
            {
                return(null);
            }

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

            FileSystem.DirectoryCreateIfNotExists(fileName);
            DscRoleGroup roleGroup = new DscRoleGroup(fileName, parent);

            parent.Groups.Add(roleGroup);

            return(roleGroup);
        }
        public HashSet <string> FindUsages(DscRoleGroup group)
        {
            HashSet <string> usages = new HashSet <string>();

            foreach (DscRoleNode node in group.Nodes)
            {
                if (node.Role.Resources.Contains(GetFullName()))
                {
                    usages.Add(node.BuildName());
                }
            }
            foreach (DscRoleGroup child in group.Groups)
            {
                usages.UnionWith(FindUsages(child));
            }
            return(usages);
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
0
 // Remove role group
 public void RemoveItem(DscRoleGroup item)
 {
     item.Parent.Groups.Remove(item);
     Directory.Delete(item.DirectoryPath, true);
 }
Exemplo n.º 12
0
 // Check if roles group already contains child with provided name
 public bool Contains(string name, DscRoleGroup parent)
 {
     return((parent != null) && (parent.Nodes.Any(x => x.Name == name) || parent.Groups.Any(x => x.Name == name)));
 }