public void mailPassword() { try { MailMessage mail = new MailMessage(); SmtpClient smtp = new SmtpClient("smtp.gmail.com"); mail.From = new MailAddress("*****@*****.**"); mail.To.Add(this.Email); mail.Subject = "Password Recovery"; mail.Body = string.Format( @"Dear {0}, Your Password for the La Pieus Aqua Aquaponics Monitoring application is: {1}", this.Username, this.Password); smtp.Port = 587; smtp.Credentials = new System.Net.NetworkCredential("additionaladdress.tanya", "LaPieusAqua"); smtp.EnableSsl = true; smtp.Send(mail); } catch (Exception) { DataAccessLayer.FileHandler file = new DataAccessLayer.FileHandler("emailErrors.csv"); List <string> error = new List <string> { "The password email could not be sent to user: " + this.Username }; file.WriteToTxt(error); } }
public List <NotificationHandler> getNotifications() { int y = 0, m = 0, d = 0, hour = 0, min = 0, sec = 0; List <NotificationHandler> notifications = new List <NotificationHandler>(); DataAccessLayer.FileHandler fh = new DataAccessLayer.FileHandler("notifications.txt"); List <string> notificationsFromTxt = fh.ReadFromTxt(); foreach (string item in notificationsFromTxt) { string[] line = item.Split('#'); string[] dateSections = line[0].ToString().Split('-'); y = Convert.ToInt32(dateSections[0]); m = Convert.ToInt32(dateSections[1]); d = Convert.ToInt32(dateSections[2]); DateTime date = new DateTime(y, m, d); char[] delimiters = new char[] { ':', '.' }; string[] timeSections = line[1].ToString().Split(delimiters, StringSplitOptions.None); hour = Convert.ToInt32(timeSections[0]); min = Convert.ToInt32(timeSections[1]); sec = Convert.ToInt32(timeSections[2]); DateTime time = new DateTime(y, m, d, hour, min, sec); NotificationHandler nh = new NotificationHandler(date, time, line[2].ToString(), line[3].ToString()); } return(notifications); }
public List <string> getSecurityQuestions() { List <string> securityQuestions = new List <string>(); DataAccessLayer.FileHandler filehandler = new DataAccessLayer.FileHandler("SecurityQuestions.txt"); securityQuestions = filehandler.ReadFromTxt(); return(securityQuestions); }
public void saveNotification() { DataAccessLayer.FileHandler fh = new DataAccessLayer.FileHandler("notifications.txt"); List <string> notifications = new List <string>(); notifications.Add(this.saveString()); fh.WriteToTxt(notifications); }
public void saveLoggedUser() { string loggedUserDetails = this.Username + ";" + this.Password; List <string> activeUser = new List <string>(); activeUser.Add(loggedUserDetails); DataAccessLayer.FileHandler fileHandler = new DataAccessLayer.FileHandler("CurrentLoggedUser.csv"); fileHandler.WriteUserAccess(activeUser); }
// In order to keep track of a user that is currently logged into the system, we make use // of a text file to store the details of the currently logged in user. public string getCurrentLoggedUser() { string user = ""; DataAccessLayer.FileHandler fileHandler = new DataAccessLayer.FileHandler("CurrentLoggedUser.csv"); List <string> currentLoggedUser = fileHandler.ReadFromTxt(); user = currentLoggedUser[0]; return(user); }
public void mailNotifcation(string email, string tankName, string sensorName, string boundStatus, decimal outOfBoundValue) { try { MailMessage mail = new MailMessage(); SmtpClient smtp = new SmtpClient("smtp.gmail.com"); mail.From = new MailAddress("*****@*****.**"); mail.To.Add(email); mail.Subject = "Sensor reading out of bounds"; if (boundStatus == "Bottom") { mail.Body = string.Format( @"IMPORTANT NOTIFICATION!, The {0} sensor found in {1} is currently {2} lower than the critical range", sensorName, tankName, outOfBoundValue); } if (boundStatus == "Top") { mail.Body = string.Format( @"IMPORTANT NOTIFICATION!, The {0} sensor found in {1} is currently {2} higher than the critical range", sensorName, tankName, outOfBoundValue); } smtp.Port = 587; smtp.Credentials = new System.Net.NetworkCredential("additionaladdress.tanya", "LaPieusAqua"); smtp.EnableSsl = true; smtp.Send(mail); } catch (Exception) { DataAccessLayer.FileHandler file = new DataAccessLayer.FileHandler("emailErrors.csv"); List <string> error = new List <string> { "The notification email could not be sent to user: " + email }; file.WriteToTxt(error); } }
public void newSensorReading(Sensor sensor) { string filename = sensor.Location + "_" + sensor.SensorName + ".txt"; List <string> allSensorValues = new List <string>(); List <SensorReading> allSensorReadings = new List <SensorReading>(); List <string> allSavedDates = new List <string>(); DateTime dateOfReading = new DateTime(); decimal reading = 0; DataAccessLayer.FileHandler fh = new DataAccessLayer.FileHandler(filename); allSensorValues = fh.ReadFromTxt(); DataAccessLayer.DataHandler dh = DataAccessLayer.DataHandler.getInstance(); allSensorReadings = dh.getSensorReadings(sensor); foreach (SensorReading item in allSensorReadings) { allSavedDates.Add(item.Date.ToString()); } foreach (string item in allSensorValues) { // Example of data format in the text file: // DateTime#SensorReading string[] fields = item.Split('#'); dateOfReading = Convert.ToDateTime(fields[0]); reading = Convert.ToDecimal(fields[1]); if (!allSavedDates.Contains(dateOfReading.ToString())) { this.Date = dateOfReading; this.ReadingVal = reading; this.SensorId = sensor.SensorID; addReading(); } } }