Ejemplo n.º 1
0
 /// <summary>
 /// 获得活动目录实体
 /// </summary>
 /// <typeparam name="T">活动目录实体类型</typeparam>
 /// <param name="de">DirectoryEntry</param>
 /// <returns>活动目录实体</returns>
 public T GetEntity <T>(DirectoryEntry de) where T : IDirectoryEntity
 {
     try {
         T entityObject = (T)Activator.CreateInstance(typeof(T));
         foreach (PropertyInfo property in typeof(T).GetProperties())
         {
             foreach (object customAttribute in property.GetCustomAttributes(true))
             {
                 DirectoryAttributeAttribute attribute = customAttribute as DirectoryAttributeAttribute;
                 if (null != attribute)
                 {
                     object value = de.Properties[attribute.Attribute].Value;
                     property.SetValue(entityObject, Convertor.ChangeType(de.Properties[attribute.Attribute].Value, property.PropertyType), null);
                 }
             }
         }
         DirectoryEntity entity = entityObject as DirectoryEntity;
         entity.ParentGuid       = de.Parent.Guid;
         entity.ParentPath       = de.Parent.Path;
         entity.Path             = de.Path;
         entity.DirectoryEntry   = de;
         entity.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(entity_PropertyChanged);
         return(entityObject);
     } catch {
         return(default(T));
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 移动实体到指定实体下
 /// </summary>
 /// <param name="entity"></param>
 public void MoveTo(DirectoryEntity entity)
 {
     this.DirectoryEntry.MoveTo(entity.DirectoryEntry);
     this._path = this.DirectoryEntry.Path;
     this._distinguishedName = this.DirectoryEntry.Properties["distinguishedName"][0].ToString();
     this._whenChanged       = DateTime.Parse(this.DirectoryEntry.Properties["whenChanged"][0].ToString());
 }
Ejemplo n.º 3
0
 /// <summary>
 /// 删除实体(提交更改后生效)
 /// </summary>
 /// <param name="entity"></param>
 public void DeleteOnSubmit(DirectoryEntity entity)
 {
     if (!_changes.ContainsKey(entity))
     {
         DirectoryChangeInfo info = new DirectoryChangeInfo {
             ChangeType = ChangeType.Delete,
             Entity     = entity
         };
         _changes.Add(entity, info);
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 插入实体(提交更改后生效)
 /// </summary>
 /// <param name="parent"></param>
 /// <param name="entity"></param>
 public void InsertOnSubmit(DirectoryEntry parent, DirectoryEntity entity)
 {
     if (!_changes.ContainsKey(entity))
     {
         DirectoryChangeInfo info = new DirectoryChangeInfo {
             ChangeType = ChangeType.Insert,
             Entity     = entity,
             Parent     = parent
         };
         _changes.Add(entity, info);
     }
 }
Ejemplo n.º 5
0
        void entity_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            DirectoryEntity entity = sender as DirectoryEntity;

            if (!_changes.ContainsKey(entity))
            {
                _changes.Add(entity, new DirectoryChangeInfo {
                    Entity     = entity,
                    ChangeType = ChangeType.Update,
                    Properties = new List <string>()
                });
            }
            if (!_changes[entity].Properties.Contains(e.PropertyName))
            {
                _changes[entity].Properties.Add(e.PropertyName);
            }
        }
Ejemplo n.º 6
0
 void entities_EntityAddedEvent(DirectoryEntry parent, DirectoryEntity sender)
 {
     this.InsertOnSubmit(parent, sender);
 }
Ejemplo n.º 7
0
 void entities_EntityDeletedEvent(DirectoryEntity sender)
 {
     this.DeleteOnSubmit(sender);
 }
Ejemplo n.º 8
0
 /// <summary>
 /// 插入实体(提交更改后生效)
 /// </summary>
 /// <param name="parent">父</param>
 /// <param name="entity"></param>
 public void InsertOnSubmit(DirectoryEntity parent, DirectoryEntity entity)
 {
     InsertOnSubmit(parent.DirectoryEntry, entity);
 }
Ejemplo n.º 9
0
 /// <summary>
 /// 插入实体(提交更改后生效)
 /// </summary>
 /// <param name="entity"></param>
 public void InsertOnSubmit(DirectoryEntity entity)
 {
     InsertOnSubmit(this.SearchRoot, entity);
 }