예제 #1
0
        public IEnumerable <DSAccount> GetAccounts(ReplicationCookie cookie)
        {
            Validator.AssertNotNull(cookie, "cookie");
            // Set Schema
            var schema = BasicSchemaFactory.CreateSchema();
            ReplicationResult result;

            do
            {
                result = this.drsConnection.ReplicateAllObjects(cookie);
                foreach (var obj in result.Objects)
                {
                    obj.Schema = schema;
                    if (!obj.IsAccount)
                    {
                        continue;
                    }
                    var account = new DSAccount(obj, this.SecretDecryptor);
                    yield return(account);
                }

                /* We are modifying the original cookie. Originally, the cookie was immutable,
                 * but the new value could not be returned because iterators do not support out/ref.
                 * This is probably a poor design and it might be done in a more elegant way. */
                cookie.Assign(result.Cookie);
            } while (result.HasMoreData);
        }
        public IEnumerable <DSAccount> GetAccounts(string domainNamingContext, ReplicationProgressHandler progressReporter = null)
        {
            Validator.AssertNotNullOrWhiteSpace(domainNamingContext, nameof(domainNamingContext));
            ReplicationCookie cookie = new ReplicationCookie(domainNamingContext);

            return(GetAccounts(cookie, progressReporter));
        }
예제 #3
0
        public void ReplicationCookie_Serialization()
        {
            Guid guid           = Guid.NewGuid();
            var  originalCookie = new ReplicationCookie("DC=adatum,DC=com", guid, 1, 2, 3);

            // Serialize
            var serializer = new DataContractSerializer(typeof(ReplicationCookie));

            byte[] binaryForm;
            using (var stream = new MemoryStream())
            {
                serializer.WriteObject(stream, originalCookie);
                binaryForm = stream.ToArray();
            }

            // Deserialize
            ReplicationCookie deserializedCookie;

            using (var stream = new MemoryStream(binaryForm))
            {
                deserializedCookie = (ReplicationCookie)serializer.ReadObject(stream);
            }

            // Test that the deserialization worked
            Assert.AreEqual(originalCookie, deserializedCookie);
        }
예제 #4
0
        public IEnumerable <DSAccount> GetAccounts(string domainNamingContext)
        {
            Validator.AssertNotNullOrWhiteSpace(domainNamingContext, "domainNamingContext");
            ReplicationCookie cookie = new ReplicationCookie(domainNamingContext);

            return(GetAccounts(cookie));
        }
예제 #5
0
        public void ReplicationCookie_GetHashCode_NotEqual()
        {
            var cookie1 = new ReplicationCookie("DC=adatum,DC=com");
            var cookie2 = new ReplicationCookie("DC=contoso,DC=com");

            Assert.AreNotEqual(cookie1.GetHashCode(), cookie2.GetHashCode());
        }
예제 #6
0
        public void ReplicationCookie_NotEqualsNonCookieNull()
        {
            var    cookie = new ReplicationCookie("DC=adatum,DC=com");
            string str    = null;

            Assert.IsFalse(cookie.Equals(str));
            Assert.IsFalse(cookie.Equals((object)str));
        }
예제 #7
0
        public void ReplicationCookie_NotEqualsNull()
        {
            var cookie1 = new ReplicationCookie("DC=adatum,DC=com");
            var cookie2 = (ReplicationCookie)null;

            Assert.IsFalse(cookie1.Equals(cookie2));
            Assert.IsFalse(cookie1.Equals((object)cookie2));
            Assert.IsFalse(cookie1 == cookie2);
            Assert.IsTrue(cookie1 != cookie2);
        }
예제 #8
0
        public void ReplicationCookie_Equals_Vector1()
        {
            var cookie1 = new ReplicationCookie("DC=adatum,DC=com");
            var cookie2 = new ReplicationCookie("DC=adatum,DC=com");

            Assert.IsTrue(cookie1.Equals((object)cookie2));
            Assert.IsTrue(cookie1.Equals(cookie2));
            Assert.IsTrue(cookie1 == cookie2);
            Assert.IsFalse(cookie1 != cookie2);
        }
예제 #9
0
        public void ReplicationCookie_Equals_Vector2()
        {
            Guid guid    = Guid.NewGuid();
            var  cookie1 = new ReplicationCookie("DC=adatum,DC=com", guid, 1, 2, 3);
            var  cookie2 = new ReplicationCookie("DC=adatum,DC=com", guid, 1, 2, 3);

            Assert.IsTrue(cookie1.Equals((object)cookie2));
            Assert.IsTrue(cookie1.Equals(cookie2));
            Assert.IsTrue(cookie1 == cookie2);
            Assert.IsFalse(cookie1 != cookie2);
        }
        public IEnumerable <DSAccount> GetAccounts(ReplicationCookie initialCookie, ReplicationProgressHandler progressReporter = null)
        {
            Validator.AssertNotNull(initialCookie, nameof(initialCookie));
            // Create AD schema
            var schema        = BasicSchemaFactory.CreateSchema();
            var currentCookie = initialCookie;
            ReplicationResult result;
            int processedObjectCount = 0;

            do
            {
                // Perform one replication cycle
                result = this.drsConnection.ReplicateAllObjects(currentCookie);

                // Report replication progress
                if (progressReporter != null)
                {
                    processedObjectCount += result.Objects.Count;
                    progressReporter(result.Cookie, processedObjectCount, result.TotalObjectCount);
                }

                // Process the returned objects
                foreach (var obj in result.Objects)
                {
                    obj.Schema = schema;
                    if (!obj.IsAccount)
                    {
                        continue;
                    }
                    var account = new DSAccount(obj, this.SecretDecryptor);
                    yield return(account);
                }

                // Update the position of the replication cursor
                currentCookie = result.Cookie;
            } while (result.HasMoreData);
        }