Пример #1
0
		static void AddMapping(LightDBDefinitionSet defs, TableDefinition[] defaultTables, SimpleFlatFieldDefinition fieldDef,
			Dictionary<string, List<SimpleDataColumn>> mappedFields, IFlatDataFieldAccessor accessor, MemberInfo member)
		{
			var column = fieldDef.Column;

			var tables = defs.EnsureTables(fieldDef.Table, defaultTables);
			object defaultValue;
			if (!String.IsNullOrEmpty(fieldDef.DefaultStringValue))
			{
				defaultValue = StringParser.Parse(fieldDef.DefaultStringValue, member.GetVariableType());
			}
			else
			{
				if (String.IsNullOrEmpty(column))
				{
					return;
				}
				defaultValue = null;
			}

			foreach (var table in tables)
			{
				var dataHolders = defs.m_tableDataHolderMap.GetOrCreate(table);
				if (!dataHolders.Contains(accessor.DataHolderDefinition))
				{
					dataHolders.Add(accessor.DataHolderDefinition);
				}

				var mappedFieldMap = mappedFields.GetOrCreate(table.Name);

				SimpleDataColumn dataColumn;
                var dbAttrs = member.GetCustomAttributes<DBAttribute>();
                var attr = dbAttrs.Where(attribute => attribute is PersistentAttribute).FirstOrDefault() as PersistentAttribute;

				if (String.IsNullOrEmpty(column))
				{
					// use default value
					mappedFieldMap.Add(dataColumn = new SimpleDataColumn(fieldDef.Name, defaultValue));
				}
				else
				{
					dataColumn = mappedFieldMap.Find((cmpField) => cmpField.ColumnName == column);
					if (dataColumn == null)
					{
                        var type = member.GetActualType();
                        if (attr != null)
                            type = attr.ReadType ?? type;
                        var reader = Converters.GetReader(type);
                        mappedFieldMap.Add(dataColumn = new SimpleDataColumn(column, reader));
					}
				}

				dataColumn.FieldList.Add(accessor);
			}
		}
Пример #2
0
		public static void ModProp(object propHolder, MemberInfo prop, CmdTrigger<RealmServerCmdArgs> trigger)
		{
			if (prop != null && ReflectUtil.Instance.CanWrite(prop, trigger.Args.Role))
			{
				var exprType = prop.GetVariableType();
				if (!exprType.IsInteger())
				{
					trigger.Reply("Can only modify Integer-values.");
				}
				else
				{
					var expr = trigger.Text.Remainder.Trim();
					if (expr.Length == 0)
					{
						trigger.Reply("No expression given");
					}
					else
					{
						object error = null;
						var value = Convert.ToInt64(prop.GetUnindexedValue(propHolder));

						if (!Utility.Eval(exprType, ref value, expr, ref error, true))
						{
							trigger.Reply("Invalid expression: " + error);
						}
						else
						{
							var actualValue = TryParseEnum(value, exprType);
							prop.SetUnindexedValue(propHolder, actualValue);
							string strValue;
							if (exprType.IsEnum)
							{
								strValue = Enum.Format(exprType, actualValue, "g");
							}
							else
							{
								strValue = value.ToString();
							}
							trigger.Reply("Success: {0} is now {1}.", prop.Name, strValue);
						}
					}
				}
			}
			else
			{
				trigger.Reply("Invalid field.");
			}
		}
Пример #3
0
		public static void SetProp(object propHolder, MemberInfo prop, CmdTrigger<RealmServerCmdArgs> trigger)
		{
			if (prop != null && ReflectUtil.Instance.CanWrite(prop, trigger.Args.Role))
			{
				var expr = trigger.Text.Remainder.Trim();
				if (expr.Length == 0)
				{
					trigger.Reply("No expression given");
				}
				else
				{
					var exprType = prop.GetVariableType();
					object actualValue = null;

					if (exprType.IsInteger())
					{
						object error = null;
						long value = 0;
						if (!Utility.Eval(exprType, ref value, expr, ref error, false))
						{
							trigger.Reply("Invalid expression: " + error);
							return;
						}
						actualValue = ConvertActualType(value, exprType);
					}
					else
					{
						if (!Utility.Parse(expr, exprType, ref actualValue))
						{
							trigger.Reply("Could not change value \"{0}\" to Type: {1}", expr, exprType);
							return;
						}
					}

					prop.SetUnindexedValue(propHolder, actualValue);
					string strValue;
					if (exprType.IsEnum)
					{
						strValue = Enum.Format(exprType, actualValue, "g");
					}
					else
					{
						strValue = actualValue.ToString();
					}
					trigger.Reply("{0} is now {1}.", prop.Name, strValue);
				}
			}
			else
			{
				trigger.Reply("Invalid field.");
			}
		}
Пример #4
0
		static void AddMapping(LightDBDefinitionSet defs, TableDefinition[] defaultTables, SimpleFlatFieldDefinition fieldDef,
			Dictionary<string, List<SimpleDataColumn>> mappedFields, IFlatDataFieldAccessor accessor, MemberInfo member)
		{
			var column = fieldDef.Column;

			var tables = defs.EnsureTables(fieldDef.Table, defaultTables);
			object defaultValue;
			if (!String.IsNullOrEmpty(fieldDef.DefaultStringValue))
			{
				defaultValue = Utility.Parse(fieldDef.DefaultStringValue, member.GetVariableType());
			}
			else
			{
				if (String.IsNullOrEmpty(column))
				{
					return;
				}
				defaultValue = null;
			}

			if (accessor.DataHolderDefinition.Type.Name.EndsWith("TrainerEntry"))
			{
				defs.ToString();
			}

			foreach (var table in tables)
			{
				var dataHolders = defs.m_tableDataHolderMap.GetOrCreate(table);
				if (!dataHolders.Contains(accessor.DataHolderDefinition))
				{
					dataHolders.Add(accessor.DataHolderDefinition);
				}

				var mappedFieldMap = mappedFields.GetOrCreate(table.Name);

				SimpleDataColumn dataColumn;

				if (String.IsNullOrEmpty(column))
				{
					// use default value
					mappedFieldMap.Add(dataColumn = new SimpleDataColumn(fieldDef.Name, defaultValue));
				}
				else
				{
					dataColumn = mappedFieldMap.Find((cmpField) => cmpField.ColumnName == column);
					if (dataColumn == null)
					{
						mappedFieldMap.Add(dataColumn = new SimpleDataColumn(column, Converters.GetReader(member.GetActualType())));
					}
				}

				dataColumn.FieldList.Add(accessor);
			}
		}