示例#1
0
        public void Ctor_Default()
        {
            var control = new LazyCommitControl();

            Assert.True(control.IsCritical);
            Assert.True(control.ServerSide);
            Assert.Equal("1.2.840.113556.1.4.619", control.Type);

            Assert.Empty(control.GetValue());
        }
示例#2
0
        static void Delete(string server, string searchBase, string filter, int connCount, System.Net.NetworkCredential nc)
        {
            using (LdapConnection conn = new LdapConnection(server))
            {
                conn.SessionOptions.ProtocolVersion = 3;
                conn.Credential = nc ?? System.Net.CredentialCache.DefaultNetworkCredentials;
                conn.AutoBind   = false;
                conn.Bind();

                IList <LdapConnection> conns = new List <LdapConnection>();
                for (int i = 0; i < connCount; i++)
                {
                    var c = new LdapConnection(server);

                    c.SessionOptions.ProtocolVersion = 3;
                    c.Credential = nc;
                    c.AutoBind   = false;
                    c.Bind();

                    conns.Add(c);
                }

                Console.WriteLine("Created {0} connections", conns.Count);

                var req = new SearchRequest
                {
                    DistinguishedName = searchBase,
                    Filter            = filter ?? "(&(objectClass=person)(cn=*CNF:*))"
                };

                req.Attributes.Add("1.1");

                req.Controls.Add(new PageResultRequestControl(1000)
                {
                    IsCritical = false
                });

                while (true)
                {
                    var resp = (SearchResponse)conn.SendRequest(req);
                    var lazy = new LazyCommitControl()
                    {
                        IsCritical = false
                    };

                    Parallel.ForEach(ISE(resp.Entries), entry =>
                    {
                        try
                        {
                            var delreq = new DeleteRequest(entry.DistinguishedName);
                            delreq.Controls.Add(lazy);

                            conns[Thread.CurrentThread.ManagedThreadId % connCount].SendRequest(delreq);

                            Console.Error.WriteLine("Deleted {0}", entry.DistinguishedName);
                        }
                        catch (Exception ex)
                        {
                            Console.Error.WriteLine("Failed to delete {0}: {1}", entry.DistinguishedName, ex.Message);
                            throw;
                        }
                    }
                                     );

                    if (resp.Controls.Length == 0)
                    {
                        break;
                    }

                    var prc = (PageResultResponseControl)resp.Controls[0];
                    if (prc.Cookie.Length == 0)
                    {
                        break;
                    }

                    Console.WriteLine("On to the next page!");

                    req.Controls.Clear();
                    req.Controls.Add(new PageResultRequestControl(prc.Cookie));
                }

                Console.WriteLine("Complete");
            }
        }