Exemplo n.º 1
0
        //private MyTreeViewItem GetRootNode(string Servername)
        //{
        //    // Bildet die root Node für den Server (Level 0)
        //    MyTreeViewItem root = new MyTreeViewItem
        //    {
        //        HeaderText = Servername,
        //        Tag = "\\\\" + Servername.ToLower(),
        //        Icon = new BitmapImage(iconUri_server)
        //    };
        //    root.IsSelected = true;
        //    root.Expanding += new RoutedEventHandler(TreeViewBeforeExpand);

        //    MyTreeViewItem subitem = new MyTreeViewItem
        //    {
        //        Header = "..."
        //    };
        //    root.Items.Add(subitem);

        //    return root;
        //}

        private MyTreeViewItem GetRootAndFirstLevelNodes(string Servername)
        {
            // Bildet die root Node für den Server (Level 0)
            MyTreeViewItem root = new MyTreeViewItem
            {
                HeaderText = Servername,
                Tag        = new[] { null, "\\\\" + Servername.ToLower() },
                Icon       = new BitmapImage(iconUri_server)
            };

            root.IsSelected = true;

            // Sucht alle Unterordner des Servers und bildet die Nodes dafür (Level 1)
            DataClassesDataContext db = new DataClassesDataContext();

            var result = from dir in db.dirs
                         where
                         dir.ParentID == null &&
                         dir.Directory.ToLower().StartsWith("\\\\" + Servername.ToLower() + "\\")
                         orderby dir.Directory
                         select new
            {
                dir.ID,
                dir.Directory
            };

            foreach (var row in result)
            {
                MyTreeViewItem node = new MyTreeViewItem
                {
                    HeaderText = Regex.Match(row.Directory, @"\w+$").Value,
                    Tag        = new [] { row.ID.ToString(), row.Directory },
                    Icon       = new BitmapImage(iconUri_folderShared)
                };
                node.Expanding += new RoutedEventHandler(TreeViewBeforeExpand);

                var subdirs = (from dirs in db.dirs
                               where dirs.ParentID == row.ID
                               select new
                {
                    dirs.ID
                }).Take(1);

                if (subdirs.Count() > 0)
                {
                    MyTreeViewItem subnode = new MyTreeViewItem
                    {
                        Header = "..."
                    };
                    node.Items.Add(subnode);
                }

                root.Items.Add(node);
            }

            return(root);
        }
Exemplo n.º 2
0
        private void Window_ContentRendered(object sender, EventArgs e)
        {
            Mouse.OverrideCursor = Cursors.Wait;
            MyTreeViewItem rootNode = GetRootAndFirstLevelNodes("Apollon");

            //MyTreeViewItem rootNode = GetRootNode("Apollon");
            treeView_Directorys.Items.Add(rootNode);
            Mouse.OverrideCursor = null;
        }
Exemplo n.º 3
0
        private void TreeViewBeforeExpand(object sender, RoutedEventArgs args)
        {
            Mouse.OverrideCursor = Cursors.Wait;
            MyTreeViewItem selectedTVI = (MyTreeViewItem)args.Source;

            if (selectedTVI.Items.Count > 0)
            {
                MyTreeViewItem node0 = (MyTreeViewItem)selectedTVI.Items[0];
                if (node0.Header.ToString() == "..." && node0.Tag == null)
                {
                    selectedTVI.Items.Clear();

                    //get the list of sub directories
                    int parentID = Convert.ToInt32(((string[])selectedTVI.Tag)[0]);
                    List <DirWithSubcount> dirs = GetDirectoriesByParentID(parentID);

                    foreach (DirWithSubcount dir in dirs)
                    {
                        MyTreeViewItem node = new MyTreeViewItem
                        {
                            HeaderText = Regex.Match(dir.Dir, @"([^\\]+)(?=[^\\]*$)").Value,
                            //keep the directory's full path in the tag for use later
                            Tag  = new[] { dir.ID.ToString(), dir.Dir },
                            Icon = new BitmapImage(iconUri_folder)
                        };

                        node.Expanding += new RoutedEventHandler(TreeViewBeforeExpand);

                        //if (getDirectories(dir).Count() > 0)
                        if (dir.Subcount > 0)
                        {
                            MyTreeViewItem subnode = new MyTreeViewItem
                            {
                                Header = "..."
                            };
                            node.Items.Add(subnode);
                        }

                        selectedTVI.Items.Add(node);
                    }
                }
            }
            Mouse.OverrideCursor = null;
        }
Exemplo n.º 4
0
        private void TreeViewSelectedItemChange(object sender, RoutedPropertyChangedEventArgs <object> e)
        {
            MyTreeViewItem selectedItem = treeView_Directorys.SelectedItem as MyTreeViewItem;
            string         fullPath     = ((string[])selectedItem.Tag)[1];
            var            folderName   = fullPath.Split('\\').Last();

            lbl_FolderName.Content = folderName;
            lbl_FolderPath.Content = fullPath;

            DataClassesDataContext db = new DataClassesDataContext();

            #region FolderOwner
            var owner = from d in db.dirs
                        join u in db.adusers on new { d.Owner } equals new { Owner = u.SID } into u_join
            from u in u_join.DefaultIfEmpty()
            join g in db.adgroups on new { d.Owner } equals new { Owner = g.SID } into g_join
            from g in g_join.DefaultIfEmpty()
            where
            d.Directory == fullPath
                select new
            {
                Name           = (u.DisplayName ?? g.Name),
                SamAccountName = (u.SamAccountName ?? g.SamAccountName),
                g.SID
            };

            if (owner.Any())
            {
                lbl_OwnerName.Content = owner.First().Name;
                img_OwnerIcon.Source  = (owner.First().SID != null) ? new BitmapImage(iconUri_group) : new BitmapImage(iconUri_user);
            }
            else
            {
                lbl_OwnerName.Content = "Keinen Besitzer gefunden";
            }
            #endregion

            listView_AccountWithPermissions.Items.Clear();
            var result = from d in db.dirs
                         join r in db.rights on new { d.ID } equals new { ID = r.DirID }
            join u in db.adusers on new { r.IdentityReference } equals new { IdentityReference = u.SID } into u_join
            from u in u_join.DefaultIfEmpty()
            join g in db.adgroups on new { r.IdentityReference } equals new { IdentityReference = g.SID } into g_join
            from g in g_join.DefaultIfEmpty()
            where
            d.Directory == fullPath &&
            r.InheritanceFlags != "None"
            select new
            {
                r.AccessControlType,
                r.FileSystemRights,
                r.IsInherited,
                r.InheritanceFlags,
                SID            = (u.SID ?? g.SID),
                SamAccountName = (u.SamAccountName ?? g.SamAccountName),
                User           = u.DisplayName,
                Group          = g.Name
            };

            List <User> UserList = new List <User>();
            foreach (var row in result)
            {
                // Wenn User dann einfach anzeigen
                if (row.User != null)
                {
                    var name = row.User;
                    name += (row.SamAccountName != null) ? $" ({row.SamAccountName})" : "";

                    UserList.Add(new User(row.AccessControlType, row.FileSystemRights, row.IsInherited, row.InheritanceFlags, row.SID, name, null));
                }
                // Wenn Gruppe dann wird die Funktion GetMemberInGroup aufgerufen die alle User die über diese Gruppe berechtigt sind abgerufen
                else
                {
                    var name = row.Group;
                    name += (row.SamAccountName != null) ? $" ({row.SamAccountName})" : "";

                    List <User> retList = new List <User>();
                    GetMemberInGroup(row.AccessControlType, row.FileSystemRights, row.IsInherited, row.InheritanceFlags, row.SID, name, retList);
                    UserList.AddRange(retList);
                }
            }

            FillAccountWithPermissonsSection(UserList);
        }