public IEnumerable <T> ParseInput <T>(string input) { var xml = XElement.Parse(input); // some more code here var parser = _parserFactory.CreateParser <T>(); return(parser.Parse(xml)); }
protected virtual void VisitSolution(string solutionPath) { var parser = _solutionParserFactory.CreateParser(solutionPath); var solution = parser.Parse(solutionPath); _codeBase.Solutions.Add(solution); }
protected virtual void VisitProject(string projectPath) { var parser = _projectParserFactory.CreateParser(projectPath); var project = parser.Parse(projectPath); project.Repository = _repositoryRegistry.Current; _codeBase.Projects.Add(project); }
public async Task <IEnumerable <IWorkTask> > WorkAsync(IDownloader downloader, IParserFactory parserFactory) { var html = await downloader.Down(url); var parser = parserFactory.CreateParser("xpath"); parser.Init(html); var keyValuePairs = parser.Parser(new ParaseRule[] { new ParaseRule() { Name = "博客列表", Path = "//div[@class=\"post_item\"]", Rules = new ParaseRule[] { new ParaseRule() { Path = "*//a[@class=\"titlelnk\"]", Name = "标题" }, new ParaseRule() { Path = "*//a[@class=\"titlelnk\"]", Name = "链接", AttrName = "href" } } } }); foreach (var item in keyValuePairs) { Console.WriteLine($"{item}"); } var nextUrlKv = parser.Parser(new ParaseRule[] { new ParaseRule() { Name = "下一页", Path = "//div[@class=\"pager\"]/a[contains(@class,'current')]/following-sibling::a[1]", AttrName = "href" } }); var results = nextUrlKv.Select(x => (IWorkTask) new SpiderTask(x.Value)); return(await Task.FromResult(results)); }
/// <summary> /// Standard implementation /// </summary> /// <returns>Consolidated schedules</returns> public IEnumerable <IRecord> Read() { var parser = _cifParserFactory.CreateParser(); return(parser.Read(Extract())); }
public IParser CreateParser() { return(new ScheduleConsolidator(_factory.CreateParser(), _logger)); }