private static List <ADObjectId> GetMasterServerIdsForDatabase(IFindAdObject <IADDatabaseAvailabilityGroup> dagLookup, IADDatabase database, out Exception exception) { IADToplogyConfigurationSession adSession = dagLookup.AdSession; List <ADObjectId> list = new List <ADObjectId>(16); exception = null; try { ADObjectId masterServerOrAvailabilityGroup = database.MasterServerOrAvailabilityGroup; if (masterServerOrAvailabilityGroup == null) { return(null); } if (masterServerOrAvailabilityGroup.IsDeleted) { ActiveManagerUtil.Tracer.TraceError <string, string>(0L, "GetMasterServerIdsForDatabase() for database '{0}' found the MasterServerOrAvailabilityGroup to be a link to a deleted object. Returning an empty collection. MasterServerOrAvailabilityGroup = [{1}]", database.Name, masterServerOrAvailabilityGroup.Name); return(null); } IADDatabaseAvailabilityGroup iaddatabaseAvailabilityGroup = dagLookup.ReadAdObjectByObjectId(masterServerOrAvailabilityGroup); if (iaddatabaseAvailabilityGroup != null) { list.AddRange(iaddatabaseAvailabilityGroup.Servers); } else { IADDatabase iaddatabase = adSession.ReadADObject <IADDatabase>(database.Id); ADObjectId adobjectId = null; if (iaddatabase != null) { adobjectId = iaddatabase.MasterServerOrAvailabilityGroup; if (!masterServerOrAvailabilityGroup.Equals(adobjectId)) { ActiveManagerUtil.Tracer.TraceDebug <ADObjectId, ADObjectId>(0L, "GetMasterServerIdsForDatabase() re-read the Database object and it made a difference. MasterServerOrDag was {0} and is now {1}", masterServerOrAvailabilityGroup, adobjectId); iaddatabaseAvailabilityGroup = adSession.ReadADObject <IADDatabaseAvailabilityGroup>(adobjectId); if (iaddatabaseAvailabilityGroup == null) { goto IL_165; } HashSet <string> hashSet = new HashSet <string>(StringComparer.OrdinalIgnoreCase); foreach (string fqdn in iaddatabaseAvailabilityGroup.StoppedMailboxServers) { hashSet.Add(MachineName.GetNodeNameFromFqdn(fqdn)); } using (MultiValuedProperty <ADObjectId> .Enumerator enumerator2 = iaddatabaseAvailabilityGroup.Servers.GetEnumerator()) { while (enumerator2.MoveNext()) { ADObjectId adobjectId2 = enumerator2.Current; if (!hashSet.Contains(adobjectId2.Name)) { list.Add(adobjectId2); } } goto IL_165; } } ActiveManagerUtil.Tracer.TraceDebug <ADObjectId>(0L, "GetMasterServerIdsForDatabase: re-reading the Database object made no difference. MasterServerOrDag is still {0}.", masterServerOrAvailabilityGroup); } IL_165: if (iaddatabaseAvailabilityGroup == null && adobjectId != null) { IADServer iadserver = adSession.ReadMiniServer(adobjectId); if (iadserver != null) { list.Add(adobjectId); } } } } catch (DataValidationException ex) { exception = ex; } catch (ADTransientException ex2) { exception = ex2; } catch (ADOperationException ex3) { exception = ex3; } catch (ADTopologyUnexpectedException ex4) { exception = ex4; } catch (ADTopologyPermanentException ex5) { exception = ex5; } if (exception != null) { ActiveManagerUtil.Tracer.TraceDebug <Exception>(0L, "GetMasterServerIdsForDatabase() got exception: {0}", exception); list = null; } return(list); }