public bool Validate(MorgueFile morgueFile) { // Morgue files can come from different game types ex) sprint. Look for this exact phrase. return morgueFile.Contents.Contains( string.Format("Dungeon Crawl Stone Soup version {0}", _crawlVersion), StringComparison.OrdinalIgnoreCase); }
private List<MorgueFile> GetMorgueFiles(IDictionary<GameFetchRequest, ScraperResponse> indexResponses, Round round) { var morgueFileRequests = new Dictionary<MorgueFile, ScraperRequest>(); var morgueFiles = new List<MorgueFile>(); foreach (GameFetchRequest gameRequest in indexResponses.Keys) { if (indexResponses[gameRequest].Success) { var games = Regex.Matches(indexResponses[gameRequest].Body, MorgueIndexRegex); foreach (Match game in games) { var morgue = new MorgueFile { CrawlerId = gameRequest.CrawlerId, ParticipantId = gameRequest.ParticipantId, Url = "http://" + indexResponses[gameRequest].Uri.Host + indexResponses[gameRequest].Uri.AbsolutePath + game.Groups[1].ToString().Trim(), FileName = game.Groups[2].ToString().Trim(), LastModified = DateTime.Parse(game.Groups[3].ToString()).AddHours(gameRequest.UtcOffset), }; // Don't look at morgues since the last process date. if (morgue.LastModified < gameRequest.MorguesSince.AddHours(gameRequest.UtcOffset)) break; // Games should be sorted by date descending. In order to help speed up processing, quit // if we've past the end date if (morgue.LastModified < round.Start) break; // Good morgue possibility. Add it to list if (morgue.LastModified <= round.End) morgueFileRequests.Add(morgue, new ScraperRequest {Uri = new Uri(morgue.Url)}); } } } foreach (var morgueResponse in _scraper.Scrape(morgueFileRequests)) { if (morgueResponse.Value.Success) { morgueResponse.Key.Contents = morgueResponse.Value.Body; morgueFiles.Add(morgueResponse.Key); } } return morgueFiles; }