public static TenantRelocationState GetTenantRelocationState(string tenantName, PartitionId partitionId, out bool isSourceTenant, bool readThrough = false) { if (string.IsNullOrEmpty(tenantName)) { throw new ArgumentNullException("tenantName"); } if (!ForestTenantRelocationsCache.IsTenantRelocationAllowed(partitionId.ForestFQDN)) { isSourceTenant = true; return(new TenantRelocationState(partitionId.ForestFQDN, TenantRelocationStatus.NotStarted)); } TenantRelocationStateCache tenantRelocationStateCache = TenantRelocationStateCache.GetInstance(); ExpiringTenantRelocationStateValue expiringTenantRelocationStateValue; if (!tenantRelocationStateCache.tenantRelocationStates.TryGetValue(tenantName, out expiringTenantRelocationStateValue) || expiringTenantRelocationStateValue.Expired || readThrough || TenantRelocationStateCache.IgnoreRelocationTimeConstraints()) { TenantRelocationState tenantRelocationState = TenantRelocationStateCache.LoadTenantRelocationState(tenantName, partitionId); ExTraceGlobals.TenantRelocationTracer.TraceDebug(0L, "TenantRelocationStateCache::GetTenantRelocationState(): Inserting new TenantRelocationState value for tenant {0} to the cache: SourceForestFQDN={1}, SourceForestState={2}, TargetForestFQDN={3}, TargetForestState={4}, TargetOrganizationId={5}", new object[] { tenantName, tenantRelocationState.SourceForestFQDN, tenantRelocationState.SourceForestState, tenantRelocationState.TargetForestFQDN, tenantRelocationState.TargetForestState, (tenantRelocationState.TargetOrganizationId != null) ? tenantRelocationState.TargetOrganizationId.ToString() : "<null>" }); expiringTenantRelocationStateValue = new ExpiringTenantRelocationStateValue(tenantRelocationState); tenantRelocationStateCache.AddOrUpdate(tenantName, expiringTenantRelocationStateValue); } if (expiringTenantRelocationStateValue.Value.TargetOrganizationId == null || expiringTenantRelocationStateValue.Value.TargetOrganizationId.OrganizationalUnit == null) { isSourceTenant = true; } else if (expiringTenantRelocationStateValue.Value.TargetOrganizationId.PartitionId != partitionId) { isSourceTenant = true; } else if (expiringTenantRelocationStateValue.Value.SourceForestFQDN == expiringTenantRelocationStateValue.Value.TargetForestFQDN) { isSourceTenant = (tenantName != expiringTenantRelocationStateValue.Value.TargetOrganizationId.OrganizationalUnit.Name); } else { isSourceTenant = false; } return(expiringTenantRelocationStateValue.Value); }
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); }
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); }