Skip to content

Commit 0813194

Browse files
committed
Renamed TodoSqlite demo to MAUITodo.
1 parent 2fa1a32 commit 0813194

Some content is hidden

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

45 files changed

+164
-164
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version = "1.0" encoding = "UTF-8" ?>
22
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
33
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4-
xmlns:local="clr-namespace:TodoSQLite"
5-
x:Class="TodoSQLite.App">
4+
xmlns:local="clr-namespace:MAUITodo"
5+
x:Class="MAUITodo.App">
66
<Application.Resources>
77
<ResourceDictionary>
88
<ResourceDictionary.MergedDictionaries>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace TodoSQLite;
1+
namespace MAUITodo;
22

33
public partial class App : Application
44
{
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
22
<Shell
3-
x:Class="TodoSQLite.AppShell"
3+
x:Class="MAUITodo.AppShell"
44
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
55
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
6-
xmlns:views="clr-namespace:TodoSQLite.Views"
6+
xmlns:views="clr-namespace:MAUITodo.Views"
77
Shell.FlyoutBehavior="Disabled">
88

99
<TabBar>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
using TodoSQLite.Views;
1+
using MAUITodo.Views;
22

3-
namespace TodoSQLite;
3+
namespace MAUITodo;
44

55
public partial class AppShell : Shell
66
{
Original file line numberDiff line numberDiff line change
@@ -1,124 +1,124 @@
1-
using PowerSync.Common.Client;
2-
using PowerSync.Common.Client.Connection;
3-
using PowerSync.Common.DB.Crud;
4-
5-
namespace TodoSQLite.Data;
6-
7-
using System;
8-
using System.Collections.Generic;
9-
using System.Net.Http;
10-
using System.Text;
11-
using System.Text.Json;
12-
using System.Threading.Tasks;
13-
14-
public class NodeConnector : IPowerSyncBackendConnector
15-
{
16-
private static readonly string StorageFilePath = "user_id.txt"; // Simulating local storage
17-
private readonly HttpClient _httpClient;
18-
19-
public string BackendUrl { get; }
20-
public string PowerSyncUrl { get; }
21-
public string UserId { get; private set; }
22-
private string? clientId;
23-
24-
public NodeConnector()
25-
{
26-
_httpClient = new HttpClient();
27-
28-
// Load or generate User ID
29-
UserId = LoadOrGenerateUserId();
30-
31-
BackendUrl = "http://localhost:6060";
32-
PowerSyncUrl = "http://localhost:8080";
33-
34-
clientId = null;
35-
}
36-
37-
public string LoadOrGenerateUserId()
38-
{
39-
if (File.Exists(StorageFilePath))
40-
{
41-
return File.ReadAllText(StorageFilePath);
42-
}
43-
44-
string newUserId = Guid.NewGuid().ToString();
45-
File.WriteAllText(StorageFilePath, newUserId);
46-
return newUserId;
47-
}
48-
49-
public async Task<PowerSyncCredentials?> FetchCredentials()
50-
{
51-
string tokenEndpoint = "api/auth/token";
52-
string url = $"{BackendUrl}/{tokenEndpoint}?user_id={UserId}";
53-
54-
HttpResponseMessage response = await _httpClient.GetAsync(url);
55-
if (!response.IsSuccessStatusCode)
56-
{
57-
throw new Exception($"Received {response.StatusCode} from {tokenEndpoint}: {await response.Content.ReadAsStringAsync()}");
58-
}
59-
60-
string responseBody = await response.Content.ReadAsStringAsync();
61-
var jsonResponse = JsonSerializer.Deserialize<Dictionary<string, string>>(responseBody);
62-
63-
if (jsonResponse == null || !jsonResponse.ContainsKey("token"))
64-
{
65-
throw new Exception("Invalid response received from authentication endpoint.");
66-
}
67-
68-
return new PowerSyncCredentials(PowerSyncUrl, jsonResponse["token"]);
69-
}
70-
71-
public async Task UploadData(IPowerSyncDatabase database)
72-
{
73-
CrudTransaction? transaction;
74-
try
75-
{
76-
transaction = await database.GetNextCrudTransaction();
77-
}
78-
catch (Exception ex)
79-
{
80-
Console.WriteLine($"UploadData Error: {ex.Message}");
81-
return;
82-
}
83-
84-
if (transaction == null)
85-
{
86-
return;
87-
}
88-
89-
clientId ??= await database.GetClientId();
90-
91-
try
92-
{
93-
var batch = new List<object>();
94-
95-
foreach (var operation in transaction.Crud)
96-
{
97-
batch.Add(new
98-
{
99-
op = operation.Op.ToString(),
100-
table = operation.Table,
101-
id = operation.Id,
102-
data = operation.OpData
103-
});
104-
}
105-
106-
var payload = JsonSerializer.Serialize(new { batch });
107-
var content = new StringContent(payload, Encoding.UTF8, "application/json");
108-
109-
HttpResponseMessage response = await _httpClient.PostAsync($"{BackendUrl}/api/data", content);
110-
111-
if (!response.IsSuccessStatusCode)
112-
{
113-
throw new Exception($"Received {response.StatusCode} from /api/data: {await response.Content.ReadAsStringAsync()}");
114-
}
115-
116-
await transaction.Complete();
117-
}
118-
catch (Exception ex)
119-
{
120-
Console.WriteLine($"UploadData Error: {ex.Message}");
121-
throw;
122-
}
123-
}
124-
}
1+
using PowerSync.Common.Client;
2+
using PowerSync.Common.Client.Connection;
3+
using PowerSync.Common.DB.Crud;
4+
5+
namespace MAUITodo.Data;
6+
7+
using System;
8+
using System.Collections.Generic;
9+
using System.Net.Http;
10+
using System.Text;
11+
using System.Text.Json;
12+
using System.Threading.Tasks;
13+
14+
public class NodeConnector : IPowerSyncBackendConnector
15+
{
16+
private static readonly string StorageFilePath = "user_id.txt"; // Simulating local storage
17+
private readonly HttpClient _httpClient;
18+
19+
public string BackendUrl { get; }
20+
public string PowerSyncUrl { get; }
21+
public string UserId { get; private set; }
22+
private string? clientId;
23+
24+
public NodeConnector()
25+
{
26+
_httpClient = new HttpClient();
27+
28+
// Load or generate User ID
29+
UserId = LoadOrGenerateUserId();
30+
31+
BackendUrl = "http://localhost:6060";
32+
PowerSyncUrl = "http://localhost:8080";
33+
34+
clientId = null;
35+
}
36+
37+
public string LoadOrGenerateUserId()
38+
{
39+
if (File.Exists(StorageFilePath))
40+
{
41+
return File.ReadAllText(StorageFilePath);
42+
}
43+
44+
string newUserId = Guid.NewGuid().ToString();
45+
File.WriteAllText(StorageFilePath, newUserId);
46+
return newUserId;
47+
}
48+
49+
public async Task<PowerSyncCredentials?> FetchCredentials()
50+
{
51+
string tokenEndpoint = "api/auth/token";
52+
string url = $"{BackendUrl}/{tokenEndpoint}?user_id={UserId}";
53+
54+
HttpResponseMessage response = await _httpClient.GetAsync(url);
55+
if (!response.IsSuccessStatusCode)
56+
{
57+
throw new Exception($"Received {response.StatusCode} from {tokenEndpoint}: {await response.Content.ReadAsStringAsync()}");
58+
}
59+
60+
string responseBody = await response.Content.ReadAsStringAsync();
61+
var jsonResponse = JsonSerializer.Deserialize<Dictionary<string, string>>(responseBody);
62+
63+
if (jsonResponse == null || !jsonResponse.ContainsKey("token"))
64+
{
65+
throw new Exception("Invalid response received from authentication endpoint.");
66+
}
67+
68+
return new PowerSyncCredentials(PowerSyncUrl, jsonResponse["token"]);
69+
}
70+
71+
public async Task UploadData(IPowerSyncDatabase database)
72+
{
73+
CrudTransaction? transaction;
74+
try
75+
{
76+
transaction = await database.GetNextCrudTransaction();
77+
}
78+
catch (Exception ex)
79+
{
80+
Console.WriteLine($"UploadData Error: {ex.Message}");
81+
return;
82+
}
83+
84+
if (transaction == null)
85+
{
86+
return;
87+
}
88+
89+
clientId ??= await database.GetClientId();
90+
91+
try
92+
{
93+
var batch = new List<object>();
94+
95+
foreach (var operation in transaction.Crud)
96+
{
97+
batch.Add(new
98+
{
99+
op = operation.Op.ToString(),
100+
table = operation.Table,
101+
id = operation.Id,
102+
data = operation.OpData
103+
});
104+
}
105+
106+
var payload = JsonSerializer.Serialize(new { batch });
107+
var content = new StringContent(payload, Encoding.UTF8, "application/json");
108+
109+
HttpResponseMessage response = await _httpClient.PostAsync($"{BackendUrl}/api/data", content);
110+
111+
if (!response.IsSuccessStatusCode)
112+
{
113+
throw new Exception($"Received {response.StatusCode} from /api/data: {await response.Content.ReadAsStringAsync()}");
114+
}
115+
116+
await transaction.Complete();
117+
}
118+
catch (Exception ex)
119+
{
120+
Console.WriteLine($"UploadData Error: {ex.Message}");
121+
throw;
122+
}
123+
}
124+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
using PowerSync.Common.Client;
33
using PowerSync.Common.MDSQLite;
44
using PowerSync.Maui.SQLite;
5-
using TodoSQLite.Models;
5+
using MAUITodo.Models;
66

7-
namespace TodoSQLite.Data;
7+
namespace MAUITodo.Data;
88

99
public class PowerSyncData
1010
{
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@
88

99

1010
<OutputType>Exe</OutputType>
11-
<RootNamespace>TodoSQLite</RootNamespace>
11+
<RootNamespace>MAUITodo</RootNamespace>
1212
<UseMaui>true</UseMaui>
1313
<SingleProject>true</SingleProject>
1414
<ImplicitUsings>enable</ImplicitUsings>
1515
<Nullable>enable</Nullable>
1616
<IsPackable>false</IsPackable>
1717

1818
<!-- Display name -->
19-
<ApplicationTitle>TodoSQLite</ApplicationTitle>
19+
<ApplicationTitle>MAUITodo</ApplicationTitle>
2020

2121
<!-- App Identifier -->
22-
<ApplicationId>com.companyname.todosqlite</ApplicationId>
22+
<ApplicationId>com.companyname.mauitodo</ApplicationId>
2323

2424
<!-- Versions -->
2525
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
using Microsoft.Extensions.DependencyInjection.Extensions;
22
using Microsoft.Extensions.Logging;
3-
using TodoSQLite.Data;
4-
using TodoSQLite.Views;
3+
using MAUITodo.Data;
4+
using MAUITodo.Views;
55

6-
namespace TodoSQLite;
6+
namespace MAUITodo;
77

88
public static class MauiProgram
99
{
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using Newtonsoft.Json;
22

3-
namespace TodoSQLite.Models;
3+
namespace MAUITodo.Models;
44

55
public class TodoItem
66
{

0 commit comments

Comments
 (0)