Earl.Crawler.Persistence
0.0.0-alpha.0.111
dotnet add package Earl.Crawler.Persistence --version 0.0.0-alpha.0.111
NuGet\Install-Package Earl.Crawler.Persistence -Version 0.0.0-alpha.0.111
<PackageReference Include="Earl.Crawler.Persistence" Version="0.0.0-alpha.0.111" />
<PackageVersion Include="Earl.Crawler.Persistence" Version="0.0.0-alpha.0.111" />
<PackageReference Include="Earl.Crawler.Persistence" />
paket add Earl.Crawler.Persistence --version 0.0.0-alpha.0.111
#r "nuget: Earl.Crawler.Persistence, 0.0.0-alpha.0.111"
#:package Earl.Crawler.Persistence@0.0.0-alpha.0.111
#addin nuget:?package=Earl.Crawler.Persistence&version=0.0.0-alpha.0.111&prerelease
#tool nuget:?package=Earl.Crawler.Persistence&version=0.0.0-alpha.0.111&prerelease
Earl Persistence Layer
The "Earl Persistence Layer" refers to a suite of APIs that enable the results of a crawl to be persisted to a backing storage mechanism.
Out-of-the-box, and by design, Earl does not collect the results of a crawl. Rather, Earl provides an Events API that leaves it up to the consumer of the IEarlCrawler contract to handle the CrawlUrlResultEvent in order to consume CrawlUrlResults.
At the lowest level of the Crawler API, this is done by specifying an ICrawlerEvents implementation for the CrawlerOptions.Events provided to the IEarlCrawler. However, more commonly used, is likely the On<TEvent>(this ICrawlerOptionsBuilder builder, CrawlerEventHandler<TEvent> handler) extension method:
var options = CrawlerOptionsBuilder.CreateDefault()
.On<CrawlUrlResultEvent>(
async ( CrawlUrlResultEvent e, CancellationToken cancellation ) =>
{
// handle the event...
}
)
.Build();
await crawler.CrawlAsync( new Uri(...), options );
The Earl Persistence Layer provides an API around such an event handler in order to ease with saving the results of a crawl. The entry point of the Persistence API is the PersistTo(this ICrawlerOptionsBuilder builder, Action<ICrawlerPersistenceOptionsBuilder> configure) extension method. This extension method exposes an ICrawlerPersistenceOptionsBuilder, which serves as an extension point for persistence implementations to offer a fluent syntax for configuration of the backing storage mechanism.
For example, the JSON Persistence API provides the ToJson(this ICrawlerPersistenceOptionsBuilder builder, Action<ICrawlerJsonPersistenceOptionsBuilder> configure) extension method to configure the persistence of crawl results to JSON files:
var options = CrawlerOptionsBuilder.CreateDefault()
.PersistTo(
persist => persist.ToJson( json => json.Destination(...) )
)
.Build();
await crawler.CrawlAsync( new Uri(...), options );
Behind the Scenes
The "Persistence Layer" can be described by the following Types, respectively defined in Earl.Crawler.Persistence.Abstractions:
ICrawlerPersistence- "Describes a service that can persist aCrawlUrlResult."ICrawlerPersistenceDescriptor- "Describes a type that describes a crawler persistence mechanism."ICrawlerPersistenceFactory- "Describes a service that can create an instance of anICrawlerPersistencefor a givenICrawlerPersistenceDescriptor."ICrawlerPersistenceInvoker- "Describes a service that can invoke theICrawlerPersistence.PersistAsync(CrawlUrlResult, CancellationToken)operation for a given configuration ofCrawlerPersistenceOptions."
When the CrawlUrlResultEvent is emitted, the ICrawlerPersistenceInvoker is resolved from the event's service provider and invoked to persist the result. The default invoker, CrawlerPersistenceInvoker, uses the ICrawlerPersistenceFactory to create ICrawlerPersistence instances for each of the CrawlerPersistenceOptions.Descriptors passed to the invoker. The default factory implementation, CrawlerPersistenceFactory, resolves a CrawlerPersistenceFactory<TDescriptor> implementation from the current service provider for the type of ICrawlerPersistenceDescriptor passed to the factory. The typed factory is in turn used to create an instance of ICrawlerPersistence to persist the result.
See PersistTo(this ICrawlerOptionsBuilder builder, Action<ICrawlerPersistenceOptionsBuilder> configure).
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net6.0
- Earl.Crawler.Events (>= 0.0.0-alpha.0.111)
- Earl.Crawler.Persistence.Abstractions (>= 0.0.0-alpha.0.111)
- Microsoft.Extensions.DependencyInjection (>= 6.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Earl.Crawler.Persistence:
| Package | Downloads |
|---|---|
|
Earl.Crawler.Persistence.Json
An implementation of Earl's "Persistence" pattern for persiting results to JSON files. |
GitHub repositories
This package is not used by any popular GitHub repositories.