mirror of
https://github.com/alexhopeoconnor/bom-local-service.git
synced 2026-10-04 03:28:11 +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
43 lines
1.9 KiB
C#
43 lines
1.9 KiB
C#
using BomLocalService.Models;
|
|
using Microsoft.Playwright;
|
|
|
|
namespace BomLocalService.Services.Scraping;
|
|
|
|
/// <summary>
|
|
/// Context shared between scraping steps
|
|
/// </summary>
|
|
public class ScrapingContext
|
|
{
|
|
public IPage Page { get; set; } = null!;
|
|
public string Suburb { get; set; } = string.Empty;
|
|
public string State { get; set; } = string.Empty;
|
|
public string CacheFolderPath { get; set; } = string.Empty;
|
|
public string DebugFolder { get; set; } = string.Empty;
|
|
public List<(string type, string text, DateTime timestamp)> ConsoleMessages { get; set; } = new();
|
|
public List<(string method, string url, int? status, string resourceType, DateTime timestamp)> NetworkRequests { get; set; } = new();
|
|
|
|
// Page state tracking
|
|
public PageState CurrentState { get; set; } = PageState.Initial;
|
|
public HashSet<string> CompletedSteps { get; set; } = new();
|
|
|
|
// Shared state between steps
|
|
public ILocator? SearchButton { get; set; }
|
|
public ILocator? SearchInput { get; set; }
|
|
public List<(string name, string desc, string fullText)>? SearchResults { get; set; }
|
|
public int? SelectedResultIndex { get; set; }
|
|
public ILocator? RadarLink { get; set; }
|
|
public ILocator? MapContainer { get; set; }
|
|
public Clip? MapBoundingBox { get; set; }
|
|
public LastUpdatedInfo? LastUpdatedInfo { get; set; }
|
|
public List<(int index, int minutesAgo)>? FrameInfo { get; set; }
|
|
public List<RadarFrame> Frames { get; set; } = new();
|
|
|
|
// State validation helpers
|
|
public bool IsHomepageLoaded => CurrentState >= PageState.HomepageLoaded;
|
|
public bool IsSearchModalOpen => CurrentState >= PageState.SearchModalOpen;
|
|
public bool IsForecastPageLoaded => CurrentState >= PageState.ForecastPageLoaded;
|
|
public bool IsRadarPageLoaded => CurrentState >= PageState.RadarPageLoaded;
|
|
public bool IsMapReady => CurrentState >= PageState.MapReady;
|
|
}
|
|
|