/// <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)); } }
/// <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()); }
/// <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); } }
/// <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); } }
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); } }
void entities_EntityAddedEvent(DirectoryEntry parent, DirectoryEntity sender) { this.InsertOnSubmit(parent, sender); }
void entities_EntityDeletedEvent(DirectoryEntity sender) { this.DeleteOnSubmit(sender); }
/// <summary> /// 插入实体(提交更改后生效) /// </summary> /// <param name="parent">父</param> /// <param name="entity"></param> public void InsertOnSubmit(DirectoryEntity parent, DirectoryEntity entity) { InsertOnSubmit(parent.DirectoryEntry, entity); }
/// <summary> /// 插入实体(提交更改后生效) /// </summary> /// <param name="entity"></param> public void InsertOnSubmit(DirectoryEntity entity) { InsertOnSubmit(this.SearchRoot, entity); }