public static KeySchema ReadSchema(byte[] buffer) { int offset = 0; KeySchema SubjectSchema = new KeySchema(); SubjectSchema.KeyName = Encoding.Default.GetString(buffer, offset, 12); offset += 12; SubjectSchema.KeyLength = BitConverter.ToInt32(buffer, 12); offset += 4; SubjectSchema.Constraint = buffer[24]; offset += 1; if (SubjectSchema.CheckConstraint(FOREIGNKEY)) { Array.Copy(buffer, offset, SubjectSchema.RelatedTableName, 0, 16); offset += 16; } if (SubjectSchema.CheckConstraint(CHECK)) { Array.Copy(buffer, offset, SubjectSchema.CheckConstraintCondition, 0, 64); offset += 64; } if (SubjectSchema.CheckConstraint(DEFAULT)) { Array.Copy(buffer, offset, SubjectSchema.DefaultValue, 0, 128); offset += 128; } if (SubjectSchema.CheckConstraint(INDEX)) { Array.Copy(buffer, offset, SubjectSchema.IndexFileName, 0, 20); offset += 20; } return(SubjectSchema); }
public static Schema ReadSchemaFile(string FileName) { FileStream SchemaReader = new FileStream(DBA.Definitions.Fields.DatabaseLocation + FileName, FileMode.Open); Schema SubjectSchema = new Schema(); byte[] Buffer = new byte[16]; SchemaReader.Read(Buffer, 0, 16); SubjectSchema.TableName = Encoding.Default.GetString(Buffer); Buffer = new byte[24]; SchemaReader.Read(Buffer, 0, 24); SubjectSchema.LastAccessed = DateTime.FromBinary(BitConverter.ToInt64(Buffer, 0)); SubjectSchema.LastEdited = DateTime.FromBinary(BitConverter.ToInt64(Buffer, 8)); SubjectSchema.LastIndexed = DateTime.FromBinary(BitConverter.ToInt64(Buffer, 16)); Buffer = new byte[8]; SchemaReader.Read(Buffer, 0, 8); SubjectSchema.recordLength = BitConverter.ToInt32(Buffer, 0); SubjectSchema.RecordsCount = BitConverter.ToInt32(Buffer, 4); while (SchemaReader.Position < SchemaReader.Length) { Buffer = new byte[256]; SchemaReader.Read(Buffer, 0, 256); SubjectSchema.Keys.Add(KeySchema.ReadSchema(Buffer)); } return(SubjectSchema); }
public static Schema WriteSchemaFile(Schema SubjectSchema) { FileStream SchemaWriter = new FileStream(DBA.Definitions.Fields.DatabaseLocation + SubjectSchema.TableName.ComputeSha1Hash() + ".tsf", FileMode.OpenOrCreate); SchemaWriter.Write(Encoding.Default.GetBytes(SubjectSchema.TableName), 0, Encoding.Default.GetByteCount(SubjectSchema.TableName)); byte[] Buffer = new byte[24]; Array.Copy(BitConverter.GetBytes(SubjectSchema.LastAccessed.ToBinary()), 0, Buffer, 0, 8); Array.Copy(BitConverter.GetBytes(SubjectSchema.LastEdited.ToBinary()), 0, Buffer, 8, 8); Array.Copy(BitConverter.GetBytes(SubjectSchema.LastIndexed.ToBinary()), 0, Buffer, 16, 8); SchemaWriter.Write(Buffer, 0, 24); SchemaWriter.Write(BitConverter.GetBytes(SubjectSchema.recordLength), 0, 4); SchemaWriter.Write(BitConverter.GetBytes(SubjectSchema.RecordsCount), 0, 4); foreach (KeySchema KS in SubjectSchema.Keys) { SchemaWriter.Write(KeySchema.WriteSchema(KS), 0, 256); } return(SubjectSchema); }
public static byte[] WriteSchema(KeySchema SubjectSchema) { int offset = 0; byte[] Buffer = new byte[256]; Array.Copy(Encoding.Default.GetBytes(SubjectSchema.KeyName), 0, Buffer, offset, 12); offset += 12; Array.Copy(BitConverter.GetBytes(SubjectSchema.KeyLength), 0, Buffer, offset, 4); offset += 4; Buffer[offset++] = SubjectSchema.Constraint; Array.Copy(SubjectSchema.RelatedTableName, 0, SubjectSchema.RelatedTableName, offset, 16); offset += 16; Array.Copy(SubjectSchema.CheckConstraintCondition, 0, Buffer, offset, 64); offset += 64; Array.Copy(SubjectSchema.DefaultValue, 0, Buffer, offset, 128); offset += 128; Array.Copy(SubjectSchema.IndexFileName, 0, Buffer, offset, 20); offset += 20; return(Buffer); }