/// <summary> /// Instantiates a new database. Each data file that's part of the database must be included in the files parameter. /// The order of the files is irrelevant. /// </summary> public Database(IEnumerable <string> files) { foreach (string file in files) { using (var fs = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read)) { byte[] fileHeaderBytes = new byte[8192]; fs.Read(fileHeaderBytes, 0, 8192); // This is kindy hackish as "this" isn't operational yet. As such, any calls to "this" will fail. // We know however that, currently, FileHeaderPage doesn't use the reference. Should be changed // later on. var fileHeaderPage = new FileHeaderPage(fileHeaderBytes, this); // Store reference to data file Files.Add(fileHeaderPage.FileID, new DataFile(fileHeaderPage.FileID, file)); } } // Instantiate buffer manager bufferManager = new BufferManager(this); // Read boot page properties var bootPage = GetBootPage(); Name = bootPage.DatabaseName; ID = bootPage.DBID; // Parse vital base tables BaseTables = new BaseTableData(this); // Startup dmv generator Dmvs = new DmvGenerator(this); }
private void InitDatabaseStream(Stream fs, string file = "") { var fileHeaderBytes = new byte[8192]; fs.Read(fileHeaderBytes, 0, 8192); // This is kindy hackish as "this" isn't operational yet. As such, any calls to "this" will fail. // We know however that, currently, FileHeaderPage doesn't use the reference. Should be changed // later on. var fileHeaderPage = new FileHeaderPage(fileHeaderBytes, this); if (BindingID == Guid.Empty) { BindingID = fileHeaderPage.BindingID; } if (BindingID != fileHeaderPage.BindingID) { throw new BindingIDMismatchException(file, BindingID, fileHeaderPage.BindingID); } fs.Seek(fs.Position - 8192, SeekOrigin.Begin); Files.Add(fileHeaderPage.FileID, fs); }