-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #640 from PinguApps/dev
Merge v2.0.0
- Loading branch information
Showing
24 changed files
with
610 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,40 @@ | ||
using System.Text.Json.Serialization; | ||
using Microsoft.Extensions.Configuration; | ||
using PinguApps.Appwrite.Shared.Requests.Databases; | ||
using PinguApps.Appwrite.Realtime; | ||
using PinguApps.Appwrite.Shared.Responses; | ||
|
||
namespace PinguApps.Appwrite.Playground; | ||
internal class App | ||
{ | ||
private readonly Client.IClientAppwriteClient _client; | ||
private readonly Server.Clients.IServerAppwriteClient _server; | ||
private readonly IRealtimeClient _realtimeClient; | ||
private readonly string? _session; | ||
|
||
public App(Client.IClientAppwriteClient client, Server.Clients.IServerAppwriteClient server, IConfiguration config) | ||
public App(Client.IClientAppwriteClient client, Server.Clients.IServerAppwriteClient server, IRealtimeClient realtimeClient, IConfiguration config) | ||
{ | ||
_client = client; | ||
_server = server; | ||
_realtimeClient = realtimeClient; | ||
_session = config.GetValue<string>("Session"); | ||
} | ||
|
||
private class Rec | ||
public record Table1 | ||
{ | ||
[JsonPropertyName("test")] | ||
public string Test { get; set; } = string.Empty; | ||
|
||
[JsonPropertyName("boolAttribute")] | ||
public bool BoolAttribute { get; set; } | ||
[JsonPropertyName("test")] public string? Test { get; init; } | ||
[JsonPropertyName("boolAttribute")] public bool BoolAttribute { get; init; } | ||
} | ||
|
||
public async Task Run(string[] args) | ||
{ | ||
var before = new Rec { Test = "test", BoolAttribute = false }; | ||
var after = new Rec { Test = "test", BoolAttribute = true }; | ||
|
||
var request = UpdateDocumentRequest.CreateBuilder() | ||
.WithDatabaseId("67541a2800221703e717") | ||
.WithCollectionId("67541a37001514b81821") | ||
.WithDocumentId("67541af9000055e59e59") | ||
.WithChanges(before, after) | ||
.Build(); | ||
|
||
var serverResponse = await _server.Databases.UpdateDocument(request); | ||
|
||
Console.WriteLine(serverResponse.Result.Match( | ||
result => result.ToString(), | ||
appwriteError => appwriteError.Message, | ||
internalError => internalError.Message)); | ||
|
||
Console.WriteLine("###############################################################################"); | ||
|
||
//Console.ReadKey(); | ||
//request.Data["test"] = "Client Update"; | ||
|
||
//var clientResponse = await _client.Databases.UpdateDocument(request); | ||
|
||
//Console.WriteLine(clientResponse.Result.Match( | ||
// result => result.ToString(), | ||
// appwriteError => appwriteError.Message, | ||
// internalError => internalError.Message)); | ||
_realtimeClient.SetSession(_session); | ||
|
||
using (_realtimeClient.Subscribe<Document<Table1>>("documents", x => | ||
{ | ||
Console.WriteLine(x.Payload); | ||
})) | ||
{ | ||
Console.ReadKey(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using PinguApps.Appwrite.Realtime.Models; | ||
|
||
namespace PinguApps.Appwrite.Realtime; | ||
internal class DummyRealtimeClient : IRealtimeClient | ||
{ | ||
public bool IsConnected => false; | ||
|
||
public Task DisconnectAsync() => Task.CompletedTask; | ||
|
||
public void SetSession(string? session) | ||
{ | ||
} | ||
|
||
public IDisposable Subscribe<T>(List<string> channels, Action<RealtimeResponseEvent<T>> callback) => new DummyDisposable(); | ||
|
||
public IDisposable Subscribe<T>(string channel, Action<RealtimeResponseEvent<T>> callback) => new DummyDisposable(); | ||
|
||
private class DummyDisposable : IDisposable | ||
{ | ||
public void Dispose() | ||
{ | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/PinguApps.Appwrite.Realtime/Exceptions/RealtimeException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using System; | ||
|
||
namespace PinguApps.Appwrite.Realtime.Exceptions; | ||
public class RealtimeException : Exception | ||
{ | ||
public int Code { get; } | ||
public RealtimeException(string message, int code) : base(message) => Code = code; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using PinguApps.Appwrite.Realtime.Models; | ||
|
||
namespace PinguApps.Appwrite.Realtime; | ||
public interface IRealtimeClient | ||
{ | ||
bool IsConnected { get; } | ||
Task DisconnectAsync(); | ||
void SetSession(string? session); | ||
IDisposable Subscribe<T>(List<string> channels, Action<RealtimeResponseEvent<T>> callback); | ||
IDisposable Subscribe<T>(string channel, Action<RealtimeResponseEvent<T>> callback); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System.ComponentModel; | ||
|
||
namespace System.Runtime.CompilerServices; | ||
|
||
#if !NET5_0_OR_GREATER | ||
|
||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
internal static class IsExternalInit { } | ||
|
||
#endif // !NET5_0_OR_GREATER |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace PinguApps.Appwrite.Realtime.Models; | ||
public record RealtimeMessage( | ||
[property: JsonPropertyName("type")] string Type, | ||
[property: JsonPropertyName("data")] JsonElement Data | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace PinguApps.Appwrite.Realtime.Models; | ||
|
||
public record RealtimeRequest( | ||
[property: JsonPropertyName("type")] string Type, | ||
[property: JsonPropertyName("data")] RealtimeRequestAuthenticate? Data | ||
); |
7 changes: 7 additions & 0 deletions
7
src/PinguApps.Appwrite.Realtime/Models/RealtimeRequestAuthenticate.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace PinguApps.Appwrite.Realtime.Models; | ||
|
||
public record RealtimeRequestAuthenticate( | ||
[property: JsonPropertyName("session")] string? Session | ||
); |
9 changes: 9 additions & 0 deletions
9
src/PinguApps.Appwrite.Realtime/Models/RealtimeResponseConnected.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System.Collections.Generic; | ||
using System.Text.Json.Serialization; | ||
using PinguApps.Appwrite.Shared.Responses; | ||
|
||
namespace PinguApps.Appwrite.Realtime.Models; | ||
public record RealtimeResponseConnected( | ||
[property: JsonPropertyName("channels")] IReadOnlyList<string> Channels, | ||
[property: JsonPropertyName("user")] User? User | ||
); |
7 changes: 7 additions & 0 deletions
7
src/PinguApps.Appwrite.Realtime/Models/RealtimeResponseError.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace PinguApps.Appwrite.Realtime.Models; | ||
public record RealtimeResponseError( | ||
[property: JsonPropertyName("code")] int Code, | ||
[property: JsonPropertyName("message")] string Message | ||
); |
12 changes: 12 additions & 0 deletions
12
src/PinguApps.Appwrite.Realtime/Models/RealtimeResponseEvent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text.Json.Serialization; | ||
using PinguApps.Appwrite.Shared.Converters; | ||
|
||
namespace PinguApps.Appwrite.Realtime.Models; | ||
public record RealtimeResponseEvent<T>( | ||
[property: JsonPropertyName("events")] IReadOnlyList<string> Events, | ||
[property: JsonPropertyName("channels")] IReadOnlyList<string> Channels, | ||
[property: JsonPropertyName("timestamp"), JsonConverter(typeof(NullableDateTimeConverter))] DateTime? Timestamp, | ||
[property: JsonPropertyName("payload")] T Payload | ||
); |
18 changes: 18 additions & 0 deletions
18
src/PinguApps.Appwrite.Realtime/Models/WebSocketOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace PinguApps.Appwrite.Realtime.Models; | ||
public class WebSocketOptions | ||
{ | ||
[JsonPropertyName("reconnectInterval")] | ||
public TimeSpan ReconnectInterval { get; set; } = TimeSpan.FromSeconds(30); | ||
|
||
[JsonPropertyName("heartbeatInterval")] | ||
public TimeSpan HeartbeatInterval { get; set; } = TimeSpan.FromSeconds(20); | ||
|
||
[JsonPropertyName("maxRetryAttempts")] | ||
public int MaxRetryAttempts { get; set; } = 5; | ||
|
||
[JsonPropertyName("retrySleepDurationProvider")] | ||
public Func<int, TimeSpan> RetrySleepDurationProvider { get; set; } = retryAttempt => TimeSpan.FromSeconds(((retryAttempt - 1) * 2) + 1); | ||
} |
60 changes: 60 additions & 0 deletions
60
src/PinguApps.Appwrite.Realtime/PinguApps.Appwrite.Realtime.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.1</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<LangVersion>latest</LangVersion> | ||
|
||
<PackageId>PinguApps.Appwrite.Realtime</PackageId> | ||
<PackageTags>Appwrite;Pingu;PinguApps;Pingu Apps;CSharp;Sdk;Realtime;Websocket;Websockets</PackageTags> | ||
<PackageIcon>icon.png</PackageIcon> | ||
<PackageReadmeFile>README.md</PackageReadmeFile> | ||
<IncludeSymbols>true</IncludeSymbols> | ||
<SymbolPackageFormat>snupkg</SymbolPackageFormat> | ||
<EmbedUntrackedSources>true</EmbedUntrackedSources> | ||
<PackageLicenseExpression>MIT</PackageLicenseExpression> | ||
<RepositoryUrl>https://github.com/PinguApps/AppwriteClient</RepositoryUrl> | ||
<RepositoryType>git</RepositoryType> | ||
<PublishRepositoryUrl>true</PublishRepositoryUrl> | ||
<Authors>Pingu</Authors> | ||
<Company>PinguApps</Company> | ||
<Description>A .NET implementation of the Appwrite Realtime SDK. Ideal for developers looking to leverage Appwrite's powerful backend capabilities in their .NET applications.</Description> | ||
<Copyright>Copyright 2025 (c) Pingu. All rights reserved.</Copyright> | ||
|
||
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);CopyProjectReferencesToPackage</TargetsForTfmSpecificBuildOutput> | ||
<GenerateDocumentationFile>true</GenerateDocumentationFile> | ||
<NoWarn>$(NoWarn);1591</NoWarn> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="9.0.1" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.1" /> | ||
<PackageReference Include="Microsoft.Extensions.Options" Version="9.0.1" /> | ||
<PackageReference Include="Refit" Version="8.0.0" /> | ||
<PackageReference Include="System.Text.Json" Version="9.0.1" /> | ||
<PackageReference Include="Websocket.Client" Version="5.1.2" /> | ||
<PackageReference Include="Polly" Version="8.5.1" /> | ||
<PackageReference Include="System.Reactive" Version="6.0.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\PinguApps.Appwrite.Shared\PinguApps.Appwrite.Shared.csproj"> | ||
<ReferenceOutputAssembly>true</ReferenceOutputAssembly> | ||
<IncludeAssets>PinguApps.Appwrite.Shared.dll;PinguApps.Appwrite.Shared.xml;PinguApps.Appwrite.Shared.pdb</IncludeAssets> | ||
</ProjectReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Include="..\..\README.md" Pack="true" PackagePath="\" /> | ||
<None Include="..\..\icon.png" Pack="true" PackagePath="\" /> | ||
</ItemGroup> | ||
|
||
<Target DependsOnTargets="ResolveReferences" Name="CopyProjectReferencesToPackage"> | ||
<ItemGroup> | ||
<BuildOutputInPackage Include="@(ReferenceCopyLocalPaths->WithMetadataValue('ReferenceSourceTarget', 'ProjectReference'))" /> | ||
<BuildOutputInPackage Include="@(ReferenceCopyLocalPaths->WithMetadataValue('ReferenceSourceTarget', 'ProjectReference')->Replace('.dll', '.xml'))" /> | ||
<BuildOutputInPackage Include="@(ReferenceCopyLocalPaths->WithMetadataValue('ReferenceSourceTarget', 'ProjectReference')->Replace('.dll', '.pdb'))" /> | ||
</ItemGroup> | ||
</Target> | ||
|
||
</Project> |
Oops, something went wrong.