static TenantRelocationSyncConfiguration() { TenantRelocationSyncConfiguration.InitializeConfigurableSettings(); TenantRelocationSyncConfiguration.InitialLinkMetadataRangedProperty = RangedPropertyHelper.CreateRangedProperty(ADRecipientSchema.LinkMetadata, new IntRange(0, TenantRelocationSyncConfiguration.InitialLinkReadSize - 1)); TenantRelocationSyncConfiguration.BaseProperties = new List <PropertyDefinition>(TenantRelocationSyncConfiguration.PropertyDefinitionsForDeletedObjects) { TenantRelocationSyncConfiguration.InitialLinkMetadataRangedProperty, TenantRelocationSyncSchema.AllAttributes, ADRecipientSchema.UsnChanged, OrganizationSchema.SupportedSharedConfigurations }.ToArray(); }
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(); }
internal static MultiValuedProperty <ADObjectId> GetLinks(ADPropertyDefinition propertyDefinition, bool deleted, SearchResultAttributeCollection attributeCollection, List <ADPropertyDefinition> rangedProperties, List <ValidationError> errors) { int num = deleted ? 0 : 1; IntRange range = new IntRange(num, num); ADPropertyDefinition adpropertyDefinition = new ADPropertyDefinition(propertyDefinition.Name, propertyDefinition.VersionAdded, typeof(ADObjectId), propertyDefinition.LdapDisplayName, propertyDefinition.Flags | ADPropertyDefinitionFlags.MultiValued, propertyDefinition.DefaultValue, PropertyDefinitionConstraint.None, PropertyDefinitionConstraint.None, null, null); adpropertyDefinition = RangedPropertyHelper.CreateRangedProperty(adpropertyDefinition, range); DirectoryAttribute directoryAttribute = attributeCollection[adpropertyDefinition.LdapDisplayName]; if (directoryAttribute != null) { return(ADValueConvertor.GetValueFromDirectoryAttribute(null, directoryAttribute, adpropertyDefinition, true, rangedProperties, null, errors, null, false) as MultiValuedProperty <ADObjectId>); } return(null); }
private IEnumerable <ADRawEntry> ReadLinks() { ExTraceGlobals.BackSyncTracer.TraceDebug((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration.ReadLinks ..."); int numberOfLinksToRead = Math.Max(0, FullSyncConfiguration.LinksPerPageLimit - base.ReturnedLinkCount) / this.PageToken.ObjectsInLinkPage; ExTraceGlobals.BackSyncTracer.TraceDebug <int>((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration.ReadLinks numberOfLinksToRead = {0}", numberOfLinksToRead); if (numberOfLinksToRead > 0) { List <PropertyDefinition> properties = new List <PropertyDefinition>(); int rangeStart = this.PageToken.LinkRangeStart; ExTraceGlobals.BackSyncTracer.TraceDebug <int>((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration.ReadLinks rangeStart = {0}", rangeStart); int rangeEnd = rangeStart + numberOfLinksToRead - 1; ExTraceGlobals.BackSyncTracer.TraceDebug <int>((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration.ReadLinks rangeEnd = {0}", rangeEnd); ADPropertyDefinition linkMetadataRangedProperty = RangedPropertyHelper.CreateRangedProperty(ADRecipientSchema.LinkMetadata, new IntRange(rangeStart, rangeEnd)); properties.Add(linkMetadataRangedProperty); properties.Add(ADRecipientSchema.UsnChanged); properties.AddRange(SyncObject.FullSyncLinkPageBackSyncProperties.Cast <PropertyDefinition>()); ADObjectId root; if (this.PageToken.UseContainerizedUsnChangedIndex && this.PageToken.PreviousState == TenantFullSyncState.EnumerateSoftDeletedObjects) { root = new ADObjectId("OU=Soft Deleted Objects," + base.RecipientSession.SessionSettings.CurrentOrganizationId.OrganizationalUnit.DistinguishedName); } else { root = base.RecipientSession.SessionSettings.CurrentOrganizationId.OrganizationalUnit; } ADRawEntry[] results = base.RecipientSession.FindADRawEntryByUsnRange(root, this.PageToken.LinkPageStart, this.PageToken.LinkPageEnd, 0, properties, this.PageToken.UseContainerizedUsnChangedIndex ? QueryScope.OneLevel : QueryScope.SubTree, this.PageToken.UseContainerizedUsnChangedIndex ? SyncRecipient.SyncRecipientObjectTypeFilterOptDisabled : SyncRecipient.SyncRecipientObjectTypeFilter); ExTraceGlobals.BackSyncTracer.TraceDebug <int>((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration.ReadLinks results count = {0}", results.Length); List <ADRawEntry> entriesWithMoreLinks = new List <ADRawEntry>(results.Length); foreach (ADRawEntry entry in results) { ExTraceGlobals.BackSyncTracer.TraceDebug <ADObjectId>((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration.ReadLinks entry {0}", entry.Id); MultiValuedProperty <LinkMetadata> metadata = (MultiValuedProperty <LinkMetadata>)entry[linkMetadataRangedProperty]; entry.propertyBag.SetField(ADRecipientSchema.LinkMetadata, metadata); if (metadata.ValueRange == null) { ExTraceGlobals.BackSyncTracer.TraceDebug((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration.ReadLinks entry has no links. Skip it."); } else { if (metadata.ValueRange.UpperBound != 2147483647) { ExTraceGlobals.BackSyncTracer.TraceDebug <int>((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration.ReadLinks add entry to entriesWithMoreLinks (count = {0})", entriesWithMoreLinks.Count); entriesWithMoreLinks.Add(entry); } base.ReturnedLinkCount += metadata.Count; ExTraceGlobals.BackSyncTracer.TraceDebug <int>((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration.ReadLinks this.ReturnedLinkCount = {0}", base.ReturnedLinkCount); this.StampTenantContext(entry); yield return(entry); } } if (entriesWithMoreLinks.Count == 0) { if (this.PageToken.UseContainerizedUsnChangedIndex && this.PageToken.PreviousState == TenantFullSyncState.EnumerateSoftDeletedObjects) { this.PageToken.SwitchToEnumerateSoftDeletedObjectsState(); ExTraceGlobals.BackSyncTracer.TraceDebug((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration.ReadLinks done enumerating links on this page, switch back to enumerate soft-deleted objects state"); } else { this.PageToken.SwitchToEnumerateLiveObjectsState(); ExTraceGlobals.BackSyncTracer.TraceDebug((long)SyncConfiguration.TraceId, "TenantFullSyncConfiguration.ReadLinks done enumerating links on this page, switch back to live objects state"); } } else { long linkPageStart = (long)entriesWithMoreLinks[0][ADRecipientSchema.UsnChanged]; long linkPageEnd = (long)entriesWithMoreLinks[entriesWithMoreLinks.Count - 1][ADRecipientSchema.UsnChanged]; this.PageToken.UpdateEnumerateLinksState(linkPageStart, linkPageEnd, rangeEnd + 1, entriesWithMoreLinks.Count); } } yield break; }
private ADRawEntry ReadNextLinkPage() { ExTraceGlobals.BackSyncTracer.TraceDebug((long)SyncConfiguration.TraceId, "ObjectFullSyncConfiguration.ReadNextLinkPage entering"); SyncObjectId objectId = this.PageToken.ObjectCookie.ObjectId; if (this.PageToken.ObjectCookie.ReadRestartsCount > 10) { if (base.EventLogger != null) { base.EventLogger.LogTooManyObjectReadRestartsEvent(objectId.ToString(), 10); } ExTraceGlobals.BackSyncTracer.TraceDebug <string>((long)SyncConfiguration.TraceId, "ObjectFullSyncConfiguration.ReadNextLinkPage TooManyObjectReadRestarts {0}", objectId.ToString()); base.ExcludedObjectReporter.ReportExcludedObject(objectId, DirectoryObjectErrorCode.Busy, ProcessingStage.ObjectFullSyncConfiguration); this.PageToken.RemoveObjectFromList(objectId, true); return(null); } int num = Math.Max(0, FullSyncConfiguration.LinksPerPageLimit - base.ReturnedLinkCount); if (num <= 10) { return(null); } List <PropertyDefinition> list = new List <PropertyDefinition>(); int linkRangeStart = this.PageToken.ObjectCookie.LinkRangeStart; ExTraceGlobals.BackSyncTracer.TraceDebug <int>((long)SyncConfiguration.TraceId, "ObjectFullSyncConfiguration.ReadNextLinkPage this.PageToken.ObjectCookie.LinkRangeStart = {0}", this.PageToken.ObjectCookie.LinkRangeStart); ADPropertyDefinition adpropertyDefinition = RangedPropertyHelper.CreateRangedProperty(ADRecipientSchema.LinkMetadata, new IntRange(linkRangeStart, linkRangeStart + num - 1)); list.Add(adpropertyDefinition); list.Add(ADRecipientSchema.UsnChanged); bool flag = !this.PageToken.ObjectCookie.EnumerateLinks; if (flag) { list.AddRange(SyncSchema.Instance.AllBackSyncBaseProperties.Cast <PropertyDefinition>()); list.AddRange(SyncObject.BackSyncProperties.Cast <PropertyDefinition>()); } else { list.AddRange(SyncObject.FullSyncLinkPageBackSyncProperties.Cast <PropertyDefinition>()); } ExTraceGlobals.BackSyncTracer.TraceDebug <string>((long)SyncConfiguration.TraceId, "ObjectFullSyncConfiguration.ReadNextLinkPage objectId.ObjectId = {0}", objectId.ObjectId); string[] externalObjectIds = new string[] { objectId.ObjectId }; Result <ADRawEntry>[] array = this.FindByExternalDirectoryObjectIds(externalObjectIds, true, list.ToArray()); Result <ADRawEntry> result = array[0]; if (result.Data != null) { ADRawEntry data = result.Data; ExTraceGlobals.BackSyncTracer.TraceDebug <ADObjectId>((long)SyncConfiguration.TraceId, "ObjectFullSyncConfiguration.ReadNextLinkPage entry = {0}", data.Id); long num2 = (long)data[ADRecipientSchema.UsnChanged]; ExTraceGlobals.BackSyncTracer.TraceDebug <long>((long)SyncConfiguration.TraceId, "ObjectFullSyncConfiguration.ReadNextLinkPage usnChanged = {0}", num2); MultiValuedProperty <LinkMetadata> multiValuedProperty = (MultiValuedProperty <LinkMetadata>)data[adpropertyDefinition]; if (!flag) { if (num2 != this.PageToken.ObjectCookie.UsnChanged) { ExTraceGlobals.BackSyncTracer.TraceDebug <long>((long)SyncConfiguration.TraceId, "ObjectFullSyncConfiguration.ReadNextLinkPage RestartObjectReadAfterObjectChange usnChanged = {0}", num2); this.PageToken.ObjectCookie.RestartObjectReadAfterObjectChange(num2); return(null); } if (this.PageToken.ObjectCookie.LinkRangeStart > 0 && !this.CheckLinkOverlap(multiValuedProperty)) { ExTraceGlobals.BackSyncTracer.TraceDebug((long)SyncConfiguration.TraceId, "ObjectFullSyncConfiguration.ReadNextLinkPage RestartObjectReadAfterTargetLinksChange"); this.PageToken.ObjectCookie.RestartObjectReadAfterTargetLinksChange(); return(null); } } result.Data.propertyBag.SetField(ADRecipientSchema.LinkMetadata, multiValuedProperty); LinkMetadata overlapLink = multiValuedProperty[0]; base.ReturnedLinkCount += multiValuedProperty.Count; if (multiValuedProperty.ValueRange != null) { if (multiValuedProperty.ValueRange.UpperBound == 2147483647) { this.PageToken.RemoveObjectFromList(objectId, true); ExTraceGlobals.BackSyncTracer.TraceDebug((long)SyncConfiguration.TraceId, "ObjectFullSyncConfiguration.ReadNextLinkPage last link page read"); } else { int num3 = multiValuedProperty.ValueRange.UpperBound - 10 + 1; ExTraceGlobals.BackSyncTracer.TraceDebug <int>((long)SyncConfiguration.TraceId, "ObjectFullSyncConfiguration.ReadNextLinkPage set this.PageToken.nextLinkPageRangeStart to {0}", num3); this.PageToken.ObjectCookie.SetNextPageData(objectId, overlapLink, num3, (long)result.Data[ADRecipientSchema.UsnChanged]); } } else { this.PageToken.RemoveObjectFromList(objectId, true); ExTraceGlobals.BackSyncTracer.TraceDebug <string>((long)SyncConfiguration.TraceId, "ObjectFullSyncConfiguration.ReadNextLinkPage this.PageToken.RemoveObjectFromList objectId = {0}", objectId.ObjectId); } return(result.Data); } ExTraceGlobals.BackSyncTracer.TraceDebug((long)SyncConfiguration.TraceId, "ObjectFullSyncConfiguration.ReadNextLinkPage FindByExternalDirectoryObjectIds returned no data."); this.PageToken.ObjectCookie.RestartObjectRead(false); return(null); }
private IEnumerable <ADRawEntry> ReadSpecialObjects() { ADObjectId exchangeServiceObject = base.RootOrgConfigurationSession.ConfigurationNamingContext.GetChildId("Services").GetChildId("Microsoft Exchange"); int numberOfLinksToRead = 1500; int rangeStart = 0; int rangeEnd = rangeStart + numberOfLinksToRead - 1; ADPropertyDefinition[] propertiesToRetrieve = new ADPropertyDefinition[] { ADObjectSchema.Id }; ADObjectId configUnitDn = new ADObjectId(this.PageToken.TenantConfigUnitObjectGuid); ADRawEntry dnResolve = base.TenantConfigurationSession.ReadADRawEntry(configUnitDn, propertiesToRetrieve); configUnitDn = dnResolve.Id; ExTraceGlobals.TenantRelocationTracer.TraceDebug <ADObjectId>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration.ReadSpecialObjects tenant CU DN = {0}", configUnitDn); MultiValuedProperty <LinkMetadata> resultValues = new MultiValuedProperty <LinkMetadata>(); ADRawEntry entry = null; long maxEntryUSN = 0L; bool done = false; while (!done) { ADPropertyDefinition adpropertyDefinition = RangedPropertyHelper.CreateRangedProperty(ADRecipientSchema.LinkMetadata, new IntRange(rangeStart, rangeEnd)); List <PropertyDefinition> list = new List <PropertyDefinition>(); list.Add(adpropertyDefinition); list.Add(ADRecipientSchema.UsnChanged); entry = base.RootOrgConfigurationSession.RetrieveTenantRelocationSyncObject(exchangeServiceObject, list); ExTraceGlobals.TenantRelocationTracer.TraceDebug <string>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration.ReadSpecialObjects object read: {0}", entry.Id.DistinguishedName); if ((long)entry[ADRecipientSchema.UsnChanged] < this.PageToken.SpecialObjectsUSN) { ExTraceGlobals.TenantRelocationTracer.TraceDebug <object, long>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration.ReadSpecialObjects USNChanged({0} < this.PageToken.SpecialObjectsUSN({1})", entry[ADRecipientSchema.UsnChanged], this.PageToken.SpecialObjectsUSN); break; } MultiValuedProperty <LinkMetadata> multiValuedProperty = (MultiValuedProperty <LinkMetadata>)entry[adpropertyDefinition]; foreach (LinkMetadata linkMetadata in multiValuedProperty) { if (linkMetadata.LocalUpdateSequenceNumber >= this.PageToken.SpecialObjectsUSN) { ADObjectId adobjectId = new ADObjectId(linkMetadata.TargetDistinguishedName); if (adobjectId.IsDescendantOf(configUnitDn)) { ExTraceGlobals.TenantRelocationTracer.TraceDebug <string, long>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration.ReadSpecialObjects valid link found: {0}, USN={1}", linkMetadata.TargetDistinguishedName, linkMetadata.LocalUpdateSequenceNumber); if (linkMetadata.LocalUpdateSequenceNumber > maxEntryUSN) { maxEntryUSN = linkMetadata.LocalUpdateSequenceNumber; } resultValues.Add(linkMetadata); } } } if (multiValuedProperty.ValueRange != null && multiValuedProperty.ValueRange.UpperBound != 2147483647) { rangeStart += numberOfLinksToRead; rangeEnd = rangeStart + numberOfLinksToRead - 1; ExTraceGlobals.TenantRelocationTracer.TraceDebug <int, int>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration.ReadSpecialObjects retrieve next page: rangeStart={0}, rangeEnd={1}", rangeStart, rangeEnd); } else { done = true; ExTraceGlobals.TenantRelocationTracer.TraceDebug((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration.ReadSpecialObjects page retrieval ends"); } } this.PageToken.SpecialObjectsUSN = ((maxEntryUSN == 0L) ? long.MaxValue : (maxEntryUSN + 1L)); ExTraceGlobals.TenantRelocationTracer.TraceDebug <long>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration.ReadSpecialObjects SpecialObjectsUSN is set to {0}", this.PageToken.SpecialObjectsUSN); ExTraceGlobals.TenantRelocationTracer.TraceDebug <int>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration.ReadSpecialObjects Number of values found = {0}", resultValues.Count); if (resultValues.Count > 0) { ADPropertyBag propertyBag = new ADPropertyBag(); propertyBag.SetField(ADObjectSchema.Id, entry.Id); propertyBag.SetField(ADRecipientSchema.UsnChanged, entry[ADRecipientSchema.UsnChanged]); propertyBag.SetField(ADRecipientSchema.LinkMetadata, resultValues); propertyBag.SetField(SyncObjectSchema.Deleted, false); TenantRelocationSyncObject specialObject = new TenantRelocationSyncObject(propertyBag, new DirectoryAttribute[0]); yield return(specialObject); } yield break; }