private IEnumerable <ADRawEntry> ReadDeletedObjects()
        {
            ExTraceGlobals.BackSyncTracer.TraceDebug((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration.ReadDeletedObjects ...");
            FullSyncConfiguration.GetPropertyDefinitions(true);
            int sizeLimit = Math.Max(1, FullSyncConfiguration.ObjectsPerPageLimit - base.ReturnedObjectCount);

            ExTraceGlobals.BackSyncTracer.TraceDebug <int>((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration.ReadDeletedObjects sizeLimit = {0}", sizeLimit);
            ADRawEntry[] results = base.RecipientSession.FindDeletedADRawEntryByUsnRange(base.RecipientSession.SessionSettings.CurrentOrganizationId.OrganizationalUnit, this.PageToken.TombstoneUpdateSequenceNumber, sizeLimit, TenantFullSyncConfiguration.PropertyDefinitionsForDeletedObjects, SyncRecipient.SyncRecipientObjectTypeFilter);
            ExTraceGlobals.BackSyncTracer.TraceDebug <int>((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration.ReadDeletedObjects results count = {0}", (results != null) ? results.Length : 0);
            long maxUsnReturned = long.MaxValue;

            foreach (ADRawEntry entry in results)
            {
                ExTraceGlobals.BackSyncTracer.TraceDebug <ADObjectId>((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration.ReadDeletedObjects entry {0}", entry.Id);
                base.ReturnedObjectCount++;
                ExTraceGlobals.BackSyncTracer.TraceDebug <int>((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration.ReadDeletedObjects this.ReturnedObjectCount = {0}", base.ReturnedObjectCount);
                maxUsnReturned = (long)entry[SyncObjectSchema.UsnChanged];
                this.StampTenantContext(entry);
                yield return(entry);
            }
            this.PageToken.TombstoneUpdateSequenceNumber = ((maxUsnReturned == long.MaxValue) ? long.MaxValue : (maxUsnReturned + 1L));
            ExTraceGlobals.BackSyncTracer.TraceDebug <long>((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration.ReadDeletedObjects set this.PageToken.TombstoneUpdateSequenceNumber to {0}", this.PageToken.TombstoneUpdateSequenceNumber);
            if (results.Length < sizeLimit)
            {
                this.FinishFullSync();
                ExTraceGlobals.BackSyncTracer.TraceDebug((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration.ReadDeletedObjects no more deleted objects, we are done");
            }
            else
            {
                ExTraceGlobals.BackSyncTracer.TraceDebug((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration.ReadDeletedObjects do nothing, page token is already up to date");
            }
            yield break;
        }
Пример #2
0
        static FullSyncConfiguration()
        {
            FullSyncConfiguration.InitializeConfigurableSettings();
            FullSyncConfiguration.InitialLinkMetadataRangedProperty = RangedPropertyHelper.CreateRangedProperty(ADRecipientSchema.LinkMetadata, new IntRange(0, FullSyncConfiguration.InitialLinkReadSize - 1));
            List <PropertyDefinition> list = new List <PropertyDefinition>(SyncSchema.Instance.AllBackSyncBaseProperties.Cast <PropertyDefinition>());

            list.AddRange(SyncObject.BackSyncProperties.Cast <PropertyDefinition>());
            list.AddRange(SyncSchema.Instance.AllBackSyncShadowBaseProperties.Cast <PropertyDefinition>());
            FullSyncConfiguration.backSyncBaseProperties = list.ToArray();
            list.Add(FullSyncConfiguration.InitialLinkMetadataRangedProperty);
            list.Add(ADRecipientSchema.UsnChanged);
            FullSyncConfiguration.backSyncBasePropertiesPlusLinks = list.ToArray();
        }
        private IEnumerable <ADRawEntry> ReadSoftDeletedObjects()
        {
            if (!this.PageToken.UseContainerizedUsnChangedIndex)
            {
                throw new InvalidOperationException("this.PageToken.UseContainerizedUsnChangedIndex is false");
            }
            ExTraceGlobals.BackSyncTracer.TraceDebug((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration ReadSoftDeletedObjects ...");
            PropertyDefinition[] properties = FullSyncConfiguration.GetPropertyDefinitions(true);
            int sizeLimit = Math.Max(1, FullSyncConfiguration.ObjectsPerPageLimit - base.ReturnedObjectCount);

            ExTraceGlobals.BackSyncTracer.TraceDebug <int>((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration.ReadSoftDeletedObjects sizeLimit = {0}", sizeLimit);
            ADObjectId root = new ADObjectId("OU=Soft Deleted Objects," + base.RecipientSession.SessionSettings.CurrentOrganizationId.OrganizationalUnit.DistinguishedName);

            ADRawEntry[] results;
            if (this.PageToken.SoftDeletedObjectUpdateSequenceNumber == 0L && !this.IsExistsSoftDeletedObjectsOU())
            {
                results = new ADRawEntry[0];
                ExTraceGlobals.BackSyncTracer.TraceDebug((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration.ReadSoftDeletedObjects - Could not find OU=Soft Deleted Objects container. Returning empty page result");
            }
            else
            {
                results = base.RecipientSession.FindADRawEntryByUsnRange(root, this.PageToken.SoftDeletedObjectUpdateSequenceNumber, long.MaxValue, sizeLimit, properties, QueryScope.OneLevel, SyncRecipient.SyncRecipientObjectTypeFilterOptDisabled);
            }
            ExTraceGlobals.BackSyncTracer.TraceDebug <int>((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration.ReadSoftDeletedObjects results count = {0}", (results != null) ? results.Length : 0);
            long startLinkPageUsn    = 0L;
            long endLinkPageUsn      = 0L;
            int  linkPageObjectCount = 0;
            long maxUsnReturned      = long.MaxValue;
            bool returnedAllResults  = true;

            foreach (ADRawEntry entry in results)
            {
                if (!this.ShouldReadMoreData())
                {
                    returnedAllResults = false;
                    break;
                }
                ExTraceGlobals.BackSyncTracer.TraceDebug <ADObjectId>((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration.ReadSoftDeletedObjects entry {0}", entry.Id);
                MultiValuedProperty <LinkMetadata> linkMetadata = (MultiValuedProperty <LinkMetadata>)entry[FullSyncConfiguration.InitialLinkMetadataRangedProperty];
                ExTraceGlobals.BackSyncTracer.TraceDebug <int>((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration.ReadSoftDeletedObjects linkMetadata count = {0}", (linkMetadata != null) ? linkMetadata.Count : 0);
                entry.propertyBag.SetField(ADRecipientSchema.LinkMetadata, linkMetadata);
                long entryUsn = (long)entry[ADRecipientSchema.UsnChanged];
                ExTraceGlobals.BackSyncTracer.TraceDebug <long>((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration.ReadSoftDeletedObjects entryUsn = {0}", entryUsn);
                if (FullSyncConfiguration.NotAllLinksRetrieved(linkMetadata))
                {
                    linkPageObjectCount++;
                    ExTraceGlobals.BackSyncTracer.TraceDebug <int>((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration.ReadSoftDeletedObjects linkPageObjectCount = {0}", linkPageObjectCount);
                    if (startLinkPageUsn == 0L)
                    {
                        startLinkPageUsn = entryUsn;
                        ExTraceGlobals.BackSyncTracer.TraceDebug <long>((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration.ReadSoftDeletedObjects set startLinkPageUsn to {0}", startLinkPageUsn);
                    }
                    endLinkPageUsn = entryUsn;
                    ExTraceGlobals.BackSyncTracer.TraceDebug <long>((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration.ReadSoftDeletedObjects set endLinkPageUsn to {0}", endLinkPageUsn);
                }
                base.ReturnedObjectCount++;
                ExTraceGlobals.BackSyncTracer.TraceDebug <int>((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration.ReadSoftDeletedObjects this.ReturnedObjectCount = {0}", base.ReturnedObjectCount);
                base.ReturnedLinkCount += linkMetadata.Count;
                ExTraceGlobals.BackSyncTracer.TraceDebug <int>((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration.ReadSoftDeletedObjects this.ReturnedLinkCount = {0}", base.ReturnedLinkCount);
                maxUsnReturned = entryUsn;
                ExTraceGlobals.BackSyncTracer.TraceDebug <long>((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration.ReadSoftDeletedObjects maxUsnReturned = {0}", maxUsnReturned);
                this.StampTenantContext(entry);
                ExTraceGlobals.BackSyncTracer.TraceDebug <ADObjectId>((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration.ReadSoftDeletedObjects yield {0}", entry.Id);
                yield return(entry);
            }
            this.PageToken.SoftDeletedObjectUpdateSequenceNumber = ((maxUsnReturned == long.MaxValue) ? long.MaxValue : (maxUsnReturned + 1L));
            ExTraceGlobals.BackSyncTracer.TraceDebug <long>((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration.ReadSoftDeletedObjects set this.PageToken.SoftDeletedObjectUpdateSequenceNumber to {0}", this.PageToken.SoftDeletedObjectUpdateSequenceNumber);
            if (linkPageObjectCount == 0)
            {
                if (results.Length < sizeLimit && returnedAllResults)
                {
                    ExTraceGlobals.BackSyncTracer.TraceDebug((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration.ReadSoftDeletedObjects switch to 'deleted objects' state");
                    this.PageToken.SwitchToEnumerateDeletedObjectsState();
                }
                else
                {
                    ExTraceGlobals.BackSyncTracer.TraceDebug((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration.ReadSoftDeletedObjects do nothing, page token is already up to date");
                }
            }
            else
            {
                ExTraceGlobals.BackSyncTracer.TraceDebug((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration.ReadSoftDeletedObjects switch to enumerate links state");
                this.PageToken.SwitchToEnumerateLinksState(startLinkPageUsn, endLinkPageUsn, linkPageObjectCount);
            }
            yield break;
        }
        private IEnumerable <ADRawEntry> ReadObjects()
        {
            ExTraceGlobals.BackSyncTracer.TraceDebug((long)SyncConfiguration.TraceId, "ObjectFullSyncConfiguration.ReadObjects entering");
            bool includeLinks = SyncConfiguration.InlcudeLinks(this.PageToken.SyncOptions);

            ExTraceGlobals.BackSyncTracer.TraceDebug <bool>((long)SyncConfiguration.TraceId, "ObjectFullSyncConfiguration.ReadObjects includeLinks = {0}", includeLinks);
            PropertyDefinition[] properties = FullSyncConfiguration.GetPropertyDefinitions(includeLinks);
            int objectCount = Math.Min(this.PageToken.ObjectIds.Count, FullSyncConfiguration.ObjectsPerPageLimit);

            ExTraceGlobals.BackSyncTracer.TraceDebug <int>((long)SyncConfiguration.TraceId, "ObjectFullSyncConfiguration.ReadObjects objectCount = {0}", objectCount);
            string[]             externalObjectIds = new string[objectCount];
            IList <SyncObjectId> objectIds         = this.PageToken.ObjectIds.ToList <SyncObjectId>();

            for (int k = 0; k < objectCount; k++)
            {
                externalObjectIds[k] = objectIds[k].ObjectId;
                ExTraceGlobals.BackSyncTracer.TraceDebug <int, string>((long)SyncConfiguration.TraceId, "ObjectFullSyncConfiguration.ReadObjects externalObjectIds[{0}] = \"{1}\"", k, externalObjectIds[k]);
            }
            ExTraceGlobals.BackSyncTracer.TraceDebug((long)SyncConfiguration.TraceId, "ObjectFullSyncConfiguration.ReadObjects FindByExternalDirectoryObjectIds ...");
            Result <ADRawEntry>[] results               = this.FindByExternalDirectoryObjectIds(externalObjectIds, true, properties);
            List <ADRawEntry>     completeEntries       = new List <ADRawEntry>();
            List <ADRawEntry>     deletedEntries        = new List <ADRawEntry>();
            List <ADRawEntry>     pagingRequiredEntries = new List <ADRawEntry>();

            for (int l = 0; l < externalObjectIds.Length; l++)
            {
                ExTraceGlobals.BackSyncTracer.TraceDebug <int, string>((long)SyncConfiguration.TraceId, "ObjectFullSyncConfiguration.ReadObjects externalObjectIds[{0}] = \"{1}\"", l, externalObjectIds[l]);
                if (results[l].Data != null)
                {
                    ADRawEntry data = results[l].Data;
                    ExTraceGlobals.BackSyncTracer.TraceDebug <int, ADObjectId>((long)SyncConfiguration.TraceId, "ObjectFullSyncConfiguration.ReadObjects found entry[{0}] = \"{1}\"", l, data.Id);
                    data.propertyBag.SetField(SyncObjectSchema.SyncObjectId, objectIds[l]);
                    if ((bool)data[SyncObjectSchema.Deleted])
                    {
                        ExTraceGlobals.BackSyncTracer.TraceDebug((long)SyncConfiguration.TraceId, "ObjectFullSyncConfiguration.ReadObjects add entry to deletedEntries");
                        deletedEntries.Add(data);
                    }
                    else
                    {
                        MultiValuedProperty <LinkMetadata> multiValuedProperty = (MultiValuedProperty <LinkMetadata>)data[FullSyncConfiguration.InitialLinkMetadataRangedProperty];
                        data.propertyBag.SetField(ADRecipientSchema.LinkMetadata, multiValuedProperty);
                        if (FullSyncConfiguration.NotAllLinksRetrieved(multiValuedProperty))
                        {
                            ExTraceGlobals.BackSyncTracer.TraceDebug((long)SyncConfiguration.TraceId, "ObjectFullSyncConfiguration.ReadObjects add entry to pagingRequiredEntries");
                            pagingRequiredEntries.Add(data);
                        }
                        else
                        {
                            ExTraceGlobals.BackSyncTracer.TraceDebug((long)SyncConfiguration.TraceId, "ObjectFullSyncConfiguration.ReadObjects add entry to completeEntries");
                            completeEntries.Add(data);
                        }
                    }
                }
                else if (results[l].Error == ProviderError.NotFound)
                {
                    ExTraceGlobals.BackSyncTracer.TraceDebug <int>((long)SyncConfiguration.TraceId, "ObjectFullSyncConfiguration.ReadObjects not found entry[{0}]", l);
                    SyncObjectId syncObjectId = objectIds[l];
                    base.ExcludedObjectReporter.ReportExcludedObject(syncObjectId, DirectoryObjectErrorCode.ObjectNotFound, ProcessingStage.ObjectFullSyncConfiguration);
                    this.PageToken.ObjectIds.Remove(syncObjectId);
                }
            }
            ExTraceGlobals.BackSyncTracer.TraceDebug((long)SyncConfiguration.TraceId, "ObjectFullSyncConfiguration.ReadObjects process deletedEntries ...");
            int i = 0;

            while (i < deletedEntries.Count && this.ShouldReadMoreData())
            {
                ExTraceGlobals.BackSyncTracer.TraceDebug <ADObjectId>((long)SyncConfiguration.TraceId, "ObjectFullSyncConfiguration.ReadObjects remove {0} from this.PageToken.ObjectIds", deletedEntries[i].Id);
                this.PageToken.ObjectIds.Remove((SyncObjectId)deletedEntries[i][SyncObjectSchema.SyncObjectId]);
                base.ReturnedObjectCount++;
                yield return(deletedEntries[i]);

                i++;
            }
            ExTraceGlobals.BackSyncTracer.TraceDebug((long)SyncConfiguration.TraceId, "ObjectFullSyncConfiguration.ReadObjects process completeEntries ...");
            int j = 0;

            while (j < completeEntries.Count && this.ShouldReadMoreData())
            {
                ExTraceGlobals.BackSyncTracer.TraceDebug <ADObjectId>((long)SyncConfiguration.TraceId, "ObjectFullSyncConfiguration.ReadObjects remove {0} from this.PageToken.ObjectIds", completeEntries[j].Id);
                this.PageToken.ObjectIds.Remove((SyncObjectId)completeEntries[j][SyncObjectSchema.SyncObjectId]);
                base.ReturnedObjectCount++;
                base.ReturnedLinkCount += ((MultiValuedProperty <LinkMetadata>)completeEntries[j][FullSyncConfiguration.InitialLinkMetadataRangedProperty]).Count;
                yield return(completeEntries[j]);

                j++;
            }
            if (this.ShouldReadMoreData() && pagingRequiredEntries.Count > 0)
            {
                ExTraceGlobals.BackSyncTracer.TraceDebug((long)SyncConfiguration.TraceId, "ObjectFullSyncConfiguration.ReadObjects read more data ...");
                ADRawEntry linkEntry = pagingRequiredEntries[0];
                ExTraceGlobals.BackSyncTracer.TraceDebug <ADObjectId>((long)SyncConfiguration.TraceId, "ObjectFullSyncConfiguration.ReadObjects linkEntry {0}", linkEntry.Id);
                base.ReturnedObjectCount++;
                MultiValuedProperty <LinkMetadata> metadata = (MultiValuedProperty <LinkMetadata>)linkEntry[FullSyncConfiguration.InitialLinkMetadataRangedProperty];
                LinkMetadata overlapLink = metadata[0];
                base.ReturnedLinkCount += metadata.Count;
                int nextPageLinkRangeStart = metadata.ValueRange.UpperBound - 10 + 1;
                this.PageToken.ObjectCookie = new FullSyncObjectCookie((SyncObjectId)linkEntry[SyncObjectSchema.SyncObjectId], overlapLink, nextPageLinkRangeStart, (long)linkEntry[ADRecipientSchema.UsnChanged], this.PageToken.ServiceInstanceId);
                yield return(linkEntry);
            }
            yield break;
        }