CreateConnection() public static method

public static CreateConnection ( ) : HangfireDbContext
return Hangfire.Mongo.Database.HangfireDbContext
示例#1
0
        private static void RecreateDatabaseAndInstallObjects()
        {
            using (var context = ConnectionUtils.CreateConnection())
            {
                try
                {
                    context.Init(new MongoStorageOptions());

                    context.DistributedLock.DeleteMany(new BsonDocument());
                    context.StateData.DeleteMany(new BsonDocument());
                    context.Job.DeleteMany(new BsonDocument());
                    context.JobQueue.DeleteMany(new BsonDocument());
                    context.Server.DeleteMany(new BsonDocument());
                }
                catch (MongoException ex)
                {
                    throw new InvalidOperationException("Unable to cleanup database.", ex);
                }
            }
        }