示例#1
0
        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);
        }
示例#2
0
 protected override void Dispose(bool disposing)
 {
     _db         = null;
     _dir        = null;
     _file       = null;
     _file_block = null;
 }
示例#3
0
        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);
        }
示例#4
0
        public EFDbIndexInput(DbFileContext db, DbDirectory dir)
        {
            Contract.Requires(_db != null && dir != null);

            _db  = db;
            _dir = dir;
        }
示例#5
0
 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.");
     }
 }
示例#6
0
        protected override void Dispose(bool disposing)
        {
            if (_isDisposed)
            {
                return;
            }
            if (disposing)
            {
                Flush();

                _db         = null;
                _dir        = null;
                _file       = null;
                _file_block = null;
            }
            _isDisposed = true;
        }
示例#7
0
        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);
        }
示例#8
0
        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);
        }
示例#9
0
        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;
        }
示例#10
0
        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();
            }
        }