コード例 #1
0
        private static TenantRelocationState LoadTenantRelocationState(string tenantName, PartitionId partitionId)
        {
            ITenantConfigurationSession session = DirectorySessionFactory.NonCacheSessionFactory.CreateTenantConfigurationSession(ConsistencyMode.PartiallyConsistent, ADSessionSettings.FromAllTenantsPartitionId(partitionId), 185, "LoadTenantRelocationState", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\RelocationCache\\TenantRelocationStateCache.cs");
            ExchangeConfigurationUnit   exchangeCUAndThrowIfNotFound = TenantRelocationStateCache.GetExchangeCUAndThrowIfNotFound(tenantName, session);

            if (exchangeCUAndThrowIfNotFound.IsCached)
            {
                ExTraceGlobals.TenantRelocationTracer.TraceDebug <string>(0L, "TenantRelocationStateCache::LoadTenantRelocationState(): Tenant {0} found in cache.", tenantName);
                if ((DateTime.UtcNow - exchangeCUAndThrowIfNotFound.WhenReadUTC).Value.TotalSeconds >= 30.0)
                {
                    ITenantConfigurationSession session2 = DirectorySessionFactory.NonCacheSessionFactory.CreateTenantConfigurationSession(ConsistencyMode.PartiallyConsistent, ADSessionSettings.FromAllTenantsPartitionId(partitionId), 203, "LoadTenantRelocationState", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\RelocationCache\\TenantRelocationStateCache.cs");
                    exchangeCUAndThrowIfNotFound = TenantRelocationStateCache.GetExchangeCUAndThrowIfNotFound(tenantName, session2);
                    ITenantConfigurationSession tenantConfigurationSession = DirectorySessionFactory.CacheSessionFactory.CreateTenantConfigurationSession(ConsistencyMode.PartiallyConsistent, ADSessionSettings.FromAllTenantsPartitionId(partitionId), 206, "LoadTenantRelocationState", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\RelocationCache\\TenantRelocationStateCache.cs");
                    tenantConfigurationSession.Delete(exchangeCUAndThrowIfNotFound);
                    tenantConfigurationSession.Save(exchangeCUAndThrowIfNotFound);
                }
            }
            if ((string.IsNullOrEmpty(exchangeCUAndThrowIfNotFound.TargetForest) && string.IsNullOrEmpty(exchangeCUAndThrowIfNotFound.RelocationSourceForestRaw)) || (!string.IsNullOrEmpty(exchangeCUAndThrowIfNotFound.RelocationSourceForestRaw) && exchangeCUAndThrowIfNotFound.RelocationStateRequested == RelocationStateRequested.Cleanup))
            {
                ExTraceGlobals.TenantRelocationTracer.TraceDebug <string, string, bool>(0L, "TenantRelocationStateCache::LoadTenantRelocationState(): Found tenant {0} on DC {1} Cached {2} - not being relocated.", tenantName, exchangeCUAndThrowIfNotFound.OriginatingServer, exchangeCUAndThrowIfNotFound.IsCached);
                return(new TenantRelocationState(partitionId.ForestFQDN, TenantRelocationStatus.NotStarted));
            }
            if (string.IsNullOrEmpty(exchangeCUAndThrowIfNotFound.ExternalDirectoryOrganizationId))
            {
                ExTraceGlobals.TenantRelocationTracer.TraceDebug <string, string, bool>(0L, "TenantRelocationStateCache::LoadTenantRelocationState(): Found tenant {0} on DC {1} Cached {2} - prepared for deletion.", tenantName, exchangeCUAndThrowIfNotFound.OriginatingServer, exchangeCUAndThrowIfNotFound.IsCached);
                TenantRelocationStatus sourceForestState;
                if (!string.IsNullOrEmpty(exchangeCUAndThrowIfNotFound.TargetForest))
                {
                    sourceForestState = exchangeCUAndThrowIfNotFound.RelocationStatus;
                }
                else
                {
                    sourceForestState = TenantRelocationStatus.NotStarted;
                }
                return(new TenantRelocationState(partitionId.ForestFQDN, sourceForestState));
            }
            if (!string.IsNullOrEmpty(exchangeCUAndThrowIfNotFound.TargetForest))
            {
                TenantRelocationRequest tenantRelocationRequest;
                Exception ex;
                TenantRelocationRequest.LoadOtherForestObjectInternal(null, exchangeCUAndThrowIfNotFound.TargetForest, exchangeCUAndThrowIfNotFound.DistinguishedName, exchangeCUAndThrowIfNotFound.ExternalDirectoryOrganizationId, true, out tenantRelocationRequest, out ex);
                if (ex != null && !(ex is CannotFindTargetTenantException))
                {
                    throw ex;
                }
                ExTraceGlobals.TenantRelocationTracer.TraceDebug <string, string>(0L, "TenantRelocationStateCache::LoadTenantRelocationState(): Found tenant {0} on DC {1} - this is relocation source.", tenantName, (tenantRelocationRequest != null) ? tenantRelocationRequest.OriginatingServer : "<unknown>");
                return(new TenantRelocationState(partitionId.ForestFQDN, exchangeCUAndThrowIfNotFound.RelocationStatus, exchangeCUAndThrowIfNotFound.TargetForest, (RelocationStatusDetailsDestination)((tenantRelocationRequest != null) ? tenantRelocationRequest.RelocationStatusDetailsRaw : RelocationStatusDetails.NotStarted), exchangeCUAndThrowIfNotFound.OrganizationId, (tenantRelocationRequest != null) ? tenantRelocationRequest.OrganizationId : null));
            }
            else
            {
                Exception ex;
                TenantRelocationRequest tenantRelocationRequest2;
                TenantRelocationRequest.LoadOtherForestObjectInternal(null, exchangeCUAndThrowIfNotFound.RelocationSourceForestRaw, exchangeCUAndThrowIfNotFound.DistinguishedName, exchangeCUAndThrowIfNotFound.ExternalDirectoryOrganizationId, false, out tenantRelocationRequest2, out ex);
                if (ex == null)
                {
                    ExTraceGlobals.TenantRelocationTracer.TraceDebug(0L, string.Format("TenantRelocationStateCache::LoadTenantRelocationState(): Found tenant {0} on DC {1} - this is relocation target.", tenantName, (tenantRelocationRequest2 != null) ? tenantRelocationRequest2.OriginatingServer : "<unknown>"));
                    return(new TenantRelocationState(exchangeCUAndThrowIfNotFound.RelocationSourceForestRaw, (tenantRelocationRequest2 != null) ? tenantRelocationRequest2.RelocationStatus : TenantRelocationStatus.NotStarted, partitionId.ForestFQDN, (RelocationStatusDetailsDestination)exchangeCUAndThrowIfNotFound.RelocationStatusDetailsSource, (tenantRelocationRequest2 != null) ? tenantRelocationRequest2.OrganizationId : null, exchangeCUAndThrowIfNotFound.OrganizationId));
                }
                if (ex is CannotFindTargetTenantException)
                {
                    return(new TenantRelocationState(partitionId.ForestFQDN, TenantRelocationStatus.NotStarted));
                }
                throw ex;
            }
        }