public static bool TryGetTenantRelocationStateByObjectId(ADObjectId identity, out TenantRelocationState state, out bool isSourceTenant)
        {
            ArgumentValidator.ThrowIfNull("identity", identity);
            state          = null;
            isSourceTenant = true;
            PartitionId partitionId = identity.GetPartitionId();

            if (!ForestTenantRelocationsCache.IsTenantRelocationAllowed(partitionId.ForestFQDN))
            {
                return(false);
            }
            ITenantConfigurationSession tenantConfigurationSession = DirectorySessionFactory.Default.CreateTenantConfigurationSession(ConsistencyMode.PartiallyConsistent, ADSessionSettings.FromAllTenantsPartitionId(partitionId), 595, "TryGetTenantRelocationStateByObjectId", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\RelocationCache\\TenantRelocationStateCache.cs");
            ADObjectId configurationUnitsRoot = tenantConfigurationSession.GetConfigurationUnitsRoot();

            if (configurationUnitsRoot.Equals(identity))
            {
                return(false);
            }
            ADObjectId adobjectId = null;

            if (identity.IsDescendantOf(configurationUnitsRoot))
            {
                adobjectId = identity.GetFirstGenerationDecendantOf(configurationUnitsRoot);
            }
            else
            {
                ADObjectId hostedOrganizationsRoot = tenantConfigurationSession.GetHostedOrganizationsRoot();
                if (hostedOrganizationsRoot.Equals(identity))
                {
                    return(false);
                }
                if (identity.IsDescendantOf(hostedOrganizationsRoot))
                {
                    adobjectId = identity.GetFirstGenerationDecendantOf(hostedOrganizationsRoot);
                }
            }
            if (adobjectId == null)
            {
                return(false);
            }
            try
            {
                state = TenantRelocationStateCache.GetTenantRelocationState(adobjectId.Name, partitionId, out isSourceTenant, false);
            }
            catch (CannotResolveTenantNameException)
            {
                return(false);
            }
            return(true);
        }
        public static TimeSpan GetTenantCacheExpirationWindow(string tenantName, PartitionId partitionId)
        {
            TenantRelocationState tenantRelocationState = null;

            try
            {
                bool flag;
                tenantRelocationState = TenantRelocationStateCache.GetTenantRelocationState(tenantName, partitionId, out flag, false);
            }
            catch (CannotResolveTenantNameException)
            {
            }
            if (tenantRelocationState != null)
            {
                return(ExpiringTenantRelocationStateValue.TenantRelocationStateExpirationWindowProvider.GetExpirationWindow(tenantRelocationState));
            }
            return(ExpiringTenantRelocationStateValue.TenantRelocationStateExpirationWindowProvider.DefaultExpirationWindow);
        }
 protected override OrganizationId RehomeScopingOrganizationIdIfNeeded(OrganizationId currentOrganizationId)
 {
     if (currentOrganizationId != null && ADSessionSettings.SessionSettingsFactory.IsTenantScopedOrganization(currentOrganizationId))
     {
         try
         {
             bool flag;
             TenantRelocationState tenantRelocationState = TenantRelocationStateCache.GetTenantRelocationState(currentOrganizationId.OrganizationalUnit.Name, currentOrganizationId.PartitionId, out flag, false);
             if (flag && tenantRelocationState != null && tenantRelocationState.SourceForestState == TenantRelocationStatus.Retired && tenantRelocationState.TargetOrganizationId != null)
             {
                 currentOrganizationId = tenantRelocationState.TargetOrganizationId;
             }
             else if (!flag && tenantRelocationState != null && tenantRelocationState.SourceForestState != TenantRelocationStatus.Retired && tenantRelocationState.OrganizationId != null)
             {
                 currentOrganizationId = tenantRelocationState.OrganizationId;
             }
         }
         catch (CannotResolveTenantNameException)
         {
         }
     }
     return(currentOrganizationId);
 }