Beispiel #1
0
        /// <summary>
        /// Removes email from JSON object to disable email notifications
        /// </summary>
        private void btnDisableEmail_Click(object sender, RoutedEventArgs e)
        {
            rcHelper  rc   = new rcHelper();
            RCDetails json = rc.GetJson(jsonFilePath);

            json.email = null;
            json.ePass = null;
            rc.WriteToFile(json);

            MessageBox.Show("Your email has been removed. \nYou will only receive toast notifications for new posts (if enabled)");
        }
Beispiel #2
0
        public void TestJsonCreationAndExistence()
        {
            rcHelper      rc  = new rcHelper();
            List <string> sc  = new List <string>();
            RCDetails     rcd = new RCDetails("rLog", "rPass", "email", "ePass", "sub", "toast", sc, sc);

            rc.WriteToFile(rcd);
            bool b = File.Exists(Directory.GetCurrentDirectory().ToString() + "/rcData.json");

            File.Delete(Directory.GetCurrentDirectory().ToString() + "/rcData.json");
            Assert.AreEqual(b, true);
        }
Beispiel #3
0
        /// <summary>
        /// Takes user reddit user name and password as input, confirms existence of all relevant JSON contents, then retrieves 15 posts using <see cref="GetPosts(string)"/>
        /// Once these posts have been retrieved, the method checks them against duplicates and matches from the JSON as well,
        /// then uses <see cref="NotifyUser(string)"/> to notify the user of any matches. After this, all variables are cleared, the thread sleeps for
        /// 180,000 ticks, and runs again.
        /// </summary>
        private async Task Listen()
        {
            //Initialize helper classes
            rcHelper       rc   = new rcHelper();
            rcConnectivity rcon = new rcConnectivity();
            RCDetails      json = new RCDetails();

            //Retrieve JSON object from local storage
            if (File.Exists(Path.Combine(Directory.GetCurrentDirectory().ToString() + jsonFilePath)))
            {
                json = rc.GetJson(jsonFilePath);
            }
            //If JSON is not found, throw exception indicating it needs to be initialized.
            else
            {
                Exception ex = new Exception("Please ensure you have properly configured your information in rcConfig.");
                rc.DebugLog(ex);
                Environment.Exit(0);
            }

            //Run remainder of method in a loop every 180,000 ticks..
            while (true)
            {
                try
                {
                    //Checks for valid entries in relevant text files, performs DebugLog() and exits environment on failure.
                    #region criteriaCheck
                    List <string> lstSearchInput   = json.searchCriteria;
                    List <string> lstDuplicateList = new List <string>();
                    if (json.dupResults != null)
                    {
                        lstDuplicateList = json.dupResults;
                    }
                    //Throw exception indicating that user needs to input search terms into rcConfig
                    if (lstSearchInput.Count < 1)
                    {
                        Exception ex = new Exception("You must ensure search terms have been set up in rcConfig.");
                        rc.DebugLog(ex);
                        System.Environment.Exit(0);
                    }

                    //Retrieve status on all variables
                    bool   toastStatus = false;
                    string sub = null;
                    bool   subEx, emailEx;
                    subEx = emailEx = false;
                    if (json.toast == "yes")
                    {
                        toastStatus = true;
                    }
                    if (json.sub != null && json.sub.Count() > 3)
                    {
                        subEx = true;
                        sub   = json.sub;
                    }
                    if (json.email != null && json.ePass != null)
                    {
                        emailEx = true;
                    }

                    //Exit environment and log error if any variable check fails
                    if (subEx == false)
                    {
                        rc.DebugLog(new Exception("Please check your subreddit existence & formatting in rcConfig."));
                        Environment.Exit(0);
                    }

                    #endregion

                    //gets list of 15 most recent posts/URLs from designated sub.
                    var           getLists      = rcon.GetPosts(sub);
                    List <string> lstResultList = getLists.Item1;
                    List <string> lstUrl        = getLists.Item2;

                    //Run lists through the NotificationList method, trimming duplicates and non-matches.
                    var           passedLists   = rc.NotificationList(lstResultList, lstUrl, lstSearchInput, lstDuplicateList);
                    List <string> lstPassedList = passedLists.Item1;
                    List <string> lstPassedUrls = passedLists.Item2;

                    //Now that the list has been trimmed, notify user of all results
                    if (lstPassedList.Count > 0)
                    {
                        if (lstPassedList.Count() == 0)
                        {
                            Console.WriteLine("No new posts were retrieved.");
                        }
                        else
                        {
                            foreach (string s in lstPassedList)
                            {
                                Console.WriteLine("Sent: " + s);
                                lstDuplicateList.Add(s);
                            }
                            if (emailEx == true)
                            {
                                rcon.NotifyUser(lstPassedList, lstPassedUrls);
                            }
                        }
                        for (int i = 0; i < lstPassedList.Count(); i++)
                        {
                            if (toastStatus == true)
                            {
                                ShowTextToast(appID, "New Reddit Post!" + lstPassedList[i], lstPassedUrls[i]);
                                await(Task.Delay(10000));
                            }
                        }
                        json.dupResults = lstDuplicateList;
                        rc.WriteToFile(json);
                    }

                    //Clear all lists, sleep, and repeat
                    lstResultList.Clear();
                    lstPassedList.Clear();
                    lstDuplicateList.Clear();
                    lstSearchInput.Clear();
                    await Task.Delay(180000);
                }
                //Generic unhandled exception catch
                catch (Exception ex)
                {
                    rc.DebugLog(ex);
                    System.Environment.Exit(0);
                }
            }
        }