2
0
Эх сурвалжийг харах

Previewer: throwing exception when cannot connect with frontend

MarcinZiabek 3 жил өмнө
parent
commit
555825e8be

+ 9 - 0
QuestPDF/Previewer/PreviewerService.cs

@@ -5,6 +5,7 @@ using System.Collections.Generic;
 using System.Diagnostics;
 using System.Net.Http;
 using System.Net.Http.Json;
+using System.Threading;
 using System.Threading.Tasks;
 using QuestPDF.Drawing;
 
@@ -102,10 +103,18 @@ namespace QuestPDF.Previewer
         
         private async Task WaitForConnection()
         {
+            var cancellationTokenSource = new CancellationTokenSource();
+            cancellationTokenSource.CancelAfter(TimeSpan.FromSeconds(10));
+            
+            var cancellationToken = cancellationTokenSource.Token; 
+            
             while (true)
             {
                 await Task.Delay(TimeSpan.FromMilliseconds(250));
 
+                if (cancellationToken.IsCancellationRequested)
+                    throw new Exception($"Cannot connect to the QuestPDF Previewer tool. Please make sure that your Operating System does not block HTTP connections on port {Port}.");
+
                 var isConnected = await IsPreviewerAvailable();
 
                 if (isConnected)

+ 1 - 1
QuestPDF/QuestPDF.csproj

@@ -4,7 +4,7 @@
         <Authors>MarcinZiabek</Authors>
         <Company>CodeFlint</Company>
         <PackageId>QuestPDF</PackageId>
-        <Version>2022.4.0</Version>
+        <Version>2022.4.1</Version>
         <PackageDescription>QuestPDF is an open-source, modern and battle-tested library that can help you with generating PDF documents by offering friendly, discoverable and predictable C# fluent API.</PackageDescription>
         <PackageReleaseNotes>$([System.IO.File]::ReadAllText("$(MSBuildProjectDirectory)/Resources/ReleaseNotes.txt"))</PackageReleaseNotes>
         <LangVersion>9</LangVersion>