Skip to content

Commit 5598f67

Browse files
authored
Merge pull request #8 from powersync-ja/wpf-demo
Added WPF todo list demo
2 parents 32860ec + fc553da commit 5598f67

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2236
-49
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Demo applications are located in the [`demos/`](./demos/) directory. Also see ou
2323
### Command-Line
2424

2525
- [demos/CommandLine](./demos/CommandLine/README.md): A CLI to-do list example app using a Node-js backend.
26+
- [demos/WPF](./demos/WPF/README.md): This is a demo WPF application that showcases how to use the [PowerSync SDK](https://www.powersync.com) for data synchronization in a to-do list application using a Node-js backend.
2627

2728
# Supported Frameworks
2829

demos/CommandLine/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
user_id.txt
1+
user_id.txt
2+
.env

demos/WPF/.config/dotnet-tools.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"version": 1,
3+
"isRoot": true,
4+
"tools": {
5+
"csharpier": {
6+
"version": "0.30.6",
7+
"commands": [
8+
"dotnet-csharpier"
9+
],
10+
"rollForward": false
11+
}
12+
}
13+
}

demos/WPF/.env.template

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
BACKEND_URL=
2+
POWERSYNC_URL=

demos/WPF/.gitignore

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
## A streamlined .gitignore for modern .NET projects
2+
## including temporary files, build results, and
3+
## files generated by popular .NET tools. If you are
4+
## developing with Visual Studio, the VS .gitignore
5+
## https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
6+
## has more thorough IDE-specific entries.
7+
##
8+
## Get latest from https://github.com/github/gitignore/blob/main/Dotnet.gitignore
9+
10+
# Build results
11+
[Dd]ebug/
12+
[Dd]ebugPublic/
13+
[Rr]elease/
14+
[Rr]eleases/
15+
x64/
16+
x86/
17+
[Ww][Ii][Nn]32/
18+
[Aa][Rr][Mm]/
19+
[Aa][Rr][Mm]64/
20+
bld/
21+
[Bb]in/
22+
[Oo]bj/
23+
[Ll]og/
24+
[Ll]ogs/
25+
26+
# .NET Core
27+
project.lock.json
28+
project.fragment.lock.json
29+
artifacts/
30+
31+
# ASP.NET Scaffolding
32+
ScaffoldingReadMe.txt
33+
34+
# NuGet Packages
35+
*.nupkg
36+
# NuGet Symbol Packages
37+
*.snupkg
38+
39+
# Others
40+
~$*
41+
*~
42+
CodeCoverage/
43+
44+
# MSBuild Binary and Structured Log
45+
*.binlog
46+
47+
# MSTest test Results
48+
[Tt]est[Rr]esult*/
49+
[Bb]uild[Ll]og.*
50+
51+
# NUnit
52+
*.VisualState.xml
53+
TestResult.xml
54+
nunit-*.xml
55+
56+
*.txt
57+
58+
*.db
59+
*.db-shm
60+
*.db-wal
61+
62+
fe.pug
63+
fe/
64+
65+
.env
66+

demos/WPF/App.xaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Application x:Class="PowersyncDotnetTodoList.App"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:converters="clr-namespace:PowersyncDotnetTodoList.Converters">
5+
<Application.Resources>
6+
<converters:BoolToStatusConverter x:Key="BoolToStatusConverter"/>
7+
<converters:StringToVisibilityConverter x:Key="StringToVisibilityConverter"/>
8+
</Application.Resources>
9+
</Application>

demos/WPF/App.xaml.cs

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
using System.Diagnostics;
2+
using System.Windows;
3+
using Microsoft.Extensions.DependencyInjection;
4+
using Microsoft.Extensions.Logging;
5+
using PowerSync.Common.Client;
6+
using PowersyncDotnetTodoList.Models;
7+
using PowersyncDotnetTodoList.Services;
8+
using PowersyncDotnetTodoList.ViewModels;
9+
using PowersyncDotnetTodoList.Views;
10+
11+
namespace PowersyncDotnetTodoList
12+
{
13+
public partial class App : Application
14+
{
15+
public static IServiceProvider? Services { get; private set; }
16+
17+
protected override async void OnStartup(StartupEventArgs e)
18+
{
19+
base.OnStartup(e);
20+
21+
var services = new ServiceCollection();
22+
ConfigureServices(services);
23+
24+
// Build the service provider
25+
Services = services.BuildServiceProvider();
26+
27+
// Initialize the database and connector
28+
var db = Services.GetRequiredService<PowerSyncDatabase>();
29+
var connector = Services.GetRequiredService<PowerSyncConnector>();
30+
await db.Init();
31+
await db.Connect(connector);
32+
await db.WaitForFirstSync();
33+
34+
var mainWindow = Services.GetRequiredService<MainWindow>();
35+
36+
var navigationService = Services.GetRequiredService<INavigationService>();
37+
navigationService.Navigate<TodoListViewModel>();
38+
39+
mainWindow.Show();
40+
}
41+
42+
private void ConfigureServices(IServiceCollection services)
43+
{
44+
ILoggerFactory loggerFactory = LoggerFactory.Create(builder =>
45+
{
46+
builder.AddConsole();
47+
builder.SetMinimumLevel(LogLevel.Information);
48+
});
49+
50+
// Register PowerSyncDatabase
51+
services.AddSingleton<PowerSyncDatabase>(sp =>
52+
{
53+
var logger = loggerFactory.CreateLogger("PowerSyncLogger");
54+
return new PowerSyncDatabase(
55+
new PowerSyncDatabaseOptions
56+
{
57+
Database = new SQLOpenOptions { DbFilename = "example.db" },
58+
Schema = AppSchema.PowerSyncSchema,
59+
Logger = logger,
60+
}
61+
);
62+
});
63+
64+
// Register IPowerSyncDatabase explicitly
65+
services.AddSingleton<IPowerSyncDatabase>(sp =>
66+
sp.GetRequiredService<PowerSyncDatabase>()
67+
);
68+
69+
// Register PowerSyncConnector
70+
services.AddSingleton<PowerSyncConnector>();
71+
72+
// Register ViewModels and Views
73+
services.AddTransient<TodoListViewModel>();
74+
services.AddTransient<TodoViewModel>();
75+
services.AddTransient<SQLConsoleViewModel>();
76+
services.AddTransient<TodoListView>();
77+
services.AddTransient<TodoView>();
78+
services.AddTransient<SQLConsoleView>();
79+
80+
services.AddSingleton<MainWindow>();
81+
services.AddSingleton<MainWindowViewModel>();
82+
83+
services.AddSingleton<INavigationService>(sp =>
84+
{
85+
var mainWindow = sp.GetRequiredService<MainWindow>();
86+
return new NavigationService(mainWindow.MainFrame, sp);
87+
});
88+
}
89+
}
90+
}

demos/WPF/AssemblyInfo.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.Windows;
2+
3+
[assembly:ThemeInfo(
4+
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
5+
//(used if a resource is not found in the page,
6+
// or application resource dictionaries)
7+
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
8+
//(used if a resource is not found in the page,
9+
// app, or any theme specific resource dictionaries)
10+
)]
26.5 KB
Loading
41.1 KB
Loading

0 commit comments

Comments
 (0)