Exemple #1
0
        public static void composeEmail(SpreadsheetFile sf, string receiver)
        {
            sf.datalist = sf.assembleData(sf);
            string emailBody = "Thermometer Data:\n\n";

            foreach (Record row in sf.datalist)
            {
                emailBody += $"{row.dateAndTime}\t{row.serialNo}\t{row.reading}\t{row.units}\n";
            }
            //Assemble new message and client and execute delivery of message
            MailMessage mail   = new MailMessage("*****@*****.**", receiver, "Thermometer Data", emailBody);
            SmtpClient  client = new SmtpClient("smtp.sparkpostmail.com", 587);

            client.EnableSsl             = true;
            client.DeliveryMethod        = SmtpDeliveryMethod.Network;
            client.UseDefaultCredentials = false;
            client.Credentials           = new NetworkCredential("SMTP_Injection", "fae8840c80dd966210101be0dfdc9ea4e709014d");
            try
            {
                client.Send(mail);
                Console.WriteLine("Email Sent! Check your inbox!");
            }
            catch (Exception e)
            {
                Console.WriteLine($"Email failed to send due to this error: {e}");
            }
        }
Exemple #2
0
        static void Main(string[] args)
        {
            string location            = System.Reflection.Assembly.GetEntryAssembly().Location;
            string executableDirectory = System.IO.Path.GetDirectoryName(location);

            Console.WriteLine(location);
            Console.WriteLine(executableDirectory);

            SpreadsheetFile sf = new SpreadsheetFile();

            sf.pathname = sf.checkFile("Please enter the filepath of the data: ");
            sf.datalist = sf.assembleData(sf);
            WarningFile wf = new WarningFile();

            wf.pathname = wf.checkFile("Please enter the file containing the warning temperature: ");
            wf.readWarnings(sf, wf);
            ConsoleWindow.consoleRequest(sf, wf.pathname);
        }
Exemple #3
0
        public static void consoleRequest(SpreadsheetFile sf, string pathname)
        {
            bool   finished = false;
            string prompt   = "";

            while (!finished)
            {
                Console.WriteLine("What would you like to do? Type 'help' for more information");
                string userResponse = Console.ReadLine();
                switch (userResponse)
                {
                case "help":
                {
                    Console.Write(@"Commands you can use: 
                            changetemp : Allows you to input a new temperature at which a warning will be produced.
                            read: display the data stored in the spreadsheet.
                            runtimer : Set up a timer for scheduling emails about the status of the thermometer.
                            display: Displays data collected so far.
                            email: recieve the data as an email.
                            reload: Reload data stored in the spreadsheet.
                            quit: Exit the program.");
                    break;
                }

                case "changetemp":
                {
                    prompt = "Please enter the warning temperature you would like to set: ";
                    bool satisfied = false;
                    while (!satisfied)
                    {
                        bool   floatEntered = false;
                        string temp         = "";
                        //ensure value entered is a float
                        while (!floatEntered)
                        {
                            Console.Write(prompt);
                            temp = Console.ReadLine();
                            double result;
                            floatEntered = Double.TryParse(temp, out result);
                            prompt       = "The value for a temperature must be a decimal number, please try again: ";
                        }

                        StreamWriter file = new StreamWriter(pathname);
                        file.WriteLine(temp);
                        Console.WriteLine(temp);
                        file.Close();
                        satisfied = true;
                        Console.WriteLine($"Teperature has been set to: {temp}°C");
                    }
                    break;
                }

                case "read":
                {
                    SpreadsheetFile.displayData(sf);
                    break;
                }

                case "runtimer":
                {
                    TimerCheck.RunTimer(sf);
                    break;
                }

                case "email":
                {
                    Console.Write("Please enter the email address you'd like the data to be sent to: ");

                    bool validated = false;
                    //check if email address given is valid
                    while (!validated)
                    {
                        string receiver = Console.ReadLine();
                        if (InputValidation.IsValidEmailAddress(receiver))
                        {
                            email.composeEmail(sf, receiver);
                            validated = true;
                        }
                        else
                        {
                            Console.WriteLine("Sorry, this email address is invalid, please try again: ");
                        }
                    }
                    break;
                }

                case "reload":
                {
                    sf.datalist = sf.assembleData(sf);
                    break;
                }

                case "updatedatabase":
                {
                    WriteToDatabase.writeData(sf);
                    break;
                }

                case "quit": {
                    Environment.Exit(0);
                    break;
                }

                default:
                {
                    Console.WriteLine("Sorry, that command is invalid. Please try again. Note: Type 'help' for more information.");
                    break;
                }
                }
            }
        }