FileInfo[] GetCreateDbFiles() { if (DbDirectory == null) { LoadMetaDirectory(); } var potentialSources = new List <FileInfo>(); var tableScripts = DbDirectory.GetSubDirectory("Tables").GetFilesOrEmpty("*.sql"); // Create tables: potentialSources.Add(DbDirectory.GetFile("@Create.Database.sql")); potentialSources.AddRange(tableScripts.Except(x => x.Name.ToLower().EndsWithAny(".fk.sql", ".data.sql"))); // Insert data: potentialSources.Add(DbDirectory.GetFile("@Create.Database.Data.sql")); potentialSources.AddRange(tableScripts.Where(x => x.Name.ToLower().EndsWith(".data.sql"))); potentialSources.Add(DbDirectory.GetFile("Customize.Database.sql")); // Add foreign keys potentialSources.AddRange(tableScripts.Where(x => x.Name.ToLower().EndsWith(".fk.sql"))); var sources = potentialSources.Where(f => f.Exists()).ToArray(); if (sources.None()) { throw new Exception("No SQL creation script file was found. I checked:\r\n" + potentialSources.ToLinesString()); } return(sources); }
protected override void Dispose(bool disposing) { _db = null; _dir = null; _file = null; _file_block = null; }
private static DbDirectory ConvertModel(Directory directory) { var dir = new DbDirectory { Id = directory.Id, Materials = new List <DbMaterial>(), Html = directory.Html, Title = directory.Title }; if (directory.Materials == null) { return(dir); } foreach (var material in directory.Materials.Select(material => new DbMaterial() { Id = material.Id, DirectoryId = dir.Id, Html = material.Html, Title = material.Title })) { dir.Materials.Add(material); } return(dir); }
public EFDbIndexInput(DbFileContext db, DbDirectory dir) { Contract.Requires(_db != null && dir != null); _db = db; _dir = dir; }
void LoadMetaDirectory() { // Not explicitly specified. Take a guess: DbDirectory = AppDomain.CurrentDomain.WebsiteRoot().Parent.GetSubDirectory("DB"); if (!DbDirectory.Exists()) { throw new Exception("Failed to find the DB folder from which to create the temp database."); } }
protected override void Dispose(bool disposing) { if (_isDisposed) { return; } if (disposing) { Flush(); _db = null; _dir = null; _file = null; _file_block = null; } _isDisposed = true; }
protected bool Open(string dirPath) { Contract.Requires(_db != null); _dir = _db.DirectorySet.SingleOrDefault(obj => obj.Name.Equals(dirPath)); if (_dir == null) { _dir = new DbDirectory(); _dir.Name = dirPath; _db.DirectorySet.Add(_dir); _db.SaveChanges(); } interalLockFactory = new EFDbLockFactory(_db, _dbGuid, dirPath); isOpen = (_dir != null); return(isOpen); }
private static Directory ConvertDBModel(DbDirectory dbDirectory) { if (dbDirectory == null) { return(null); } var dir = new Directory { Id = dbDirectory.Id, Html = dbDirectory.Html, Title = dbDirectory.Title }; foreach (var material in dbDirectory.Materials.Select(EFMaterialRepository.ConvertDBModel)) { dir.Materials.Add(material); } return(dir); }
protected override void Dispose(bool disposing) { // 清掉所有這個Directory所產生的Lock if (_disposed) { return; } if (disposing) { isOpen = false; _db.Dispose(); _db = null; } interalLockFactory = null; _db = null; _dir = null; _disposed = true; }
public void TestDBSchema() { Guid guid = Guid.NewGuid(); using (DbFileContext db = new DbFileContext()) { DbDirectory dir = new DbDirectory() { Name = "a_dir_" + guid.ToString(), }; db.DirectorySet.Add(dir); DbFileInfo file = new DbFileInfo("a_file"); dir.FileSet.Add(file); DbFileBlock block = new DbFileBlock(100); byte[] bytes = Encoding.UTF8.GetBytes("Hello World"); Array.Copy(bytes, block.RawData, bytes.Length); file.BlockSet.Add(block); db.SaveChanges(); } }