示例#1
0
 public int IndexOf(ActiveDirectorySiteLink link)
 {
     if (link != null)
     {
         string propertyValue = (string)PropertyManager.GetPropertyValue(link.context, link.cachedEntry, PropertyManager.DistinguishedName);
         int    num           = 0;
         while (num < base.InnerList.Count)
         {
             ActiveDirectorySiteLink item = (ActiveDirectorySiteLink)base.InnerList[num];
             string str = (string)PropertyManager.GetPropertyValue(item.context, item.cachedEntry, PropertyManager.DistinguishedName);
             if (Utils.Compare(str, propertyValue) != 0)
             {
                 num++;
             }
             else
             {
                 return(num);
             }
         }
         return(-1);
     }
     else
     {
         throw new ArgumentNullException("link");
     }
 }
        public bool Contains(ActiveDirectorySiteLink link)
        {
            if (link == null)
            {
                throw new ArgumentNullException("link");
            }

            if (!link.existing)
            {
                throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, SR.SiteLinkNotCommitted, link.Name));
            }

            string dn = (string)PropertyManager.GetPropertyValue(link.context, link.cachedEntry, PropertyManager.DistinguishedName);

            for (int i = 0; i < InnerList.Count; i++)
            {
                ActiveDirectorySiteLink tmp = (ActiveDirectorySiteLink)InnerList[i];
                string tmpDn = (string)PropertyManager.GetPropertyValue(tmp.context, tmp.cachedEntry, PropertyManager.DistinguishedName);

                if (Utils.Compare(tmpDn, dn) == 0)
                {
                    return(true);
                }
            }
            return(false);
        }
        private void GetLinks()
        {
            ArrayList arrayLists = new ArrayList();

            NativeComInterfaces.IAdsPathname pathname = (NativeComInterfaces.IAdsPathname)(new NativeComInterfaces.Pathname());
            pathname.EscapedMode = 4;
            string str = "siteLinkList";

            arrayLists.Add(str);
            Hashtable valuesWithRangeRetrieval = Utils.GetValuesWithRangeRetrieval(this.cachedEntry, "(objectClass=*)", arrayLists, SearchScope.Base);
            ArrayList item = (ArrayList)valuesWithRangeRetrieval[str.ToLower(CultureInfo.InvariantCulture)];

            if (item != null)
            {
                for (int i = 0; i < item.Count; i++)
                {
                    string item1 = (string)item[i];
                    pathname.Set(item1, 4);
                    string str1 = pathname.Retrieve(11);
                    str1 = str1.Substring(3);
                    DirectoryEntry          directoryEntry          = DirectoryEntryManager.GetDirectoryEntry(this.context, item1);
                    ActiveDirectorySiteLink activeDirectorySiteLink = new ActiveDirectorySiteLink(this.context, str1, this.transport, true, directoryEntry);
                    this.links.Add(activeDirectorySiteLink);
                }
                return;
            }
            else
            {
                return;
            }
        }
        public int IndexOf(ActiveDirectorySiteLink link)
        {
            if (link == null)
            {
                throw new ArgumentNullException("link");
            }

            if (!link.existing)
            {
                throw new InvalidOperationException(Res.GetString(Res.SiteLinkNotCommitted, link.Name));
            }

            string dn = (string)PropertyManager.GetPropertyValue(link.context, link.cachedEntry, PropertyManager.DistinguishedName);

            for (int i = 0; i < InnerList.Count; i++)
            {
                ActiveDirectorySiteLink tmp = (ActiveDirectorySiteLink)InnerList[i];
                string tmpDn = (string)PropertyManager.GetPropertyValue(tmp.context, tmp.cachedEntry, PropertyManager.DistinguishedName);

                if (Utils.Compare(tmpDn, dn) == 0)
                {
                    return(i);
                }
            }
            return(-1);
        }
 public int IndexOf(ActiveDirectorySiteLink link)
 {
     if (link != null)
     {
         if (link.existing)
         {
             string propertyValue = (string)PropertyManager.GetPropertyValue(link.context, link.cachedEntry, PropertyManager.DistinguishedName);
             int    num           = 0;
             while (num < base.InnerList.Count)
             {
                 ActiveDirectorySiteLink item = (ActiveDirectorySiteLink)base.InnerList[num];
                 string str = (string)PropertyManager.GetPropertyValue(item.context, item.cachedEntry, PropertyManager.DistinguishedName);
                 if (Utils.Compare(str, propertyValue) != 0)
                 {
                     num++;
                 }
                 else
                 {
                     return(num);
                 }
             }
             return(-1);
         }
         else
         {
             object[] name = new object[1];
             name[0] = link.Name;
             throw new InvalidOperationException(Res.GetString("SiteLinkNotCommitted", name));
         }
     }
     else
     {
         throw new ArgumentNullException("link");
     }
 }
        public ActiveDirectorySiteLink this[int index]
        {
            get
            {
                return((ActiveDirectorySiteLink)InnerList[index]);
            }
            set
            {
                ActiveDirectorySiteLink link = (ActiveDirectorySiteLink)value;

                if (link == null)
                {
                    throw new ArgumentNullException("value");
                }

                if (!link.existing)
                {
                    throw new InvalidOperationException(Res.GetString(Res.SiteLinkNotCommitted, link.Name));
                }

                if (!Contains(link))
                {
                    List[index] = link;
                }
                else
                {
                    throw new ArgumentException(Res.GetString(Res.AlreadyExistingInCollection, link), "value");
                }
            }
        }
        public void Remove(ActiveDirectorySiteLink link)
        {
            if (link == null)
            {
                throw new ArgumentNullException("link");
            }

            if (!link.existing)
            {
                throw new InvalidOperationException(Res.GetString(Res.SiteLinkNotCommitted, link.Name));
            }

            string dn = (string)PropertyManager.GetPropertyValue(link.context, link.cachedEntry, PropertyManager.DistinguishedName);

            for (int i = 0; i < InnerList.Count; i++)
            {
                ActiveDirectorySiteLink tmp = (ActiveDirectorySiteLink)InnerList[i];
                string tmpDn = (string)PropertyManager.GetPropertyValue(tmp.context, tmp.cachedEntry, PropertyManager.DistinguishedName);

                if (Utils.Compare(tmpDn, dn) == 0)
                {
                    List.Remove(tmp);
                    return;
                }
            }

            // something that does not exist in the collectio
            throw new ArgumentException(Res.GetString(Res.NotFoundInCollection, link), "link");
        }
 public int Add(ActiveDirectorySiteLink link)
 {
     if (link != null)
     {
         if (link.existing)
         {
             if (this.Contains(link))
             {
                 object[] objArray = new object[1];
                 objArray[0] = link;
                 throw new ArgumentException(Res.GetString("AlreadyExistingInCollection", objArray), "link");
             }
             else
             {
                 return(base.List.Add(link));
             }
         }
         else
         {
             object[] name = new object[1];
             name[0] = link.Name;
             throw new InvalidOperationException(Res.GetString("SiteLinkNotCommitted", name));
         }
     }
     else
     {
         throw new ArgumentNullException("link");
     }
 }
        private void GetLinks()
        {
            ArrayList propertyList = new ArrayList();

            NativeComInterfaces.IAdsPathname?pathCracker = null;
            pathCracker = (NativeComInterfaces.IAdsPathname) new NativeComInterfaces.Pathname();
            // need to turn off the escaping for name
            pathCracker.EscapedMode = NativeComInterfaces.ADS_ESCAPEDMODE_OFF_EX;
            string propertyName = "siteLinkList";

            propertyList.Add(propertyName);
            Hashtable values        = Utils.GetValuesWithRangeRetrieval(cachedEntry !, "(objectClass=*)", propertyList, SearchScope.Base);
            ArrayList siteLinkLists = (ArrayList)values[propertyName.ToLowerInvariant()] !;

            // somehow no site link list
            if (siteLinkLists == null)
            {
                return;
            }

            // construct the site link object
            for (int i = 0; i < siteLinkLists.Count; i++)
            {
                string dn = (string)siteLinkLists[i] !;
                // escaping manipulation
                pathCracker.Set(dn, NativeComInterfaces.ADS_SETTYPE_DN);
                string rdn = pathCracker.Retrieve(NativeComInterfaces.ADS_FORMAT_LEAF);
                Debug.Assert(rdn != null && Utils.Compare(rdn, 0, 3, "CN=", 0, 3) == 0);
                rdn = rdn.Substring(3);
                DirectoryEntry          entry = DirectoryEntryManager.GetDirectoryEntry(context, dn);
                ActiveDirectorySiteLink link  = new ActiveDirectorySiteLink(context, rdn, _transport, true, entry);

                _links.Add(link);
            }
        }
		public int Add(ActiveDirectorySiteLink link)
		{
			if (link != null)
			{
				if (link.existing)
				{
					if (this.Contains(link))
					{
						object[] objArray = new object[1];
						objArray[0] = link;
						throw new ArgumentException(Res.GetString("AlreadyExistingInCollection", objArray), "link");
					}
					else
					{
						return base.List.Add(link);
					}
				}
				else
				{
					object[] name = new object[1];
					name[0] = link.Name;
					throw new InvalidOperationException(Res.GetString("SiteLinkNotCommitted", name));
				}
			}
			else
			{
				throw new ArgumentNullException("link");
			}
		}
        private void GetLinks()
        {
            ArrayList propertiesToLoad = new ArrayList();

            NativeComInterfaces.IAdsPathname pathname = null;
            pathname             = (NativeComInterfaces.IAdsPathname) new NativeComInterfaces.Pathname();
            pathname.EscapedMode = 4;
            string str = "siteLinkList";

            propertiesToLoad.Add(str);
            ArrayList list2 = (ArrayList)Utils.GetValuesWithRangeRetrieval(this.cachedEntry, "(objectClass=*)", propertiesToLoad, 0)[str.ToLower(CultureInfo.InvariantCulture)];

            if (list2 != null)
            {
                for (int i = 0; i < list2.Count; i++)
                {
                    string bstrADsPath = (string)list2[i];
                    pathname.Set(bstrADsPath, 4);
                    string                  siteLinkName   = pathname.Retrieve(11).Substring(3);
                    DirectoryEntry          directoryEntry = DirectoryEntryManager.GetDirectoryEntry(this.context, bstrADsPath);
                    ActiveDirectorySiteLink link           = new ActiveDirectorySiteLink(this.context, siteLinkName, this.transport, true, directoryEntry);
                    this.links.Add(link);
                }
            }
        }
示例#12
0
		public int IndexOf(ActiveDirectorySiteLink link)
		{
			if (link != null)
			{
				string propertyValue = (string)PropertyManager.GetPropertyValue(link.context, link.cachedEntry, PropertyManager.DistinguishedName);
				int num = 0;
				while (num < base.InnerList.Count)
				{
					ActiveDirectorySiteLink item = (ActiveDirectorySiteLink)base.InnerList[num];
					string str = (string)PropertyManager.GetPropertyValue(item.context, item.cachedEntry, PropertyManager.DistinguishedName);
					if (Utils.Compare(str, propertyValue) != 0)
					{
						num++;
					}
					else
					{
						return num;
					}
				}
				return -1;
			}
			else
			{
				throw new ArgumentNullException("link");
			}
		}
        public static ActiveDirectorySiteLink FindByName(DirectoryContext context, string siteLinkName, ActiveDirectoryTransportType transport)
        {
            DirectoryEntry          directoryEntry;
            ActiveDirectorySiteLink link2;

            ValidateArgument(context, siteLinkName, transport);
            context = new DirectoryContext(context);
            try
            {
                directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
                string str = (string)PropertyManager.GetPropertyValue(context, directoryEntry, PropertyManager.ConfigurationNamingContext);
                string dn  = "CN=Inter-Site Transports,CN=Sites," + str;
                if (transport == ActiveDirectoryTransportType.Rpc)
                {
                    dn = "CN=IP," + dn;
                }
                else
                {
                    dn = "CN=SMTP," + dn;
                }
                directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, dn);
            }
            catch (COMException exception)
            {
                throw ExceptionHelper.GetExceptionFromCOMException(context, exception);
            }
            catch (ActiveDirectoryObjectNotFoundException)
            {
                throw new ActiveDirectoryOperationException(Res.GetString("ADAMInstanceNotFoundInConfigSet", new object[] { context.Name }));
            }
            try
            {
                SearchResult result = new ADSearcher(directoryEntry, "(&(objectClass=siteLink)(objectCategory=SiteLink)(name=" + Utils.GetEscapedFilterValue(siteLinkName) + "))", new string[] { "distinguishedName" }, SearchScope.OneLevel, false, false).FindOne();
                if (result == null)
                {
                    Exception exception2 = new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ActiveDirectorySiteLink), siteLinkName);
                    throw exception2;
                }
                DirectoryEntry entry = result.GetDirectoryEntry();
                link2 = new ActiveDirectorySiteLink(context, siteLinkName, transport, true, entry);
            }
            catch (COMException exception3)
            {
                if (exception3.ErrorCode != -2147016656)
                {
                    throw ExceptionHelper.GetExceptionFromCOMException(context, exception3);
                }
                if (Utils.CheckCapability(DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE), Capability.ActiveDirectoryApplicationMode) && (transport == ActiveDirectoryTransportType.Smtp))
                {
                    throw new NotSupportedException(Res.GetString("NotSupportTransportSMTP"));
                }
                throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ActiveDirectorySiteLink), siteLinkName);
            }
            finally
            {
                directoryEntry.Dispose();
            }
            return(link2);
        }
        public void AddRange(ActiveDirectorySiteLink[] links)
        {
            if (links == null)
                throw new ArgumentNullException("links");

            for (int i = 0; i < links.Length; i = i + 1)
                this.Add(links[i]);
        }
    public int IndexOf(ActiveDirectorySiteLink link)
    {
      Contract.Requires(link != null);
      Contract.Ensures(Contract.Result<int>() >= -1);
      Contract.Ensures(Contract.Result<int>() < this.Count);

      return default(int);
    }
        public int IndexOf(ActiveDirectorySiteLink link)
        {
            Contract.Requires(link != null);
            Contract.Ensures(Contract.Result <int>() >= -1);
            Contract.Ensures(Contract.Result <int>() < this.Count);

            return(default(int));
        }
        public int Add(ActiveDirectorySiteLink link)
        {
            if (link == null)
                throw new ArgumentNullException("link");

            if (!link.existing)
                throw new InvalidOperationException(Res.GetString(Res.SiteLinkNotCommitted, link.Name));

            if (!Contains(link))
                return List.Add(link);
            else
                throw new ArgumentException(Res.GetString(Res.AlreadyExistingInCollection, link), "link");
        }
        protected override void OnSetComplete(int index, object oldValue, object newValue)
        {
            ActiveDirectorySiteLink newLink = (ActiveDirectorySiteLink)newValue;
            string newdn = (string)PropertyManager.GetPropertyValue(newLink.context, newLink.cachedEntry, PropertyManager.DistinguishedName);

            try
            {
                de.Properties["siteLinkList"][index] = newdn;
            }
            catch (COMException e)
            {
                throw ExceptionHelper.GetExceptionFromCOMException(context, e);
            }
        }
        protected override void OnRemoveComplete(int index, object value)
        {
            ActiveDirectorySiteLink link = (ActiveDirectorySiteLink)value;
            string dn = (string)PropertyManager.GetPropertyValue(link.context, link.cachedEntry, PropertyManager.DistinguishedName);

            try
            {
                de.Properties["siteLinkList"].Remove(dn);
            }
            catch (COMException e)
            {
                throw ExceptionHelper.GetExceptionFromCOMException(context, e);
            }
        }
        protected override void OnSetComplete(int index, object oldValue, object newValue)
        {
            ActiveDirectorySiteLink activeDirectorySiteLink = (ActiveDirectorySiteLink)newValue;
            string propertyValue = (string)PropertyManager.GetPropertyValue(activeDirectorySiteLink.context, activeDirectorySiteLink.cachedEntry, PropertyManager.DistinguishedName);

            try
            {
                this.de.Properties["siteLinkList"][index] = propertyValue;
            }
            catch (COMException cOMException1)
            {
                COMException cOMException = cOMException1;
                throw ExceptionHelper.GetExceptionFromCOMException(this.context, cOMException);
            }
        }
 public int Add(ActiveDirectorySiteLink link)
 {
     if (link == null)
     {
         throw new ArgumentNullException("link");
     }
     if (!link.existing)
     {
         throw new InvalidOperationException(Res.GetString("SiteLinkNotCommitted", new object[] { link.Name }));
     }
     if (this.Contains(link))
     {
         throw new ArgumentException(Res.GetString("AlreadyExistingInCollection", new object[] { link }), "link");
     }
     return(base.List.Add(link));
 }
 public void Insert(int index, ActiveDirectorySiteLink link)
 {
     if (link == null)
     {
         throw new ArgumentNullException("value");
     }
     if (!link.existing)
     {
         throw new InvalidOperationException(Res.GetString("SiteLinkNotCommitted", new object[] { link.Name }));
     }
     if (this.Contains(link))
     {
         throw new ArgumentException(Res.GetString("AlreadyExistingInCollection", new object[] { link }), "link");
     }
     base.List.Insert(index, link);
 }
 protected override void OnInsertComplete(int index, object value)
 {
     if (this.initialized)
     {
         ActiveDirectorySiteLink link = (ActiveDirectorySiteLink)value;
         string str = (string)PropertyManager.GetPropertyValue(link.context, link.cachedEntry, PropertyManager.DistinguishedName);
         try
         {
             this.de.Properties["siteLinkList"].Add(str);
         }
         catch (COMException exception)
         {
             throw ExceptionHelper.GetExceptionFromCOMException(this.context, exception);
         }
     }
 }
 public int IndexOf(ActiveDirectorySiteLink link)
 {
     if (link == null)
     {
         throw new ArgumentNullException("link");
     }
     string str = (string) PropertyManager.GetPropertyValue(link.context, link.cachedEntry, PropertyManager.DistinguishedName);
     for (int i = 0; i < base.InnerList.Count; i++)
     {
         ActiveDirectorySiteLink link2 = (ActiveDirectorySiteLink) base.InnerList[i];
         string str2 = (string) PropertyManager.GetPropertyValue(link2.context, link2.cachedEntry, PropertyManager.DistinguishedName);
         if (Utils.Compare(str2, str) == 0)
         {
             return i;
         }
     }
     return -1;
 }
示例#25
0
        public int IndexOf(ActiveDirectorySiteLink link)
        {
            if (link == null)
            {
                throw new ArgumentNullException("link");
            }
            string str = (string)PropertyManager.GetPropertyValue(link.context, link.cachedEntry, PropertyManager.DistinguishedName);

            for (int i = 0; i < base.InnerList.Count; i++)
            {
                ActiveDirectorySiteLink link2 = (ActiveDirectorySiteLink)base.InnerList[i];
                string str2 = (string)PropertyManager.GetPropertyValue(link2.context, link2.cachedEntry, PropertyManager.DistinguishedName);
                if (Utils.Compare(str2, str) == 0)
                {
                    return(i);
                }
            }
            return(-1);
        }
        public int IndexOf(ActiveDirectorySiteLink link)
        {
            if (link == null)
                throw new ArgumentNullException("link");

            string dn = (string)PropertyManager.GetPropertyValue(link.context, link.cachedEntry, PropertyManager.DistinguishedName);

            for (int i = 0; i < InnerList.Count; i++)
            {
                ActiveDirectorySiteLink tmp = (ActiveDirectorySiteLink)InnerList[i];
                string tmpDn = (string)PropertyManager.GetPropertyValue(tmp.context, tmp.cachedEntry, PropertyManager.DistinguishedName);

                if (Utils.Compare(tmpDn, dn) == 0)
                {
                    return i;
                }
            }
            return -1;
        }
示例#27
0
        public bool Contains(ActiveDirectorySiteLink link)
        {
            if (link == null)
            {
                throw new ArgumentNullException("link");
            }

            string dn = (string)PropertyManager.GetPropertyValue(link.context, link.cachedEntry, PropertyManager.DistinguishedName);

            for (int i = 0; i < InnerList.Count; i++)
            {
                ActiveDirectorySiteLink tmp = (ActiveDirectorySiteLink)InnerList[i];
                string tmpDn = (string)PropertyManager.GetPropertyValue(tmp.context, tmp.cachedEntry, PropertyManager.DistinguishedName);

                if (Utils.Compare(tmpDn, dn) == 0)
                {
                    return(true);
                }
            }
            return(false);
        }
        public void Insert(int index, ActiveDirectorySiteLink link)
        {
            if (link == null)
            {
                throw new ArgumentNullException("value");
            }

            if (!link.existing)
            {
                throw new InvalidOperationException(Res.GetString(Res.SiteLinkNotCommitted, link.Name));
            }

            if (!Contains(link))
            {
                List.Insert(index, link);
            }
            else
            {
                throw new ArgumentException(Res.GetString(Res.AlreadyExistingInCollection, link), "link");
            }
        }
        public int Add(ActiveDirectorySiteLink link)
        {
            if (link == null)
            {
                throw new ArgumentNullException("link");
            }

            if (!link.existing)
            {
                throw new InvalidOperationException(Res.GetString(Res.SiteLinkNotCommitted, link.Name));
            }

            if (!Contains(link))
            {
                return(List.Add(link));
            }
            else
            {
                throw new ArgumentException(Res.GetString(Res.AlreadyExistingInCollection, link), "link");
            }
        }
        public bool Contains(ActiveDirectorySiteLink link)
        {
            if (link == null)
                throw new ArgumentNullException("link");

            if (!link.existing)
                throw new InvalidOperationException(Res.GetString(Res.SiteLinkNotCommitted, link.Name));

            string dn = (string)PropertyManager.GetPropertyValue(link.context, link.cachedEntry, PropertyManager.DistinguishedName);

            for (int i = 0; i < InnerList.Count; i++)
            {
                ActiveDirectorySiteLink tmp = (ActiveDirectorySiteLink)InnerList[i];
                string tmpDn = (string)PropertyManager.GetPropertyValue(tmp.context, tmp.cachedEntry, PropertyManager.DistinguishedName);

                if (Utils.Compare(tmpDn, dn) == 0)
                {
                    return true;
                }
            }
            return false;
        }
 public ActiveDirectorySiteLink this[int index]
 {
     get
     {
         return((ActiveDirectorySiteLink)base.InnerList[index]);
     }
     set
     {
         ActiveDirectorySiteLink activeDirectorySiteLink = value;
         if (activeDirectorySiteLink != null)
         {
             if (activeDirectorySiteLink.existing)
             {
                 if (this.Contains(activeDirectorySiteLink))
                 {
                     object[] objArray = new object[1];
                     objArray[0] = activeDirectorySiteLink;
                     throw new ArgumentException(Res.GetString("AlreadyExistingInCollection", objArray), "value");
                 }
                 else
                 {
                     base.List[index] = activeDirectorySiteLink;
                     return;
                 }
             }
             else
             {
                 object[] name = new object[1];
                 name[0] = activeDirectorySiteLink.Name;
                 throw new InvalidOperationException(Res.GetString("SiteLinkNotCommitted", name));
             }
         }
         else
         {
             throw new ArgumentNullException("value");
         }
     }
 }
        public int IndexOf(ActiveDirectorySiteLink link)
        {
            if (link == null)
            {
                throw new ArgumentNullException("link");
            }
            if (!link.existing)
            {
                throw new InvalidOperationException(Res.GetString("SiteLinkNotCommitted", new object[] { link.Name }));
            }
            string str = (string)PropertyManager.GetPropertyValue(link.context, link.cachedEntry, PropertyManager.DistinguishedName);

            for (int i = 0; i < base.InnerList.Count; i++)
            {
                ActiveDirectorySiteLink link2 = (ActiveDirectorySiteLink)base.InnerList[i];
                string str2 = (string)PropertyManager.GetPropertyValue(link2.context, link2.cachedEntry, PropertyManager.DistinguishedName);
                if (Utils.Compare(str2, str) == 0)
                {
                    return(i);
                }
            }
            return(-1);
        }
 public ActiveDirectorySiteLink this[int index]
 {
     get
     {
         return((ActiveDirectorySiteLink)base.InnerList[index]);
     }
     set
     {
         ActiveDirectorySiteLink link = value;
         if (link == null)
         {
             throw new ArgumentNullException("value");
         }
         if (!link.existing)
         {
             throw new InvalidOperationException(Res.GetString("SiteLinkNotCommitted", new object[] { link.Name }));
         }
         if (this.Contains(link))
         {
             throw new ArgumentException(Res.GetString("AlreadyExistingInCollection", new object[] { link }), "value");
         }
         base.List[index] = link;
     }
 }
 private void GetLinks()
 {
     ArrayList propertiesToLoad = new ArrayList();
     NativeComInterfaces.IAdsPathname pathname = null;
     pathname = (NativeComInterfaces.IAdsPathname) new NativeComInterfaces.Pathname();
     pathname.EscapedMode = 4;
     string str = "siteLinkList";
     propertiesToLoad.Add(str);
     ArrayList list2 = (ArrayList) Utils.GetValuesWithRangeRetrieval(this.cachedEntry, "(objectClass=*)", propertiesToLoad, 0)[str.ToLower(CultureInfo.InvariantCulture)];
     if (list2 != null)
     {
         for (int i = 0; i < list2.Count; i++)
         {
             string bstrADsPath = (string) list2[i];
             pathname.Set(bstrADsPath, 4);
             string siteLinkName = pathname.Retrieve(11).Substring(3);
             DirectoryEntry directoryEntry = DirectoryEntryManager.GetDirectoryEntry(this.context, bstrADsPath);
             ActiveDirectorySiteLink link = new ActiveDirectorySiteLink(this.context, siteLinkName, this.transport, true, directoryEntry);
             this.links.Add(link);
         }
     }
 }
		public void AddRange (ActiveDirectorySiteLink[] links)
		{
			throw new NotImplementedException ();
		}
		public void CopyTo (ActiveDirectorySiteLink[] array, int index)
		{
			throw new NotImplementedException ();
		}
		public void Insert (int index, ActiveDirectorySiteLink link)
		{
			throw new NotImplementedException ();
		}
示例#38
0
		public static ActiveDirectorySiteLink FindByName(DirectoryContext context, string siteLinkName, ActiveDirectoryTransportType transport)
		{
			DirectoryEntry directoryEntry;
			ActiveDirectorySiteLink activeDirectorySiteLink;
			ActiveDirectorySiteLink.ValidateArgument(context, siteLinkName, transport);
			context = new DirectoryContext(context);
			try
			{
				directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
				string propertyValue = (string)PropertyManager.GetPropertyValue(context, directoryEntry, PropertyManager.ConfigurationNamingContext);
				string str = string.Concat("CN=Inter-Site Transports,CN=Sites,", propertyValue);
				if (transport != ActiveDirectoryTransportType.Rpc)
				{
					str = string.Concat("CN=SMTP,", str);
				}
				else
				{
					str = string.Concat("CN=IP,", str);
				}
				directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, str);
			}
			catch (COMException cOMException1)
			{
				COMException cOMException = cOMException1;
				throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException);
			}
			catch (ActiveDirectoryObjectNotFoundException activeDirectoryObjectNotFoundException)
			{
				object[] name = new object[1];
				name[0] = context.Name;
				throw new ActiveDirectoryOperationException(Res.GetString("ADAMInstanceNotFoundInConfigSet", name));
			}
			try
			{
				try
				{
					string[] strArrays = new string[1];
					strArrays[0] = "distinguishedName";
					ADSearcher aDSearcher = new ADSearcher(directoryEntry, string.Concat("(&(objectClass=siteLink)(objectCategory=SiteLink)(name=", Utils.GetEscapedFilterValue(siteLinkName), "))"), strArrays, SearchScope.OneLevel, false, false);
					SearchResult searchResult = aDSearcher.FindOne();
					if (searchResult != null)
					{
						DirectoryEntry directoryEntry1 = searchResult.GetDirectoryEntry();
						ActiveDirectorySiteLink activeDirectorySiteLink1 = new ActiveDirectorySiteLink(context, siteLinkName, transport, true, directoryEntry1);
						activeDirectorySiteLink = activeDirectorySiteLink1;
					}
					else
					{
						Exception exception = new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ActiveDirectorySiteLink), siteLinkName);
						throw exception;
					}
				}
				catch (COMException cOMException3)
				{
					COMException cOMException2 = cOMException3;
					if (cOMException2.ErrorCode != -2147016656)
					{
						throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException2);
					}
					else
					{
						DirectoryEntry directoryEntry2 = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
						if (!Utils.CheckCapability(directoryEntry2, Capability.ActiveDirectoryApplicationMode) || transport != ActiveDirectoryTransportType.Smtp)
						{
							throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ActiveDirectorySiteLink), siteLinkName);
						}
						else
						{
							throw new NotSupportedException(Res.GetString("NotSupportTransportSMTP"));
						}
					}
				}
			}
			finally
			{
				directoryEntry.Dispose();
			}
			return activeDirectorySiteLink;
		}
示例#39
0
		public bool Contains (ActiveDirectorySiteLink link)
		{
			throw new NotImplementedException ();
		}
		public void AddRange(ActiveDirectorySiteLink[] links)
		{
			if (links != null)
			{
				for (int i = 0; i < (int)links.Length; i++)
				{
					this.Add(links[i]);
				}
				return;
			}
			else
			{
				throw new ArgumentNullException("links");
			}
		}
 public bool Contains(ActiveDirectorySiteLink link)
 {
     throw new NotImplementedException();
 }
示例#42
0
        private void GetLinks()
        {
            DirectoryEntry de = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
            string config = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.ConfigurationNamingContext);
            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
            {
                foreach (SearchResult result in results)
                {
                    // construct the sitelinks at the same time
                    DirectoryEntry connectionEntry = result.GetDirectoryEntry();
                    string cn = (string)PropertyManager.GetSearchResultPropertyValue(result, PropertyManager.Cn);
                    string transport = Utils.GetDNComponents((string)PropertyManager.GetSearchResultPropertyValue(result, PropertyManager.DistinguishedName))[1].Value;
                    ActiveDirectorySiteLink link = null;
                    if (String.Compare(transport, "IP", StringComparison.OrdinalIgnoreCase) == 0)
                        link = new ActiveDirectorySiteLink(context, cn, ActiveDirectoryTransportType.Rpc, true, connectionEntry);
                    else if (String.Compare(transport, "SMTP", StringComparison.OrdinalIgnoreCase) == 0)
                        link = new ActiveDirectorySiteLink(context, cn, ActiveDirectoryTransportType.Smtp, true, connectionEntry);
                    else
                    {
                        // should not happen
                        string message = Res.GetString(Res.UnknownTransport, transport);
                        throw new ActiveDirectoryOperationException(message);
                    }

                    _links.Add(link);
                }
            }
            finally
            {
                results.Dispose();
                de.Dispose();
            }
        }
示例#43
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();
            }
        }
        public void Remove(ActiveDirectorySiteLink link)
        {
            if (link == null)
                throw new ArgumentNullException("link");

            if (!link.existing)
                throw new InvalidOperationException(Res.GetString(Res.SiteLinkNotCommitted, link.Name));

            string dn = (string)PropertyManager.GetPropertyValue(link.context, link.cachedEntry, PropertyManager.DistinguishedName);

            for (int i = 0; i < InnerList.Count; i++)
            {
                ActiveDirectorySiteLink tmp = (ActiveDirectorySiteLink)InnerList[i];
                string tmpDn = (string)PropertyManager.GetPropertyValue(tmp.context, tmp.cachedEntry, PropertyManager.DistinguishedName);

                if (Utils.Compare(tmpDn, dn) == 0)
                {
                    List.Remove(tmp);
                    return;
                }
            }

            // something that does not exist in the collectio
            throw new ArgumentException(Res.GetString(Res.NotFoundInCollection, link), "link");
        }
        public void Insert(int index, ActiveDirectorySiteLink link)
        {
            if (link == null)
                throw new ArgumentNullException("value");

            if (!link.existing)
                throw new InvalidOperationException(Res.GetString(Res.SiteLinkNotCommitted, link.Name));

            if (!Contains(link))
                List.Insert(index, link);
            else
                throw new ArgumentException(Res.GetString(Res.AlreadyExistingInCollection, link), "link");
        }
        private void GetLinks()
        {
            ArrayList propertyList = new ArrayList();
            NativeComInterfaces.IAdsPathname pathCracker = null;
            pathCracker = (NativeComInterfaces.IAdsPathname)new NativeComInterfaces.Pathname();
            // need to turn off the escaping for name
            pathCracker.EscapedMode = NativeComInterfaces.ADS_ESCAPEDMODE_OFF_EX;
            string propertyName = "siteLinkList";

            propertyList.Add(propertyName);
            Hashtable values = Utils.GetValuesWithRangeRetrieval(cachedEntry, "(objectClass=*)", propertyList, SearchScope.Base);
            ArrayList siteLinkLists = (ArrayList)values[propertyName.ToLower(CultureInfo.InvariantCulture)];

            // somehow no site link list
            if (siteLinkLists == null)
                return;

            // construct the site link object
            for (int i = 0; i < siteLinkLists.Count; i++)
            {
                string dn = (string)siteLinkLists[i];
                // escaping manipulation
                pathCracker.Set(dn, NativeComInterfaces.ADS_SETTYPE_DN);
                string rdn = pathCracker.Retrieve(NativeComInterfaces.ADS_FORMAT_LEAF);
                Debug.Assert(rdn != null && Utils.Compare(rdn, 0, 3, "CN=", 0, 3) == 0);
                rdn = rdn.Substring(3);
                DirectoryEntry entry = DirectoryEntryManager.GetDirectoryEntry(context, dn);
                ActiveDirectorySiteLink link = new ActiveDirectorySiteLink(context, rdn, _transport, true, entry);

                _links.Add(link);
            }
        }
 public void Insert(int index, ActiveDirectorySiteLink link)
 {
     throw new NotImplementedException();
 }
		private void GetLinks()
		{
			ArrayList arrayLists = new ArrayList();
			NativeComInterfaces.IAdsPathname pathname = (NativeComInterfaces.IAdsPathname)(new NativeComInterfaces.Pathname());
			pathname.EscapedMode = 4;
			string str = "siteLinkList";
			arrayLists.Add(str);
			Hashtable valuesWithRangeRetrieval = Utils.GetValuesWithRangeRetrieval(this.cachedEntry, "(objectClass=*)", arrayLists, SearchScope.Base);
			ArrayList item = (ArrayList)valuesWithRangeRetrieval[str.ToLower(CultureInfo.InvariantCulture)];
			if (item != null)
			{
				for (int i = 0; i < item.Count; i++)
				{
					string item1 = (string)item[i];
					pathname.Set(item1, 4);
					string str1 = pathname.Retrieve(11);
					str1 = str1.Substring(3);
					DirectoryEntry directoryEntry = DirectoryEntryManager.GetDirectoryEntry(this.context, item1);
					ActiveDirectorySiteLink activeDirectorySiteLink = new ActiveDirectorySiteLink(this.context, str1, this.transport, true, directoryEntry);
					this.links.Add(activeDirectorySiteLink);
				}
				return;
			}
			else
			{
				return;
			}
		}
        // How to create a site link. Note, that this example assigns a single site to this site link
        public static void CreateSiteLink(string siteName, string siteLinkName)
        {
            try
            {
                DirectoryContext forestContext = new DirectoryContext(
                                            DirectoryContextType.Forest);

                //bind to a specific site in the forest
                ActiveDirectorySite site = ActiveDirectorySite.FindByName(
                                                                forestContext,
                                                                siteName);

                // rpc is the default transport type (smtp is the other,
                // this is how you can create a transport type variable to
                // later assign to the link
                ActiveDirectoryTransportType adTpt =
                                            ActiveDirectoryTransportType.Rpc;

                // using the overload requiring the transport type to
                // demonstrate how to assign a transport type to this link.
                ActiveDirectorySiteLink link = new ActiveDirectorySiteLink(
                                                    forestContext,
                                                    siteLinkName,
                                                    adTpt);

                // configure the ActiveDirectorySiteLink object
                link.Cost = 100;
                link.DataCompressionEnabled = true;

                // create an AD schedule object for setting intersite replication
                ActiveDirectorySchedule linkSchedule =
                                                new ActiveDirectorySchedule();

                // set the schedule for 5:30 am to 6:30 am
                linkSchedule.SetDailySchedule(HourOfDay.Zero,
                                              MinuteOfHour.Zero,
                                              HourOfDay.TwentyThree,
                                              MinuteOfHour.FortyFive);

                // set the schedule for 5:30 pm to 6:30 pm
                /*linkSchedule.SetDailySchedule(HourOfDay.Seventeen,
                                              MinuteOfHour.Thirty,
                                              HourOfDay.Eighteen,
                                              MinuteOfHour.Thirty);
                */
                // apply the replication schedule to the link
                link.InterSiteReplicationSchedule = linkSchedule;

                // enable inter-site change notification. Typically used for fast,
                // uncongested links between sites
                link.NotificationEnabled = true;

                // replicate every twelve hours
                TimeSpan linkTimeSpan = new TimeSpan(0, 15, 0);

                // assign the TimeSpan object to the ReplicationInterval property
                link.ReplicationInterval = linkTimeSpan;

                // configure the link so there is no reciprocal replication
                link.ReciprocalReplicationEnabled = false;

                // assign a site to this site link.
                link.Sites.Add(site);

                // commit the link to the directory
                link.Save();

                Console.BackgroundColor = ConsoleColor.Black;
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("\nLink \"{0}\" was created successfully", link.Name);
                Console.ResetColor();

            }
            catch (Exception e)
            {
                Console.WriteLine("\r\nUnexpected exception occured:\n\t{0}\n{1}",
                      e.GetType().Name, e.Message);

            }
        }
		public void Remove (ActiveDirectorySiteLink link)
		{
			throw new NotImplementedException ();
		}
示例#51
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();
			}
		}
示例#52
0
		public int IndexOf (ActiveDirectorySiteLink link)
		{
			throw new NotImplementedException ();
		}
示例#53
0
 internal int Add(ActiveDirectorySiteLink link)
 {
     return(InnerList.Add(link));
 }
 public void CopyTo(ActiveDirectorySiteLink[] array, int index)
 {
     List.CopyTo(array, index);
 }
 public int IndexOf(ActiveDirectorySiteLink link)
 {
     throw new NotImplementedException();
 }
 public void CopyTo(ActiveDirectorySiteLink[] links, int index)
 {
     InnerList.CopyTo(links, index);
 }
 public void Remove(ActiveDirectorySiteLink link)
 {
     throw new NotImplementedException();
 }
 internal int Add(ActiveDirectorySiteLink link)
 {
     return InnerList.Add(link);
 }
 public static ActiveDirectorySiteLink FindByName(DirectoryContext context, string siteLinkName, ActiveDirectoryTransportType transport)
 {
     DirectoryEntry directoryEntry;
     ActiveDirectorySiteLink link2;
     ValidateArgument(context, siteLinkName, transport);
     context = new DirectoryContext(context);
     try
     {
         directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
         string str = (string) PropertyManager.GetPropertyValue(context, directoryEntry, PropertyManager.ConfigurationNamingContext);
         string dn = "CN=Inter-Site Transports,CN=Sites," + str;
         if (transport == ActiveDirectoryTransportType.Rpc)
         {
             dn = "CN=IP," + dn;
         }
         else
         {
             dn = "CN=SMTP," + dn;
         }
         directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, dn);
     }
     catch (COMException exception)
     {
         throw ExceptionHelper.GetExceptionFromCOMException(context, exception);
     }
     catch (ActiveDirectoryObjectNotFoundException)
     {
         throw new ActiveDirectoryOperationException(Res.GetString("ADAMInstanceNotFoundInConfigSet", new object[] { context.Name }));
     }
     try
     {
         SearchResult result = new ADSearcher(directoryEntry, "(&(objectClass=siteLink)(objectCategory=SiteLink)(name=" + Utils.GetEscapedFilterValue(siteLinkName) + "))", new string[] { "distinguishedName" }, SearchScope.OneLevel, false, false).FindOne();
         if (result == null)
         {
             Exception exception2 = new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ActiveDirectorySiteLink), siteLinkName);
             throw exception2;
         }
         DirectoryEntry entry = result.GetDirectoryEntry();
         link2 = new ActiveDirectorySiteLink(context, siteLinkName, transport, true, entry);
     }
     catch (COMException exception3)
     {
         if (exception3.ErrorCode != -2147016656)
         {
             throw ExceptionHelper.GetExceptionFromCOMException(context, exception3);
         }
         if (Utils.CheckCapability(DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE), Capability.ActiveDirectoryApplicationMode) && (transport == ActiveDirectoryTransportType.Smtp))
         {
             throw new NotSupportedException(Res.GetString("NotSupportTransportSMTP"));
         }
         throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ActiveDirectorySiteLink), siteLinkName);
     }
     finally
     {
         directoryEntry.Dispose();
     }
     return link2;
 }
示例#60
0
        public static ActiveDirectorySiteLink FindByName(DirectoryContext context, string siteLinkName, ActiveDirectoryTransportType transport)
        {
            ValidateArgument(context, siteLinkName, transport);

            //  work with copy of the context
            context = new DirectoryContext(context);

            // bind to the rootdse to get the configurationnamingcontext
            DirectoryEntry de;

            try
            {
                de = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
                string config = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.ConfigurationNamingContext);
                string containerDN = "CN=Inter-Site Transports,CN=Sites," + config;
                if (transport == ActiveDirectoryTransportType.Rpc)
                    containerDN = "CN=IP," + containerDN;
                else
                    containerDN = "CN=SMTP," + containerDN;
                de = DirectoryEntryManager.GetDirectoryEntry(context, containerDN);
            }
            catch (COMException e)
            {
                throw ExceptionHelper.GetExceptionFromCOMException(context, e);
            }
            catch (ActiveDirectoryObjectNotFoundException)
            {
                // this is the case where the context is a config set and we could not find an ADAM instance in that config set
                throw new ActiveDirectoryOperationException(Res.GetString(Res.ADAMInstanceNotFoundInConfigSet, context.Name));
            }

            try
            {
                ADSearcher adSearcher = new ADSearcher(de,
                                                      "(&(objectClass=siteLink)(objectCategory=SiteLink)(name=" + Utils.GetEscapedFilterValue(siteLinkName) + "))",
                                                      new string[] { "distinguishedName" },
                                                      SearchScope.OneLevel,
                                                      false, /* don't need paged search */
                                                      false /* don't need to cache result */
                                                      );
                SearchResult srchResult = adSearcher.FindOne();
                if (srchResult == null)
                {
                    // no such sitelink object
                    Exception e = new ActiveDirectoryObjectNotFoundException(Res.GetString(Res.DSNotFound), typeof(ActiveDirectorySiteLink), siteLinkName);
                    throw e;
                }
                else
                {
                    DirectoryEntry connectionEntry = srchResult.GetDirectoryEntry();
                    // it is an existing site object
                    ActiveDirectorySiteLink link = new ActiveDirectorySiteLink(context, siteLinkName, transport, true, connectionEntry);
                    return link;
                }
            }
            catch (COMException e)
            {
                if (e.ErrorCode == unchecked((int)0x80072030))
                {
                    // if it is ADAM and transport type is SMTP, throw NotSupportedException.
                    DirectoryEntry tmpDE = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
                    if (Utils.CheckCapability(tmpDE, Capability.ActiveDirectoryApplicationMode) && transport == ActiveDirectoryTransportType.Smtp)
                    {
                        throw new NotSupportedException(Res.GetString(Res.NotSupportTransportSMTP));
                    }
                    else
                    {
                        // object is not found since we cannot even find the container in which to search
                        throw new ActiveDirectoryObjectNotFoundException(Res.GetString(Res.DSNotFound), typeof(ActiveDirectorySiteLink), siteLinkName);
                    }
                }

                throw ExceptionHelper.GetExceptionFromCOMException(context, e);
            }
            finally
            {
                de.Dispose();
            }
        }