protected virtual void Dispose(bool disposing) { if (!this.disposed) { if (disposing) { context.Dispose(); } } this.disposed = true; }
private void CreateSomeDummyData() { if (AllowMongoDB) { MongoClient mongoClient = new MongoClient(MongoDatabaseConenction.ConnectionString); IMongoDatabase mongoDatabase = mongoClient.GetDatabase(MongoDatabaseConenction.DataSource); IMongoCollection <DatabaseConnection> mongoCollection = mongoDatabase.GetCollection <DatabaseConnection>("databases"); mongoCollection.InsertOne(MongoDatabaseConenction); IMongoCollection <App> mongoAppCollection = mongoDatabase.GetCollection <App>("apps"); mongoAppCollection.InsertOne(SampleApp()); } if (AllowPostgreSQL) { PortalDbContext postgreContext = GetPostgreSQLContext(); postgreContext.Database.EnsureCreated(); postgreContext.Databases.Add(PostgreSqlDatabaseConnection); postgreContext.Apps.Add(SampleApp()); postgreContext.SaveChanges(); postgreContext.Dispose(); } if (AllowSQLServer) { PortalDbContext sqlContext = GetSQLServerContext(); sqlContext.Database.EnsureCreated(); sqlContext.Databases.Add(SqlServerDatabaseConnection); sqlContext.Apps.Add(SampleApp()); // Sql Server must create a table for storing file sqlContext.Database.ExecuteSqlRaw("Create table [dbo].[uploadFiles] ([id] [nvarchar](450) NOT NULL, [file] [varbinary](max) NULL, CONSTRAINT [PK_uploadFiles] PRIMARY KEY CLUSTERED ( [id] ASC )WITH(PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON[PRIMARY]) ON[PRIMARY] TEXTIMAGE_ON[PRIMARY]"); sqlContext.SaveChanges(); sqlContext.Dispose(); } if (AllowMySQL) { PortalDbContext mysqlContext = GetMySQLContext(); mysqlContext.Database.EnsureCreated(); mysqlContext.Databases.Add(MySqlDatabaseConnection); mysqlContext.Apps.Add(SampleApp()); mysqlContext.Database.ExecuteSqlRaw("Create table `uploadFiles`(`id` varchar(255) NOT NULL, `file` mediumblob NULL, PRIMARY KEY(`id`)) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci"); mysqlContext.SaveChanges(); mysqlContext.Dispose(); } }
public void Dispose() { // Remove all created databases if (AllowMongoDB) { MongoClient mongoClient = new MongoClient(MongoDatabaseConenction.ConnectionString); mongoClient.DropDatabase(MongoDatabaseConenction.DataSource); } if (AllowPostgreSQL) { PortalDbContext postgreContext = GetPostgreSQLContext(); postgreContext.Database.EnsureDeleted(); postgreContext.Dispose(); LetPortalServiceManagementDbContext postgreServiceContext = GetPostgreServiceContext(); postgreServiceContext.Database.EnsureDeleted(); postgreServiceContext.Dispose(); } if (AllowSQLServer) { PortalDbContext sqlContext = GetSQLServerContext(); sqlContext.Database.EnsureDeleted(); sqlContext.Dispose(); LetPortalServiceManagementDbContext sqlServiceContext = GetSQLServerServiceContext(); sqlServiceContext.Database.EnsureDeleted(); sqlServiceContext.Dispose(); } if (AllowMySQL) { PortalDbContext mysqlContext = GetMySQLContext(); mysqlContext.Database.EnsureDeleted(); mysqlContext.Dispose(); LetPortalServiceManagementDbContext mysqlServiceContext = GetMySQLServiceContext(); mysqlServiceContext.Database.EnsureDeleted(); mysqlServiceContext.Dispose(); } GC.SuppressFinalize(this); }