Example #1
0
		private void GetAdjacentSites()
		{
			ActiveDirectoryTransportType activeDirectoryTransportType;
			DirectoryEntry directoryEntry = DirectoryEntryManager.GetDirectoryEntry(this.context, WellKnownDN.RootDSE);
			string item = (string)directoryEntry.Properties["configurationNamingContext"][0];
			string str = string.Concat("CN=Inter-Site Transports,CN=Sites,", item);
			directoryEntry = DirectoryEntryManager.GetDirectoryEntry(this.context, str);
			string[] strArrays = new string[2];
			strArrays[0] = "cn";
			strArrays[1] = "distinguishedName";
			ADSearcher aDSearcher = new ADSearcher(directoryEntry, string.Concat("(&(objectClass=siteLink)(objectCategory=SiteLink)(siteList=", Utils.GetEscapedFilterValue((string)PropertyManager.GetPropertyValue(this.context, this.cachedEntry, PropertyManager.DistinguishedName)), "))"), strArrays, SearchScope.Subtree);
			SearchResultCollection searchResultCollections = null;
			try
			{
				searchResultCollections = aDSearcher.FindAll();
			}
			catch (COMException cOMException1)
			{
				COMException cOMException = cOMException1;
				throw ExceptionHelper.GetExceptionFromCOMException(this.context, cOMException);
			}
			try
			{
				ActiveDirectorySiteLink activeDirectorySiteLink = null;
				foreach (SearchResult searchResult in searchResultCollections)
				{
					string searchResultPropertyValue = (string)PropertyManager.GetSearchResultPropertyValue(searchResult, PropertyManager.DistinguishedName);
					string searchResultPropertyValue1 = (string)PropertyManager.GetSearchResultPropertyValue(searchResult, PropertyManager.Cn);
					string value = Utils.GetDNComponents(searchResultPropertyValue)[1].Value;
					if (string.Compare(value, "IP", StringComparison.OrdinalIgnoreCase) != 0)
					{
						if (string.Compare(value, "SMTP", StringComparison.OrdinalIgnoreCase) != 0)
						{
							object[] objArray = new object[1];
							objArray[0] = value;
							string str1 = Res.GetString("UnknownTransport", objArray);
							throw new ActiveDirectoryOperationException(str1);
						}
						else
						{
							activeDirectoryTransportType = ActiveDirectoryTransportType.Smtp;
						}
					}
					else
					{
						activeDirectoryTransportType = ActiveDirectoryTransportType.Rpc;
					}
					try
					{
						activeDirectorySiteLink = new ActiveDirectorySiteLink(this.context, searchResultPropertyValue1, activeDirectoryTransportType, true, searchResult.GetDirectoryEntry());
						foreach (ActiveDirectorySite site in activeDirectorySiteLink.Sites)
						{
							if (Utils.Compare(site.Name, this.Name) == 0 || this.adjacentSites.Contains(site))
							{
								continue;
							}
							this.adjacentSites.Add(site);
						}
					}
					finally
					{
						activeDirectorySiteLink.Dispose();
					}
				}
			}
			finally
			{
				searchResultCollections.Dispose();
				directoryEntry.Dispose();
			}
		}
Example #2
0
        private void GetAdjacentSites()
        {
            DirectoryEntry de = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
            string config = (string)de.Properties["configurationNamingContext"][0];
            string transportContainer = "CN=Inter-Site Transports,CN=Sites," + config;
            de = DirectoryEntryManager.GetDirectoryEntry(context, transportContainer);
            ADSearcher adSearcher = new ADSearcher(de,
                                                  "(&(objectClass=siteLink)(objectCategory=SiteLink)(siteList=" + Utils.GetEscapedFilterValue((string)PropertyManager.GetPropertyValue(context, cachedEntry, PropertyManager.DistinguishedName)) + "))",
                                                  new string[] { "cn", "distinguishedName" },
                                                  SearchScope.Subtree);
            SearchResultCollection results = null;

            try
            {
                results = adSearcher.FindAll();
            }
            catch (COMException e)
            {
                throw ExceptionHelper.GetExceptionFromCOMException(context, e);
            }

            try
            {
                ActiveDirectorySiteLink link = null;

                foreach (SearchResult result in results)
                {
                    string dn = (string)PropertyManager.GetSearchResultPropertyValue(result, PropertyManager.DistinguishedName);
                    string linkName = (string)PropertyManager.GetSearchResultPropertyValue(result, PropertyManager.Cn);
                    string transportName = (string)Utils.GetDNComponents(dn)[1].Value;
                    ActiveDirectoryTransportType transportType;
                    if (String.Compare(transportName, "IP", StringComparison.OrdinalIgnoreCase) == 0)
                        transportType = ActiveDirectoryTransportType.Rpc;
                    else if (String.Compare(transportName, "SMTP", StringComparison.OrdinalIgnoreCase) == 0)
                        transportType = ActiveDirectoryTransportType.Smtp;
                    else
                    {
                        // should not happen
                        string message = Res.GetString(Res.UnknownTransport, transportName);
                        throw new ActiveDirectoryOperationException(message);
                    }

                    try
                    {
                        link = new ActiveDirectorySiteLink(context, linkName, transportType, true, result.GetDirectoryEntry());
                        foreach (ActiveDirectorySite tmpSite in link.Sites)
                        {
                            // don't add itself                            
                            if (Utils.Compare(tmpSite.Name, Name) == 0)
                                continue;

                            if (!_adjacentSites.Contains(tmpSite))
                                _adjacentSites.Add(tmpSite);
                        }
                    }
                    finally
                    {
                        link.Dispose();
                    }
                }
            }
            finally
            {
                results.Dispose();
                de.Dispose();
            }
        }