GetDatabaseName() public static method

public static GetDatabaseName ( ) : string
return string
Example #1
0
 private static void RecreateDatabaseAndInstallObjects()
 {
     try
     {
         var client         = new MongoClient(ConnectionUtils.GetConnectionString());
         var database       = client.GetDatabase(ConnectionUtils.GetDatabaseName());
         var storageOptions = new MongoStorageOptions();
         var names          = MongoMigrationManager.RequiredSchemaVersion.CollectionNames(storageOptions.Prefix);
         foreach (var name in names.Where(n => !n.EndsWith(".schema")))
         {
             var collection = database.GetCollection <BsonDocument>(name);
             if (name.EndsWith(".signal"))
             {
                 CleanSignalCollection(collection);
             }
             else
             {
                 CleanCollection(collection);
             }
         }
     }
     catch (MongoException ex)
     {
         throw new InvalidOperationException("Unable to cleanup database.", ex);
     }
 }
Example #2
0
        public override void Before(MethodInfo methodUnderTest)
        {
            Monitor.Enter(GlobalLock);

            if (Initialized)
            {
                RecreateDatabaseAndInstallObjects();
                return;
            }

            // Drop the database and do not run any
            // migrations to initialize the database.
            var client = new MongoClient(ConnectionUtils.GetConnectionString());

            client.DropDatabase(ConnectionUtils.GetDatabaseName());
        }
        private static void RecreateDatabaseAndInstallObjects()
        {
            using (HangfireDbContext context = new HangfireDbContext(ConnectionUtils.GetConnectionString(), ConnectionUtils.GetDatabaseName()))
            {
                try
                {
                    context.Init();

                    context.Identifiers.DeleteMany(new BsonDocument());
                    context.DistributedLock.DeleteMany(new BsonDocument());
                    context.AggregatedCounter.DeleteMany(new BsonDocument());
                    context.Counter.DeleteMany(new BsonDocument());
                    context.Hash.DeleteMany(new BsonDocument());
                    context.Job.DeleteMany(new BsonDocument());
                    context.JobParameter.DeleteMany(new BsonDocument());
                    context.JobQueue.DeleteMany(new BsonDocument());
                    context.List.DeleteMany(new BsonDocument());
                    context.Server.DeleteMany(new BsonDocument());
                    context.Set.DeleteMany(new BsonDocument());
                    context.State.DeleteMany(new BsonDocument());
                }
                catch (MongoException ex)
                {
                    throw new InvalidOperationException("Unable to cleanup database.", ex);
                }
            }
        }
Example #4
0
        private static void RecreateDatabaseAndInstallObjects()
        {
            using (HangfireDbContext context = new HangfireDbContext(ConnectionUtils.GetConnectionString(), ConnectionUtils.GetDatabaseName()))
            {
                context.Init();

                MongoCollection[] collections =
                {
                    context.DistributedLock,
                    context.Counter,
                    context.Hash,
                    context.Job,
                    context.JobParameter,
                    context.JobQueue,
                    context.List,
                    context.Server,
                    context.Set,
                    context.State
                };

                foreach (MongoCollection collection in collections)
                {
                    WriteConcernResult result = collection.RemoveAll();
                    if (result.Ok == false)
                    {
                        throw new InvalidOperationException("Unable to cleanup database.");
                    }
                }
            }
        }