Skip to content

Commit f294557

Browse files
authored
Merge pull request #39 from spo-kissa/fixed-problem-with-settings
Fix the timing of the database migration.
2 parents 5067390 + 85ac1ce commit f294557

3 files changed

Lines changed: 24 additions & 14 deletions

File tree

spoclient/App.axaml.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using SpoClient.Setting;
1717
using SpoClient.Setting.Models;
1818
using System.Globalization;
19+
using System.Threading.Tasks;
1920

2021
namespace spoclient
2122
{
@@ -37,11 +38,17 @@ protected override AvaloniaObject CreateShell()
3738
protected override void RegisterTypes(IContainerRegistry containerRegistry)
3839
{
3940
containerRegistry.RegisterSingleton<IEventAggregator, EventAggregator>();
40-
containerRegistry.RegisterSingleton<SettingManager>(() => SettingManager.Instance);
41-
containerRegistry.RegisterSingleton<SqliteConnection>(() =>
41+
containerRegistry.RegisterSingleton<SqliteConnection?>(() =>
4242
{
43-
return SettingManager.Instance.OpenAsync("spoclient.setting").Result;
43+
return Task.Run<SqliteConnection?>(async () =>
44+
{
45+
var c = await SettingManager.Instance.OpenAsync("spoclient.setting");
46+
var migrator = new Migrator(c!);
47+
await migrator.ApplyMigrationsFromResourcesAsync("SpoClient.Setting.SQL.Migrations");
48+
return c;
49+
}).Result;
4450
});
51+
containerRegistry.RegisterSingleton<SettingManager>(() => SettingManager.Instance);
4552
containerRegistry.RegisterSingleton<IAppSettings, AppSettings>();
4653
containerRegistry.RegisterSingleton<ILocalizationManager>((c) =>
4754
{

spoclient/Plugins/Recipe/RecipeV1Loader.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,21 @@ public class RecipeV1Loader
1515
public static IEnumerable<IRecipePlugin> FindRecipePlugins()
1616
{
1717
var location = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Plugin");
18-
var files = Directory.EnumerateFiles(location, "*.v1.dll", SearchOption.AllDirectories);
19-
foreach (var file in files)
18+
if (Directory.Exists(location))
2019
{
21-
using var loader = PluginLoader.CreateFromAssemblyFile(file, false, [typeof(IRecipePlugin), typeof(IRecipe), typeof(ISimpleRecipe)]);
22-
var plugin = loader.LoadDefaultAssembly();
23-
foreach (var recipePluginType in plugin.GetTypes().Where(t => typeof(IRecipePlugin).IsAssignableFrom(t) && !t.IsAbstract))
20+
var files = Directory.EnumerateFiles(location, "*.v1.dll", SearchOption.AllDirectories);
21+
foreach (var file in files)
2422
{
25-
var recipePlugin = Activator.CreateInstance(recipePluginType) as IRecipePlugin;
26-
if (recipePlugin is not null)
23+
using var loader = PluginLoader.CreateFromAssemblyFile(file, false, [typeof(IRecipePlugin), typeof(IRecipe), typeof(ISimpleRecipe)]);
24+
var plugin = loader.LoadDefaultAssembly();
25+
foreach (var recipePluginType in plugin.GetTypes().Where(t => typeof(IRecipePlugin).IsAssignableFrom(t) && !t.IsAbstract))
2726
{
28-
Debug.WriteLine(recipePlugin.Name);
29-
yield return recipePlugin;
27+
var recipePlugin = Activator.CreateInstance(recipePluginType) as IRecipePlugin;
28+
if (recipePlugin is not null)
29+
{
30+
Debug.WriteLine(recipePlugin.Name);
31+
yield return recipePlugin;
32+
}
3033
}
3134
}
3235
}

spoclient/Views/MainAppSplashContent.axaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ public async Task InitApp()
4343
//await settings.OpenAsync("spoclient.setting");
4444

4545

46-
var migrator = new Migrator(settings.Connection!);
47-
await migrator.ApplyMigrationsFromResourcesAsync("SpoClient.Setting.SQL.Migrations");
46+
//var migrator = new Migrator(settings.Connection!);
47+
//await migrator.ApplyMigrationsFromResourcesAsync("SpoClient.Setting.SQL.Migrations");
4848

4949

5050
LoadingText.Text = "Loading Plugins...";

0 commit comments

Comments
 (0)