/// <summary> /// A predicate that defines a set of criteria and determines whether /// the specified entity meets those criteria defined in the filter. /// </summary> /// <param name="ent">The entity</param> /// <param name="filter">The filter info</param> /// <returns>True if the entity meets the criteria False otherwise</returns> protected virtual bool QuickFilter(Entity ent, FilterInfo filter) { bool found = false; List <ColumnInfo> cols = ((List <ColumnInfo>)filter.Columns).FindAll(col => col.Searchable); foreach (ColumnInfo col in cols) { if (!string.IsNullOrEmpty(ent.GetProperty(col.Name))) { if (col.SearchType == FilterInfo.ColumnSearchType.LIKE) { found = ent.GetProperty(col.Name).IndexOf(filter.Search, StringComparison.CurrentCultureIgnoreCase) >= 0; } else { found = ent.GetProperty(col.Name).Equals(filter.Search, StringComparison.CurrentCultureIgnoreCase); } } if (found) { return(found); } } return(found); }
public void SanitizerTestResolveSimpleCompoundStat() { string expression = "10+STR/4"; double expected = 10 + MockPlayer.GetProperty("STR").Value / 4; double actual = SanitizerInstance.SanitizeCompoundStat(MockPlayer, expression); Assert.AreEqual(expected, actual); }
public void SanitizerTestResolveSimpleSkill() { string expression = $"{LConstants.HARM_F}({LConstants.TargetKeyword},{LConstants.SourceKeyword}, T, {LConstants.GET_PROP_F}({LConstants.SourceKeyword}, STR))"; double expected = MockEnemy.GetProperty(Entity.HP_KEY).Value - MockPlayer.GetProperty("STR").Value; SanitizerInstance.SanitizeSkill(expression, MockPlayer, MockEnemy); Assert.AreEqual(expected, MockEnemy.GetProperty(Entity.HP_KEY).Value); }
private static void DeterminePrimaryKeyByConvention(Entity entity) { var property = entity.GetProperty("Id") ?? entity.GetProperty("id"); if (property != default) { property.SetPrimiaryKey(true, Enums.ConfigurationSource.Convention); } }
/// <summary> /// Determines the file name depending on the specified entity. /// </summary> /// <param name="entity">The entity</param> /// <returns>The file name</returns> protected virtual string GetFileName(Entity entity) { string fileName = entity.GetTableName(); if (entity.GetTableName().Equals("Cities") && !string.IsNullOrEmpty(entity.GetProperty("CountryCode"))) { fileName = "Cities/" + fileName + entity.GetProperty("CountryCode"); } fileName += ".txt"; LoggerHelper.Debug("FileName: " + fileName); return(fileName); }
public void FunctionalTreeConverterTestComplexFunctionWithAttributes() { string expression = $"{LConstants.GET_PROP_F}({MockPlayer.Key},STR)*100+{LConstants.MAX_F}({LConstants.GET_PROP_F}({MockPlayer.Key},AGI),3)"; double expected = MockPlayer.GetProperty("STR").Value * 100 + (MockPlayer.GetProperty("AGI").Value > 3? MockPlayer.GetProperty("AGI").Value : 3); Assert.AreEqual(expected, TreeResolver.Resolve(expression, Engine).Value.ToDouble()); }
/// <summary> /// It will determine the JoinType that will be performe for this field. /// </summary> /// <param name="joinInfo">The entity representing the join configuration</param> /// <returns>The join type</returns> public static Field.FKType GetJoinType(Entity joinInfo) { if (string.IsNullOrEmpty(joinInfo.GetProperty("JoinType")) || joinInfo.GetProperty("JoinType") == "LEFT") { return(Field.FKType.Left); //Default is Left } else if (joinInfo.GetProperty("JoinType") == "INNER") { return(Field.FKType.Inner); } else { return(Field.FKType.Right); } }
/// <summary> /// A predicate that defines a set of criteria and determines whether /// the specified entity meets those criteria. /// </summary> /// <param name="ent">The entity</param> /// <param name="col">The column info</param> /// <returns>True if the entity meets the criteria False otherwise</returns> protected virtual bool DateFilter(Entity ent, ColumnInfo col) { string[] rangeValues = col.Search.Split(new string[] { "_RANGE_" }, StringSplitOptions.None); if (!string.IsNullOrEmpty(rangeValues[0]) && !string.IsNullOrEmpty(rangeValues[1])) { DateTime from = new DateTime(); DateTime to = new DateTime(); DateTime value = new DateTime(); if (DateTime.TryParse(rangeValues[0], out from) && DateTime.TryParse(rangeValues[1], out to) && DateTime.TryParse(ent.GetProperty(col.Name), out value)) { if (value.CompareTo(from) >= 0 && value.CompareTo(to) <= 0) { return(true); } } } else if (!string.IsNullOrEmpty(rangeValues[0])) { DateTime from = new DateTime(); DateTime value = new DateTime(); if (DateTime.TryParse(rangeValues[0], out from) && DateTime.TryParse(ent.GetProperty(col.Name), out value)) { if (value.CompareTo(from) >= 0) { return(true); } } } else if (!string.IsNullOrEmpty(rangeValues[1])) { DateTime to = new DateTime(); DateTime value = new DateTime(); if (DateTime.TryParse(rangeValues[1], out to) && DateTime.TryParse(ent.GetProperty(col.Name), out value)) { if (value.CompareTo(to) <= 0) { return(true); } } } return(false); }
protected void Page_Load(object sender, EventArgs e) { LoggerHelper.Start(); if (!IsPostBack) { string loginName = GetUserLogin(); LoggerHelper.Debug("loginName = " + loginName); if (string.IsNullOrEmpty(loginName)) { LoggerHelper.Debug("Session expired redirenting to logon page."); Response.Redirect(Request.ApplicationPath + "/Logon.aspx"); } if (!AuthorizationUtils.UserHavePermissions()) { LoggerHelper.Debug("user don't have permissions to access this page redirenting."); Response.Redirect(Request.ApplicationPath + "/InvalidAccess.aspx"); } Entity user = GetUser(loginName); if (user != null) { Session["CurrentUserName"] = user.GetProperty("UserName"); } if (!Page.ClientScript.IsClientScriptBlockRegistered("menuGlobals")) { StringBuilder menuGlobals = new StringBuilder(); menuGlobals.Append("\n<script type='text/javascript'>\n"); AuthorizationUtils.AppendModulesInfo(menuGlobals); menuGlobals.Append("const LOGIN_NAME = '").Append(loginName).Append("';\n"); if (user != null) { menuGlobals.Append("const USER_ID = '").Append(user.GetProperty("USE_ID")).Append("';\n"); menuGlobals.Append("const USER_NAME = '").Append(user.GetProperty("USER_NAME")).Append("';\n"); } menuGlobals.Append("</script>"); Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "menuGlobals", menuGlobals.ToString()); } } LoggerHelper.End(); }
public void PerformBehaviour(Entity target, Entity instigator) { if (!EnsureHasProperty(target)) { return; } var now = Timer.GetTime(); var nextMoan = target.GetProperty((short)GameEntityPropertyEnum.NextZombieMoan).DoubleValue; if (now < nextMoan) { return; } SetNextMoan(target, now); var soundId = StaticRng.Random.Next(0, _availableMoans.Length); if (_lastSound + MinGroanDelay > now) { return; } _lastSound = now; Engine.PlaySoundOnEntity(target, (byte)AudioChannel.Entity, _availableMoans[soundId]); }
public static void DecreaseWeaponUseCount(this Entity entity) { if (entity.HasProperty(GameEntityPropertyEnum.WeaponUseCount)) { entity.GetProperty(GameEntityPropertyEnum.WeaponUseCount).ByteValue -= 1; } }
public static void SetMovementSpeed(this Entity entity, float speed) { var prop = entity.GetProperty(EntityPropertyEnum.MovementVector); var movementVector = prop.VectorValue.NormalizeRet() * speed; prop.VectorValue = movementVector; }
public override void Execute(Dungeon D, Entity E) { if ((!E.HasPullChain) && (E.ReverseConnectors.Count == 0) && E.GetProperty("DoorState") != "open") { Info(E, "Door has neither a pullchain nor a connector pending to it"); } }
public IList <Entity> GetLatestOrderByClient(Entity entity) { LoggerHelper.Info("Start"); IList <Entity> list = new List <Entity>(); try { StringBuilder query = new StringBuilder(); IList <DBParam> queryParams = new List <DBParam>(); query.Append("SELECT TOP 1 ITE_Nombre,Interna,Entrega,OrdenCompra,Requisicion,Terminal "); query.Append("FROM tblOrdenes WHERE ClientId = @p0 ORDER BY ITE_Nombre DESC"); LoggerHelper.Debug(query.ToString()); queryParams.Add(new DBParam(queryParams, entity.GetProperty("ClientId"), DbType.String, false)); ResultSetHandler <IList <Entity> > h = new EntityHandler <Entity>(entity); list = GetQueryRunner().Query(GetConnection(), new StatementWrapper(query, queryParams), h); } catch (Exception e) { LoggerHelper.Error(e); throw new Exception("Unable to Get Latest Order By Client.", e); } finally { LoggerHelper.Info("End"); } return(list); }
private string BuildError(Entity entity) { if (this.MessageBuilder != null) { return(this.MessageBuilder(entity)); } var propertyFormat = "属性 {0} 的值是 {1}".Translate(); var error = new StringBuilder("已经存在"); bool first = true; foreach (IProperty property in this.Properties) { if (!first) { error.Append("、".Translate()); } first = false; var value = entity.GetProperty(property); error.AppendFormat(propertyFormat, Display(property), value); } error.Append(" 的实体 ".Translate()) .Append(Display(entity.GetType())); return(error.ToString()); }
public void FindProperties() { if (this.input1Binding == null) { Entity entity = this.Input1Target.Value.Target; if (entity != null && entity.Active) { Property <bool> targetProperty = entity.GetProperty <bool>(this.Input1TargetProperty); if (targetProperty != null) { this.input1Binding = new Binding <bool>(this.Input1, targetProperty); entity.Add(this.input1Binding); entity.Add(new CommandBinding(entity.Delete, delegate() { this.input1Binding = null; })); } } } if (this.input2Binding == null) { Entity entity = this.Input2Target.Value.Target; if (entity != null && entity.Active) { Property <bool> targetProperty = entity.GetProperty <bool>(this.Input2TargetProperty); if (targetProperty != null) { this.input2Binding = new Binding <bool>(this.Input2, targetProperty); entity.Add(this.input2Binding); entity.Add(new CommandBinding(entity.Delete, delegate() { this.input2Binding = null; })); } } } }
protected override void Validate(Entity entity, RuleArgs e) { var property = e.Property; bool isNull = false; if (property is IRefProperty) { var id = entity.GetRefNullableId((property as IRefProperty).RefIdProperty); isNull = id == null; } else { var value = entity.GetProperty(property); if (property.PropertyType == typeof(string)) { isNull = string.IsNullOrEmpty(value as string); } else { isNull = value == null; } } if (isNull) { e.BrokenDescription = string.Format("{0} 里没有输入值。".Translate(), e.DisplayProperty()); } }
protected override void Validate(Entity entity, RuleArgs e) { var value = Convert.ToDouble(entity.GetProperty(e.Property)); var min = this.Min; if (value < min) { if (this.MessageBuilder != null) { e.BrokenDescription = this.MessageBuilder(entity); } else { e.BrokenDescription = string.Format("{0} 不能低于 {1}。".Translate(), e.DisplayProperty(), min); } } else { var max = this.Max; if (value > max) { if (this.MessageBuilder != null) { e.BrokenDescription = this.MessageBuilder(entity); } else { e.BrokenDescription = string.Format("{0} 不能超过 {1}。".Translate(), e.DisplayProperty(), max); } } } }
public void PerformBehaviour(Entity target, Entity instigator) { if (instigator == null) { // angry at nobody. return; } if (!instigator.HasProperty((int)EntityPropertyEnum.RemotePlayer)) { // not angry at a player. return; } List <int> aggroList; if (target.HasProperty((int)GameEntityPropertyEnum.AggroList)) { aggroList = (List <int>)target.GetProperty((int)GameEntityPropertyEnum.AggroList).ObjectValue; } else { aggroList = new List <int>(5); target.SetProperty(new EntityProperty((int)GameEntityPropertyEnum.AggroList, aggroList) { IsDirtyable = false }); } if (!aggroList.Contains(instigator.EntityId)) { aggroList.Add(instigator.EntityId); } }
public LuminanceTest( IKernel kernel, ContentManager content, GraphicsDevice device) : base("Luminance", kernel) { this.kernel = kernel; this.content = content; this.device = device; UI.Root.Gestures.Bind((g, t, d) => light.GetProperty <Vector3>("colour").Value = new Vector3(5), new KeyPressed(Keys.L)); UI.Root.Gestures.Bind((g, t, d) => light.GetProperty <Vector3>("colour").Value = Vector3.Zero, new KeyReleased(Keys.L)); }
/// <summary> /// 递归读取根对象的所有子对象 /// </summary> /// <param name="entity"></param> private void ReadChildren(Entity entity) { var allProperties = entity.PropertiesContainer.GetNonReadOnlyCompiledProperties(); var childrenList = new List <IList <Entity> >(); //遍历所有子属性,读取孩子列表 for (int i = 0, c = allProperties.Count; i < c; i++) { var property = allProperties[i]; if (property is IListProperty) { var children = entity.GetProperty(property) as IList <Entity>; if (children != null && children.Count > 0) { //所有孩子列表中的实体,都加入到对应的实体列表中。 //并递归读取孩子的孩子实体。 var entityType = children[0].GetType(); var list = this.FindAggregateList(entityType); childrenList.Add(list); for (int j = 0, c2 = children.Count; j < c2; j++) { var child = children[j]; list.Add(child); this.ReadChildren(child); } } } } }
public string SaveTemplate(HttpRequest request) { LoggerHelper.Info("Start"); Entity entity = null; try { Page page = GetPage(request); entity = CreateEntity(request, page); List <PageField> fields = GetEscapeFields(page); foreach (PageField field in fields) { LoggerHelper.Debug(field.FieldName + " is escapetext"); string escapeText = Microsoft.JScript.GlobalObject.unescape(entity.GetProperty(field.FieldName)); entity.SetProperty(field.FieldName, escapeText); } GetCatalogDAO(page).SaveEntity(entity); } catch (Exception e) { LoggerHelper.Error(e); return(ErrorResponse(e)); } finally { LoggerHelper.Info("End"); } return(SuccessResponse(entity)); }
/// <summary> /// Handles the spawn event. /// </summary> public override void OnSpawn() { PhysEnt = Entity.GetProperty <T3>(); Entity.OnSpawnEvent.AddEvent(SpawnHandle, this, 0); Entity.OnTick += TickHandle; PhysEnt.DespawnEvent += RemoveJoints; }
internal void UpdateVisibility(Entity currData) { if (this._meta != null) { bool isVisible = false; var visibilityIndicator = this._meta.VisibilityIndicator; //如果是动态计算,则尝试从数据中获取是否可见的值。 if (visibilityIndicator.IsDynamic) { if (currData != null) { isVisible = (bool)currData.GetProperty(visibilityIndicator.Property); } else { isVisible = true; } } else { isVisible = visibilityIndicator.VisiblityType == VisiblityType.AlwaysShow; } this.IsVisible = isVisible; } }
protected override void Validate(Entity entity, RuleArgs e) { var value = entity.GetProperty(e.Property) as string; if (!string.IsNullOrEmpty(value)) { var min = this.Min; if (value.Length < min) { e.BrokenDescription = string.Format( "{0} 不能低于 {1} 个字符。".Translate(), e.DisplayProperty(), min ); } else { var max = this.Max; if (value.Length > max) { e.BrokenDescription = string.Format( "{0} 不能超过 {1} 个字符。".Translate(), e.DisplayProperty(), max ); } } } }
public void PerformBehaviour(Entity target, Entity instigator) { if (!target.HasProperty((int)GameEntityPropertyEnum.AggroList)) { // no aggro list, nobody to give experience to. return; } var aggroList = (List <int>)(target.GetProperty((int)GameEntityPropertyEnum.AggroList).ObjectValue); if (aggroList.Count == 0) { return; } var xpAmount = _xpAmount / aggroList.Count; foreach (var entityId in aggroList) { var entity = _gameServer.Engine.GetEntity(entityId); if (entity == null) { continue; } var player = entity.GetPlayer(_gameServer.Engine); if (player == null) { continue; } _levelling.GiveExperienceToPlayer(player, entity, xpAmount); } }
/****/ public static byte GetWeaponUseCount(this Entity entity) { if (!entity.HasProperty(GameEntityPropertyEnum.WeaponUseCount)) { return(0); } return(entity.GetProperty(GameEntityPropertyEnum.WeaponUseCount).ByteValue); }
/**/ public static bool GetIsHuman(this Entity entity) { if (!entity.HasProperty(GameEntityPropertyEnum.IsHuman)) { return(false); } return(entity.GetProperty(GameEntityPropertyEnum.IsHuman).BoolValue); } public static void SetIsHuman(this Entity entity, bool value) { entity.SetProperty(new EntityProperty((short)GameEntityPropertyEnum.IsHuman, value)); } /**/ public static bool GetIsZombie(this Entity entity) { if (!entity.HasProperty(GameEntityPropertyEnum.IsZombie)) { return(false); } return(entity.GetProperty(GameEntityPropertyEnum.IsZombie).BoolValue); }
/****/ public static float GetVisibleRating(this Entity entity) { if (!entity.HasProperty(GameEntityPropertyEnum.VisibleRating)) { return(0); } return(entity.GetProperty(GameEntityPropertyEnum.VisibleRating).FloatValue); }
/**/ public static int GetChaseThinkCount(this Entity entity) { return(entity.GetProperty(GameEntityPropertyEnum.ChaseThinkCount).IntValue); } public static void IncrementChaseThinkCount(this Entity entity) { if (!entity.HasProperty(GameEntityPropertyEnum.ChaseThinkCount)) { entity.SetProperty(new EntityProperty((short)GameEntityPropertyEnum.ChaseThinkCount, (int)1)); } else { var prop = entity.GetProperty(GameEntityPropertyEnum.ChaseThinkCount); prop.IntValue = prop.IntValue + 1; } } /**/ public static double GetChaseStartTime(this Entity entity) { if (!entity.HasProperty(GameEntityPropertyEnum.ChaseStartTime)) { return(0); } return(entity.GetProperty(GameEntityPropertyEnum.ChaseStartTime).DoubleValue); }
/// <summary> /// 子类重写以实现过滤逻辑 /// </summary> /// <param name="entity"></param> /// <param name="input"></param> /// <returns></returns> protected virtual bool CanShow(Entity entity, string input) { if (this.IgnoreCase) input = input.ToLower(); foreach (var filterProperty in this.GetFilterProperty(entity)) { var value = entity.GetProperty(filterProperty) as string; if (value != null) { if (this.IgnoreCase) value = value.ToLower(); if(value.Contains(input)) return true; } } return false; }
/// <summary> /// 有必要的话,就修改Name /// </summary> /// <param name="newObject"></param> private void TryModifyName(Entity newObject, bool modifyName) { if (modifyName) { if (newObject is IHasHame) { var no = newObject as IHasHame; no.Name += "-新增"; } else { var mp = newObject.PropertiesContainer.GetAvailableProperties().Find("Name"); if (mp != null && !mp.IsReadOnly) { string name = newObject.GetProperty(mp).ToString(); newObject.SetProperty(mp, name + "-新增"); } } } }
/// <summary> /// 冗余路径中非首位的引用属的值作为值属性进行冗余,那么同样要进行值属性更新操作。 /// </summary> /// <param name="entity">The entity.</param> /// <param name="path">The path.</param> /// <param name="refChanged">该引用属性值变化了</param> private void UpdateRedundancyByRefValue(Entity entity, RedundantPath path, IRefIdProperty refChanged) { var newValue = entity.GetProperty(refChanged); this.UpdateRedundancy(entity, path.Redundancy, newValue, path.RefPathes, entity.Id); }
private static void CalculateCollectValue(Entity entity, IManagedProperty property, ManagedPropertyChangedEventArgs args) { var distance = Convert.ToDouble(args.NewValue) - Convert.ToDouble(args.OldValue); var oldValue = Convert.ToDouble(entity.GetProperty(property)); entity.SetProperty(property, oldValue + distance); }
/// <summary> /// 递归读取根对象的所有子对象 /// </summary> /// <param name="entity"></param> private void ReadChildren(Entity entity) { var allProperties = entity.PropertiesContainer.GetNonReadOnlyCompiledProperties(); var childrenList = new List<IList<Entity>>(); //遍历所有子属性,读取孩子列表 for (int i = 0, c = allProperties.Count; i < c; i++) { var property = allProperties[i]; if (property is IListProperty) { var children = entity.GetProperty(property) as IList<Entity>; if (children != null && children.Count > 0) { //所有孩子列表中的实体,都加入到对应的实体列表中。 //并递归读取孩子的孩子实体。 var entityType = children[0].GetType(); var list = this.FindAggregateList(entityType); childrenList.Add(list); for (int j = 0, c2 = children.Count; j < c2; j++) { var child = children[j]; list.Add(child); this.ReadChildren(child); } } } } }
/// <summary> /// 根据SelectedValuePath指定的值,获取目标属性值 /// </summary> /// <param name="entity"></param> /// <returns></returns> public static object GetSelectedValue(this SelectionViewMeta rvi, Entity entity) { var selectedValuePath = rvi.SelectedValuePath ?? Entity.IdProperty; //如果是一个引用属性,则返回引用属性的 Id var refProperty = selectedValuePath as IRefProperty; if (refProperty != null) { var meta = refProperty.GetMeta(entity); return refProperty.Nullable ? entity.GetRefNullableId(refProperty.RefIdProperty) : entity.GetRefId(refProperty.RefIdProperty); } return entity.GetProperty(selectedValuePath); }
internal static void EntityToJson(EntityViewMeta evm, Entity entity, EntityJson entityJson) { var isTree = evm.EntityMeta.IsTreeEntity; foreach (var propertyVM in evm.EntityProperties) { var property = propertyVM.PropertyMeta; var mp = property.ManagedProperty; if (mp != null) { //如果非树型实体,则需要排除树型实体的两个属性。 if (!isTree && (mp == Entity.TreeIndexProperty || mp == Entity.TreePIdProperty)) { continue; } //引用属性 if (propertyVM.IsReference) { var refMp = mp as IRefProperty; object value = string.Empty; var id = entity.GetRefNullableId(refMp.RefIdProperty); if (id != null) { value = id; } var idName = refMp.RefIdProperty.Name; entityJson.SetProperty(idName, value); //同时写入引用属性的视图属性,如 BookCategoryId_Label if (id != null && propertyVM.CanShowIn(ShowInWhere.List)) { var titleProperty = propertyVM.SelectionViewMeta.RefTypeDefaultView.TitleProperty; if (titleProperty != null) { var lazyRefEntity = entity.GetRefEntity(refMp.RefEntityProperty); var titleMp = titleProperty.PropertyMeta.ManagedProperty; if (titleMp != null) { value = lazyRefEntity.GetProperty(titleMp); } else { value = ObjectHelper.GetPropertyValue(lazyRefEntity, titleProperty.Name); } var name = EntityModelGenerator.LabeledRefProperty(idName); entityJson.SetProperty(name, value); } } } //一般托管属性 else { var pRuntimeType = property.PropertyType; var serverType = ServerTypeHelper.GetServerType(pRuntimeType); if (serverType.Name != SupportedServerType.Unknown) { var value = entity.GetProperty(mp); value = ToClientValue(pRuntimeType, value); entityJson.SetProperty(mp.Name, value); } } } //一般 CLR 属性 else { var pRuntimeType = property.PropertyType; var serverType = ServerTypeHelper.GetServerType(pRuntimeType); if (serverType.Name != SupportedServerType.Unknown) { var value = ObjectHelper.GetPropertyValue(entity, property.Name); value = ToClientValue(pRuntimeType, value); entityJson.SetProperty(property.Name, value); } } } }
/// <summary> /// 检测某个实体对象的某个实体属性是否可以只读。 /// </summary> /// <param name="entity"></param> /// <param name="property"></param> /// <returns></returns> internal static bool CheckIsReadOnly(Entity entity, WPFEntityPropertyViewMeta property) { //类指明为只读 var indicator = property.ReadonlyIndicator; if (indicator.Status == ReadOnlyStatus.ReadOnly || property.Owner.NotAllowEdit) { return true; } //检测动态属性 if (indicator.Status == ReadOnlyStatus.Dynamic && entity != null) { return (bool)entity.GetProperty(indicator.Property); } return false; }
public void ApplyToBlock(Entity block) { block.GetProperty<string>("CollisionSoundCue").Value = this.RubbleCue; block.Get<PhysicsBlock>().Box.Mass = this.Density; this.ApplyToEffectBlock(block.Get<ModelInstance>()); }
/// <summary> /// 清除子对象集合 /// </summary> /// <param name="oldEntity">The old entity.</param> /// <param name="entityInfo">The entity information.</param> protected virtual void MakeSavedCore(Entity oldEntity, EntityMeta entityInfo) { foreach (var item in entityInfo.ChildrenProperties) { var mp = item.ManagedProperty as IListProperty; //如果是懒加载属性,并且没有加载数据时,不需要遍历此属性值 if (!oldEntity.FieldExists(mp)) continue; var children = oldEntity.GetProperty(mp) as EntityList; if (children == null) continue; //清除已删除数据 children.CastTo<EntityList>().DeletedList.Clear(); //所有子对象,都标记为已保存 for (int i = children.Count - 1; i >= 0; i--) { var child = children[i] as Entity; if (child.IsDirty || child.IsNew) MakeSaved(child); } } oldEntity.MarkSaved(); }
/// <summary> /// 删除不必要的对象,只留下需要保存的“脏”数据 /// </summary> /// <param name="diffEntity">The difference entity.</param> /// <param name="entityInfo">The entity information.</param> protected virtual void ClearDataCore(Entity diffEntity, EntityMeta entityInfo) { foreach (var item in entityInfo.ChildrenProperties) { var mp = item.ManagedProperty; //如果是懒加载属性,并且没有加载数据时,不需要遍历此属性值 if (!diffEntity.FieldExists(mp)) continue; var children = diffEntity.GetProperty(mp) as EntityList; if (children == null) continue; for (int i = children.Count - 1; i >= 0; i--) { var child = children[i]; if (!child.IsDirty) { children.Remove(child); children.DeletedList.Remove(child); } else { this.ClearData(child); } } } }
/// <summary> /// 尝试更新冗余属性值。 /// </summary> internal void UpdateRedundancies(Entity entity) { //如果有一些在冗余属性路径中的属性的值改变了,则开始更新数据库的中的所有冗余字段的值。 Entity dbEntity = null; var propertiesInPath = _repository.GetPropertiesInRedundancyPath(); for (int i = 0, c = propertiesInPath.Count; i < c; i++) { var property = propertiesInPath[i]; //如果只有一个属性,那么就是它变更引起的更新 //否则,需要从数据库获取原始值来对比检测具体哪些属性值变更,然后再发起冗余更新。 bool isChanged = c == 1; var refProperty = property as IRefIdProperty; if (refProperty != null) { if (!isChanged) { if (dbEntity == null) { dbEntity = ForceGetById(entity); } var dbId = dbEntity.GetRefId(refProperty); var newId = entity.GetRefId(refProperty); isChanged = !object.Equals(dbId, newId); } if (isChanged) { foreach (var path in property.InRedundantPathes) { //如果这条路径中是直接把引用属性的值作为值属性进行冗余,那么同样要进行值属性更新操作。 if (path.ValueProperty.Property == property) { this.UpdateRedundancyByRefValue(entity, path, refProperty); } //如果是引用变更了,并且只有一个 RefPath,则不需要处理。 //因为这个已经在属性刚变更时的处理函数中实时处理过了。 else if (path.RefPathes.Count > 1) { this.UpdateRedundancyByIntermidateRef(entity, path, refProperty); } } } } else { var newValue = entity.GetProperty(property); if (!isChanged) { if (dbEntity == null) { dbEntity = ForceGetById(entity); } var dbValue = dbEntity.GetProperty(property); isChanged = !object.Equals(dbValue, newValue); } if (isChanged) { foreach (var path in property.InRedundantPathes) { UpdateRedundancyByValue(entity, path, newValue); } } } } entity.UpdateRedundancies = false; }