// This method splits up the information held in the bodt textbox depending on wether it
        // is a URL or not. If it finds a URL, it removes the URL and replaces it with a quarantined message
        #region Quarantine Method
        private string QuarantineURL()
        {
            string swap = "";

            var links = BodyTextBox.Split("\t\n ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Where(s => s.StartsWith("http://") || s.StartsWith("www.") || s.StartsWith("https://") ||
                                                                                                              s.StartsWith("HTTP://") || s.StartsWith("WWW.") || s.StartsWith("HTTPS://"));

            foreach (string s in links)
            {
                if (BodyTextBox.Contains(s))
                {
                    swap = BodyTextBox.Replace(s, "<URL Quarantined>");

                    saveRegular = true;
                }
            }
            //MessageBox.Show(swap);
            return(swap);
        }
Пример #2
0
        // This method contains the functionality to be executed when button is pressed.
        // It ensures all fileds are filled before sending, creates and saves an tweet object,
        // and provides expanded form of any abbreviations. It also takes mentions and hashtags
        // from body and saves them to trends file
        private void SendButtonClick()
        {
            List <string> CsvLines = new List <String>(); // list to hold information to be sent to trends file

            Textspeak();                                  // Call Textspeak method

            // If statement prompts user to fill in all fields before message can be sent, by checking if the
            // component is empty
            if (string.IsNullOrWhiteSpace(HeaderTextBox) || string.IsNullOrWhiteSpace(SenderTextBox) || string.IsNullOrWhiteSpace(BodyTextBox))
            {
                MessageBox.Show("Please Enter All Values");
                return;
            }

            // Split body text and save strings that begin with an '@' or '#' to trnds file
            var links = BodyTextBox.Split("\t\n ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Where(s => s.StartsWith("@") || s.StartsWith("#"));

            foreach (string s in links)
            {
                CsvLines.Add(s);
                File.AppendAllLines("Data/trends.csv", CsvLines);
            }

            // If statement checks if body contains textspeak abbreviation, if true creates new object and adds
            // textspeak, then saves to json file
            if (saveRegular == true)
            {
                Tweet tweetMessage = new Tweet()
                {
                    Header = HeaderTextBox,
                    Sender = SenderTextBox,
                    Body   = newMessage
                };

                SaveToFile save = new SaveToFile();

                // If cannot be saved display error message, otherwise save file
                if (!save.ToJsonTweet(tweetMessage))
                {
                    MessageBox.Show("Error While Saving\n" + save.ErrorCode);
                }
                else
                {
                    MessageBox.Show("Order Saved");
                    save = null;
                }
            }

            // If statement checks if body contains textspeak abbreviation, if false creates new object and saves standard body,
            // then saves to json file
            if (saveRegular == false)
            {
                Tweet tweetMessage = new Tweet()
                {
                    Header = HeaderTextBox,
                    Sender = SenderTextBox,
                    Body   = BodyTextBox
                };

                SaveToFile save = new SaveToFile();

                // If cannot be saved display error message, otherwise save file
                if (!save.ToJsonTweet(tweetMessage))
                {
                    MessageBox.Show("Error While Saving\n" + save.ErrorCode);
                }
                else
                {
                    MessageBox.Show("Order Saved");
                    save = null;
                }
            }
        }