Disco.Services.Interop.ActiveDirectory.ADDomain.Initialize C# (CSharp) Method

Initialize() private method

private Initialize ( ) : void
return void
        private void Initialize()
        {
            this.Name = Domain.Name;

            var dc = Domain.FindDomainController();

            string ldapPath = string.Format("LDAP://{0}/", dc.Name);

            using (var adRootDSE = new DirectoryEntry(ldapPath + "RootDSE"))
            {
                this.DistinguishedName = adRootDSE.Properties["defaultNamingContext"][0].ToString();
                this.ConfigurationNamingContext = adRootDSE.Properties["configurationNamingContext"][0].ToString();
            }

            using (var adDomainRoot = new DirectoryEntry(ldapPath + this.DistinguishedName))
            {
                this.SecurityIdentifier = new SecurityIdentifier((byte[])(adDomainRoot.Properties["objectSid"][0]), 0);
            }

            using (var configSearchRoot = new DirectoryEntry(ldapPath + "CN=Partitions," + this.ConfigurationNamingContext))
            {
                var configSearchFilter = string.Format("(&(objectcategory=Crossref)(dnsRoot={0})(netBIOSName=*))", this.Name);

                using (var configSearcher = new DirectorySearcher(configSearchRoot, configSearchFilter, new string[] { "NetBIOSName" }, System.DirectoryServices.SearchScope.OneLevel))
                {
                    SearchResult configResult = configSearcher.FindOne();
                    if (configResult != null)
                        this.NetBiosName = configResult.Properties["NetBIOSName"][0].ToString();
                    else
                        this.NetBiosName = null;
                }
            }
        }