Пример #1
0
 private void btnAdd_Click(object sender, EventArgs e)
 {
     using (var form = new frmSearchDialog())
     {
         var result = form.ShowDialog();
         if (result == DialogResult.OK)
         {
             updateProgress(true);
             Thread thAddObjectsToUser = new Thread(() =>
             {
                 Thread.CurrentThread.Name = "thAddObjectsToUser";
                 var tagsToLoad            = form.returnObjectsTags;
                 foreach (var tag in tagsToLoad)
                 {
                     string[] tagArray        = tag.ToString().Split(',');
                     PrincipalContext context = new PrincipalContext(ContextType.Domain, frmMain.domainAccountData[0], frmMain.domainAccountData[1], frmMain.domainAccountData[2]);
                     dLibAd.AddMemberToGroup(tagArray[0], context, usrToUpdate.Account, context, adObjectType.User);
                 }
                 try
                 {
                     this.Invoke((MethodInvoker) delegate { updateProgress(false); cachedGroups = false; queryUserGroups(false); });
                 }
                 catch { Thread.CurrentThread.Abort(); }
             });
             thAddObjectsToUser.Start();
         }
     }
 }
Пример #2
0
        private void userToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (var form = new frmSearchDialog())
            {
                bool memberPageActive = false;
                form.searchType = 0;
                var result = form.ShowDialog();
                if (result == DialogResult.OK)
                {
                    if (tbControlGroupInfo.SelectedTab == tbControlGroupInfo.TabPages["tbpMembers"])
                    {
                        updateProgressGroupMembers(true);
                        memberPageActive = true;
                    }
                    else
                    {
                        updateProgressGroupGroups(true);
                    }
                    Thread thAddObjectsToGroup = new Thread(() =>
                    {
                        Thread.CurrentThread.Name = "thAddObjectsToGroup";
                        var tagsToLoad            = form.returnObjectsTags;
                        foreach (var tag in tagsToLoad)
                        {
                            string[] tagArray        = tag.ToString().Split(',');
                            PrincipalContext context = new PrincipalContext(ContextType.Domain, frmMain.domainAccountData[0], frmMain.domainAccountData[1], frmMain.domainAccountData[2]);

                            if (memberPageActive)
                            {
                                dLibAd.AddMemberToGroup(groupToQuery, context, tagArray[0], context, adObjectType.Group);
                            }
                            else
                            {
                                dLibAd.AddMemberToGroup(tagArray[0], context, groupToQuery, context, adObjectType.Group);
                            }
                        }
                        try
                        {
                            if (memberPageActive)
                            {
                                this.Invoke((MethodInvoker) delegate { updateProgressGroupMembers(false); cachedGroupMembers = false; queryGroupMembers(false); });
                            }
                            else
                            {
                                this.Invoke((MethodInvoker) delegate { updateProgressGroupGroups(false); cachedGroupGroups = false; queryGroupGroups(false); });
                            }
                        }
                        catch { Thread.CurrentThread.Abort(); }
                    });
                    thAddObjectsToGroup.Start();
                }
            }
        }