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 =>
|
||||
{
|
||||
|
||||
@@ -14,7 +14,7 @@ using Microsoft.UI.Xaml.Media;
|
||||
using Microsoft.UI.Xaml.Navigation;
|
||||
using Windows.Foundation;
|
||||
using Windows.Foundation.Collections;
|
||||
using WinWARP.Core.Services;
|
||||
using WinWARP.Core.Services.Interfaces;
|
||||
using WinWARP.Core.ViewModels;
|
||||
using WinWARP.Ui.Services;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WinUI3Localizer;
|
||||
using WinWARP.Core.Services;
|
||||
using WinWARP.Core.Services.Interfaces;
|
||||
|
||||
namespace WinWARP.Ui.Services;
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Navigation;
|
||||
using WinWARP.Core.Services;
|
||||
using WinWARP.Core.Services.Interfaces;
|
||||
|
||||
namespace WinWARP.Ui.Services;
|
||||
|
||||
|
||||
@@ -6,9 +6,23 @@
|
||||
xmlns:local="using:WinWARP.Ui.Views"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:m="using:WinWARP.Core.Models.Entities"
|
||||
mc:Ignorable="d">
|
||||
|
||||
<Grid>
|
||||
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<Button Grid.Row="0" Command="{x:Bind ViewModel.AddSubscriptionCommand}" Content="Add Subscription" />
|
||||
<TextBox Grid.Row="1" Text="{x:Bind ViewModel.NewSubscriptionLink, Mode=TwoWay}" />
|
||||
<ListBox Grid.Row="2" ItemsSource="{x:Bind ViewModel.Subscriptions}">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate x:DataType="m:Subscription">
|
||||
<TextBlock Text="{x:Bind Link}" />
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
</Grid>
|
||||
</Page>
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices.WindowsRuntime;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Controls.Primitives;
|
||||
@@ -12,6 +13,7 @@ using Microsoft.UI.Xaml.Media;
|
||||
using Microsoft.UI.Xaml.Navigation;
|
||||
using Windows.Foundation;
|
||||
using Windows.Foundation.Collections;
|
||||
using WinWARP.Core.ViewModels;
|
||||
|
||||
// To learn more about WinUI, the WinUI project structure,
|
||||
// and more about our project templates, see: http://aka.ms/winui-project-info.
|
||||
@@ -22,8 +24,14 @@ namespace WinWARP.Ui.Views;
|
||||
/// </summary>
|
||||
public sealed partial class SubsSettingsPage : Page
|
||||
{
|
||||
public SubsSettingsViewModel ViewModel { get; }
|
||||
|
||||
public SubsSettingsPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
ViewModel = App.Services.GetRequiredService<SubsSettingsViewModel>();
|
||||
DataContext = ViewModel;
|
||||
ViewModel.LoadSubscriptionsAsync().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
<WindowsAppSdkBootstrapInitialize>true</WindowsAppSdkBootstrapInitialize>
|
||||
<EnableMsixTooling>true</EnableMsixTooling>
|
||||
<Nullable>enable</Nullable>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<None Remove="Views\HomePage.xaml" />
|
||||
@@ -55,12 +56,9 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CommunityToolkit.WinUI.Behaviors" Version="8.2.251219" />
|
||||
<PackageReference Include="CommunityToolkit.WinUI.Controls.SettingsControls" Version="8.2.251219" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="10.0.10" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="10.0.10" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.10" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.11" />
|
||||
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.28000.2526" />
|
||||
<PackageReference Include="Microsoft.WindowsAppSDK" Version="2.3.1" />
|
||||
<PackageReference Include="SQLitePCLRaw.lib.e_sqlite3" Version="3.53.3" />
|
||||
<PackageReference Include="Microsoft.WindowsAppSDK" Version="2.4.0" />
|
||||
<PackageReference Include="WinUI3Localizer" Version="2.3.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user