mirror of
https://github.com/alexhopeoconnor/bom-local-service.git
synced 2026-10-03 21:21:59 +10:00
Major architectural changes: - Replace monolithic ScrapingService with workflow-based system - Extract scraping logic into discrete, testable steps - Add configuration-driven selectors, JavaScript templates, and text patterns - Implement step registry and workflow factory for extensibility - Add PageState tracking and step dependencies - Make IWorkflow generic to support different response types New components: - Scraping steps organized by category (Navigation, Search, Map, Metadata, Capture) - BaseScrapingStep base class with common dependencies - ScrapingContext for shared state between steps - RadarScrapingWorkflow orchestrating step execution - SelectorService for configurable element selection - Configuration models (SelectorConfig, TextPatternsConfig, JavaScriptTemplatesConfig) Performance and monitoring: - Add step-level timing metrics with historical tracking - Log step durations and compare to averages - Warn on slow steps/workflows (50%+ slower than average) - Integrate metrics with CacheService Configuration improvements: - Externalize all selectors to appsettings.json - Externalize JavaScript templates to appsettings.json - Externalize text patterns to appsettings.json - Support Docker configuration via mounted appsettings.json - Remove hardcoded waits, use configurable timeouts Bug fixes: - Fix DebugService collection modification exception - Fix ResetToFirstFrameStep click interception with JavaScript fallback - Remove minutes ago fallback, use timestamp parsing only - Update timestamp parsing for new BOM website format Documentation: - Update README with new architecture details - Add configuration section with Docker guidance - Add development guidelines for extending scraping system - Add performance monitoring documentation
67 lines
2.7 KiB
C#
67 lines
2.7 KiB
C#
using BomLocalService.Services.Interfaces;
|
|
using BomLocalService.Services.Scraping;
|
|
using Microsoft.Playwright;
|
|
|
|
namespace BomLocalService.Services.Scraping.Steps.Map;
|
|
|
|
public class PauseRadarStep : BaseScrapingStep
|
|
{
|
|
public override string Name => "PauseRadar";
|
|
public override string[] Prerequisites => new[] { "WaitForMapReady" };
|
|
|
|
public PauseRadarStep(
|
|
ILogger<PauseRadarStep> logger,
|
|
ISelectorService selectorService,
|
|
IDebugService debugService,
|
|
IConfiguration configuration)
|
|
: base(logger, selectorService, debugService, configuration)
|
|
{
|
|
}
|
|
|
|
public override bool CanExecute(ScrapingContext context)
|
|
{
|
|
return context.IsMapReady;
|
|
}
|
|
|
|
public override async Task<ScrapingStepResult> ExecuteAsync(ScrapingContext context, CancellationToken cancellationToken)
|
|
{
|
|
try
|
|
{
|
|
Logger.LogInformation("Step {Step}: Checking if radar loop is paused", Name);
|
|
|
|
var playPauseButton = SelectorService.GetLocator(context.Page, Selectors.PlayPauseButton);
|
|
await playPauseButton.WaitForAsync(new LocatorWaitForOptions { Timeout = 5000 });
|
|
|
|
var buttonLabel = await playPauseButton.Locator(Selectors.PlayPauseLabel.Selectors[0]).TextContentAsync();
|
|
if (buttonLabel?.Trim().Equals(TextPatterns.ExpectedTexts["PauseButtonLabel"], StringComparison.OrdinalIgnoreCase) == true)
|
|
{
|
|
Logger.LogInformation("Step {Step}: Radar is playing, pausing it", Name);
|
|
await playPauseButton.ClickAsync();
|
|
await context.Page.WaitForTimeoutAsync(300);
|
|
|
|
buttonLabel = await playPauseButton.Locator(Selectors.PlayPauseLabel.Selectors[0]).TextContentAsync();
|
|
if (buttonLabel?.Trim().Equals(TextPatterns.ExpectedTexts["PlayButtonLabel"], StringComparison.OrdinalIgnoreCase) != true)
|
|
{
|
|
Logger.LogWarning("Step {Step}: Radar may not be paused after click, continuing anyway", Name);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Logger.LogInformation("Step {Step}: Radar is already paused", Name);
|
|
}
|
|
|
|
await SaveDebugAsync(context, 8, "radar_paused", cancellationToken);
|
|
|
|
context.CurrentState = PageState.SlideshowPaused;
|
|
return ScrapingStepResult.Successful();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Logger.LogError(ex, "Step {Step} failed", Name);
|
|
await SaveErrorDebugAsync(context, $"Failed to pause radar: {ex.Message}", cancellationToken);
|
|
return ScrapingStepResult.Failed($"Failed to pause radar: {ex.Message}");
|
|
}
|
|
}
|
|
}
|
|
|