コード例 #1
0
ファイル: LightDBMgr.cs プロジェクト: uvbs/Asda2-Server
        public static void MapNestedArray(this LightDBDefinitionSet defs, IDataField dataField,
                                          IDataFieldDefinition fieldDef, Dictionary <string, List <SimpleDataColumn> > mappedFields)
        {
            NestedArrayFieldDefinition arrayFieldDefinition = (NestedArrayFieldDefinition)fieldDef;
            NestedArrayDataField       nestedArrayDataField = (NestedArrayDataField)dataField;

            TableDefinition[] defaultTables =
                defs.EnsureTables(arrayFieldDefinition.Table, dataField.DataHolderDefinition);
            foreach (FlatArrayFieldDefinition segment in arrayFieldDefinition.Segments)
            {
                SimpleFlatFieldDefinition[] columns = segment.GetColumns(nestedArrayDataField.Length);
                for (int index = 0; index < columns.Length; ++index)
                {
                    SimpleFlatFieldDefinition fieldDef1 = columns[index];
                    IDataField dataField1;
                    if (!((NestedArrayAccessor)nestedArrayDataField.ArrayAccessors[index]).InnerFields.TryGetValue(
                            segment.Name, out dataField1))
                    {
                        throw new DataHolderException("NestedArray definition {0} refered to non-existing field {1}",
                                                      new object[2]
                        {
                            (object)nestedArrayDataField,
                            (object)segment
                        });
                    }
                    LightDBMgr.AddMapping(defs, defaultTables, fieldDef1, mappedFields,
                                          (IFlatDataFieldAccessor)dataField1, dataField1.MappedMember);
                }
            }
        }
コード例 #2
0
ファイル: LightDBMgr.cs プロジェクト: uvbs/Asda2-Server
        public static void MapFlatSimple(this LightDBDefinitionSet defs, IDataField dataField,
                                         IDataFieldDefinition fieldDef, Dictionary <string, List <SimpleDataColumn> > mappedFields)
        {
            SimpleFlatFieldDefinition fieldDef1 = (SimpleFlatFieldDefinition)fieldDef;

            LightDBMgr.AddMapping(defs, defs.GetDefaultTables(dataField.DataHolderDefinition), fieldDef1, mappedFields,
                                  (IFlatDataFieldAccessor)dataField, dataField.MappedMember);
        }
コード例 #3
0
ファイル: LightDBMgr.cs プロジェクト: uvbs/Asda2-Server
        private static DataFieldDefinition CreateFlatSimple(IDataField dataField)
        {
            SimpleFlatFieldDefinition flatFieldDefinition = new SimpleFlatFieldDefinition();

            flatFieldDefinition.Name   = dataField.Name;
            flatFieldDefinition.Column = "";
            return((DataFieldDefinition)flatFieldDefinition);
        }
コード例 #4
0
ファイル: LightDBMgr.cs プロジェクト: uvbs/Asda2-Server
        public static void MapFlatArray(this LightDBDefinitionSet defs, IDataField dataField,
                                        IDataFieldDefinition fieldDef, Dictionary <string, List <SimpleDataColumn> > mappedFields)
        {
            FlatArrayFieldDefinition arrayFieldDefinition = (FlatArrayFieldDefinition)fieldDef;
            FlatArrayDataField       flatArrayDataField   = (FlatArrayDataField)dataField;

            TableDefinition[] defaultTables =
                defs.EnsureTables(arrayFieldDefinition.Table, dataField.DataHolderDefinition);
            SimpleFlatFieldDefinition[] columns        = arrayFieldDefinition.GetColumns(flatArrayDataField.Length);
            IDataFieldAccessor[]        arrayAccessors = flatArrayDataField.ArrayAccessors;
            for (int index = 0; index < columns.Length; ++index)
            {
                SimpleFlatFieldDefinition fieldDef1 = columns[index];
                LightDBMgr.AddMapping(defs, defaultTables, fieldDef1, mappedFields,
                                      (IFlatDataFieldAccessor)arrayAccessors[index], dataField.MappedMember);
            }
        }
コード例 #5
0
ファイル: LightDBMgr.cs プロジェクト: uvbs/Asda2-Server
        private static void AddMapping(LightDBDefinitionSet defs, TableDefinition[] defaultTables,
                                       SimpleFlatFieldDefinition fieldDef, Dictionary <string, List <SimpleDataColumn> > mappedFields,
                                       IFlatDataFieldAccessor accessor, MemberInfo member)
        {
            string column = fieldDef.Column;

            TableDefinition[] tableDefinitionArray = 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 = (object)null;
            }

            foreach (TableDefinition key in tableDefinitionArray)
            {
                List <DataHolderDefinition> holderDefinitionList =
                    defs.m_tableDataHolderMap.GetOrCreate <TableDefinition, DataHolderDefinition>(key);
                if (!holderDefinitionList.Contains(accessor.DataHolderDefinition))
                {
                    holderDefinitionList.Add(accessor.DataHolderDefinition);
                }
                List <SimpleDataColumn> simpleDataColumnList =
                    mappedFields.GetOrCreate <string, SimpleDataColumn>(key.Name);
                PersistentAttribute persistentAttribute =
                    ((IEnumerable <DBAttribute>)member.GetCustomAttributes <DBAttribute>())
                    .Where <DBAttribute>((Func <DBAttribute, bool>)(attribute => attribute is PersistentAttribute))
                    .FirstOrDefault <DBAttribute>() as PersistentAttribute;
                SimpleDataColumn simpleDataColumn;
                if (string.IsNullOrEmpty(column))
                {
                    simpleDataColumnList.Add(simpleDataColumn = new SimpleDataColumn(fieldDef.Name, defaultValue));
                }
                else
                {
                    simpleDataColumn =
                        simpleDataColumnList.Find(
                            (Predicate <SimpleDataColumn>)(cmpField => cmpField.ColumnName == column));
                    if (simpleDataColumn == null)
                    {
                        Type type1 = member.GetActualType();
                        if (persistentAttribute != null)
                        {
                            Type type2 = persistentAttribute.ReadType;
                            if ((object)type2 == null)
                            {
                                type2 = type1;
                            }
                            type1 = type2;
                        }

                        IFieldReader reader = Converters.GetReader(type1);
                        simpleDataColumnList.Add(simpleDataColumn = new SimpleDataColumn(column, reader));
                    }
                }

                simpleDataColumn.FieldList.Add(accessor);
            }
        }
コード例 #6
0
ファイル: LightDBMgr.cs プロジェクト: NecroSharper/WCell
        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);
            }
        }