//获取清除字段标记的描述 public string GetDescription(EntityMember em) { string des = em.Column.Description; des = ClearNote(des); return(des); }
/// <summary>places it. /// Creates instance of an entity, attached to the given chunk, and at the given chunk indices and adds it to entity data. /// </summary> /// <param name="prefabName">Name of prefab to instance for entity</param> /// <param name="chunk">Map chunk to spawn entity</param> /// <param name="tileIndices">Tile indices in the chunk to spawn entity</param> /// <returns>Entity component of new instance.</returns> internal Entity Spawn(string prefabName, Chunk chunk, IntegerPair tileIndices) { GameObject prefab = prefabDictionary[prefabName]; GameObject gOEntity; gOEntity = Instantiate( prefab, screenManager.GetScreenPositionAt(new Coordinates(chunk.lowerLeft.InWorld.X + tileIndices.I, chunk.lowerLeft.InWorld.Y + tileIndices.J)), Quaternion.identity ); EntityMember entityMember = gOEntity.GetComponent <EntityMember>(); if (entityMember) { if (!Place(entityMember, chunk, tileIndices)) { Destroy(entityMember.gameObject); return(null); } return(entityMember); } else { return(null); } }
/// <summary> /// Initializes the view. /// </summary> public void Initializing(EntityMemberBox box, EntityMember member) { if (box == null) { throw new ArgumentNullException("box"); } }
/// <summary> /// Updates the entity location data, to the given chunk and it's tile indices /// </summary> /// <param name="entityMember">An entity component.</param> /// <param name="chunk">Chunk to place entity.</param> /// <param name="tileIndices">Tile indices in chunk to place entity.</param> /// <returns></returns> internal bool Place(EntityMember entityMember, Chunk chunk, IntegerPair tileIndices) { if (entityMember && chunk != null) { if (!IsOccupied(new Coordinates(chunk, tileIndices), entityMember.Type)) { entityMember.SetLocation(chunk, tileIndices); if (entityMember.Type == "Player" && !playerCollection.Contains(entityMember)) { playerCollection.Add(entityMember); } else if (entityMember.Type == "Mob" && !mobCollection.Contains(entityMember)) { mobCollection.Add(entityMember); } //else if other types entityMember.Placed = true; return(true); } } return(false); }
/// <summary> /// Constructor. /// </summary> protected EntityMemberBinding(EntityMember member, string propertyName, object dataSource, string dataMember) : base(propertyName, dataSource, dataMember) { if (member == null) { throw new ArgumentNullException("member"); } _member = member; }
public void ImplicitCastTest() { EntityMember m1 = (ushort)2; Assert.Equal(EntityFieldType.UInt16, m1.ValueType); Assert.Equal(2, m1.UInt16Value); Assert.True(m1.HasValue); }
/// <summary> /// 根据成员路径填充相应的成员的值 /// </summary> /// <param name="target">Target.</param> /// <param name="path">eg: Order.Customer.ID or Name</param> private static void FillMemberValue(Entity target, ReadOnlySpan <char> path, DbDataReader reader, int clIndex) { if (reader.IsDBNull(clIndex)) //null直接跳过 { return; } var indexOfDot = path.IndexOf('.'); if (indexOfDot < 0) { ref EntityMember m = ref target.TryGetMember(path, out bool found); if (!found) //不存在的作为附加成员 { target.AddAttached(path.ToString(), reader.GetValue(clIndex)); } else { //Log.Warn($"Fill {target.Model.Name}.{path.ToString()} value={reader.GetValue(clIndex).ToString()}"); m.Flag.HasLoad = m.Flag.HasValue = true; switch (m.ValueType) { case EntityFieldType.String: m.ObjectValue = reader.GetString(clIndex); break; case EntityFieldType.Binary: m.ObjectValue = (byte[])reader.GetValue(clIndex); break; case EntityFieldType.Guid: m.GuidValue = reader.GetGuid(clIndex); break; case EntityFieldType.Decimal: m.DecimalValue = reader.GetDecimal(clIndex); break; case EntityFieldType.DateTime: m.DateTimeValue = reader.GetDateTime(clIndex); break; case EntityFieldType.Double: m.DoubleValue = reader.GetDouble(clIndex); break; case EntityFieldType.Float: m.FloatValue = reader.GetFloat(clIndex); break; case EntityFieldType.Enum: m.Int32Value = reader.GetInt32(clIndex); break; case EntityFieldType.Int64: m.Int64Value = reader.GetInt64(clIndex); break; case EntityFieldType.UInt64: m.UInt64Value = unchecked ((ulong)reader.GetInt64(clIndex)); break; case EntityFieldType.Int32: m.Int32Value = reader.GetInt32(clIndex); break; case EntityFieldType.UInt32: m.UInt32Value = unchecked ((uint)reader.GetInt32(clIndex)); break; case EntityFieldType.Int16: m.Int16Value = reader.GetInt16(clIndex); break; case EntityFieldType.UInt16: m.UInt16Value = unchecked ((ushort)reader.GetInt16(clIndex)); break; case EntityFieldType.Byte: m.ByteValue = reader.GetByte(clIndex); break; case EntityFieldType.Boolean: m.BooleanValue = reader.GetBoolean(clIndex); break; default: throw new NotSupportedException(m.ValueType.ToString()); } } }
public static string GetMemberName(EntityMember field) { if (field == null) { throw new ArgumentNullException(nameof(field)); } return(ToHuman(field.Name)); }
// 2008-18-8 - JM - changing signature so system can differentiate when the first parameter is null //internal TokenEvaluationResults(Exception ex, string error) internal TokenEvaluationResults(object owner, EntityMember member, object value, Exception ex, string error) : this(owner, member, value) { // set... //_member = member; //_value = value; _exception = ex; _error = error; _hasError = true; }
internal DtoEntityMemberField(string name, string jsonName, PropertyInfo dtoProp, EntityMember concreteMember) : base(name, jsonName, dtoProp) { if (concreteMember == null) { throw new ArgumentNullException("concreteMember"); } this.Member = concreteMember; }
/// <summary> /// Initializes the view. /// </summary> public void Initializing(EntityMemberBox box, EntityMember member) { if (box == null) { throw new ArgumentNullException("box"); } // readonly... this.ReadOnly = box.ReadOnly; }
public void SetFieldTest() { var entity = new EntityMember(); entity.SetField(fieldId: 555, value: "value"); var result = entity.Fields.Find(x => x.Id == 555).Values[0].Value; Assert.AreEqual(result, "value"); }
internal unsafe static int CalcMemberSize(ref EntityMember m, int *varSize, bool withNull) { if (m.MemberType == EntityMemberType.DataField) { if (m.HasValue) { switch (m.ValueType) { //TODO: others case EntityFieldType.EntityId: case EntityFieldType.Guid: case EntityFieldType.Decimal: return(2 + 16); case EntityFieldType.Boolean: return(2); //注意: bool值存储在标记位内,参考编码规则 case EntityFieldType.Byte: return(2 + 1); case EntityFieldType.DateTime: case EntityFieldType.Int64: case EntityFieldType.UInt64: case EntityFieldType.Double: return(2 + 8); case EntityFieldType.Enum: case EntityFieldType.Float: case EntityFieldType.UInt32: case EntityFieldType.Int32: return(2 + 4); case EntityFieldType.Int16: case EntityFieldType.UInt16: return(2 + 2); case EntityFieldType.Binary: { *varSize = ((byte[])m.ObjectValue).Length; return(2 + 3 + *varSize); } case EntityFieldType.String: { *varSize = CalcStringUtf8Size((string)m.ObjectValue); return(2 + 3 + *varSize); } default: return(0); } } else { if (withNull) { return(2); } } } return(0); }
internal bool Move(EntityMember entityMember, Vector2 directionVector) { if (entitiesManager & entityMember) { return(entitiesManager.SetMovement(entityMember, directionVector)); } else { return(false); } }
private Behaviors GetBehaviors(EntityMember entityMember) { if (entityMember) { return(entityMember.GetComponent <Behaviors>()); } else { return(null); } }
public void SetFieldAndTypeTest() { var entity = new EntityMember(); entity.SetField(fieldId: 555, value: "value", 888); var value = entity.Fields.Find(x => x.Id == 555).Values[0].Value; var @enum = entity.Fields.Find(x => x.Id == 555).Values[0].Enum; Assert.AreEqual(value, "value"); Assert.AreEqual(@enum, 888); }
public KeyPredicate(ushort id, KeyPredicateType type, DateTime value) { Type = type; Value = new EntityMember() { Id = id, DateTimeValue = value, MemberType = EntityMemberType.DataField, ValueType = EntityFieldType.DateTime }; Value.Flag.HasValue = true; }
internal EntityMember Value; //TODO:考虑AnyValue public KeyPredicate(ushort id, KeyPredicateType type, string value) { Type = type; Value = new EntityMember() { Id = id, ObjectValue = value, MemberType = EntityMemberType.DataField, ValueType = EntityFieldType.String }; Value.Flag.HasValue = value != null; }
/// <summary> /// Updates the entity coordinates, as long as the location isn't occupied /// </summary> /// <param name="entityMember">An entity component</param> /// <param name="coordinates">Map coordinates</param> /// <returns>True if successful, false if entity is null, or coordinates are occupied.</returns> internal bool Place(EntityMember entityMember, Coordinates coordinates) { Chunk chunk = worldManager.GetLoadedChunk(coordinates); if (chunk != null) { return(Place(entityMember, chunk, new IntegerPair(coordinates.InChunks.I, coordinates.InChunks.J))); } else { return(false); } }
/// <summary> /// Initializes the view. /// </summary> public void Initializing(EntityMemberBox box, EntityMember member) { if (box == null) { throw new ArgumentNullException("box"); } if (member == null) { throw new ArgumentNullException("member"); } // set... _member = member; }
public void SetAndGetFieldAndTypeTest() { var entity = new EntityMember(); entity.SetField(fieldId: 555, value: "value", 888); var result = entity.GetField(555); Assert.IsInstanceOfType(result, typeof(Field)); Assert.AreEqual(result.Id, 555); Assert.AreEqual(result.Values.Count, 1); Assert.AreEqual(result.Values[0].Enum, 888); Assert.AreEqual(result.Values[0].Value, "value"); }
/// <summary> /// Constructor. /// </summary> public MemberEditorEventArgs(Control innerEditor, EntityMember member) { if (innerEditor == null) { throw new ArgumentNullException("innerEditor"); } if (member == null) { throw new ArgumentNullException("member"); } _innerEditor = innerEditor; _member = member; }
/// <summary> /// Deserialization constructor. /// </summary> /// <param name="info"></param> /// <param name="context"></param> protected SelectMapField(SerializationInfo info, StreamingContext context) { if (info == null) { throw new ArgumentNullException("info"); } // get... _resultOrdinal = info.GetInt32("_resultOrdinal"); _field = (EntityField)EntityMember.Restore(info, OnNotFound.ThrowException); if (_field == null) { throw new InvalidOperationException("_field is null."); } }
public void GetNullFieldTest() { var entity = new EntityMember(); entity.Fields.Add(new Field { Id = 555, Values = new List <FieldValue> { new FieldValue { Enum = 444, Value = "value" } } }); var result = entity.GetField(0); Assert.IsNull(result); }
internal static string BuildInsertEntityCommand(Entity entity, bool checkExists = false) { //TODO: use Prepared statements and cache it, 另可考虑JSON方式 var model = entity.Model; var sb = StringBuilderCache.Acquire(); sb.Append($"INSERT INTO \"{model.Name}\" ("); var vsb = StringBuilderCache.Acquire(); vsb.Append(") VALUES ("); for (int i = 0; i < entity.Members.Length; i++) { ref EntityMember m = ref entity.Members[i]; if (m.HasValue || m.HasChanged) { if (i != 0) { sb.Append(','); vsb.Append(','); } switch (m.MemberType) { case EntityMemberType.DataField: { DataFieldModel fm = (DataFieldModel)model.GetMember(m.Id, true); sb.Append($"\"{fm.Name}\""); BuildDataFieldValue(vsb, ref m); } break; //case EntityMemberType.FieldSet: // { // FieldSetModel fm = (FieldSetModel)model.GetMember(m.Id, true); // sb.Append($"\"{fm.Name}\""); // BuildFieldSetValue(vsb, ref m); // } // break; default: throw new NotSupportedException("Not supported member type"); } } }
public void MemberSameTest() { EntityMember m1 = new EntityMember(); m1.MemberType = EntityMemberType.DataField; m1.ValueType = EntityFieldType.String; m1.ObjectValue = new string('A', 5); m1.Flag.HasValue = true; EntityMember m2 = new EntityMember(); m2.MemberType = EntityMemberType.DataField; m2.ValueType = EntityFieldType.String; m2.ObjectValue = new string('A', 5); m2.Flag.HasValue = true; Assert.True(Equals(m1.ObjectValue, m2.ObjectValue)); }
internal PlayerEntity SpawnPlayer(string name) { Coordinates spawnCoords = worldManager.world.PlayerSpawnCoordinates; EntityMember otherPlayer = playerCollection.MemberAt(spawnCoords); EntityMember otherMob = mobCollection.MemberAt(spawnCoords); if (otherPlayer) { Despawn(otherPlayer); // temporary solution } else if (otherMob) { Despawn(otherMob); // temporary solution } PlayerEntity player = (PlayerEntity)Spawn("Player", spawnCoords); player.name = name; return(player); }
internal SqlJoin(string alias, JoinType type, ChildToParentEntityLink link) : this(alias, type) { if (link == null) { throw new ArgumentNullException("link"); } // set... _targetMember = link; // et... _targetEntityType = link.ParentEntityType; if (_targetEntityType == null) { throw new InvalidOperationException("_targetEntityType is null."); } // keys... _targetKeyFields = _targetEntityType.GetKeyFields(); if (_targetKeyFields == null) { throw new InvalidOperationException("'_targetKeyFields' is null."); } if (_targetKeyFields.Length == 0) { throw new InvalidOperationException("'_targetKeyFields' is zero-length."); } // get... _sourceFields = link.GetLinkFields(); if (_sourceFields == null) { throw new InvalidOperationException("_sourceFields is null."); } if (_targetKeyFields.Length != _sourceFields.Length) { throw new InvalidOperationException(string.Format("Length mismatch for '_targetKeyFields' and '_sourceFields': {0} cf {1}.", _targetKeyFields.Length, _sourceFields.Length)); } }
internal unsafe void WriteMember(ref EntityMember m, int *varSize, bool writeNull, bool orderDescFlag) { //如果分区键成员或索引键成员,需要写入排序标记 var mid = m.Id; if (orderDescFlag) { mid |= 1 << IdUtil.MEMBERID_ORDER_OFFSET; } //根据成员类型按存储格式写入 if (m.MemberType == EntityMemberType.DataField) { if (m.HasValue) { //TODO: fix others switch (m.ValueType) { case EntityFieldType.String: WriteUInt16((ushort)(mid | IdUtil.STORE_FIELD_VAR_FLAG)); WriteString((string)m.ObjectValue, varSize); break; case EntityFieldType.Binary: WriteUInt16((ushort)(mid | IdUtil.STORE_FIELD_VAR_FLAG)); WriteBytes((byte[])m.ObjectValue, varSize); break; case EntityFieldType.UInt16: WriteUInt16((ushort)(mid | 2)); WriteUInt16(m.UInt16Value); break; case EntityFieldType.Int32: WriteUInt16((ushort)(mid | 4)); WriteInt32(m.Int32Value); break; case EntityFieldType.UInt64: WriteUInt16((ushort)(mid | 8)); WriteUInt64(m.UInt64Value); break; case EntityFieldType.Guid: WriteUInt16((ushort)(mid | IdUtil.STORE_FIELD_16_LEN_FLAG)); WriteGuid(m.GuidValue); break; case EntityFieldType.EntityId: WriteUInt16((ushort)(mid | IdUtil.STORE_FIELD_16_LEN_FLAG)); WriteGuid((EntityId)m.ObjectValue); break; case EntityFieldType.Byte: WriteUInt16((ushort)(mid | 1)); dataPtr[index++] = m.ByteValue; break; case EntityFieldType.DateTime: WriteUInt16((ushort)(mid | 8)); WriteInt64(m.DateTimeValue.Ticks); break; case EntityFieldType.Boolean: var flag = m.BooleanValue ? IdUtil.STORE_FIELD_BOOL_TRUE_FLAG : IdUtil.STORE_FIELD_BOOL_FALSE_FLAG; WriteUInt16((ushort)(mid | flag)); break; case EntityFieldType.Float: WriteUInt16((ushort)(mid | 4)); WriteFloat(m.FloatValue); break; case EntityFieldType.Double: WriteUInt16((ushort)(mid | 8)); WriteDouble(m.DoubleValue); break; default: throw ExceptionHelper.NotImplemented($"{m.ValueType}"); } } else { if (writeNull) { WriteUInt16((ushort)(mid | IdUtil.STORE_FIELD_NULL_FLAG)); } } } }
/// <summary> /// Evaluates the property expansion, returning more details. /// </summary> /// <param name="propertyName"></param> /// <returns></returns> private TokenEvaluationResults EvaluateInternal(string propertyName, EvaluateFlags flags, bool useAdvancedMethod) { if (propertyName == null) { throw new ArgumentNullException("propertyName"); } if (propertyName.Length == 0) { throw new ArgumentOutOfRangeException("'propertyName' is zero-length."); } // mbr - 13-06-2007 - force string? bool forceString = false; if ((int)(flags & EvaluateFlags.ConvertResultToString) != 0) { forceString = true; } // check... if (Host == null) { throw new InvalidOperationException("'Host' is null."); } // walk... try { // mbr - 02-02-2006 - if the context is dictionary, then go in one level... object useObject = null; string toEvaluate = propertyName; if (Context is IDictionary) { // trim... int index = propertyName.IndexOf("."); string remaining = null; if (index != -1) { propertyName = toEvaluate.Substring(0, index).Trim(); remaining = toEvaluate.Substring(index + 1).Trim(); } // get... useObject = ((IDictionary)this.Context)[propertyName]; if (useObject == null) { var e = new TokenEvaluatorEventArgs(propertyName); this.OnTokenNotFound(e); // return... if (e.WasResultSet) { // mbr - 2013-06-07 - step through into the remaining items... //return new TokenEvaluationResults(null, DoStringConversion(e.Result)); useObject = e.Result; } else { // mbr - 2009-04-24 - if we are ignoring missing values, send back an error... if ((int)(flags & EvaluateFlags.IgnoreMissingValues) != 0) { return(new TokenEvaluationResults(useObject, null, null, null, string.Format("(Couldn't evaluate [{0}])", propertyName))); } else { return(null); } } } // anything else? if (remaining == null || remaining.Length == 0) { if (forceString) { return(new TokenEvaluationResults(useObject, null, DoStringConversion(useObject))); } else { return(new TokenEvaluationResults(useObject, null, useObject)); } } // flip... toEvaluate = remaining; } else { useObject = this.Context; } // mbr - 25-07-2008 - ok, if we have an entity and a single part expression, look for the field, otherwise use data binder... if (useAdvancedMethod && useObject is Entity && toEvaluate.IndexOf(".") == -1) { // find that member! EntityType et = EntityType.GetEntityType(useObject, OnNotFound.ThrowException); if (et == null) { throw new InvalidOperationException("et is null."); } // we're looking for a value... object value = null; EntityMember usedMember = null; // find... EntityField field = et.Fields[toEvaluate]; if (field != null) { usedMember = field; value = field.GetValue(useObject); } else { EntityProperty prop = et.Properties[toEvaluate]; if (prop != null) { usedMember = prop; value = prop.GetValue(useObject); } else { // ChildToParentEntityLink link = (ChildToParentEntityLink)et.ChildLinks[toEvaluate]; // if(link != null) // { // usedMember = link; // value = link.GetValue(useObject); // } // else value = DataBinder.Eval(useObject, toEvaluate); } } // convert... if (forceString) { value = DoStringConversion(value); } // return the value... return(new TokenEvaluationResults(useObject, usedMember, value)); } else { // eval from there... object value = DataBinder.Eval(useObject, toEvaluate); if (forceString) { value = DoStringConversion(value); } // return the value... return(new TokenEvaluationResults(useObject, null, value)); } } catch (Exception ex) { if (this.Log.IsWarnEnabled) { this.Log.Warn(string.Format("Failed to evaluate '{0}'.", propertyName), ex); } // mbr - 25-07-2008 - changed to use object... //return string.Format("(Couldn't evaluate [{0}])", propertyName); return(new TokenEvaluationResults(null, null, null, ex, string.Format("(Couldn't evaluate [{0}])", propertyName))); } }