コード例 #1
0
        public ActiveDirectorySubnet(DirectoryContext context, string subnetName)
        {
            ActiveDirectorySubnet.ValidateArgument(context, subnetName);
            context      = new DirectoryContext(context);
            this.context = context;
            this.name    = subnetName;
            DirectoryEntry directoryEntry = null;

            using (directoryEntry)
            {
                try
                {
                    directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
                    string propertyValue = (string)PropertyManager.GetPropertyValue(context, directoryEntry, PropertyManager.ConfigurationNamingContext);
                    string str           = string.Concat("CN=Subnets,CN=Sites,", propertyValue);
                    directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, str);
                    string escapedPath = string.Concat("cn=", this.name);
                    escapedPath      = Utils.GetEscapedPath(escapedPath);
                    this.cachedEntry = directoryEntry.Children.Add(escapedPath, "subnet");
                }
                catch (COMException cOMException1)
                {
                    COMException cOMException = cOMException1;
                    ExceptionHelper.GetExceptionFromCOMException(context, cOMException);
                }
                catch (ActiveDirectoryObjectNotFoundException activeDirectoryObjectNotFoundException)
                {
                    object[] name = new object[1];
                    name[0] = context.Name;
                    throw new ActiveDirectoryOperationException(Res.GetString("ADAMInstanceNotFoundInConfigSet", name));
                }
            }
        }
コード例 #2
0
        public static ActiveDirectorySubnet FindByName(DirectoryContext context, string subnetName)
        {
            DirectoryEntry        directoryEntry;
            ActiveDirectorySubnet activeDirectorySubnet;
            ActiveDirectorySubnet activeDirectorySubnet1;

            ActiveDirectorySubnet.ValidateArgument(context, subnetName);
            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=Subnets,CN=Sites,", propertyValue);
                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));
            }
            using (directoryEntry)
            {
                try
                {
                    string[] strArrays = new string[1];
                    strArrays[0] = "distinguishedName";
                    ADSearcher   aDSearcher   = new ADSearcher(directoryEntry, string.Concat("(&(objectClass=subnet)(objectCategory=subnet)(name=", Utils.GetEscapedFilterValue(subnetName), "))"), strArrays, SearchScope.OneLevel, false, false);
                    SearchResult searchResult = aDSearcher.FindOne();
                    if (searchResult != null)
                    {
                        string         str1            = null;
                        DirectoryEntry directoryEntry1 = searchResult.GetDirectoryEntry();
                        if (directoryEntry1.Properties.Contains("siteObject"))
                        {
                            NativeComInterfaces.IAdsPathname pathname = (NativeComInterfaces.IAdsPathname)(new NativeComInterfaces.Pathname());
                            pathname.EscapedMode = 4;
                            string item = (string)directoryEntry1.Properties["siteObject"][0];
                            pathname.Set(item, 4);
                            string str2 = pathname.Retrieve(11);
                            str1 = str2.Substring(3);
                        }
                        if (str1 != null)
                        {
                            activeDirectorySubnet = new ActiveDirectorySubnet(context, subnetName, str1, true);
                        }
                        else
                        {
                            activeDirectorySubnet = new ActiveDirectorySubnet(context, subnetName, null, true);
                        }
                        activeDirectorySubnet.cachedEntry = directoryEntry1;
                        activeDirectorySubnet1            = activeDirectorySubnet;
                    }
                    else
                    {
                        Exception exception = new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ActiveDirectorySubnet), subnetName);
                        throw exception;
                    }
                }
                catch (COMException cOMException3)
                {
                    COMException cOMException2 = cOMException3;
                    if (cOMException2.ErrorCode != -2147016656)
                    {
                        throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException2);
                    }
                    else
                    {
                        throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ActiveDirectorySubnet), subnetName);
                    }
                }
            }
            return(activeDirectorySubnet1);
        }