Ejemplo n.º 1
0
        public SimpleFlatFieldDefinition[] GetColumns(int length)
        {
            Column[] expliciteColumns = ExpliciteColumns;
            if (Pattern == null && expliciteColumns == null)
            {
                throw new DataHolderException(
                          "Array-field \"{0}\" had no Pattern NOR an explicit set of Columns - Make sure either of them are set and valid.",
                          this);
            }
            if (Pattern != null && expliciteColumns != null)
            {
                throw new DataHolderException(
                          "Array-field \"{0}\" defined Pattern AND an explicit set of Columns - Make sure to only specify one.",
                          (object)this);
            }
            if (Pattern != null)
            {
                List <SimpleFlatFieldDefinition> flatFieldDefinitionList = new List <SimpleFlatFieldDefinition>();
                for (int offset = Offset; offset < Offset + length; ++offset)
                {
                    flatFieldDefinitionList.Add(new SimpleFlatFieldDefinition(Table,
                                                                              Patterns.Compile(Pattern, offset)));
                }
                return(flatFieldDefinitionList.ToArray());
            }

            length = expliciteColumns.Length;
            SimpleFlatFieldDefinition[] flatFieldDefinitionArray = new SimpleFlatFieldDefinition[length];
            for (int index = 0; index < length; ++index)
            {
                flatFieldDefinitionArray[index] =
                    new SimpleFlatFieldDefinition(expliciteColumns[index].Table, expliciteColumns[index].Name);
            }
            return(flatFieldDefinitionArray);
        }
Ejemplo n.º 2
0
        public SimpleFlatFieldDefinition[] GetColumns(int length)
        {
            var cols = ExpliciteColumns;

            if (Pattern == null && cols == null)
            {
                throw new DataHolderException("Array-field \"{0}\" had no Pattern NOR an explicit set of Columns - Make sure either of them are set and valid.", this);
            }

            if (Pattern != null && cols != null)
            {
                throw new DataHolderException("Array-field \"{0}\" defined Pattern AND an explicit set of Columns - Make sure to only specify one.", this);
            }

            if (Pattern != null)
            {
                var list = new List <SimpleFlatFieldDefinition>();
                for (var i = Offset; i < Offset + length; i++)
                {
                    list.Add(new SimpleFlatFieldDefinition(Table, Patterns.Compile(Pattern, i)));
                }
                return(list.ToArray());
            }

            //if (cols.Length > length)
            //{
            //    throw new DataHolderException("Array-field \"{0}\" had an invalid amount of Columns ({1}) - Required: {2}", this, ExpliciteColumns.Length, length);
            //}


            length = cols.Length;
            var defs = new SimpleFlatFieldDefinition[length];

            for (var i = 0; i < length; i++)
            {
                defs[i] = new SimpleFlatFieldDefinition(cols[i].Table, cols[i].Name);
            }
            return(defs);
        }
Ejemplo n.º 3
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);
			}
		}
Ejemplo n.º 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);
			}
		}
        public SimpleFlatFieldDefinition[] GetColumns(int length)
        {
            var cols = ExpliciteColumns;
            if (Pattern == null && cols == null)
            {
                throw new DataHolderException("Array-field \"{0}\" had no Pattern NOR an explicit set of Columns - Make sure either of them are set and valid.", this);
            }

            if (Pattern != null && cols != null)
            {
                throw new DataHolderException("Array-field \"{0}\" defined Pattern AND an explicit set of Columns - Make sure to only specify one.", this);
            }

            if (Pattern != null)
            {
                var list = new List<SimpleFlatFieldDefinition>();
                for (var i = Offset; i < Offset + length; i++)
                {
                    list.Add(new SimpleFlatFieldDefinition(Table, Patterns.Compile(Pattern, i)));
                }
                return list.ToArray();
            }

            //if (cols.Length > length)
            //{
            //    throw new DataHolderException("Array-field \"{0}\" had an invalid amount of Columns ({1}) - Required: {2}", this, ExpliciteColumns.Length, length);
            //}

            length = cols.Length;
            var defs = new SimpleFlatFieldDefinition[length];
            for (var i = 0; i < length; i++)
            {
                defs[i] = new SimpleFlatFieldDefinition(cols[i].Table, cols[i].Name);
            }
            return defs;
        }