Ejemplo n.º 1
0
        private static MiniServer GetAnyBackEndServer(int versionNumber, bool needsExactVersionMatch)
        {
            MiniServer miniServer = null;

            try
            {
                miniServer = ServersCache.GetDeterministicBackEndServerForASite(versionNumber, null, needsExactVersionMatch, null);
            }
            catch (ServerHasNotBeenFoundException)
            {
            }
            if (miniServer != null)
            {
                return(miniServer);
            }
            try
            {
                ServersCache.CacheLockForServersDictionary.EnterReadLock();
                miniServer = ServersCache.FindMiniServerInListWithoutAffinity(ServersCache.ServersDictionary.Values.ToList <ServersCache.ServerInfo>(), versionNumber, needsExactVersionMatch);
            }
            finally
            {
                ServersCache.CacheLockForServersDictionary.ExitReadLock();
            }
            if (miniServer != null)
            {
                return(miniServer);
            }
            MiniServer oneMailboxServerForASite = ServersCache.GetOneMailboxServerForASite(null, versionNumber, needsExactVersionMatch);

            ServersCache.UpdateMiniServerIntoCache(oneMailboxServerForASite);
            return(oneMailboxServerForASite);
        }
Ejemplo n.º 2
0
        private static MiniServer GetDeterministicBackEndServerForASite(int versionNumber, string identifier, bool needsExactVersionMatch = false, ADObjectId adSiteId = null)
        {
            ADObjectId adobjectId = (adSiteId != null) ? adSiteId : ServersCache.LocalSiteId;
            bool       flag       = ServersCache.IsLocalSite(adobjectId);
            MiniServer miniServer = ServersCache.FindAndReturnMiniServerFromCacheForASite(adobjectId, versionNumber, identifier, needsExactVersionMatch);

            if (miniServer != null)
            {
                return(miniServer);
            }
            if (flag)
            {
                if (ServersCache.SiteToServersDictionary.ContainsKey(adobjectId) && DateTime.UtcNow - ServersCache.LastRefreshTimeForLocalSiteCache <= ServersCache.RefreshInterval)
                {
                    throw new ServerHasNotBeenFoundException(versionNumber, identifier, needsExactVersionMatch, adobjectId.Name);
                }
                lock (ServersCache.LockForLocalSiteDiscovery)
                {
                    if (ServersCache.SiteToServersDictionary.ContainsKey(adobjectId) && DateTime.UtcNow - ServersCache.LastRefreshTimeForLocalSiteCache <= ServersCache.RefreshInterval)
                    {
                        MiniServer miniServer2 = ServersCache.FindAndReturnMiniServerFromCacheForASite(adobjectId, versionNumber, identifier, needsExactVersionMatch);
                        if (miniServer2 == null)
                        {
                            ServersCache.Tracer.TraceError(0L, "ServersCache: No server with the version number {0}, identifier '{1}', needsExactVersionMatch {2} and siteId.Name {3} in the cache for local site.", new object[]
                            {
                                versionNumber,
                                identifier,
                                needsExactVersionMatch,
                                adobjectId.Name
                            });
                        }
                        return(miniServer2);
                    }
                    ADPagedReader <MiniServer>     adpagedReader = ServersCache.ReadLocalSiteMailboxServers();
                    List <ServersCache.ServerInfo> list          = null;
                    if (adpagedReader == null)
                    {
                        throw new ServerHasNotBeenFoundException(versionNumber, identifier, needsExactVersionMatch, adobjectId.Name);
                    }
                    list = new List <ServersCache.ServerInfo>();
                    foreach (MiniServer miniServer3 in adpagedReader)
                    {
                        ServersCache.ServerInfo item = new ServersCache.ServerInfo(DateTime.UtcNow, miniServer3);
                        list.Add(item);
                    }
                    try
                    {
                        ServersCache.CacheLockForServersDictionary.EnterWriteLock();
                        foreach (ServersCache.ServerInfo serverInfo in list)
                        {
                            ServersCache.ServersDictionary[serverInfo.MiniServer.Fqdn] = serverInfo;
                        }
                    }
                    finally
                    {
                        ServersCache.CacheLockForServersDictionary.ExitWriteLock();
                    }
                    if (list.Count == 0)
                    {
                        throw new ServerHasNotBeenFoundException(versionNumber, identifier, needsExactVersionMatch, adobjectId.Name);
                    }
                    ServersCache.LastRefreshTimeForLocalSiteCache = DateTime.UtcNow;
                    try
                    {
                        ServersCache.CacheLockForSiteToServersDictionary.EnterWriteLock();
                        ServersCache.SiteToServersDictionary[adobjectId] = list;
                    }
                    finally
                    {
                        ServersCache.CacheLockForSiteToServersDictionary.ExitWriteLock();
                    }
                    MiniServer miniServer4 = ServersCache.FindAndReturnMiniServerFromCacheForASite(adobjectId, versionNumber, identifier, needsExactVersionMatch);
                    if (miniServer4 == null)
                    {
                        throw new ServerHasNotBeenFoundException(versionNumber, identifier, needsExactVersionMatch, adobjectId.Name);
                    }
                    return(miniServer4);
                }
            }
            MiniServer oneMailboxServerForASite = ServersCache.GetOneMailboxServerForASite(adobjectId, versionNumber, needsExactVersionMatch);

            ServersCache.UpdateMiniServerIntoCache(oneMailboxServerForASite);
            return(oneMailboxServerForASite);
        }