Esempio n. 1
0
        private IEnumerable <ADRawEntry> ReadDeletedObjects()
        {
            ExTraceGlobals.TenantRelocationTracer.TraceDebug((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration.ReadDeletedObjects ...");
            int sizeLimit = Math.Max(1, TenantRelocationSyncConfiguration.ObjectsPerPageLimit - base.ReturnedObjectCount);

            ExTraceGlobals.TenantRelocationTracer.TraceDebug <int>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration.ReadDeletedObjects sizeLimit = {0}", sizeLimit);
            ADRawEntry[] results = null;
            if (this.PageToken.State == TenantRelocationSyncState.EnumerateConfigUnitDeletedObjects)
            {
                ITenantConfigurationSession tenantConfigurationSession = DirectorySessionFactory.Default.CreateTenantConfigurationSession(true, ConsistencyMode.PartiallyConsistent, ADSessionSettings.FromOrganizationIdWithoutRbacScopesServiceOnly(base.RecipientSession.SessionSettings.CurrentOrganizationId), 629, "ReadDeletedObjects", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\Sync\\TenantRelocationSync\\TenantRelocationSyncConfiguration.cs");
                tenantConfigurationSession.DomainController          = base.RecipientSession.DomainController;
                tenantConfigurationSession.LogSizeLimitExceededEvent = false;
                tenantConfigurationSession.UseGlobalCatalog          = false;
                tenantConfigurationSession.UseConfigNC = !ADSession.IsTenantConfigInDomainNC(base.RecipientSession.SessionSettings.GetAccountOrResourceForestFqdn());
                results = tenantConfigurationSession.FindDeletedTenantSyncObjectByUsnRange(base.RecipientSession.SessionSettings.CurrentOrganizationId.OrganizationalUnit, this.PageToken.ConfigUnitTombstoneUSN, sizeLimit, TenantRelocationSyncConfiguration.PropertyDefinitionsForDeletedObjects);
            }
            else
            {
                ITenantRecipientSession tenantRecipientSession = DirectorySessionFactory.Default.CreateTenantRecipientSession(true, ConsistencyMode.PartiallyConsistent, ADSessionSettings.FromOrganizationIdWithoutRbacScopesServiceOnly(base.RecipientSession.SessionSettings.CurrentOrganizationId), 649, "ReadDeletedObjects", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\Sync\\TenantRelocationSync\\TenantRelocationSyncConfiguration.cs");
                tenantRecipientSession.DomainController          = base.RecipientSession.DomainController;
                tenantRecipientSession.LogSizeLimitExceededEvent = false;
                tenantRecipientSession.UseGlobalCatalog          = false;
                results = tenantRecipientSession.FindDeletedTenantSyncObjectByUsnRange(base.RecipientSession.SessionSettings.CurrentOrganizationId.OrganizationalUnit, this.PageToken.OrganizationalUnitTombstoneUSN, sizeLimit, TenantRelocationSyncConfiguration.PropertyDefinitionsForDeletedObjects);
            }
            ExTraceGlobals.TenantRelocationTracer.TraceDebug <int>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration.ReadDeletedObjects results count = {0}", (results != null) ? results.Length : 0);
            long maxUsnReturned = long.MaxValue;

            foreach (ADRawEntry entry in results)
            {
                ExTraceGlobals.TenantRelocationTracer.TraceDebug <ADObjectId>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration.ReadDeletedObjects entry {0}", entry.Id);
                base.ReturnedObjectCount++;
                ExTraceGlobals.TenantRelocationTracer.TraceDebug <int>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration.ReadDeletedObjects this.ReturnedObjectCount = {0}", base.ReturnedObjectCount);
                maxUsnReturned = (long)entry[ADRecipientSchema.UsnChanged];
                yield return(entry);
            }
            if (this.PageToken.State == TenantRelocationSyncState.EnumerateConfigUnitDeletedObjects)
            {
                this.PageToken.ConfigUnitTombstoneUSN = ((maxUsnReturned == long.MaxValue) ? long.MaxValue : (maxUsnReturned + 1L));
                ExTraceGlobals.TenantRelocationTracer.TraceDebug <long>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration.ReadDeletedObjects set this.PageToken.ConfigUnitTombstoneUSN to {0}", this.PageToken.ConfigUnitTombstoneUSN);
            }
            else
            {
                this.PageToken.OrganizationalUnitTombstoneUSN = ((maxUsnReturned == long.MaxValue) ? long.MaxValue : (maxUsnReturned + 1L));
                ExTraceGlobals.TenantRelocationTracer.TraceDebug <long>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration.ReadDeletedObjects set this.PageToken.OrganizationalUnitTombstoneUSN to {0}", this.PageToken.OrganizationalUnitTombstoneUSN);
            }
            if (results.Length < sizeLimit)
            {
                this.PageToken.SwitchToNextState();
                ExTraceGlobals.TenantRelocationTracer.TraceDebug((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration.ReadDeletedObjects no more deleted objects, we are done");
            }
            else
            {
                ExTraceGlobals.TenantRelocationTracer.TraceDebug((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration.ReadDeletedObjects do nothing, page token is already up to date");
            }
            yield break;
        }
        public ADRawEntry[] FindDeletedADRawEntryByUsnRange(ADObjectId lastKnownParentId, long startUsn, int sizeLimit, IEnumerable <PropertyDefinition> properties)
        {
            if (sizeLimit > ADDataSession.RangedValueDefaultPageSize)
            {
                throw new ArgumentOutOfRangeException("sizeLimit");
            }
            QueryFilter filter = new AndFilter(new QueryFilter[]
            {
                new ComparisonFilter(ComparisonOperator.GreaterThanOrEqual, ADRecipientSchema.UsnChanged, startUsn),
                new ComparisonFilter(ComparisonOperator.Equal, ADObjectSchema.OrganizationalUnitRoot, lastKnownParentId)
            });
            ADObjectId rootId = ADSession.IsTenantConfigInDomainNC(base.SessionSettings.GetAccountOrResourceForestFqdn()) ? ADSession.GetDeletedObjectsContainer(lastKnownParentId.DomainId) : ADSession.GetDeletedObjectsContainer(base.ConfigurationNamingContext);

            return(base.Find <ADRawEntry>(rootId, QueryScope.OneLevel, filter, ADDataSession.SortByUsn, sizeLimit, properties, true));
        }
Esempio n. 3
0
        public override IEnumerable <ADRawEntry> GetDataPage()
        {
            ExTraceGlobals.TenantRelocationTracer.TraceDebug((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration GetDataPage ...");
            WatermarkMap watermarks         = SyncConfiguration.GetReplicationCursors(base.RootOrgConfigurationSession);
            WatermarkMap configNcWatermarks = SyncConfiguration.GetReplicationCursors(base.RootOrgConfigurationSession, true, false);
            string       dcName             = base.RootOrgConfigurationSession.DomainController;

            ExTraceGlobals.TenantRelocationTracer.TraceDebug <string>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration dcName {0}", dcName);
            base.TenantConfigurationSession.DomainController = dcName;
            base.RecipientSession.DomainController           = dcName;
            Guid watermarksInvocationId = base.RootOrgConfigurationSession.GetInvocationIdByFqdn(dcName);

            ExTraceGlobals.TenantRelocationTracer.TraceDebug <Guid>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration watermarksInvocationId {0}", watermarksInvocationId);
            long maxUsn = watermarks[watermarksInvocationId];

            ExTraceGlobals.TenantRelocationTracer.TraceDebug <long>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration maxUsn {0}", maxUsn);
            this.PageToken.IsTenantConfigUnitInConfigNc = !ADSession.IsTenantConfigInDomainNC(base.RecipientSession.SessionSettings.GetAccountOrResourceForestFqdn());
            if (this.PageToken.InvocationId == Guid.Empty)
            {
                this.PageToken.SetInvocationId(watermarksInvocationId, dcName);
                ExTraceGlobals.TenantRelocationTracer.TraceDebug <Guid>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration set this.PageToken.InvocationId to {0}", this.PageToken.InvocationId);
            }
            this.moreDataForThisPage = true;
            while (this.ShouldReadMoreData())
            {
                ExTraceGlobals.TenantRelocationTracer.TraceDebug <string>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration this.PageToken.State = {0}", this.PageToken.State.ToString());
                switch (this.PageToken.State)
                {
                case TenantRelocationSyncState.PreSyncAllObjects:
                    if (this.PageToken.PreSyncLdapPagingCookie == null)
                    {
                        this.PageToken.PendingConfigNcWatermarks     = configNcWatermarks;
                        this.PageToken.PendingWatermarks             = watermarks;
                        this.PageToken.PendingWatermarksInvocationId = watermarksInvocationId;
                        ExTraceGlobals.TenantRelocationTracer.TraceDebug <Guid>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration set this.PageToken.PendingWatermarksInvocationId to {0}", this.PageToken.PendingWatermarksInvocationId);
                    }
                    foreach (ADRawEntry entry in this.PreSyncAllObjects())
                    {
                        ExTraceGlobals.TenantRelocationTracer.TraceDebug <ADObjectId>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration PreSyncAllObjects yield {0}", entry.Id);
                        yield return(entry);
                    }
                    break;

                case TenantRelocationSyncState.EnumerateConfigUnitLiveObjects:
                    foreach (ADRawEntry entry2 in this.ReadLiveObjects(maxUsn))
                    {
                        ExTraceGlobals.TenantRelocationTracer.TraceDebug <ADObjectId>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration EnumerateConfigUnitLiveObjects yield {0}", entry2.Id);
                        yield return(entry2);
                    }
                    this.PageToken.PendingWatermarksInvocationId = watermarksInvocationId;
                    ExTraceGlobals.TenantRelocationTracer.TraceDebug <Guid>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration set this.PageToken.PendingWatermarksInvocationId to {0}", this.PageToken.PendingWatermarksInvocationId);
                    if (this.PageToken.IsTenantConfigUnitInConfigNc)
                    {
                        this.PageToken.PendingConfigNcWatermarks = configNcWatermarks;
                    }
                    else
                    {
                        this.PageToken.PendingWatermarks = watermarks;
                    }
                    break;

                case TenantRelocationSyncState.EnumerateConfigUnitLinksInPage:
                    ExTraceGlobals.TenantRelocationTracer.TraceDebug((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration EnumerateConfigUnitLinksInPage skips");
                    this.PageToken.SwitchToEnumerateLiveObjectsState();
                    break;

                case TenantRelocationSyncState.EnumerateOrganizationalUnitLiveObjects:
                    foreach (ADRawEntry entry3 in this.ReadLiveObjects(maxUsn))
                    {
                        ExTraceGlobals.TenantRelocationTracer.TraceDebug <ADObjectId>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration EnumerateOrganizationalUnitLiveObjects yield {0}", entry3.Id);
                        yield return(entry3);
                    }
                    if (this.PageToken.IsTenantConfigUnitInConfigNc)
                    {
                        this.PageToken.PendingWatermarksInvocationId = watermarksInvocationId;
                        ExTraceGlobals.TenantRelocationTracer.TraceDebug <Guid>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration set this.PageToken.PendingWatermarksInvocationId to {0}", this.PageToken.PendingWatermarksInvocationId);
                        this.PageToken.PendingWatermarks = watermarks;
                    }
                    break;

                case TenantRelocationSyncState.EnumerateOrganizationalUnitLinksInPage:
                    ExTraceGlobals.TenantRelocationTracer.TraceDebug((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration EnumerateConfigUnitLinksInPage skips");
                    this.PageToken.SwitchToEnumerateLiveObjectsState();
                    break;

                case TenantRelocationSyncState.EnumerateConfigUnitDeletedObjects:
                    foreach (ADRawEntry entry4 in this.ReadDeletedObjects())
                    {
                        ExTraceGlobals.TenantRelocationTracer.TraceDebug <ADObjectId>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration EnumerateConfigUnitDeletedObjects yield {0}", entry4.Id);
                        yield return(entry4);
                    }
                    break;

                case TenantRelocationSyncState.EnumerateOrganizationalUnitDeletedObjects:
                    if (!this.PageToken.IsTenantConfigUnitInConfigNc)
                    {
                        this.PageToken.SwitchToNextState();
                    }
                    else
                    {
                        foreach (ADRawEntry entry5 in this.ReadDeletedObjects())
                        {
                            ExTraceGlobals.TenantRelocationTracer.TraceDebug <ADObjectId>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration EnumerateOrganizationalUnitDeletedObjects yield {0}", entry5.Id);
                            yield return(entry5);
                        }
                    }
                    break;

                case TenantRelocationSyncState.EnumerateSpecialObjects:
                    foreach (ADRawEntry entry6 in this.ReadSpecialObjects())
                    {
                        ExTraceGlobals.TenantRelocationTracer.TraceDebug <ADObjectId>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration EnumerateSpecialObjects yield {0}", entry6.Id);
                        yield return(entry6);
                    }
                    if (!this.PageToken.IsTenantConfigUnitInConfigNc)
                    {
                        this.PageToken.PendingWatermarksInvocationId = watermarksInvocationId;
                        ExTraceGlobals.TenantRelocationTracer.TraceDebug <Guid>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration set this.PageToken.PendingWatermarksInvocationId to {0}", this.PageToken.PendingWatermarksInvocationId);
                        this.PageToken.PendingConfigNcWatermarks = configNcWatermarks;
                    }
                    this.PageToken.SwitchToNextState();
                    break;

                default:
                    ExTraceGlobals.TenantRelocationTracer.TraceError <string>((long)SyncConfiguration.TraceId, "Invalid PageToken stat {0}", this.PageToken.State.ToString());
                    throw new ArgumentException(this.PageToken.State.ToString());
                }
            }
            ExTraceGlobals.TenantRelocationTracer.TraceDebug <long>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration this.PageToken.OrganizationalUnitObjectUSN = {0}", this.PageToken.OrganizationalUnitObjectUSN);
            if (this.PageToken.OrganizationalUnitObjectUSN > maxUsn + 1L)
            {
                this.PageToken.OrganizationalUnitObjectUSN = maxUsn + 1L;
                ExTraceGlobals.TenantRelocationTracer.TraceDebug <long>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration set this.PageToken.OrganizationalUnitObjectUSN to {0}", this.PageToken.OrganizationalUnitObjectUSN);
            }
            ExTraceGlobals.TenantRelocationTracer.TraceDebug <long>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration this.PageToken.OrganizationalUnitTombstoneUSN = {0}", this.PageToken.OrganizationalUnitTombstoneUSN);
            if (this.PageToken.OrganizationalUnitTombstoneUSN > maxUsn + 1L)
            {
                this.PageToken.OrganizationalUnitTombstoneUSN = maxUsn + 1L;
                ExTraceGlobals.TenantRelocationTracer.TraceDebug <long>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration set this.PageToken.OrganizationalUnitTombstoneUSN to {0}", this.PageToken.OrganizationalUnitTombstoneUSN);
            }
            ExTraceGlobals.TenantRelocationTracer.TraceDebug <long>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration this.PageToken.ConfigUnitObjectUSN = {0}", this.PageToken.ConfigUnitObjectUSN);
            if (this.PageToken.ConfigUnitObjectUSN > maxUsn + 1L)
            {
                this.PageToken.ConfigUnitObjectUSN = maxUsn + 1L;
                ExTraceGlobals.TenantRelocationTracer.TraceDebug <long>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration this.PageToken.ConfigUnitObjectUSN = {0}", this.PageToken.ConfigUnitObjectUSN);
            }
            ExTraceGlobals.TenantRelocationTracer.TraceDebug <long>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration this.PageToken.ConfigUnitTombstoneUSN = {0}", this.PageToken.ConfigUnitTombstoneUSN);
            if (this.PageToken.ConfigUnitTombstoneUSN > maxUsn + 1L)
            {
                this.PageToken.ConfigUnitTombstoneUSN = maxUsn + 1L;
                ExTraceGlobals.TenantRelocationTracer.TraceDebug <long>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration this.PageToken.ConfigUnitTombstoneUSN = {0}", this.PageToken.ConfigUnitTombstoneUSN);
            }
            ExTraceGlobals.TenantRelocationTracer.TraceDebug <long>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration this.PageToken.SpecialObjectsUSN = {0}", this.PageToken.SpecialObjectsUSN);
            if (this.PageToken.SpecialObjectsUSN > maxUsn + 1L)
            {
                this.PageToken.SpecialObjectsUSN = maxUsn + 1L;
                ExTraceGlobals.TenantRelocationTracer.TraceDebug <long>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration this.PageToken.SpecialObjectsUSN = {0}", this.PageToken.SpecialObjectsUSN);
            }
            this.PageToken.LastReadFailureStartTime = DateTime.MinValue;
            ExTraceGlobals.TenantRelocationTracer.TraceDebug <DateTime>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration set this.PageToken.LastReadFailureStartTime to {0}", this.PageToken.LastReadFailureStartTime);
            this.PageToken.Timestamp = DateTime.UtcNow;
            ExTraceGlobals.TenantRelocationTracer.TraceDebug <DateTime>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration set this.PageToken.Timestamp to {0}", this.PageToken.Timestamp);
            yield break;
        }