@@ -86,28 +86,9 @@ static int Main(string[] args)
8686 //Converting the connectionstring into entiy framwork style connectionstring
8787 string csharpConnectionString = transformConnectionString ( ) ;
8888
89- var builder = new DbContextOptionsBuilder < CsharpDbContext > ( ) ;
90- switch ( _dbSystem )
91- {
92- case "sqlite" :
93- builder . UseSqlite ( csharpConnectionString ) ;
94- break ;
95- default :
96- builder . UseNpgsql ( csharpConnectionString ) ;
97- break ;
98- }
99- var options = builder . Options ;
100- CsharpDbContext _context ;
101- switch ( _dbSystem )
102- {
103- case "sqlite" :
104- _context = new SqliteDbContext ( options ) ;
105- break ;
106- default :
107- _context = new PostgresDbContext ( options ) ;
108- break ;
109- }
110- _context . Database . Migrate ( ) ;
89+ var builderOptions = createDbContextOptions ( csharpConnectionString ) ;
90+ CsharpDbContext context = createDbContext ( builderOptions ) ;
91+ context . Database . Migrate ( ) ;
11192
11293 List < string > allFiles = new List < string > ( ) ;
11394 foreach ( var p in _rootDir )
@@ -156,41 +137,14 @@ static int Main(string[] args)
156137 private static async Task < int > ParalellRun ( string csharpConnectionString , int threadNum ,
157138 List < SyntaxTree > trees , CSharpCompilation compilation )
158139 {
159- var builder = new DbContextOptionsBuilder < CsharpDbContext > ( ) ;
160- switch ( _dbSystem )
161- {
162- case "sqlite" :
163- builder . UseSqlite ( csharpConnectionString ) ;
164- break ;
165- default :
166- builder . UseNpgsql ( csharpConnectionString ) ;
167- break ;
168- }
169- var options = builder . Options ;
170- CsharpDbContext dbContext ;
171- switch ( _dbSystem )
172- {
173- case "sqlite" :
174- dbContext = new SqliteDbContext ( options ) ;
175- break ;
176- default :
177- dbContext = new PostgresDbContext ( options ) ;
178- break ;
179- }
140+
141+ var builderOptions = createDbContextOptions ( csharpConnectionString ) ;
142+ CsharpDbContext dbContext = createDbContext ( builderOptions ) ;
180143 var contextList = new List < CsharpDbContext > ( ) ;
181144 contextList . Add ( dbContext ) ;
182145 for ( int i = 1 ; i < threadNum ; i ++ )
183146 {
184- CsharpDbContext dbContextInstance ;
185- switch ( _dbSystem )
186- {
187- case "sqlite" :
188- dbContextInstance = new SqliteDbContext ( options ) ;
189- break ;
190- default :
191- dbContextInstance = new PostgresDbContext ( options ) ;
192- break ;
193- }
147+ CsharpDbContext dbContextInstance = createDbContext ( builderOptions ) ;
194148 contextList . Add ( dbContextInstance ) ;
195149 }
196150
@@ -340,5 +294,36 @@ private static string transformConnectionString()
340294
341295 return csharpConnectionString ;
342296 }
297+
298+ private static DbContextOptions < CsharpDbContext > createDbContextOptions ( string connectionString )
299+ {
300+ var builder = new DbContextOptionsBuilder < CsharpDbContext > ( ) ;
301+ switch ( _dbSystem )
302+ {
303+ case "sqlite" :
304+ builder . UseSqlite ( connectionString ) ;
305+ break ;
306+ default :
307+ builder . UseNpgsql ( connectionString ) ;
308+ break ;
309+ }
310+
311+ return builder . Options ;
312+ }
313+ private static CsharpDbContext createDbContext ( DbContextOptions < CsharpDbContext > options )
314+ {
315+ CsharpDbContext context ;
316+ switch ( _dbSystem )
317+ {
318+ case "sqlite" :
319+ context = new SqliteDbContext ( options ) ;
320+ break ;
321+ default :
322+ context = new PostgresDbContext ( options ) ;
323+ break ;
324+ }
325+
326+ return context ;
327+ }
343328 }
344329}
0 commit comments