예제 #1
0
 private static void UpdateMiniServerIntoCache(MiniServer miniServer)
 {
     ServersCache.ServerInfo serverInfo = null;
     if (miniServer != null)
     {
         try
         {
             ServersCache.CacheLockForServersDictionary.EnterWriteLock();
             serverInfo = new ServersCache.ServerInfo(DateTime.UtcNow, miniServer);
             ServersCache.ServersDictionary[miniServer.Fqdn] = serverInfo;
         }
         finally
         {
             ServersCache.CacheLockForServersDictionary.ExitWriteLock();
         }
         ADObjectId serverSite = miniServer.ServerSite;
         if (!ServersCache.IsLocalSite(serverSite))
         {
             try
             {
                 ServersCache.CacheLockForSiteToServersDictionary.EnterWriteLock();
                 if (ServersCache.SiteToServersDictionary.ContainsKey(serverSite))
                 {
                     ServersCache.UpdateServerInfoInList(ServersCache.SiteToServersDictionary[serverSite], serverInfo);
                 }
                 else
                 {
                     List <ServersCache.ServerInfo> list = new List <ServersCache.ServerInfo>();
                     list.Add(serverInfo);
                     ServersCache.SiteToServersDictionary[serverSite] = list;
                 }
             }
             finally
             {
                 ServersCache.CacheLockForSiteToServersDictionary.ExitWriteLock();
             }
         }
     }
 }
예제 #2
0
 private static void UpdateServerInfoInList(List <ServersCache.ServerInfo> list, ServersCache.ServerInfo serverInfo)
 {
     if (list != null || list.Count > 0)
     {
         int num = list.FindIndex((ServersCache.ServerInfo x) => string.Compare(x.MiniServer.Fqdn, serverInfo.MiniServer.Fqdn, true) == 0);
         if (num != -1)
         {
             list.RemoveAt(num);
         }
         list.Insert(0, serverInfo);
     }
 }
예제 #3
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);
        }