Exemple #1
0
        public void addTest()
        {
            sirList list            = new sirList();
            string  testVar         = "Test string";
            string  mixedStringTest = "123456ABCDEF_%^";

            list.add(mixedStringTest);
            list.add(testVar);
            Assert.AreEqual(sirList.SIRlist.ElementAt(0), mixedStringTest);
            Assert.AreEqual(sirList.SIRlist.ElementAt(1), testVar);
        }
Exemple #2
0
        public void countTest()
        {
            sirList list = new sirList();

            sirList.SIRlist.Clear();
            string testVar         = "Test string";
            string mixedStringTest = "123456ABCDEF_%^";

            list.add(mixedStringTest);
            list.add(testVar);
            Assert.AreEqual(list.count(), 2);
        }
Exemple #3
0
        public void returnValueTest()
        {
            sirList list = new sirList();

            sirList.SIRlist.Clear();
            string testVar         = "Test string with many characters in it";
            string mixedStringTest = "123456ABCDEF_%^";

            list.add(mixedStringTest);
            list.add(testVar);
            Assert.AreEqual(list.returnValue(0), mixedStringTest);
            Assert.AreEqual(list.returnValue(1), testVar);
        }
Exemple #4
0
        public void emailDisplay(sirList sir, urlQuarantinedList urlList)
        {
            //if listbox needs refreshing, do so
            if (lstSIR.HasItems)
            {
                lstSIR.Items.Clear();
            }
            //then add new list to it
            for (int i = 0; i < sir.count(); i++)
            {
                lstSIR.Items.Add(sir.returnValue(i));
            }

            if (lstURLs.HasItems)
            {
                lstURLs.Items.Clear();
            }
            for (int i = 0; i < urlList.count(); i++)
            {
                lstURLs.Items.Add(urlList.returnValue(i));
            }
        }
Exemple #5
0
        public void EmailSIR()
        {
            MainWindow mainWindow = new MainWindow();
            string     testHeader = "E123456789";
            string     testBody   = "[email protected] SIR 04/05/18 Sort Code: 99-99-99 Nature of Incident: Staff Attack My body message is http:\\example.com URL example";

            mainWindow.sortMessageType(testHeader, testBody);
            email emailAsset = new email();

            mainWindow.assignAttributes(emailAsset, testBody);
            List <string> incidents = new List <string>();
            sirList       SIRList   = new sirList();

            incidents = mainWindow.createIncidentList(incidents);
            mainWindow.assignEmailSubject(emailAsset, incidents, SIRList);
            urlQuarantinedList quarantinedList = new urlQuarantinedList();

            mainWindow.removeUrls(emailAsset, quarantinedList);

            Assert.AreEqual(emailAsset.Sender, "*****@*****.**");
            Assert.AreEqual(emailAsset.IsSIR, true);
            Assert.AreEqual(emailAsset.Subject, "SIR 04/05/18");
            Assert.AreEqual(emailAsset.Body, "Sort Code: 99-99-99 Nature of Incident: Staff Attack My body message is <URL Quarantined> URL example");
        }
Exemple #6
0
        public void Email()
        {
            MainWindow mainWindow = new MainWindow();
            string     testHeader = "E123456789";
            string     testBody   = "[email protected] this is my subject!! This is my test body with a http:\\example.com URL example";

            mainWindow.sortMessageType(testHeader, testBody);
            email emailAsset = new email();

            mainWindow.assignAttributes(emailAsset, testBody);
            List <string> incidents = new List <string>();
            sirList       SIRList   = new sirList();

            incidents = mainWindow.createIncidentList(incidents);
            mainWindow.assignEmailSubject(emailAsset, incidents, SIRList);
            urlQuarantinedList quarantinedList = new urlQuarantinedList();

            mainWindow.removeUrls(emailAsset, quarantinedList);

            Assert.AreEqual(emailAsset.Sender, "*****@*****.**");
            Assert.AreEqual(emailAsset.IsSIR, false);
            Assert.AreEqual(emailAsset.Subject, "this is my subject!!");
            Assert.AreEqual(emailAsset.Body, "This is my test body with a <URL Quarantined> URL example");
        }
Exemple #7
0
        private void btnSend_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                //read in message from input
                string header = txtHeader.Text;
                string body   = txtBody.Text;

                if (txtHeader.Text != "" || txtBody.Text != "")
                {
                    if (!txtBody.Text.Contains(" "))
                    {
                        throw new Exception("Please ensure there is a space between the sender and the main body text.");
                    }


                    //determine message type
                    string type = sortMessageType(header, body);

                    if (type == null)
                    {
                        MessageBox.Show("Message type could not be determined. Check header.");
                    }



                    List <message> msgList = new List <message>();


                    switch (type)
                    {
                    case "E":
                        email emailAsset = new email();
                        //assign sender and body text to message
                        assignAttributes(emailAsset, body);
                        assignId(emailAsset);

                        List <string> incidents = new List <string>();
                        sirList       SIRList   = new sirList();

                        //fill list of registered incidents
                        incidents = createIncidentList(incidents);
                        assignEmailSubject(emailAsset, incidents, SIRList);
                        urlQuarantinedList quarantinedList = new urlQuarantinedList();
                        removeUrls(emailAsset, quarantinedList);
                        //display details on UI
                        emailDisplay(SIRList, quarantinedList);
                        serialiser(emailAsset, msgList);
                        break;

                    case "T":
                        tweet tweetAsset = new tweet();
                        //assign sender and body text to message
                        assignAttributes(tweetAsset, body);
                        assignId(tweetAsset);
                        removeTextspeak(tweetAsset);
                        trendingList trending = new trendingList();
                        detectHashtags(tweetAsset, trending);
                        mentionsList mentions = new mentionsList();
                        detectMentions(tweetAsset, mentions);
                        tweetDisplay(tweetAsset, trending, mentions);
                        serialiser(tweetAsset, msgList);
                        break;

                    case "S":
                        sms smsAsset = new sms();
                        //assign sender and body text to message
                        assignAttributes(smsAsset, body);
                        assignId(smsAsset);
                        //identify textspeak and add extension of it
                        removeTextspeak(smsAsset);
                        serialiser(smsAsset, msgList);
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemple #8
0
        public void assignEmailSubject(email asset, List <string> incidents, sirList SIRList)
        {
            if (asset.Body.Length >= 40)
            {
                string SIRstring = asset.Body.Substring(0, 12);
                if (Regex.IsMatch(SIRstring, "SIR [0-9][0-9]/[0-9][0-9]/[0-9][0-9]"))
                {
                    string   sortCode;
                    string[] splitString = asset.Body.Split(null);
                    if (splitString[2] == "Sort" && splitString[3] == "Code:" && splitString[5] == "Nature" && splitString[6] == "of" && splitString[7] == "Incident:")
                    {
                        asset.IsSIR = true;

                        if (Regex.IsMatch(splitString[4], "[0-9][0-9]-[0-9][0-9]-[0-9][0-9]"))
                        {
                            sortCode = splitString[4];
                        }
                        else
                        {
                            throw new Exception("Sort code invalid");
                        }

                        asset.Subject = SIRstring.Substring(0, 12);
                        string[] sirInfo = new string[2];
                        sirInfo[0] = sortCode;

                        string sirIncident = splitString[8];

                        bool found = false;
                        //check if incident given is a recognised incident in the list
                        for (int i = 0; i < incidents.Count(); i++)
                        {
                            if (incidents[i].Equals(sirIncident))
                            {
                                found      = true;
                                sirInfo[1] = sirIncident;
                                break;
                            }
                        }

                        /*if the incident is not found yet the message has been identified as an SIR
                         * then check if the incident consists of two words, such as "ATM Theft"
                         */
                        if (!found)
                        {
                            sirIncident = splitString[8] + " " + splitString[9];
                            for (int i = 0; i < incidents.Count(); i++)
                            {
                                if (incidents[i].Equals(sirIncident))
                                {
                                    found      = true;
                                    sirInfo[1] = sirIncident;
                                    break;
                                }
                            }
                        }
                        if (!found)
                        {
                            throw new Exception("The incident listed is not a registered incident");
                        }
                        string sirInfoJoined = string.Join(" ", sirInfo[0], sirInfo[1]);
                        SIRList.add(sirInfoJoined);
                        asset.Body = asset.Body.Substring(12);
                        return;
                    }
                }

                else if (SIRstring.Contains("SIR"))
                {
                    throw new Exception("This message has been detected as a Significant Incident Report, however the format of the of the subject is incorrect.");
                }
            }
            //if message is standard email
            if (!asset.IsSIR && asset.Body.Length >= 20)
            {
                asset.Subject = asset.Body.Substring(0, 20);
                string newBodyText = asset.Body.Remove(0, 20);
                asset.Body = newBodyText;
            }
            else
            {
                throw new Exception("The subject of the message is less than 20 characters");
            }
        }