Added EF and DB to the core, crude demo in the UI
This commit is contained in:
+43
-20
@@ -4,6 +4,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices.WindowsRuntime;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
@@ -12,20 +13,22 @@ using Microsoft.UI.Xaml.Data;
|
||||
using Microsoft.UI.Xaml.Input;
|
||||
using Microsoft.UI.Xaml.Media;
|
||||
using Microsoft.UI.Xaml.Navigation;
|
||||
using Microsoft.UI.Xaml.Shapes;
|
||||
using Windows.ApplicationModel;
|
||||
using Windows.ApplicationModel.Activation;
|
||||
using Windows.Foundation;
|
||||
using Windows.Foundation.Collections;
|
||||
using Windows.UI.ApplicationSettings;
|
||||
using WinUI3Localizer;
|
||||
using WinWARP.Core.Services;
|
||||
using WinWARP.Core.ViewModels;
|
||||
using WinWARP.Core.ViewModels.ConfigSettings;
|
||||
using WinWARP.Core.ViewModels.Settings;
|
||||
using WinWARP.Core.Data;
|
||||
using WinWARP.Ui.Services;
|
||||
using WinWARP.Ui.Views;
|
||||
using WinWARP.Ui.Views.Settings;
|
||||
using WinWARP.Core.Services.Implementations;
|
||||
using WinWARP.Core.Services.Interfaces;
|
||||
using System.Diagnostics;
|
||||
|
||||
// To learn more about WinUI, the WinUI project structure,
|
||||
// and more about our project templates, see: http://aka.ms/winui-project-info.
|
||||
@@ -52,34 +55,34 @@ public partial class App : Application
|
||||
{
|
||||
InitializeComponent();
|
||||
Services = ConfigureServices();
|
||||
|
||||
using var context = Services.GetRequiredService<IDbContextFactory<AppDbContext>>().CreateDbContext();
|
||||
context.Database.EnsureCreated();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the services for dependency injection.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private static IServiceProvider ConfigureServices()
|
||||
private static ServiceProvider ConfigureServices()
|
||||
{
|
||||
var services = new ServiceCollection();
|
||||
|
||||
var navigationService = new NavigationService();
|
||||
navigationService.Configure(typeof(HomeViewModel), typeof(HomePage));
|
||||
navigationService.Configure(typeof(SettingsViewModel), typeof(SettingsPage));
|
||||
navigationService.Configure(typeof(SubsSettingsViewModel), typeof(SubsSettingsPage));
|
||||
navigationService.Configure(typeof(ConfigSettingsViewModel), typeof(ConfigSettingsPage));
|
||||
// DB
|
||||
Debug.WriteLine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "WinWARP", "app.db"));
|
||||
services.AddDbContextFactory<AppDbContext>(options =>
|
||||
{
|
||||
var folder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "WinWARP");
|
||||
|
||||
navigationService.Configure(typeof(GeneralSettingsViewModel), typeof(GeneralSettingsPage));
|
||||
navigationService.Configure(typeof(UpdateSettingsViewModel), typeof(UpdateSettingsPage));
|
||||
if (!Directory.Exists(folder))
|
||||
{
|
||||
Directory.CreateDirectory(folder);
|
||||
}
|
||||
|
||||
navigationService.Configure(typeof(InboundSettingsViewModel), typeof(InboundSettingsPage));
|
||||
navigationService.Configure(typeof(RoutingSettingsViewModel), typeof(RoutingSettingsPage));
|
||||
navigationService.Configure(typeof(DnsSettingsViewModel), typeof(DnsSettingsPage));
|
||||
navigationService.Configure(typeof(TlsSettingsViewModel), typeof(TlsSettingsPage));
|
||||
navigationService.Configure(typeof(WarpSettingsViewModel), typeof(WarpSettingsPage));
|
||||
|
||||
services.AddSingleton<ILocalizationService, LocalizationService>();
|
||||
|
||||
services.AddSingleton<INavigationService>(navigationService);
|
||||
var dbPath = Path.Combine(folder, "app.db");
|
||||
options.UseSqlite($"Data Source={dbPath}");
|
||||
});
|
||||
services.AddTransient<ISubscriptionDbService, SubscriptionDbService>();
|
||||
|
||||
// ViewModels
|
||||
services.AddTransient<HomeViewModel>();
|
||||
@@ -97,6 +100,26 @@ public partial class App : Application
|
||||
|
||||
// Views
|
||||
services.AddTransient<MainWindow>();
|
||||
|
||||
// UI services
|
||||
var navigationService = new NavigationService();
|
||||
navigationService.Configure(typeof(HomeViewModel), typeof(HomePage));
|
||||
navigationService.Configure(typeof(SettingsViewModel), typeof(SettingsPage));
|
||||
navigationService.Configure(typeof(SubsSettingsViewModel), typeof(SubsSettingsPage));
|
||||
navigationService.Configure(typeof(ConfigSettingsViewModel), typeof(ConfigSettingsPage));
|
||||
|
||||
navigationService.Configure(typeof(GeneralSettingsViewModel), typeof(GeneralSettingsPage));
|
||||
navigationService.Configure(typeof(UpdateSettingsViewModel), typeof(UpdateSettingsPage));
|
||||
|
||||
navigationService.Configure(typeof(InboundSettingsViewModel), typeof(InboundSettingsPage));
|
||||
navigationService.Configure(typeof(RoutingSettingsViewModel), typeof(RoutingSettingsPage));
|
||||
navigationService.Configure(typeof(DnsSettingsViewModel), typeof(DnsSettingsPage));
|
||||
navigationService.Configure(typeof(TlsSettingsViewModel), typeof(TlsSettingsPage));
|
||||
navigationService.Configure(typeof(WarpSettingsViewModel), typeof(WarpSettingsPage));
|
||||
|
||||
services.AddSingleton<INavigationService>(navigationService);
|
||||
|
||||
services.AddSingleton<ILocalizationService, LocalizationService>();
|
||||
|
||||
return services.BuildServiceProvider();
|
||||
}
|
||||
@@ -109,7 +132,7 @@ public partial class App : Application
|
||||
{
|
||||
|
||||
var stringsFolderPath = System.IO.Path.Combine(AppContext.BaseDirectory, "Strings");
|
||||
ILocalizer localizer = await new LocalizerBuilder()
|
||||
var localizer = await new LocalizerBuilder()
|
||||
.AddStringResourcesFolderForLanguageDictionaries(stringsFolderPath)
|
||||
.SetOptions(options =>
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user