Previewer: added presence notification
This commit is contained in:
@@ -13,7 +13,13 @@ using QuestPDF.Previewer.Inspection;
|
||||
|
||||
namespace QuestPDF.Previewer
|
||||
{
|
||||
|
||||
internal sealed class NotifyPresenceRequest
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public bool IsDotnet6OrBeyond { get; set; }
|
||||
public bool IsDotnet3OrBeyond { get; set; }
|
||||
public bool IsExecutedInUnitTest { get; set; }
|
||||
}
|
||||
|
||||
internal sealed class GenericError
|
||||
{
|
||||
@@ -53,6 +59,8 @@ namespace QuestPDF.Previewer
|
||||
|
||||
internal class PreviewerService
|
||||
{
|
||||
private string ClientId { get; } = Guid.NewGuid().ToString("D");
|
||||
|
||||
private int Port { get; }
|
||||
private HttpClient HttpClient { get; }
|
||||
|
||||
@@ -107,13 +115,10 @@ namespace QuestPDF.Previewer
|
||||
|
||||
//var previewerVersion = await GetPreviewerVersion();
|
||||
//CheckVersionCompatibility(previewerVersion);
|
||||
|
||||
StartNotifyPresenceTask();
|
||||
}
|
||||
|
||||
public async Task Disconnect()
|
||||
{
|
||||
await HttpClient.GetAsync("/v1/disconnect");
|
||||
}
|
||||
|
||||
|
||||
private async Task<bool> IsPreviewerAvailable()
|
||||
{
|
||||
try
|
||||
@@ -126,6 +131,33 @@ namespace QuestPDF.Previewer
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void StartNotifyPresenceTask()
|
||||
{
|
||||
Task.Run(async () =>
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
NotifyPresence();
|
||||
await Task.Delay(1000);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public async Task NotifyPresence()
|
||||
{
|
||||
var payload = new NotifyPresenceRequest
|
||||
{
|
||||
Id = ClientId,
|
||||
IsDotnet6OrBeyond = RuntimeDetector.IsNet6OrGreater,
|
||||
IsDotnet3OrBeyond = RuntimeDetector.IsNet3OrGreater,
|
||||
IsExecutedInUnitTest = UnitTestDetector.RunningInUnitTest
|
||||
};
|
||||
|
||||
await HttpClient.PostAsJsonAsync("/v1/notify/presence", payload);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public async Task ShowDocumentPreview(DocumentPreviewResult documentPreviewResult)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
namespace QuestPDF.Previewer;
|
||||
|
||||
public static class RuntimeDetector
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
public static bool IsNet6OrGreater => true;
|
||||
#else
|
||||
public static bool IsNet6OrGreater => false;
|
||||
#endif
|
||||
|
||||
#if NETCOREAPP3_0_OR_GREATER
|
||||
public static bool IsNet3OrGreater => true;
|
||||
#else
|
||||
public static bool IsNet6OrGreater => false;
|
||||
#endif
|
||||
}
|
||||
@@ -17,10 +17,9 @@
|
||||
<PackageTags>pdf report file export generate generation tool create creation render portable document format quest html library converter open source free standard core</PackageTags>
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
<Nullable>enable</Nullable>
|
||||
<TargetFrameworks>net462;netstandard2.0;netcoreapp2.0;netcoreapp3.0;net6.0</TargetFrameworks>
|
||||
<TargetFrameworks>net6.0</TargetFrameworks>
|
||||
<IncludeSymbols>true</IncludeSymbols>
|
||||
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user