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); } } }
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."); } } } }