Пример #1
0
        public ADRenameUserDlg(ADUCDirectoryNode dirnode, string parentDN)
            : this()
        {
            this.ParentDN       = parentDN;
            this._dirnode       = dirnode;
            this.renameUserInfo = new RenameUserInfo();
            int ret = -1;

            List <LdapEntry> ldapEntries = null;

            ret = _dirnode.LdapContext.ListChildEntriesSynchronous(
                _dirnode.DistinguishedName,
                LdapAPI.LDAPSCOPE.BASE,
                "(objectClass=*)",
                null,
                false,
                out ldapEntries);

            if (ldapEntries == null || ldapEntries.Count == 0)
            {
                return;
            }

            LdapEntry ldapNextEntry = ldapEntries[0];

            string[] attrsList = ldapNextEntry.GetAttributeNames();

            if (attrsList != null)
            {
                foreach (string attr in attrsList)
                {
                    string sValue = "";

                    LdapValue[] attrValues = ldapNextEntry.GetAttributeValues(attr, _dirnode.LdapContext);

                    if (attrValues != null && attrValues.Length > 0)
                    {
                        foreach (LdapValue value in attrValues)
                        {
                            sValue = sValue + "," + value.stringData;
                        }
                    }

                    if (sValue.StartsWith(","))
                    {
                        sValue = sValue.Substring(1);
                    }
                    if (string.Compare(sValue, "") == 0)
                    {
                        sValue = "<Not Set>";
                    }

                    if (string.Compare(attr, "cn") == 0)
                    {
                        this.FullNametextbox.Text = sValue;
                        renameUserInfo.fullName   = sValue;
                    }

                    if (string.Compare(attr, "displayName") == 0)
                    {
                        this.displaynametextBox.Text = sValue;
                        renameUserInfo.displayName   = sValue;
                    }

                    if (string.Compare(attr, "givenName") == 0)
                    {
                        this.FnametextBox.Text = sValue;
                        renameUserInfo.fName   = sValue;
                    }

                    if (string.Compare(attr, "initials") == 0)
                    {
                        this.InitialtextBox.Text = sValue;
                        renameUserInfo.initials  = sValue;
                    }

                    if (string.Compare(attr, "sn") == 0)
                    {
                        this.LnametextBox.Text = sValue;
                        renameUserInfo.lName   = sValue;
                    }

                    if (string.Compare(attr, "userPrincipalName") == 0)
                    {
                        string[] pre = sValue.Split('@');
                        this.logonNametextBox.Text = pre[0].Trim();
                        renameUserInfo.logonName   = sValue;
                    }

                    if (string.Compare(attr, "sAMAccountName") == 0)
                    {
                        this.userlogonPretextBox.Text   = sValue;
                        renameUserInfo.userPrelogonname = sValue;
                    }
                }
            }

            string[] prefixes = dirnode.LdapContext.DomainName.Split('.');
            string   prefix   = string.Concat(prefixes[0].ToUpper(), "\\");

            this.prelogontextBox.Text = prefix;

            this.domainNamecomboBox.Items.Add(dirnode.LdapContext.DomainName);
            this.domainNamecomboBox.SelectedIndex = 0;
        }
Пример #2
0
        public ADRenameUserDlg(ADUCDirectoryNode dirnode, string parentDN)
            : this()
        {
            this.ParentDN = parentDN;
            this._dirnode = dirnode;
            this.renameUserInfo = new RenameUserInfo();
            int ret = -1;

            List<LdapEntry> ldapEntries = null;

            ret = _dirnode.LdapContext.ListChildEntriesSynchronous(
            _dirnode.DistinguishedName,
            LdapAPI.LDAPSCOPE.BASE,
            "(objectClass=*)",
            null,
            false,
            out ldapEntries);

            if (ldapEntries == null || ldapEntries.Count == 0)
            {
                return;
            }

            LdapEntry ldapNextEntry = ldapEntries[0];

            string[] attrsList = ldapNextEntry.GetAttributeNames();

            if (attrsList != null)
            {
                foreach (string attr in attrsList)
                {
                    string sValue = "";

                    LdapValue[] attrValues = ldapNextEntry.GetAttributeValues(attr, _dirnode.LdapContext);

                    if (attrValues != null && attrValues.Length > 0)
                    {
                        foreach (LdapValue value in attrValues)
                        {
                            sValue = sValue + "," + value.stringData;
                        }
                    }

                    if (sValue.StartsWith(","))
                    {
                        sValue = sValue.Substring(1);
                    }
                    if (string.Compare(sValue, "") == 0)
                    {
                        sValue = "<Not Set>";
                    }

                    if (string.Compare(attr, "cn") == 0)
                    {
                        this.FullNametextbox.Text = sValue;
                        renameUserInfo.fullName = sValue;
                    }

                    if (string.Compare(attr, "displayName") == 0)
                    {
                        this.displaynametextBox.Text = sValue;
                        renameUserInfo.displayName = sValue;
                    }

                    if (string.Compare(attr, "givenName") == 0)
                    {
                        this.FnametextBox.Text = sValue;
                        renameUserInfo.fName = sValue;
                    }

                    if (string.Compare(attr, "initials") == 0)
                    {
                        this.InitialtextBox.Text = sValue;
                        renameUserInfo.initials = sValue;
                    }

                    if (string.Compare(attr, "sn") == 0)
                    {
                        this.LnametextBox.Text = sValue;
                        renameUserInfo.lName = sValue;
                    }

                    if (string.Compare(attr, "userPrincipalName") == 0)
                    {
                        string[] pre = sValue.Split('@');
                        this.logonNametextBox.Text = pre[0].Trim();
                        renameUserInfo.logonName = sValue;
                    }

                    if (string.Compare(attr, "sAMAccountName") == 0)
                    {
                        this.userlogonPretextBox.Text = sValue;
                        renameUserInfo.userPrelogonname = sValue;
                    }
                }
            }

            string[] prefixes = dirnode.LdapContext.DomainName.Split('.');
            string prefix = string.Concat(prefixes[0].ToUpper(), "\\");
            this.prelogontextBox.Text = prefix;

            this.domainNamecomboBox.Items.Add(dirnode.LdapContext.DomainName);
            this.domainNamecomboBox.SelectedIndex = 0;
        }