コード例 #1
0
        /// <summary>
        /// Confirms contents of email and email password boxes and encrypts/writes contents to JSON object using <see cref="NewEmail(string, string)"/> if valid.
        /// </summary>
        private void btnSubmitEmail_click(object sender, RoutedEventArgs e)
        {
            //Initialize helper class
            rcHelper rc = new rcHelper();

            try
            {
                //Initialize all variables from email and ePass fields.
                #region variable_Initialization
                //Initialize email and password variables
                string email = null;
                string ePass = null;

                //Check for valid input in txtEmail textbox
                if (txtEmail.Text != null && rc.IsEmailValid(txtEmail.Text) == true)
                {
                    email = txtEmail.Text;
                }
                //If invalid, display error & return
                else
                {
                    MessageBox.Show("Please enter a valid email address");
                    return;
                }

                //Ensure password exists
                if (pwdEmail.Password.Count() > 0)
                {
                    ePass = pwdEmail.Password;
                }
                //If null or empty, display error & return
                else
                {
                    MessageBox.Show("Please input your email password.");
                    return;
                }
                #endregion

                //Tests email credentials & writes them to JSON object if valid.
                if (email != null && ePass != null)
                {
                    bool eLog = rc.NewEmail(email, ePass);
                    if (eLog == false)
                    {
                        MessageBox.Show("Your email address or password was incorrect.");
                        return;
                    }
                    MessageBox.Show("Email credentials accepted & saved");
                    if (rc.ApplicationReady() == true)
                    {
                        MessageBox.Show("You may now run RedditCrawler!");
                    }
                }
            }
            //Generic exception handling
            catch (Exception ex)
            {
                rc.DebugLog(ex);
            }
        }
コード例 #2
0
        //Region containing all button events
        #region buttonClicks

        /// <summary>
        /// Confirms contents of subreddit textbox and writes contents to JSON object using <see cref="NewSub(string)"/> if valid.
        /// </summary>
        private void btnSubmitSub_click(object sender, RoutedEventArgs e)
        {
            rcHelper rc = new rcHelper();

            try
            {
                //Initialize all variables from subreddit field
                #region variable_Initialization
                //Initialize subreddit variable
                string sub = null;

                //Check for valid input in txtSubreddit textbox
                if (txtSubreddit.Text != null && txtSubreddit.Text.Count() > 3 && txtSubreddit.Text.StartsWith("/r/"))
                {
                    sub = txtSubreddit.Text;
                }
                //Display error message if subreddit textbox is empty or contains improperly formatted text.
                else
                {
                    MessageBox.Show("Please input the subreddit you'd like to monitor. \nMake sure it begins with \"/r/\"");
                    return;
                }
                #endregion

                //Write details of text boxes to JSON object, displaying message if it was accepted.
                if (sub != null)
                {
                    rc.NewSub(sub);
                    MessageBox.Show("Subreddit accepted");
                    if (rc.ApplicationReady() == true)
                    {
                        MessageBox.Show("You may now run RedditCrawler!");
                    }
                }
            }
            //Generic exception handling.
            catch (Exception ex)
            {
                rc.DebugLog(ex);
            }
        }
コード例 #3
0
        /// <summary>
        /// Confirms contents of search criteria box and writes contents
        /// to JSON object after conversion to a list
        /// </summary>
        private void btnSubmitSearch_Click(object sender, RoutedEventArgs e)
        {
            //Initialize helper class
            rcHelper rc = new rcHelper();

            try
            {
                //Initialize all search-based variables.
                #region variable_Initialization
                //Initialize TextRange
                TextRange searchCriteria = null;

                //analyzes entries in search terms rich textbox, confirms there is input present.
                var start      = rtfSearchTerms.Document.ContentStart;
                var end        = rtfSearchTerms.Document.ContentEnd;
                int difference = start.GetOffsetToPosition(end);
                if (difference > 1)
                {
                    searchCriteria = new TextRange(start, end);
                }
                //If input is not present or is too small, user is directed to input terms in the RTF box
                else
                {
                    MessageBox.Show("Please input the terms you'd like to listen for. \nBe sure to put each term on a new line");
                    return;
                }

                #endregion

                //Only continues if searchCriteria is not null
                if (searchCriteria != null)
                {
                    try
                    {
                        //Retrieves text from searchCriteria TextRange as a string
                        string sl = searchCriteria.Text.ToString();

                        //Separates searchCriteria string sl into a list of strings separated by line breaks.
                        List <string> scList = sl.Split(new[] { Environment.NewLine }, StringSplitOptions.None).ToList();

                        //Removes empty and NewLine entries from list
                        for (int i = 0; i < scList.Count; i++)
                        {
                            if (scList[i] == "" || scList[i] == null || scList[i] == Environment.NewLine)
                            {
                                scList.RemoveAt(i);
                            }
                        }

                        //Runs filtered list into NewSearchCriteria method.
                        rc.NewSearchCriteria(scList);
                    }
                    //Generic exception handling.
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                        rc.DebugLog(ex);
                        Environment.Exit(1);
                    }
                    MessageBox.Show("Criteria successfully updated.");
                    if (rc.ApplicationReady() == true)
                    {
                        MessageBox.Show("You may now run RedditCrawler!");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                rc.DebugLog(ex);
                Environment.Exit(1);
            }
        }