コード例 #1
0
        //Processes Emails
        private void ProcessStandardEmail()
        {
            //Validates URL's and replaces them with <URL Quarantined> and saves to Quarantine.csv
            var MessageHeaderText = MessageHeaderTextBox.ToString();
            var MessageBodyText   = MessageBodyTextBox.ToString();

            string[] splitMessageBodyText = MessageBodyTextBox.ToString().Split(' ');

            for (int i = 4; i < splitMessageBodyText.Length; i++)
            {
                Uri result;

                bool isUri = Uri.TryCreate(splitMessageBodyText[i], UriKind.Absolute, out result) &&
                             (result.Scheme == Uri.UriSchemeHttp || result.Scheme == Uri.UriSchemeHttps);

                if (isUri == true)
                {
                    Quarantine quarantine = new Quarantine()
                    {
                        link = splitMessageBodyText[i]
                    };

                    Database.Quarantine_Database.SaveToQuarantine save1 = new Database.Quarantine_Database.SaveToQuarantine();

                    if (!save1.ToCsv(quarantine))
                    {
                        MessageBox.Show("Error while saving\n" + save1.ErrorCode);
                    }
                    else
                    {
                        save1 = null;
                    }

                    MessageBodyText = MessageBodyText.Replace(splitMessageBodyText[i], "<URL Quarantined>");
                }
            }
            MessagesProcessor msgProcessor = new MessagesProcessor()
            {
                msgType = MessageHeaderText,
                msgBody = MessageBodyText
            };

            File.AppendAllText("C:/VS Database/ProcessedMessages.json", JsonConvert.SerializeObject(msgProcessor));
            MessageBox.Show("Message Processed Successfully:" + Environment.NewLine + "Message Type - " + MessageHeaderText + Environment.NewLine + "Message Body - " + MessageBodyText);
        }
コード例 #2
0
        private void ProcessSIREmail()
        {
            //Validates URL's and replaces them with <URL Quarantined> and saves to Quarantine.csv
            var MessageHeaderText = MessageHeaderTextBox.ToString();
            var MessageBodyText   = MessageBodyTextBox.ToString();

            string[] splitMessageBodyText = MessageBodyTextBox.ToString().Split(' ');

            for (int i = 4; i < splitMessageBodyText.Length; i++)
            {
                Uri result;

                bool isUri = Uri.TryCreate(splitMessageBodyText[i], UriKind.Absolute, out result) &&
                             (result.Scheme == Uri.UriSchemeHttp || result.Scheme == Uri.UriSchemeHttps);

                if (isUri == true)
                {
                    Quarantine quarantine = new Quarantine()
                    {
                        link = splitMessageBodyText[i]
                    };

                    Database.Quarantine_Database.SaveToQuarantine save1 = new Database.Quarantine_Database.SaveToQuarantine();

                    if (!save1.ToCsv(quarantine))
                    {
                        MessageBox.Show("Error while saving\n" + save1.ErrorCode);
                    }
                    else
                    {
                        save1 = null;
                    }

                    MessageBodyText = MessageBodyText.Replace(splitMessageBodyText[i], "<URL Quarantined>");
                }
            }
            MessagesProcessor msgProcessor = new MessagesProcessor()
            {
                msgType = MessageHeaderText,
                msgBody = MessageBodyText
            };

            File.AppendAllText("C:/VS Database/ProcessedMessages.json", JsonConvert.SerializeObject(msgProcessor));
            MessageBox.Show("Message Processed Successfully:" + Environment.NewLine + "Message Type - " + MessageHeaderText + Environment.NewLine + "Message Body - " + MessageBodyText);

            //Saves SI to SIReportsDB.csv
            Database.SIReports_Database.SaveSIReportsToFile save4 = new Database.SIReports_Database.SaveSIReportsToFile();

            string[] NOIArray1w =
            { "Raid",
              "Terrorism" };

            var noi1w      = splitMessageBodyText[12];
            var noifound1w = Array.Exists(NOIArray1w, s => s.Equals(noi1w));

            string[] NOIArray2w =
            { "Staff Attack",
              "Device Damage",
              "Customer Attack",
              "Staff Abuse",
              "Bomb Threat",
              "Suspicious Incident",
              "Sport Injury" };

            var noi2w      = splitMessageBodyText[12] + " " + splitMessageBodyText[13];
            var noifound2w = Array.Exists(NOIArray2w, s => s.Equals(noi2w));

            string[] NOIArray3w =
            { "Theft of Properties",
              "Personal Info Leak" };

            var noi3w      = splitMessageBodyText[12] + " " + splitMessageBodyText[13] + " " + splitMessageBodyText[14];
            var noifound3w = Array.Exists(NOIArray3w, s => s.Equals(noi3w));

            if (noifound1w == true)
            {
                SIReports siReports = new SIReports()
                {
                    SportCentreCode  = splitMessageBodyText[8],
                    NatureOfIncident = splitMessageBodyText[12]
                };

                if (!save4.ToCsv(siReports))
                {
                    MessageBox.Show("Error while saving\n" + save4.ErrorCode);
                }
                else
                {
                    save4 = null;
                }
            }

            if (noifound2w == true)
            {
                SIReports siReports = new SIReports()
                {
                    SportCentreCode  = splitMessageBodyText[8],
                    NatureOfIncident = splitMessageBodyText[12] + " " + splitMessageBodyText[13]
                };

                if (!save4.ToCsv(siReports))
                {
                    MessageBox.Show("Error while saving\n" + save4.ErrorCode);
                }
                else
                {
                    save4 = null;
                }
            }

            if (noifound3w == true)
            {
                SIReports siReports = new SIReports()
                {
                    SportCentreCode  = splitMessageBodyText[8],
                    NatureOfIncident = splitMessageBodyText[12] + " " + splitMessageBodyText[13] + " " + splitMessageBodyText[14]
                };

                if (!save4.ToCsv(siReports))
                {
                    MessageBox.Show("Error while saving\n" + save4.ErrorCode);
                }
                else
                {
                    save4 = null;
                }
            }
        }