Ejemplo n.º 1
0
        /// <summary>
        /// 解析DirectoryEntry对象。
        /// </summary>
        /// <param name="entry">DirectoryEntry对象。</param>
        /// <param name="demandSchema">要求的对象SchemaClass,以便检验对象类型。</param>
        protected void Parse(DirectoryEntry entry, SchemaClass demandSchema)
        {
            // this.Parse(entry);      // ERROR -- 如何调用this的

            this.ParsePrivate(entry);

            if (this.schema != demandSchema)
            {
                entry.Close();
                entry.Dispose();

                throw new SchemaClassException("对象类型不是" + demandSchema.ToString("F"));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 解析SearchResult对象。
        /// </summary>
        /// <param name="result">SearchResult对象。应当包括必要的属性。</param>
        /// <param name="demandSchema">要求的对象SchemaClass,以便检验对象类型。</param>
        protected void Parse(SearchResult result, SchemaClass demandSchema)
        {
            string nativeGuid = "";

            foreach (byte g in (byte[])result.Properties["objectguid"][0])
            {
                nativeGuid += g.ToString("x2");
            }
            this.guid = Utils.ConvertNativeGuidToGuid(nativeGuid);
            this.dn   = Utils.EscapeDNBackslashedChar(Utils.GetProperty(result, "distinguishedname"));   // 转义反斜杠'/'字符

            this.path = Utils.GetProperty(result, "adspath");
            this.name = Utils.GetProperty(result, "name");

            List <string> ocList = new List <string>();

            foreach (object oc in result.Properties["objectclass"])
            {
                ocList.Add(oc.ToString());
            }
            this.objectClass    = ocList.ToArray();
            this.objectCategory = Utils.GetProperty(result, "objectcategory");

            this.schema = SchemaClass.none;
            foreach (string oc in this.objectClass)
            {
                // 暂时只分析这三个
                switch (oc)
                {
                case "organizationalUnit":
                    this.schema = SchemaClass.organizationalUnit;
                    break;

                case "group":
                    this.schema = SchemaClass.group;
                    break;

                case "user":
                    this.schema = SchemaClass.user;
                    break;
                }
                if (this.schema != SchemaClass.none)
                {
                    break;
                }
            }

            // OU 没有objectSid
            if (schema == SchemaClass.user || schema == SchemaClass.group)
            {
                this.objectSid = (byte[])(result.Properties["objectsid"][0]);
            }
            else
            {
                this.objectSid = new byte[] { }
            };


            this.whenCreated = DateTime.Parse(Utils.GetProperty(result, "whenCreated"));

            if (this.schema != demandSchema)
            {
                throw new SchemaClassException("对象类型不是" + demandSchema.ToString("F"));
            }
        }