private static void StartUpdating()
        {
            Console.WriteLine($"Getting updates on {DateTime.Now}");
            var freshNewsCount = Helper.UpdateNewsDb();

            if (freshNewsCount > 0)
            {
                Helper.ShowNotify(freshNewsCount + " fresh news downloaded");
            }
            Console.WriteLine($"Update finished on {DateTime.Now}");
            Console.WriteLine(new string('*', 50));
        }
        private static void GenerateDoc()
        {
            Console.WriteLine($"Generating Doc on {DateTime.Now}");
            var news = Helper.CategorizeNewsByAttackType(Helper.GetUnGeneratedNews());

            if (!news.Any())
            {
                Helper.ShowNotify("No News to generate Document");
                return;
            }

            DocHelper.GenerateDocument(news.Take(100).ToList());
            if (news.Count > 100)
            {
                DocHelper.GenerateDocument(news.Skip(100).ToList());
            }
            Helper.ShowNotify("TechWatch document generated");

            new Thread(() =>
            {
                DbHelper.UpdateDbSetNewsReadBit(news);
            }).Start();
        }
Exemple #3
0
        internal static void UpdateDbSetNewsReadBit(List <Model.News> newsList)
        {
            using (var db = new SQLiteConnection("Data Source=NewsArchive.db;Version=3;"))
            {
                db.Open();

                var           query = "";
                SQLiteCommand cmd;

                foreach (var item in newsList)
                {
                    try
                    {
                        query = $"UPDATE News SET Reported = 'True' WHERE Identifier = '{item.Identifier}';";
                        cmd   = new SQLiteCommand(query, db);
                        cmd.ExecuteNonQuery();
                    }
                    catch (Exception e)
                    {
                        Helper.ShowNotify(e.Message, e.StackTrace, "Update db bit");
                    }
                }
            }
        }
        public static void GenerateDocument(List <Model.News> news)
        {
            try
            {
                var document = new Document();
                var section  = document.AddSection();

                #region Styling Document
                var headerStyle = new ParagraphStyle(document)
                {
                    Name = HeaderStyleName
                };
                headerStyle.CharacterFormat.FontName         = "Calibri";
                headerStyle.CharacterFormat.FontSize         = 16;
                headerStyle.CharacterFormat.TextColor        = Color.CornflowerBlue;
                headerStyle.CharacterFormat.CharacterSpacing = 0;
                headerStyle.CharacterFormat.Bold             = true;
                document.Styles.Add(headerStyle);

                var titleStyle = new ParagraphStyle(document)
                {
                    Name = TitleStyleName
                };
                titleStyle.CharacterFormat.FontName = "Calibri";
                titleStyle.CharacterFormat.FontSize = 14;
                //titleStyle.ParagraphFormat.BeforeSpacing = 6;
                titleStyle.CharacterFormat.Bold      = true;
                titleStyle.CharacterFormat.TextColor = Color.Black;
                document.Styles.Add(titleStyle);

                var urlStyle = new ParagraphStyle(document)
                {
                    Name = UrlStyleName
                };
                urlStyle.CharacterFormat.FontName  = "Calibri";
                urlStyle.CharacterFormat.FontSize  = 7;
                urlStyle.CharacterFormat.TextColor = Color.Black;
                document.Styles.Add(urlStyle);
                #endregion

                var mainParagraph = section.AddParagraph();
                var category      = news[0].AttackCategory;
                mainParagraph.AppendText($"{category.GetEnumDescription()}");
                mainParagraph.ApplyStyle(HeaderStyleName);
                //mainParagraph.BreakCharacterFormat.FontName = "Calibri";

                //DbHelper.UpdateDbSetNewsReadBit(news);

                foreach (var newsItem in news)
                {
                    if (newsItem.AttackCategory != category)
                    {
                        category = newsItem.AttackCategory;
                        mainParagraph.AppendText("\n" + new string('*', 50));

                        mainParagraph = section.AddParagraph();
                        //mainParagraph.AppendText($"{category.GetEnumDescription()} ({news.Count(n => n.AttackCategory == category)})");
                        mainParagraph.AppendText($"{category.GetEnumDescription()}");
                        mainParagraph.ApplyStyle(HeaderStyleName);
                    }

                    mainParagraph = section.AddParagraph();
                    //mainParagraph.AppendHyperlink(newsItem.Url, newsItem.Title, HyperlinkType.WebLink);
                    mainParagraph.AppendText((newsItem.Title.Length <= 15 && newsItem.Title.Contains("CVE")) ? StripTagsCharArray(newsItem.Description) : newsItem.Title);
                    mainParagraph.ApplyStyle(TitleStyleName);

                    mainParagraph = section.AddParagraph();
                    //mainParagraph.AppendText(newsItem.Url);
                    mainParagraph.AppendText(newsItem.PublishDate.ToString(CultureInfo.InvariantCulture) + Environment.NewLine);
                    mainParagraph.AppendHyperlink(newsItem.Url, newsItem.Url, HyperlinkType.WebLink);
                    mainParagraph.ApplyStyle(UrlStyleName);
                }
                SaveDoc(document);
            }
            catch (Exception exception)
            {
                Helper.ShowNotify(exception.Message, exception.StackTrace, "Generating Document");
            }
        }