Manage the update of some data at the
start of the database
This commit is contained in:
@@ -9,6 +9,7 @@ using skydiveLogs_api.DomainBusiness.Interfaces;
|
||||
using skydiveLogs_api.Ioc;
|
||||
using skydiveLogs_api.Settings;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace skydiveLogs_api
|
||||
@@ -106,14 +107,21 @@ namespace skydiveLogs_api
|
||||
private void CheckAndInitDb(IServiceCollection services)
|
||||
{
|
||||
string connectionString = Configuration.GetConnectionString("DefaultConnection");
|
||||
string dbFile = connectionString.Replace("Filename=", string.Empty);
|
||||
var dictionary = connectionString.Split(';')
|
||||
.Select(part => part.Split('='))
|
||||
.Where(part => part.Length == 2)
|
||||
.ToDictionary(sp => sp[0], sp => sp[1]);
|
||||
|
||||
string dbFile = dictionary["Filename"]; //connectionString.Replace("Filename=", string.Empty);
|
||||
|
||||
|
||||
var serviceProvider = services.BuildServiceProvider();
|
||||
var initDbService = serviceProvider.GetRequiredService<IInitDbService>();
|
||||
|
||||
if (!File.Exists(dbFile))
|
||||
{
|
||||
var serviceProvider = services.BuildServiceProvider();
|
||||
var initDbService = serviceProvider.GetRequiredService<IInitDbService>();
|
||||
initDbService.GenerateDb();
|
||||
}
|
||||
else
|
||||
initDbService.Update();
|
||||
}
|
||||
|
||||
#endregion Private Methods
|
||||
|
||||
Reference in New Issue
Block a user