示例#1
0
        public IList<MetaTableInfo> Load()
        {
            var tables = new List<MetaTableInfo>();
            using (var binaryReader = new BinaryReader(new FileStream(this.MetaFileName, FileMode.Open, FileAccess.Read, FileShare.Read)))
            {
                var tableCount = binaryReader.ReadInt32();

                for (int i = 0; i < tableCount; i++)
                {
                    var tableGUID = binaryReader.ReadStringMM();
                    var tableName = binaryReader.ReadStringMM();
                    var filePath = binaryReader.ReadStringMM();

                    var fieldCount = binaryReader.ReadInt32();
                    var fields = new List<MetaFieldInfo>();

                    for (int j = 0; j < fieldCount; j++)
                    {
                        var fieldInfo = new MetaFieldInfo();
                        fieldInfo.FieldName = binaryReader.ReadStringMM();
                        fields.Add(fieldInfo);
                    }

                    var table = new MetaTableInfo(fields);
                    table.TableGUID = tableGUID;
                    table.TableName = tableName;
                    table.FilePath = filePath;
                    table.InitializeAccess = false;

                    tables.Add(table);
                }
            }

            return tables;
        }
示例#2
0
        public IList <MetaTableInfo> Load()
        {
            var tables = new List <MetaTableInfo>();

            using (var binaryReader = new BinaryReader(new FileStream(this.MetaFileName, FileMode.Open, FileAccess.Read, FileShare.Read)))
            {
                var tableCount = binaryReader.ReadInt32();

                for (int i = 0; i < tableCount; i++)
                {
                    var tableGUID = binaryReader.ReadStringMM();
                    var tableName = binaryReader.ReadStringMM();
                    var filePath  = binaryReader.ReadStringMM();

                    var fieldCount = binaryReader.ReadInt32();
                    var fields     = new List <MetaFieldInfo>();

                    for (int j = 0; j < fieldCount; j++)
                    {
                        var fieldInfo = new MetaFieldInfo();
                        fieldInfo.FieldName = binaryReader.ReadStringMM();
                        fields.Add(fieldInfo);
                    }

                    var table = new MetaTableInfo(fields);
                    table.TableGUID        = tableGUID;
                    table.TableName        = tableName;
                    table.FilePath         = filePath;
                    table.InitializeAccess = false;

                    tables.Add(table);
                }
            }

            return(tables);
        }
示例#3
0
        private MetaTableInfo CreateNewTable(Type tableType)
        {
            //
            // 根据指定的类型,创建一个新的数据表,并添加到数据表集合,存储到数据库元数据信息文件中。
            //

            // 需要为table 的index 赋值

            var properties = tableType.GetProperties(BindingFlags.DeclaredOnly);

            var fields = new List <MetaFieldInfo>();

            var tableGUID = string.Empty;

            foreach (var propertyInfo in properties)
            {
                //
                // 能够作为实体字段的属性必须是可读,可写,并且支持的基础类型。
                //

                if (propertyInfo.CanRead && propertyInfo.CanWrite && IsTypeSupport(propertyInfo.PropertyType))
                {
                    var field = new MetaFieldInfo
                    {
                        FieldName         = propertyInfo.Name,
                        FieldPropertyInfo = propertyInfo
                    };

                    fields.Add(field);

                    tableGUID += propertyInfo.Name + "-";
                }
            }

            if (fields.Count == 0)
            {
                throw new ArgumentException("Entity type [" + tableType.FullName + "] is not persistable.");
            }

            var table = new MetaTableInfo(fields);

            table.TableName = tableType.FullName;
            table.TableGUID = tableGUID;

            //
            // 配置对象生成完成,开始生成对应的文件信息
            //

            table.FilePath = table.TableName + "_meta.hd";
            var tableMetaFilePath = Path.Combine(Path.GetDirectoryName(this.Config.DatabaseMetaFileName), table.FilePath);

            if (File.Exists(tableMetaFilePath))
            {
                File.Delete(tableMetaFilePath);
            }

            using (var binaryWriter = new BinaryWriter(File.Create(tableMetaFilePath)))
            {
                binaryWriter.Write(0);
            }

            return(table);
        }