コード例 #1
0
        private void InitialiseDatabase(string databaseFolderPath, bool keepLicenceFile)
        {
            TestSession.DeleteFolderIfExists(databaseFolderPath);
            Directory.CreateDirectory(databaseFolderPath);
            TestSession.CopyLicenceToDatabaseFolder(databaseFolderPath);
            Session = new TestSession(databaseFolderPath);
            Session.BeginUpdate();
            // Registering the persistable types will allow the database to be used without a
            // VelocityDB licence file.
            Schema.Instance.RegisterPersistableTypes(Session);
            Session.Commit();
            // Not documented in the VelocityDB manual, in order for the database to be used
            // without a licence file, we also need to first add one of each entity type,
            // which we can and will delete after removing the licence file from the database.
            // I'm fairly sure this has something to do with the VelocityDB Indexes, as (a) we
            // did not have to do this before Indexes were introduced, and (b) it is still not
            // necessary to do it for Schema, the one persistable type that does not use
            // Indexes. There has to be a better way.
            Data = new TestData(new QueryHelper());
            Session.BeginUpdate();
            AddOneOfEachEntityTypePersisted(Data, Session);
            Session.Commit();
            if (!keepLicenceFile)
            {
                RemoveLicenceFileFromDatabase();
            }
            Session.BeginUpdate();
            DeleteOneOfEachEntityType();
            Session.Commit();
            var databaseFolder = new DirectoryInfo(databaseFolderPath);

            foreach (var file in databaseFolder.GetFiles())
            {
                if (string.Compare(
                        file.Name, "1.odb", StringComparison.OrdinalIgnoreCase) != 0 &&
                    string.Compare(
                        file.Name, "2.odb", StringComparison.OrdinalIgnoreCase) != 0)
                {
                    file.Delete();
                }
            }
        }