internal static Guid GetPreferredDCWithContainerizedUsnChanged(string serviceInstanceName)
        {
            if (!SyncConfiguration.EnableContainerizedUsnChangedOptimization())
            {
                throw new InvalidOperationException("SyncConfiguration.EnableContainerizedUsnChangedOptimization() == false");
            }
            if (serviceInstanceName == null)
            {
                throw new ArgumentNullException("serviceInstanceName");
            }
            string text = serviceInstanceName.ToLowerInvariant() + "_PreferredContainerizedUsnChangedDC";
            string configurationValue = SyncConfiguration.GetConfigurationValue <string>(text, null);

            if (configurationValue != null)
            {
                List <Guid> list = new List <Guid>();
                foreach (string text2 in configurationValue.Split(new char[]
                {
                    ','
                }))
                {
                    Guid item;
                    if (Guid.TryParse(text2, out item))
                    {
                        list.Add(item);
                        ExTraceGlobals.BackSyncTracer.TraceDebug <string, string>((long)SyncConfiguration.TraceId, "GetPreferredDCWithContainerizedUsnChanged Adding a valid DC invocation id: {0} for service instance {1}.", text2, serviceInstanceName);
                    }
                    else
                    {
                        ExTraceGlobals.BackSyncTracer.TraceDebug <string, string>((long)SyncConfiguration.TraceId, "GetPreferredDCWithContainerizedUsnChanged Invalid DC invocation id: {0} defined for service instance {1}. Skipping it.", text2, serviceInstanceName);
                    }
                }
                if (list.Count > 0)
                {
                    Random random = new Random();
                    return(list.ElementAt(random.Next(list.Count)));
                }
                ExTraceGlobals.BackSyncTracer.TraceDebug <string>((long)SyncConfiguration.TraceId, "GetPreferredDCWithContainerizedUsnChanged - Found no valid DC invocation ids for service instance: {0}", serviceInstanceName);
            }
            else
            {
                ExTraceGlobals.BackSyncTracer.TraceDebug <string>((long)SyncConfiguration.TraceId, "GetPreferredDCWithContainerizedUsnChanged - RegistryValue: {0} is null", text);
            }
            return(Guid.Empty);
        }
 public TenantFullSyncPageToken(Guid invocationId, Guid tenantExternalDirectoryId, ADObjectId tenantOuId, ServiceInstanceId serviceInstanceId, bool useDirSyncBasedTfs = false)
 {
     ExTraceGlobals.TenantFullSyncTracer.TraceDebug((long)this.TenantExternalDirectoryId.GetHashCode(), "New TenantFullSyncPageToken");
     this.Version = 3;
     ExTraceGlobals.TenantFullSyncTracer.TraceDebug <int>((long)this.TenantExternalDirectoryId.GetHashCode(), "TenantFullSyncPageToken this.Version = {0}", this.Version);
     this.TenantExternalDirectoryId = tenantExternalDirectoryId;
     ExTraceGlobals.TenantFullSyncTracer.TraceDebug <Guid>((long)this.TenantExternalDirectoryId.GetHashCode(), "TenantFullSyncPageToken this.TenantExternalDirectoryId = {0}", this.TenantExternalDirectoryId);
     this.TenantObjectGuid = tenantOuId.ObjectGuid;
     ExTraceGlobals.TenantFullSyncTracer.TraceDebug <Guid>((long)this.TenantExternalDirectoryId.GetHashCode(), "TenantFullSyncPageToken this.TenantObjectGuid = {0}", this.TenantObjectGuid);
     this.State = TenantFullSyncState.EnumerateLiveObjects;
     ExTraceGlobals.TenantFullSyncTracer.TraceDebug <string>((long)this.TenantExternalDirectoryId.GetHashCode(), "TenantFullSyncPageToken this.State = {0}", this.State.ToString());
     this.ServiceInstanceId = serviceInstanceId;
     ExTraceGlobals.TenantFullSyncTracer.TraceDebug <ServiceInstanceId>((long)this.TenantExternalDirectoryId.GetHashCode(), "TenantFullSyncPageToken this.ServiceInstanceId = {0}", this.ServiceInstanceId);
     this.ErrorObjectsAndFailureCounts = new Dictionary <string, int>();
     this.SequenceId             = Guid.NewGuid();
     this.SequenceStartTimestamp = DateTime.UtcNow;
     ExTraceGlobals.TenantFullSyncTracer.TraceDebug <Guid, DateTime>((long)this.TenantExternalDirectoryId.GetHashCode(), "TenantFullSyncPageToken Starting a new sequence this.SequenceId = {0} this.SequenceStartTimestamp = {1} ", this.SequenceId, this.SequenceStartTimestamp);
     this.TenantScopedBackSyncCookie = (useDirSyncBasedTfs ? new BackSyncCookie(this.ServiceInstanceId) : null);
     this.InvocationId = (useDirSyncBasedTfs ? this.TenantScopedBackSyncCookie.InvocationId : invocationId);
     ExTraceGlobals.TenantFullSyncTracer.TraceDebug <Guid>((long)this.TenantExternalDirectoryId.GetHashCode(), "TenantFullSyncPageToken this.InvocationId = {0}", this.InvocationId);
     this.UseContainerizedUsnChangedIndex = false;
     if (SyncConfiguration.EnableContainerizedUsnChangedOptimization())
     {
         Guid preferredDCWithContainerizedUsnChanged = SyncConfiguration.GetPreferredDCWithContainerizedUsnChanged(this.ServiceInstanceId.InstanceId);
         if (preferredDCWithContainerizedUsnChanged != Guid.Empty)
         {
             this.InvocationId = preferredDCWithContainerizedUsnChanged;
             this.UseContainerizedUsnChangedIndex = true;
             ExTraceGlobals.TenantFullSyncTracer.TraceDebug <Guid>((long)this.TenantExternalDirectoryId.GetHashCode(), "TenantFullSyncPageToken overwriting this.InvocationId = {0} and this.UseContainerizedUsnChangedIndex = true", this.InvocationId);
         }
         else
         {
             ExTraceGlobals.TenantFullSyncTracer.TraceDebug <ServiceInstanceId>((long)this.TenantExternalDirectoryId.GetHashCode(), "TenantFullSyncPageToken: Could not find preferred DC for service instance {0}. Containerized USN index will NOT be used.", this.ServiceInstanceId);
         }
     }
     if (this.UseContainerizedUsnChangedIndex && useDirSyncBasedTfs)
     {
         throw new InvalidOperationException("Invalid configuration - cannot use Containerized UsnChanged Index and Dirsync based TFS simultaneously.");
     }
     if (this.UseContainerizedUsnChangedIndex)
     {
         this.PreviousState = this.State;
     }
 }