public IEnumerable <IGameRecord> Traverse(ISeed relativeRoot, ISeedRootContext context) { string platformId = context.GetAllOfType("platform").FirstOrDefault()?.Content.Value; if (!this.StoneProvider.Platforms.Keys.Contains(platformId)) { yield break; } var platform = this.StoneProvider.Platforms[platformId]; var fileRecords = this.FileTraverser.Traverse(relativeRoot, context); foreach (var resultSeed in context.GetAllOfType("result")) { var children = context.GetChildren(resultSeed); var metadataSeeds = context.GetDescendants(resultSeed) .DistinctBy(p => p.Content.Type).Select(p => p.Content); var gameRecord = new GameRecord(platform, resultSeed.Content.Value); foreach (var content in metadataSeeds) { gameRecord.Metadata[$"game_{content.Type}"] = content.Value; } foreach (var file in fileRecords.Concat(this.FileTraverser.Traverse(resultSeed, context))) { gameRecord.Files.Add(file); } yield return(gameRecord); } }
public override IEnumerable <ISeed> Filter(IEnumerable <ISeed> seedsToTrim, ISeedRootContext context) { var clientResult = seedsToTrim.FirstOrDefault(s => s.Source == ScrapeJob.ClientSeedSource); if (clientResult != null) { yield return(clientResult); yield break; } var crc32Results = seedsToTrim.Where(s => context[s.Parent]?.Content.Type == "search_crc32"); var mostDetailedCrc32 = crc32Results.OrderByDescending(s => context.GetChildren(s).Count()).FirstOrDefault(); var mostDetailedTitle = (from seed in seedsToTrim let parent = context[seed.Parent] where parent?.Content.Type == "search_title" let title = context.GetChildren(seed).FirstOrDefault(s => s.Content.Type == "title") where title != null let r = title.Content.Value let distance = r.CompareTitle(parent.Content.Value) orderby distance, context.GetChildren(seed).Count() select seed).FirstOrDefault(); yield return((from seed in new[] { mostDetailedCrc32, mostDetailedTitle } orderby context.GetChildren(seed).Count() select seed).FirstOrDefault()); }
public override IEnumerable <ISeed> Filter(IEnumerable <ISeed> seedsToTrim, ISeedRootContext context) { foreach (var seed in seedsToTrim) { if (seed.Content.Value == "Goodbye World") { yield return(seed); } } }
public IEnumerable <IFileRecord> Traverse(ISeed relativeRoot, ISeedRootContext context) { foreach (var fileSeed in context.GetChildren(relativeRoot).Where(s => s.Content.Type == "file")) { var children = context.GetChildren(fileSeed); var mimetypeSeed = children.FirstOrDefault(s => s.Content.Type == "mimetype"); if (mimetypeSeed == null) { continue; } var metadataSeeds = context.GetDescendants(fileSeed) .DistinctBy(p => p.Content.Type).Select(p => p.Content); // var fileRecord = new FileRecord(fileSeed.Content.Value, mimetypeSeed.Content.Value); foreach (var content in metadataSeeds) { // fileRecord.Metadata[$"file_{content.Type}"] = content.Value; } yield return(null); } }
public override async IAsyncEnumerable <IRecordMetadata> Traverse(IGame game, ISeed relativeRoot, ISeedRootContext context) { foreach (var result in context.GetAllOfType("result").SelectMany(s => context.GetChildren(s).Distinct())) { if (game.Record.Metadata.ContainsKey($"game_{result.Content.Type}")) { continue; } game.Record.Metadata.Add($"game_{result.Content.Type}", result.Content.Value); yield return((game.Record.Metadata as IDictionary <string, IRecordMetadata>)[$"game_{result.Content.Type}"]); } }
/// <inheritdoc /> public abstract IEnumerable <ISeed> Filter(IEnumerable <ISeed> seedsToTrim, ISeedRootContext context);
public async Task <IEnumerable <TProducts> > TraverseAll(TEffectTarget sideEffectContext, ISeed relativeRoot, ISeedRootContext context) { IList <TProducts> list = new List <TProducts>(); await foreach (var product in this.Traverse(sideEffectContext, relativeRoot, context).ConfigureAwait(false)) { list.Add(product); } return(list); }
public abstract IAsyncEnumerable <TProducts> Traverse(TEffectTarget sideEffectContext, ISeed relativeRoot, ISeedRootContext context);
public abstract IAsyncEnumerable <TProducts> Traverse(TEffectTarget sideEffectContext, ISeed relativeRoot, ISeedRootContext context, CancellationToken cancellationToken = default);