using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Nethereum.Contracts.Services; namespace Nethereum.BlockchainProcessing.BlockProcessing.CrawlerSteps { public abstract class CrawlerStep { public bool Enabled { get; set; } = true; protected IEthApiContractService EthApi { get; } public CrawlerStep( IEthApiContractService ethApi ) { EthApi = ethApi; } public abstract Task GetStepDataAsync(TParentStep parentStep); public virtual async Task> ExecuteStepAsync(TParentStep parentStep, IEnumerable executionStepsCollection) { if (!Enabled) throw new Exception("Crawler step is not enabled"); var processStepValue = await GetStepDataAsync(parentStep).ConfigureAwait(false); if (processStepValue == null) return null; var stepsToProcesss = await executionStepsCollection.FilterMatchingStepAsync(processStepValue).ConfigureAwait(false); if (stepsToProcesss.Any()) { await stepsToProcesss.ExecuteCurrentStepAsync(processStepValue).ConfigureAwait(false); } return new CrawlerStepCompleted(stepsToProcesss, processStepValue); } } }