示例#1
0
        public async Task Execute()
        {
            string inputUrl = string.Empty;
            string filePath = string.Empty;
            string text     = string.Empty;

            Console.WriteLine("Please enter a web page url");
            inputUrl = Console.ReadLine();

            Console.WriteLine("Trying to load web page");
            filePath = await _webPageLoader.DownloadPageAsync(inputUrl);

            Console.WriteLine("Page was successfully loaded");

            Console.WriteLine("File parsing");
            text = _htmlParser.ParseHtmlFile(filePath);

            Console.WriteLine("Calculating statistics");
            var textAnalyzer = new TextAnalyzer(text);
            var wordStats    = textAnalyzer.CountWordRepetitions();

            Console.WriteLine($"Statistics for URL: {inputUrl}");

            StringBuilder statInfo = new StringBuilder();

            wordStats.OrderByDescending(kvp => kvp.Value)
            .ForEach(kvp => statInfo.AppendLine($"{kvp.Key} - {kvp.Value}"));

            Console.WriteLine(statInfo);

            Console.WriteLine($"Saving statistics to database");
            await _dao.SaveAnalysisStatsAsync(new TextAnalysisRecord(DateTime.Now, inputUrl, statInfo.ToString()));
        }