Exemplo n.º 1
0
        static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine("Please provide config.ini file as parameter!");
                Console.WriteLine("Exiting application...");
                return;
            }


            string configFile = args[0];


            if (!File.Exists(configFile))
            {
                Console.WriteLine("Configuration file does not exist! Exiting application...");
                return;
            }
            else
            {
                cfm = new ConfigurationFileManager(configFile);
            }


            if (cfm.EmailRecipentsSourceType == "url")
            {
                LoadRecipientsFromWeb(cfm.EmailRecipentsSource);
            }
            else
            {
                LoadRecipients(cfm.EmailRecipentsSource);
            }


            if (!File.Exists(_LastEntries))
            {
                File.Create(_LastEntries).Dispose();
            }


            WebClient wc      = new WebClient();
            string    content = wc.DownloadString(cfm.WebsiteUrl);


            HtmlDocument doc = new HtmlDocument();

            doc.LoadHtml(content);

            var titles    = doc.DocumentNode.SelectNodes(cfm.WebsiteNodeTitle);
            var datetimes = doc.DocumentNode.SelectNodes(cfm.WebsiteNodePublishedAt);
            var posts     = doc.DocumentNode.SelectNodes(cfm.WebsiteNodeMessageBody);


            if (titles.Count == datetimes.Count && datetimes.Count == posts.Count)
            {
                for (int i = 0; i < titles.Count; i++)
                {
                    publishedArticles.Add(new Article(titles[i], datetimes[i], posts[i]));
                }
            }

            artManager.ReadLoggedArticles();
            List <Article> newArts = artManager.CompareArticleAndGetNewArticles(publishedArticles);

            if (newArts.Count != 0)
            {
                artManager.SaveLoggedArticles(publishedArticles);
#if (!DEBUG)
                foreach (Article newArt in newArts)
                {
                    SendEmail(newArt.HtmlTitle, newArt.HtmlPost);
                }
#endif
                //Console.WriteLine(string.Format("{0} new article(s) found. Email(s) sent.", newArts.Count));
                UpdateLog(string.Format("{0} new article(s) found. Email(s) sent.", newArts.Count));
            }

            UpdateLastCheck();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine("Please provide CONFIG filename as parameter!");
                return;
            }

            Console.WriteLine("Loading CONFIG file...");
            string configFile = args[0];


            if (!File.Exists(configFile))
            {
                Console.WriteLine("CONFIG file does not exist! Exiting application...");
                return;
            }
            else
            {
                cfm = new ConfigurationFileManager(configFile);


                LunchMenuUrl = cfm.LunchMenuUrl;
                DbService.SetConnectionParameters(cfm.DbServer, cfm.DbUser, cfm.DbPass, cfm.DbName);
            }


            Console.WriteLine("Downloading document...");
            DownloadPDF();

            Console.WriteLine("Calculate hash...");
            string fileHash = CalculateSHA256CheckSum(_menufilename);

            Console.WriteLine(string.Format("{0}: {1}", _menufilename, fileHash));

            Console.WriteLine("Creating new name for a document...");
            string newfilename = string.Format("{0:yyyy-MM-dd_HH-mm-ss}.pdf", DateTime.Now);

            Console.WriteLine("Checking if file was processed...");
            if (DbService.CheckIfExistsInDatabase(fileHash))
            {
                Console.WriteLine("Document has been already processed. Quitting...");
                return;
            }

            Console.WriteLine("Copying document...");
            File.Copy(_menufilename, newfilename);

            Console.WriteLine("Processing menu...");
            string menu = GetRawTextFromFile(newfilename);

            LunchMenu lm = new LunchMenu(menu);

            Console.WriteLine(lm.ToString());

            Console.WriteLine("Saving to database...");
            DbService.SaveLunchMenuToDatabaseAsync(lm).Wait();

            Console.WriteLine("Logging this session...");
            DbService.LogMenuSavedAsync(fileHash, lm).Wait();
        }