-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
227 additions
and
68 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace ScreenshotCreator.Api; | ||
|
||
public static partial class Log | ||
{ | ||
private const string Prefix = nameof(Api); | ||
} |
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,10 @@ | ||
using Microsoft.Playwright; | ||
|
||
namespace ScreenshotCreator.Logic; | ||
|
||
public interface IPlaywrightHelper | ||
{ | ||
ValueTask<IPage> InitializePlaywrightAsync(); | ||
|
||
Task WaitAsync(); | ||
} |
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,7 +1,6 @@ | ||
namespace ScreenshotCreator.Logic; | ||
|
||
public interface IScreenshotCreator | ||
: IAsyncDisposable | ||
{ | ||
Task CreateScreenshotAsync(uint width, uint height); | ||
} |
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,6 @@ | ||
namespace ScreenshotCreator.Logic; | ||
|
||
public static partial class Log | ||
{ | ||
private const string Prefix = nameof(Logic); | ||
} |
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,54 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Options; | ||
using Microsoft.Playwright; | ||
|
||
namespace ScreenshotCreator.Logic; | ||
|
||
[ExcludeFromCodeCoverage] | ||
public sealed class PlaywrightHelper : IPlaywrightHelper, IAsyncDisposable | ||
{ | ||
private readonly ILogger<PlaywrightHelper> _logger; | ||
private readonly ScreenshotOptions _screenshotOptions; | ||
private IPlaywright? _playwright; | ||
private IBrowser? _browser; | ||
private IPage? _page; | ||
private bool _disposed; | ||
|
||
public PlaywrightHelper(IOptions<ScreenshotOptions> options, ILogger<PlaywrightHelper> logger) | ||
{ | ||
_logger = logger; | ||
_screenshotOptions = options.Value; | ||
} | ||
|
||
public async ValueTask DisposeAsync() | ||
{ | ||
if (_disposed) return; | ||
|
||
if (_browser != null) await _browser.DisposeAsync(); | ||
_playwright?.Dispose(); | ||
|
||
_disposed = true; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async ValueTask<IPage> InitializePlaywrightAsync() | ||
{ | ||
if (_page != null) | ||
{ | ||
_logger.ReusingPlaywrightPage(); | ||
return _page; | ||
} | ||
|
||
_playwright = await Playwright.CreateAsync(); | ||
_browser = await _playwright.Chromium.LaunchAsync(); | ||
_page = await _browser.NewPageAsync(new BrowserNewPageOptions { TimezoneId = Environment.GetEnvironmentVariable("TZ") }); | ||
|
||
_logger.PlaywrightInitialized(); | ||
|
||
return _page; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async Task WaitAsync() => await Task.Delay(TimeSpan.FromSeconds(_screenshotOptions.TimeBetweenHttpCallsInSeconds)); | ||
} |
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
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
Oops, something went wrong.