public static MasterTable Open(string databasePath, string tableName, FieldInfo[] info) { MasterTable table = new MasterTable(); table.Fields = info; table.file = SequentialFile.Open(string.Format(@"{0}\{1}.mst", databasePath, tableName)); return table; }
private static int CalculateRecordLength(FieldInfo[] fields) { int recLen = 1; //first byte contains IsDeleted flag foreach (FieldInfo field in fields) { recLen += field.ByteLength; } return recLen; }
public static DataTable Create(string databasePath, string tableName, FieldInfo[] info) { DataTable table = new DataTable(); int recordLength = 0; //calculate record length recordLength = CalculateRecordLength(info); //create file to store data in table.Fields = info; table.file = SequentialFile.Create(string.Format(@"{0}\{1}.dat", databasePath, tableName), recordLength); //return reference to new table return table; }
public static MasterTable Create(string databasePath, string tableName, FieldInfo[] info) { MasterTable table = new MasterTable(); int recordLength = 0; //calculate record length foreach (FieldInfo field in info) { recordLength += field.ByteLength; } //create file to store data in table.Fields = info; table.file = SequentialFile.Create(string.Format(@"{0}\{1}.mst", databasePath, tableName), recordLength); //return reference to new table return table; }
public static Record FromBytes(byte[] bytes, FieldInfo[] fields) { //init int byteOffset = 0; Record record = new Record(); record.Data = new object[fields.Length]; //get IsDeleted byte record.IsDeleted = BitConverter.ToBoolean(bytes, byteOffset); byteOffset += 1; //get data for all fields for(int i=0; i < fields.Length; i++) { //DataType type = fields[i].Type; //int byteLen = fields[i].ByteLength; //int Len = fields[i].Length; //if (type == DataType.Boolean) //{ // record.Data[i] = BitConverter.ToBoolean(bytes, byteOffset); // byteOffset += byteLen; // } //else if (type == DataType.Integer) //{ // record.Data[i] = BitConverter.ToInt32(bytes, byteOffset); // byteOffset += byteLen; //} //else if (type == DataType.Text) //{ // StringBuilder sb = new StringBuilder(Len); // Encoding.UTF32. // = BitConverter.ToBoolean(bytes, byteOffset); // byteOffset += byteLen; //} //else //{ //} } //return record to caller return record; }
static void Main(string[] args) { FieldInfo[] fieldMasterFields = new FieldInfo[4]; FieldInfo[] objectMasterFields = new FieldInfo[3]; fieldMasterFields[0] = new FieldInfo("Table", DataType.Text, 128); fieldMasterFields[1] = new FieldInfo("Name", DataType.Text, 128); fieldMasterFields[2] = new FieldInfo("Type", DataType.Text, 128); fieldMasterFields[3] = new FieldInfo("Length", DataType.Integer, 1); objectMasterFields[0] = new FieldInfo("Name", DataType.Text, 128); objectMasterFields[1] = new FieldInfo("Type", DataType.Text, 128); objectMasterFields[2] = new FieldInfo("Name", DataType.Text, 128); MasterTable fieldMaster = MasterTable.Create(@".\data", "fields", fieldMasterFields); MasterTable objectMaster = MasterTable.Create(@".\data", "objects", objectMasterFields); DataTable heroes = DataTable.Create(@".\data", "heroes", fieldMasterFields); DataTable villans = DataTable.Create(@".\data", "villans", objectMasterFields); }