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
|
||||
|
||||
@@ -15,6 +15,6 @@
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Filename=./Data/JumpsDb.db"
|
||||
"DefaultConnection": "Filename=./Data/JumpsDb.db;connection=shared"
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,6 @@
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Filename=./Data/JumpsDb.db"
|
||||
"DefaultConnection": "Filename=./Data/JumpsDb.db;connection=shared"
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,6 @@
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Filename=./Data/JumpsDb.db"
|
||||
"DefaultConnection": "Filename=./Data/JumpsDb.db;connection=shared"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,4 +31,12 @@
|
||||
<ProjectReference Include="..\skydiveLogs-api.Domain\skydiveLogs-api.Domain.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Update="Update\jumpType.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
|
||||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user