Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/css/extra.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.wy-nav-content {
max-width: 1200px !important;
}
2 changes: 2 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Client platforms that have been tested include:

* [Avalonia][avalonia]
* [.NET MAUI][maui]
* [Uno Platform][uno]
* [Windows Presentation Framework (WPF)][wpf]
* [Windows UI Library (WinUI) 3][winui3]

Expand Down Expand Up @@ -43,5 +44,6 @@ Find out more about developing datasync applications:
[dotnetfdn]: https://dotnetfoundation.org/
[avalonia]: https://www.avaloniaui.net/
[maui]: https://dotnet.microsoft.com/apps/maui
[uno]: https://platform.uno/
[wpf]: https://learn.microsoft.com/dotnet/desktop/wpf/overview/
[winui3]: https://learn.microsoft.com/windows/apps/winui/winui3/
74 changes: 74 additions & 0 deletions docs/samples/todoapp/unoplatform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# TodoApp client for Uno Platform

!!! info
The Uno Platform sample has been kindly contributed to the community by [@trydalch](https://github.com/trydalch).

## Run the application first

The Uno Platform sample uses an in-memory Sqlite store for storing its data. To run the application locally:

* [Configure Visual Studio for Uno Platform development](https://platform.uno/visual-studio/).
* Open `samples/todoapp/TodoApp.Uno/TodoApp.Uno.sln` in Visual Studio.
* Select a target (in the top bar), then press F5 to run the application.
* For Windows, select **TodoApp.Uno (WinAppSDK Packaged)**.
* For other platforms, select the correct emulator or simulator from the target selection drop-down.

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.

!!! info Tested platforms
The TodoApp.Uno sample is known to work on Android and Desktop. We have not tested on other platforms.

## Deploy a datasync server to Azure

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.

## Update the application for datasync operations

All the changes are isolated to the `Database/AppDbContext.cs` file in the `TodoApp.Uno` project.

1. Change the definition of the class so that it inherits from `OfflineDbContext`:

public class AppDbContext(DbContextOptions<AppDbContext> options) : OfflineDbContext(options)
{
// Rest of the class
}

2. Add the `OnDatasyncInitialization()` method:

protected override void OnDatasyncInitialization(DatasyncOfflineOptionsBuilder optionsBuilder)
{
HttpClientOptions clientOptions = new()
{
Endpoint = new Uri("https://YOURSITEHERE.azurewebsites.net/"),
HttpPipeline = [new LoggingHandler()]
};
_ = optionsBuilder.UseHttpClientOptions(clientOptions);
}

Replace the Endpoint with the URI of your datasync service.

3. Update the `SynchronizeAsync()` method.

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.

public async Task SynchronizeAsync(CancellationToken cancellationToken = default)
{
PushResult pushResult = await this.PushAsync(cancellationToken);
if (!pushResult.IsSuccessful)
{
throw new ApplicationException($"Push failed: {pushResult.FailedRequests.FirstOrDefault().Value.ReasonPhrase}");
}

PullResult pullResult = await this.PullAsync(cancellationToken);
if (!pullResult.IsSuccessful)
{
throw new ApplicationException($"Pull failed: {pullResult.FailedRequests.FirstOrDefault().Value.ReasonPhrase}");
}
}

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.

!!! tip
The first synchronization can take a while because of the cold-start of the service. Watch the debug output to see the synchronization happening.

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.
6 changes: 5 additions & 1 deletion mkdocs.shared.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ validation:
plugins:
- search
- mermaid2

extra_css:
- css/extra.css

markdown_extensions:
- smarty: {}
Expand All @@ -37,7 +40,7 @@ nav:
- The basics: in-depth/server/index.md
- Databases:
- Azure SQL: in-depth/server/db/azuresql.md
- Cosmos: in-depth/server/db/cosmos.md
- "CosmosDB (EFCore)": in-depth/server/db/cosmos.md
- In Memory: in-depth/server/db/in-memory.md
- LiteDb: in-depth/server/db/litedb.md
- MongoDb: in-depth/server/db/mongodb.md
Expand All @@ -59,5 +62,6 @@ nav:
- The server: samples/todoapp/server.md
- Avalonia: samples/todoapp/avalonia.md
- MAUI: samples/todoapp/maui.md
- "Uno Plaform": samples/todoapp/unoplatform.md
- WinUI3: samples/todoapp/winui3.md
- WPF: samples/todoapp/wpf.md