Skip to content

Commit 4111eab

Browse files
authored
(#293) Uno Platform sample docs. (#301)
* (#293) Docs for the Uno sample * (#293) Added link to Uno Platform as a supported platform
1 parent 9eb02ee commit 4111eab

File tree

4 files changed

+84
-1
lines changed

4 files changed

+84
-1
lines changed

docs/css/extra.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.wy-nav-content {
2+
max-width: 1200px !important;
3+
}

docs/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Client platforms that have been tested include:
1313

1414
* [Avalonia][avalonia]
1515
* [.NET MAUI][maui]
16+
* [Uno Platform][uno]
1617
* [Windows Presentation Framework (WPF)][wpf]
1718
* [Windows UI Library (WinUI) 3][winui3]
1819

@@ -43,5 +44,6 @@ Find out more about developing datasync applications:
4344
[dotnetfdn]: https://dotnetfoundation.org/
4445
[avalonia]: https://www.avaloniaui.net/
4546
[maui]: https://dotnet.microsoft.com/apps/maui
47+
[uno]: https://platform.uno/
4648
[wpf]: https://learn.microsoft.com/dotnet/desktop/wpf/overview/
4749
[winui3]: https://learn.microsoft.com/windows/apps/winui/winui3/

docs/samples/todoapp/unoplatform.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# TodoApp client for Uno Platform
2+
3+
!!! info
4+
The Uno Platform sample has been kindly contributed to the community by [@trydalch](https://github.com/trydalch).
5+
6+
## Run the application first
7+
8+
The Uno Platform sample uses an in-memory Sqlite store for storing its data. To run the application locally:
9+
10+
* [Configure Visual Studio for Uno Platform development](https://platform.uno/visual-studio/).
11+
* Open `samples/todoapp/TodoApp.Uno/TodoApp.Uno.sln` in Visual Studio.
12+
* Select a target (in the top bar), then press F5 to run the application.
13+
* For Windows, select **TodoApp.Uno (WinAppSDK Packaged)**.
14+
* For other platforms, select the correct emulator or simulator from the target selection drop-down.
15+
16+
If you bump into issues at this point, ensure you can properly develop and run Uno Platform applications for the desktop outside of the datasync service.
17+
18+
!!! info Tested platforms
19+
The TodoApp.Uno sample is known to work on Android and Desktop. We have not tested on other platforms.
20+
21+
## Deploy a datasync server to Azure
22+
23+
Before you begin adjusting the application for offline usage, you must [deploy a datasync service](./server.md). Make a note of the URI of the service before continuing.
24+
25+
## Update the application for datasync operations
26+
27+
All the changes are isolated to the `Database/AppDbContext.cs` file in the `TodoApp.Uno` project.
28+
29+
1. Change the definition of the class so that it inherits from `OfflineDbContext`:
30+
31+
public class AppDbContext(DbContextOptions<AppDbContext> options) : OfflineDbContext(options)
32+
{
33+
// Rest of the class
34+
}
35+
36+
2. Add the `OnDatasyncInitialization()` method:
37+
38+
protected override void OnDatasyncInitialization(DatasyncOfflineOptionsBuilder optionsBuilder)
39+
{
40+
HttpClientOptions clientOptions = new()
41+
{
42+
Endpoint = new Uri("https://YOURSITEHERE.azurewebsites.net/"),
43+
HttpPipeline = [new LoggingHandler()]
44+
};
45+
_ = optionsBuilder.UseHttpClientOptions(clientOptions);
46+
}
47+
48+
Replace the Endpoint with the URI of your datasync service.
49+
50+
3. Update the `SynchronizeAsync()` method.
51+
52+
The `SynchronizeAsync()` method is used by the application to synchronize data to and from the datasync service. It is called primarily from the `MainViewModel` which drives the UI interactions for the main list.
53+
54+
public async Task SynchronizeAsync(CancellationToken cancellationToken = default)
55+
{
56+
PushResult pushResult = await this.PushAsync(cancellationToken);
57+
if (!pushResult.IsSuccessful)
58+
{
59+
throw new ApplicationException($"Push failed: {pushResult.FailedRequests.FirstOrDefault().Value.ReasonPhrase}");
60+
}
61+
62+
PullResult pullResult = await this.PullAsync(cancellationToken);
63+
if (!pullResult.IsSuccessful)
64+
{
65+
throw new ApplicationException($"Pull failed: {pullResult.FailedRequests.FirstOrDefault().Value.ReasonPhrase}");
66+
}
67+
}
68+
69+
You can now re-run your application. Watch the console logs to show the interactions with the datasync service. Press the refresh button to synchronize data with the cloud. When you restart the application, your changes will automatically populate the database again.
70+
71+
!!! tip
72+
The first synchronization can take a while because of the cold-start of the service. Watch the debug output to see the synchronization happening.
73+
74+
Obviously, you will want to do much more in a "real world" application, including proper error handling, authentication, and using a Sqlite file instead of an in-memory database. This example shows off the minimum required to add datasync services to an application.

mkdocs.shared.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ validation:
1212
plugins:
1313
- search
1414
- mermaid2
15+
16+
extra_css:
17+
- css/extra.css
1518

1619
markdown_extensions:
1720
- smarty: {}
@@ -37,7 +40,7 @@ nav:
3740
- The basics: in-depth/server/index.md
3841
- Databases:
3942
- Azure SQL: in-depth/server/db/azuresql.md
40-
- Cosmos: in-depth/server/db/cosmos.md
43+
- "CosmosDB (EFCore)": in-depth/server/db/cosmos.md
4144
- In Memory: in-depth/server/db/in-memory.md
4245
- LiteDb: in-depth/server/db/litedb.md
4346
- MongoDb: in-depth/server/db/mongodb.md
@@ -59,5 +62,6 @@ nav:
5962
- The server: samples/todoapp/server.md
6063
- Avalonia: samples/todoapp/avalonia.md
6164
- MAUI: samples/todoapp/maui.md
65+
- "Uno Plaform": samples/todoapp/unoplatform.md
6266
- WinUI3: samples/todoapp/winui3.md
6367
- WPF: samples/todoapp/wpf.md

0 commit comments

Comments
 (0)