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 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 static ActiveDirectorySubnet FindByName(DirectoryContext context, string subnetName)
        {
            DirectoryEntry        directoryEntry;
            ActiveDirectorySubnet subnet2;

            ValidateArgument(context, subnetName);
            context = new DirectoryContext(context);
            try
            {
                directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
                string str = (string)PropertyManager.GetPropertyValue(context, directoryEntry, PropertyManager.ConfigurationNamingContext);
                string dn  = "CN=Subnets,CN=Sites," + str;
                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=subnet)(objectCategory=subnet)(name=" + Utils.GetEscapedFilterValue(subnetName) + "))", new string[] { "distinguishedName" }, SearchScope.OneLevel, false, false).FindOne();
                if (result == null)
                {
                    Exception exception2 = new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ActiveDirectorySubnet), subnetName);
                    throw exception2;
                }
                string         siteName = null;
                DirectoryEntry entry2   = result.GetDirectoryEntry();
                if (entry2.Properties.Contains("siteObject"))
                {
                    NativeComInterfaces.IAdsPathname pathname = (NativeComInterfaces.IAdsPathname) new NativeComInterfaces.Pathname();
                    pathname.EscapedMode = 4;
                    string bstrADsPath = (string)entry2.Properties["siteObject"][0];
                    pathname.Set(bstrADsPath, 4);
                    siteName = pathname.Retrieve(11).Substring(3);
                }
                ActiveDirectorySubnet subnet = null;
                if (siteName == null)
                {
                    subnet = new ActiveDirectorySubnet(context, subnetName, null, true);
                }
                else
                {
                    subnet = new ActiveDirectorySubnet(context, subnetName, siteName, true);
                }
                subnet.cachedEntry = entry2;
                subnet2            = subnet;
            }
            catch (COMException exception3)
            {
                if (exception3.ErrorCode == -2147016656)
                {
                    throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ActiveDirectorySubnet), subnetName);
                }
                throw ExceptionHelper.GetExceptionFromCOMException(context, exception3);
            }
            finally
            {
                if (directoryEntry != null)
                {
                    directoryEntry.Dispose();
                }
            }
            return(subnet2);
        }
 public static ActiveDirectorySubnet FindByName(DirectoryContext context, string subnetName)
 {
     DirectoryEntry directoryEntry;
     ActiveDirectorySubnet subnet2;
     ValidateArgument(context, subnetName);
     context = new DirectoryContext(context);
     try
     {
         directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
         string str = (string) PropertyManager.GetPropertyValue(context, directoryEntry, PropertyManager.ConfigurationNamingContext);
         string dn = "CN=Subnets,CN=Sites," + str;
         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=subnet)(objectCategory=subnet)(name=" + Utils.GetEscapedFilterValue(subnetName) + "))", new string[] { "distinguishedName" }, SearchScope.OneLevel, false, false).FindOne();
         if (result == null)
         {
             Exception exception2 = new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ActiveDirectorySubnet), subnetName);
             throw exception2;
         }
         string siteName = null;
         DirectoryEntry entry2 = result.GetDirectoryEntry();
         if (entry2.Properties.Contains("siteObject"))
         {
             NativeComInterfaces.IAdsPathname pathname = (NativeComInterfaces.IAdsPathname) new NativeComInterfaces.Pathname();
             pathname.EscapedMode = 4;
             string bstrADsPath = (string) entry2.Properties["siteObject"][0];
             pathname.Set(bstrADsPath, 4);
             siteName = pathname.Retrieve(11).Substring(3);
         }
         ActiveDirectorySubnet subnet = null;
         if (siteName == null)
         {
             subnet = new ActiveDirectorySubnet(context, subnetName, null, true);
         }
         else
         {
             subnet = new ActiveDirectorySubnet(context, subnetName, siteName, true);
         }
         subnet.cachedEntry = entry2;
         subnet2 = subnet;
     }
     catch (COMException exception3)
     {
         if (exception3.ErrorCode == -2147016656)
         {
             throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ActiveDirectorySubnet), subnetName);
         }
         throw ExceptionHelper.GetExceptionFromCOMException(context, exception3);
     }
     finally
     {
         if (directoryEntry != null)
         {
             directoryEntry.Dispose();
         }
     }
     return subnet2;
 }