コード例 #1
0
        /// <summary>
        /// Saves an article to database
        /// </summary>
        public void SaveDB()
        {
            try
            {
                DBAcessHandler dBAcessHandler = new DBAcessHandler();
                dBAcessHandler.SaveArticle(ParsedArticle);

                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine($"Article saved to Database: {AppSettings.DBSavePath}!");
                Console.ResetColor();
            }
            catch (Exception ex)
            {
                ExceptionConsoleLogger.PrintException("Database saving exception: ", ex);
            }
        }
コード例 #2
0
        /// <summary>
        /// Saves an article to disk
        /// </summary>
        public void Save()
        {
            try
            {
                ArticleSaveHandler fs = new ArticleSaveHandler(ParsedArticle, AppSettings.FileSavePath);

                fs.SaveArticle();

                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine($"Article saved to {AppSettings.FileSavePath}!");
                Console.ResetColor();
            }
            catch (Exception ex)
            {
                ExceptionConsoleLogger.PrintException("File saving exception:", ex);
            }
        }
コード例 #3
0
        /// <summary>
        /// Starts parsing an article
        /// </summary>
        public void StartParse()
        {
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("Parsing has been started.");
            try
            {
                var        result = new HttpRequestHandler(ArticleUrl).GetPageSourceCodeAsync().Result;
                HtmlParser hp     = new HtmlParser(result);
                ParsedArticle = hp.ParseArticle();

                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine($"Article parsed! Title: {ParsedArticle.AtricleTitle}; Symbols count: {ParsedArticle.ArticleText.Length}");
                Console.ResetColor();
            }
            catch (Exception ex)
            {
                ExceptionConsoleLogger.PrintException("Parsing exception:", ex);
            }
        }