public void MakeTree(List <DirectoryNode> nodeSelected)
        {
            NodesSelected = nodeSelected;
            var ldapData = GetData();

            _ldapDirectoriesEndpoints = ldapData;
            var listNode = new ObservableCollection <DirectoryNode>();

            if (ldapData != null)
            {
                var directories = ldapData.Directories;
                if (directories != null && directories.Count > 0)
                {
                    var domainDir = directories.Find(r => r.FolderName == DomainName);
                    if (domainDir != null)
                    {
                        var rootId   = domainDir.Id;
                        var rootName = DomainName;
                        // create root, build subtree and return it
                        var node = new DirectoryNode
                        {
                            GuidString = rootId,
                            Title      = rootName,
                            IsFolder   = true,
                            NodeWidth  = 350,
                            NodeColor  = "#000000"
                        };

                        MakeLDAPSubTree(node, ldapData);

                        listNode.Add(node);
                    }
                }
            }
            foreach (var node in nodeSelected)
            {
                var parentNodes = new List <DirectoryNode>();
                GetParentDirectoryNodes(parentNodes, node);
                parentNodes.RemoveAt(0);
                foreach (var pn in parentNodes)
                {
                    if (!NodeIdExpand.Contains(pn.GuidString))
                    {
                        NodeIdExpand.Add(pn.GuidString);
                    }
                }
            }
            TreeDataSource = listNode;
        }
        private void MakeLDAPSubTree(DirectoryNode parentNode, LDAPDirectoriesEndpoints ldapData)
        {
            // find all children of parent node (they have parentId = id of parent node)
            var nodes = new List <DirectoryNode>();

            if (ldapData != null)
            {
                nodes = ldapData.Directories.Where(e => e.ParentId == parentNode.GuidString)
                        .Select(e => new DirectoryNode
                {
                    GuidString = e.Id,
                    Title      = e.FolderName,
                    IsFolder   = true,
                    NodeColor  = "#000000",
                    NodeWidth  = 350
                }).OrderBy(o => o.Title).ToList();


                // build subtree for each child and add it in parent's children collection
                foreach (var node in nodes)
                {
                    MakeLDAPSubTree(node, ldapData);
                    parentNode.DirectoryNodes.Add(node);
                }

                // find all children of parent node (they have parentId = id of parent node)
                var nodes2 = ldapData.Endpoints.Where(
                    e => e.LDAPDirectoryId != null && e.LDAPDirectoryId == parentNode.GuidString)
                             .Select(
                    e =>
                    new DirectoryNode
                {
                    GuidString   = e.Id,
                    Title        = e.SystemName,
                    IsFolder     = false,
                    ComputerType = e.ComputerType,
                    NodeWidth    = 350,
                    Managed      = e.Managed,
                    NodeColor    = "#000000"
                }).OrderBy(o => o.Title);
                foreach (var node in nodes2)
                {
                    parentNode.DirectoryNodes.Add(node);
                }
            }
        }
Ejemplo n.º 3
0
 private void Worker_DoWork(object sender, DoWorkEventArgs e)
 {
     try
     {
         var dir = e.Argument as LDAPDirectory;
         if (dir != null)
         {
             var ldap = new LDAP
             {
                 Type                 = LDAPTypeStore,
                 Domain               = DomainName,
                 Server               = Server,
                 User                 = User,
                 Port                 = Port,
                 IsSecureLDAP         = IsSecure,
                 Password             = Password,
                 SyncInterval         = SyncInterval,
                 ShowEndpoints        = IsShowEndpoints,
                 ShowFolders          = IsShowFolders,
                 Id                   = Id,
                 HideManagedEndpoints = IsHideManagedEndPoints,
                 HideEmptyFolders     = IsHideEmptyFolders,
                 DistinguishedName    = dir.DistinguishedName
             };
             var resultDeserialize = ServiceManager.Invoke(sc => RequestResponseUtils.GetData <LDAPDirectoriesEndpoints>(
                                                               sc.GetLDAPByDistinguishedName,
                                                               ldap));
             if (resultDeserialize != null)
             {
                 if (!ApplicationContext.LdapDirectoriesEndpointsDictionary.ContainsKey(Id))
                 {
                     var addValue = new LDAPDirectoriesEndpoints();
                     ApplicationContext.LdapDirectoriesEndpointsDictionary.AddOrUpdate(Id, addValue, (key, oldValue) => addValue);
                 }
                 ApplicationContext.LdapDirectoriesEndpointsDictionary[Id].Directories.AddRange(resultDeserialize.Directories);
                 ApplicationContext.LdapDirectoriesEndpointsDictionary[Id].Endpoints.AddRange(resultDeserialize.Endpoints);
                 _view.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() =>
                 {
                     if (IsActived)
                     {
                         var ldapViewModel = PageNavigatorHelper.GetMainContentViewModel <LDAPViewModel>();
                         if (ldapViewModel != null)
                         {
                             var ldapData = new LDAP
                             {
                                 Type = LDAPTypeStore,
                                 Domain = DomainName,
                                 Server = Server,
                                 User = User,
                                 Port = Port,
                                 IsSecureLDAP = IsSecure,
                                 Password = Password,
                                 SyncInterval = SyncInterval,
                                 ShowEndpoints = IsShowEndpoints,
                                 ShowFolders = IsShowFolders,
                                 Id = Id,
                                 HideManagedEndpoints = IsHideManagedEndPoints,
                                 HideEmptyFolders = IsHideEmptyFolders
                             };
                             ldapViewModel.BuildLDAPTree(ldapData);
                         }
                     }
                 }));
             }
         }
     }
     catch (Exception)
     {
         ApplicationContext.IsBusy = false;
     }
 }
Ejemplo n.º 4
0
        private void SyncDataBk_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (!ApplicationContext.LdapDirectoriesEndpointsDictionary.ContainsKey(Id))
            {
                var addValue = new LDAPDirectoriesEndpoints();
                ApplicationContext.LdapDirectoriesEndpointsDictionary.AddOrUpdate(Id, addValue, (key, oldValue) => addValue);
            }
            ApplicationContext.LdapDirectoriesEndpointsDictionary[Id].Directories = _ldapDirectories;
            ApplicationContext.LdapDirectoriesEndpointsDictionary[Id].Endpoints   = new List <LDAPEndpoint>();
            var ldapViewModel = PageNavigatorHelper.GetMainContentViewModel <LDAPViewModel>();

            if (IsActived)
            {
                if (ldapViewModel != null)
                {
                    var ldap = new LDAP
                    {
                        Type                 = LDAPTypeStore,
                        Domain               = DomainName,
                        Server               = Server,
                        User                 = User,
                        Port                 = Port,
                        IsSecureLDAP         = IsSecure,
                        Password             = Password,
                        SyncInterval         = SyncInterval,
                        ShowEndpoints        = IsShowEndpoints,
                        ShowFolders          = IsShowFolders,
                        Id                   = Id,
                        HideManagedEndpoints = IsHideManagedEndPoints,
                        HideEmptyFolders     = IsHideEmptyFolders
                    };
                    ldapViewModel.BuildLDAPTree(ldap);
                }
            }
            if (_ldapDirectories == null || (_ldapDirectories != null && !_ldapDirectories.Any()))
            {
                IsLoading                 = false;
                ComputerCount             = 0;
                ApplicationContext.IsBusy = false;
            }
            List <BackgroundWorker> workers = new List <BackgroundWorker>();

            foreach (var dir in _ldapDirectories)
            {
                if (dir.FolderName != DomainName)
                {
                    var worker = new BackgroundWorker();
                    worker.DoWork += Worker_DoWork;
                    workers.Add(worker);
                    worker.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs args)
                    {
                        BackgroundWorker wk = (BackgroundWorker)s;
                        workers.Remove(wk);
                        if (workers.Count == 0)
                        {
                            IsLoading     = false;
                            ComputerCount = ApplicationContext.LdapDirectoriesEndpointsDictionary.ContainsKey(Id)? ApplicationContext.LdapDirectoriesEndpointsDictionary[Id].Endpoints.Count:0;
                            ldapViewModel.Refresh();
                            ApplicationContext.IsBusy = false;
                        }
                    };
                    worker.RunWorkerAsync(dir);
                }
            }
        }