Exemple #1
0
        static void Main(string[] args)
        {
            var rootObject       = new RootObject();
            var checkedGamesData = new Dictionary <string, string>();
            var changedGamesData = new Dictionary <string, string>();

            var mail = new EmailComposer();

            mail.InitializeOutlookComposer();

            var outputHandler = new OutputHandler();

            Console.SetOut(outputHandler);

            InitializePaths();
            UpdateTrackedGameData(ref checkedGamesData, ref changedGamesData);
            UpdateTrackedGameSystemData(checkedGamesData);

            try
            {
                using (StreamReader r = new StreamReader(Path.Combine(dataDirectory, "main_data.json")))
                {
                    var json = r.ReadToEnd();
                    rootObject = JsonConvert.DeserializeObject <RootObject>(json);
                    if (rootObject.Usernames is null)
                    {
                        Console.WriteLine("The list of usernames in the 'main_data.json' file is empty.");
                    }
                    else
                    {
                        UpdateTrackedUserData(rootObject, ref checkedGamesData, changedGamesData);
                    }
                }
            }
            catch (FileNotFoundException)
            {
                //FileNotFoundHandler.AbortProgramToDueMissingCriticalFile("main_data.json", dataDirectory);
            }

            WriteRecentChanges(outputHandler, rootObject);
            rootObject.LastAccess = DateTime.Now;
            rootObject.SaveProperties(Path.Combine(dataDirectory, "main_data.json"));
            try
            {
                mail.SendEmail($"RA Scraping Results, " +
                               $"{rootObject.LastAccess.ToString("yyyy/MM/dd, H:mm tt")}",
                               outputHandler.Output.ToString());
            }
            catch (SmtpException)
            {
                File.WriteAllText(
                    Path.Combine(dataDirectory,
                                 $"error_{rootObject.LastAccess.ToString("yyyy-MM-dd  H,mm tt")}.txt"),
                    outputHandler.Output.ToString());
            }
        }