Skip to content
Open
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
29 changes: 25 additions & 4 deletions generate_upload_package.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
if (Test-Path -Path .\UltimatePDF_ExternalLogic.zip -PathType Leaf) {
Remove-Item -Path .\UltimatePDF_ExternalLogic.zip -Force
$zipPath = ".\UltimatePDF_ExternalLogic.zip"
$projectPath = "src\UltimatePDF_ExternalLogic\UltimatePDF_ExternalLogic.csproj"
$publishDir = ".\src\UltimatePDF_ExternalLogic\bin\Release\net10.0\linux-x64\publish\"

if (Test-Path -Path $zipPath -PathType Leaf) {
Write-Host "Removing existing package: $zipPath"
Remove-Item -Path $zipPath -Force
}

Write-Host "Setting execution policy for current user (Unrestricted)..."
Set-ExecutionPolicy -Scope CurrentUser Unrestricted
dotnet publish src\UltimatePDF_ExternalLogic.sln -c Release -r linux-x64 --self-contained false
Compress-Archive -Path .\src\UltimatePDF_ExternalLogic\bin\Release\net10.0\linux-x64\publish\* -Update -DestinationPath UltimatePDF_ExternalLogic.zip

# Only the main project is needed to produce the upload package (test projects aren't part of it).
Write-Host "Publishing $projectPath for linux-x64 (Release, framework-dependent)..."
dotnet publish $projectPath -c Release -r linux-x64 --self-contained false

# dotnet publish doesn't throw in PowerShell on failure, so without this check a failed build
# would silently get packaged from stale (or missing) publish output.
if ($LASTEXITCODE -ne 0) {
Write-Host "dotnet publish failed with exit code $LASTEXITCODE. Aborting package creation." -ForegroundColor Red
exit $LASTEXITCODE
}

Write-Host "Compressing publish output into $zipPath..."
Compress-Archive -Path (Join-Path $publishDir '*') -Update -DestinationPath $zipPath

Write-Host "Package created: $zipPath" -ForegroundColor Green
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -7,41 +8,42 @@
using PuppeteerSharp;
using UltimatePDF_ExternalLogic.Utils;

namespace OutSystems.UltimatePDF_ExternalLogic.BrowserExecution {
public class BrowserInstancePool {
namespace OutSystems.UltimatePDF_ExternalLogic.BrowserExecution;
public class BrowserInstancePool {

private readonly SemaphoreSlim mutex = new(1, 1);
private readonly SemaphoreSlim mutex = new(1, 1);

private static readonly List<PooledBrowserInstance> pool = new();
private static readonly List<PooledBrowserInstance> pool = new();

public BrowserInstancePool() {
}

private async Task<PooledBrowserInstance> NewBrowserInstance(Logger logger) {
await mutex.WaitAsync();
try {
var instance = pool.FirstOrDefault(i => i.IsHealthy);
public BrowserInstancePool() {
}

if (instance == null) {
logger.Log("Create new Browser Instance");
private async Task<PooledBrowserInstance> NewBrowserInstance(Logger logger) {
using var activity = Activity.Current?.Source.StartActivity("BrowserInstancePool.NewBrowserInstance");
await mutex.WaitAsync();
try {
var instance = pool.FirstOrDefault(i => i.IsHealthy);

var browserLauncher = new HeadlessChromiumPuppeteerLauncher(logger.GetLoggerFactory("browser.txt"));
var browser = await browserLauncher.LaunchAsync();
instance = new PooledBrowserInstance(browser);
pool.Add(instance);
}
if (instance == null) {
logger.Log("Create new Browser Instance");

return instance;
} finally {
mutex.Release();
var browserLauncher = new HeadlessChromiumPuppeteerLauncher(logger.GetLoggerFactory("browser.txt"));
var browser = await browserLauncher.LaunchAsync();
instance = new PooledBrowserInstance(browser);
pool.Add(instance);
}
}

public async Task<PooledPage> NewPooledPage(Logger logger) {
var instance = await NewBrowserInstance(logger);
var page = await instance.Browser.NewPageAsync();
var pooledPage = new PooledPage(page, logger);
return pooledPage;
return instance;
} finally {
mutex.Release();
}
}

public async Task<PooledPage> NewPooledPage(Logger logger) {
using var activity = Activity.Current?.Source.StartActivity("BrowserInstancePool.NewPooledPage");
var instance = await NewBrowserInstance(logger);
var page = await instance.Browser.NewPageAsync();
var pooledPage = new PooledPage(page, logger);
return pooledPage;
}
}
Loading