public List<LcpsAdsContainer> GetContainers(LcpsAdsObject root, LcpsAdsObjectTypes containerTypes, bool recursive)
        {
            try
            {
                string catFilter = "(objectClass={0})";
                List<string> _cats = new List<string>();

                if (containerTypes.HasFlag(LcpsAdsObjectTypes.Domain))
                    _cats.Add(string.Format(catFilter, "domain"));

                if (containerTypes.HasFlag(LcpsAdsObjectTypes.OrganizationalUnit))
                    _cats.Add(string.Format(catFilter, "organizationalUnit"));

                if (containerTypes.HasFlag(LcpsAdsObjectTypes.Group))
                {
                    _cats.Add(string.Format(catFilter, "group"));
                    _cats.Add(string.Format(catFilter, "container"));
                }

                if (containerTypes.HasFlag(LcpsAdsObjectTypes.User))
                    throw new Exception("User is an unsupported option in this context");

                string f = "(|" + string.Join("", _cats.ToArray()) + ")";

                DirectorySearcher s = new DirectorySearcher(root.DirectoryEntry, f);
                if (recursive)
                    s.SearchScope = SearchScope.Subtree;
                else
                    s.SearchScope = SearchScope.OneLevel;

                List<LcpsAdsContainer> containers = new List<LcpsAdsContainer>();

                foreach(SearchResult r in s.FindAll())
                {
                    LcpsAdsContainer c = new LcpsAdsContainer(r.GetDirectoryEntry());
                    containers.Add(c);
                }

                return containers.OrderBy(x => x.Name).ToList();
            }
            catch (Exception ex)
            {
                throw new Exception("An error occured while attempting to get a list of containers", ex);
            }
        }
Exemple #2
0
        private void LoadChildren(ref AnvilTreeNode n, LcpsAdsContainer parent)
        {
            LcpsAdsObjectTypes t = LcpsAdsObjectTypes.OrganizationalUnit;

            if (Groups)
                t = t | LcpsAdsObjectTypes.Group;

            List<LcpsAdsContainer> cc = parent.GetContainers(parent, t, false);
            foreach (LcpsAdsContainer c in cc)
            {
                AnvilTreeNode child = new AnvilTreeNode()
                {
                    Text = c.Name,
                    Value = c.ObjectGuid.ToString(),
                    LinkClass = c.ObjectCategory.ToString()
                };

                if(String.IsNullOrEmpty(c.Name))
                    child.Text = c.AdsPath;

                switch (c.ObjectType)
                {
                    case LcpsAdsObjectTypes.Unknown:
                        child.InitGlyph = "fa fa-question";
                        child.ItemGlyphCss = "fa-question";
                        child.SelectedItemGlyphCss = "fa-question";
                        break;
                    case LcpsAdsObjectTypes.Container:
                        child.InitGlyph = "fa fa-folder-o";
                        child.ItemGlyphCss = "fa-folder-o";
                        child.SelectedItemGlyphCss = "fa-folder-o";
                        break;
                    case LcpsAdsObjectTypes.Domain:
                        child.InitGlyph = "fa fa-globe";
                        child.ItemGlyphCss = "fa-globe";
                        child.SelectedItemGlyphCss = "fa-globe";
                        break;
                    case LcpsAdsObjectTypes.OrganizationalUnit:
                        child.InitGlyph = "fa fa-folder-o";
                        child.ItemGlyphCss = "fa-folder-o";
                        child.SelectedItemGlyphCss = "fa-folder-o";
                        break;
                    case LcpsAdsObjectTypes.Group:
                        child.InitGlyph = "fa fa-group";
                        child.ItemGlyphCss = "fa-group";
                        child.SelectedItemGlyphCss = "fa-group";
                        break;
                }

                if (c.ObjectType == LcpsAdsObjectTypes.OrganizationalUnit | c.ObjectType == LcpsAdsObjectTypes.Container)
                    LoadChildren(ref child, c);

                n.Children.Add(child);
            }
        }