/// <summary> /// Inserts a user into the database to keep track of how many users RemindMe has (after version 2.6.02) /// </summary> /// <param name="uniqueString"></param> public static void InsertOrUpdateUser(string uniqueString) { try { new Thread(() => { //Don't do anything without internet if (!BLIO.HasInternetAccess()) { return; } if (!string.IsNullOrWhiteSpace(uniqueString)) { DLOnlineDatabase.InsertOrUpdateUser(uniqueString, IOVariables.RemindMeVersion); } else { BLIO.Log("Invalid uniqueString version string parameter in BLOnlineDatabase.InsertUser(). String: " + uniqueString); } }).Start(); } catch (Exception exc) { BLIO.Log("BLOnlineDatabase.InsertUser() failed: exception occured: " + exc.ToString()); BLIO.WriteError(exc, "BLOnlineDatabase.InsertUser() failed: exception occured: " + exc.ToString(), false); } }
/// <summary> /// Logs an exception to the online database /// </summary> /// <param name="ex">The exception that is going to be logged</param> /// <param name="exceptionDate">The date the exception is logged at</param> public static void AddException(Exception ex, DateTime exceptionDate, string pathToSystemLog) { try { new Thread(() => { //Don't do anything without internet if (!BLIO.HasInternetAccess()) { return; } if (ex != null && ex.Message != null && ex.StackTrace != null && exceptionDate != null) { DLOnlineDatabase.AddException(ex, exceptionDate, pathToSystemLog); } else { BLIO.Log("BLOnlineDatabase.AddException() failed: parameter(s) null"); } }).Start(); } catch (Exception exc) { BLIO.Log("BLOnlineDatabase.AddException() failed: exception occured: " + exc.ToString()); BLIO.WriteError(exc, "BLOnlineDatabase.AddException() failed: exception occured: " + exc.ToString(), false); } }
/// <summary> /// Adds a new entry to the database where a user updates their RemindMe version /// </summary> /// <param name="updateDate">Date of update</param> /// <param name="previousVersion">The previously installed RemindMe version on his/her machine</param> /// <param name="updateVersion">The version the user updated to</param> public static void AddNewUpgrade(DateTime updateDate, string previousVersion, string updateVersion) { try { new Thread(() => { //Don't do anything without internet if (!BLIO.HasInternetAccess()) { return; } if (!string.IsNullOrWhiteSpace(previousVersion) && !string.IsNullOrWhiteSpace(updateVersion)) { DLOnlineDatabase.AddNewUpgrade(updateDate, previousVersion, updateVersion); } else { BLIO.Log("Invalid previous/update version string parameter in BLOnlineDatabase.AddNewUpdate()"); } }).Start(); } catch (Exception exc) { BLIO.Log("BLOnlineDatabase.AddNewUpdate() failed: exception occured: " + exc.ToString()); BLIO.WriteError(exc, "BLOnlineDatabase.AddNewUpdate() failed: exception occured: " + exc.ToString(), false); } }
/// <summary> /// Inserts an e-mail into the database. In case sending the e-mail didn't work, it is still registered in the db /// </summary> /// <param name="uniqueString">The user's unique string</param> /// <param name="emailMessage">The e-mail message</param> /// <param name="emailSubject">The e-mail subject</param> /// <param name="eMailAddress">The users e-mail address. This is optional</param> public static void InsertEmailAttempt(string uniqueString, string emailMessage, string emailSubject, string eMailAddress = "") { try { new Thread(() => { //Don't do anything without internet if (!BLIO.HasInternetAccess()) { return; } if (!string.IsNullOrWhiteSpace(uniqueString)) { DLOnlineDatabase.InsertEmailAttempt(uniqueString, emailMessage, emailSubject, eMailAddress); } else { BLIO.Log("Invalid uniqueString version string parameter in BLOnlineDatabase.InsertEmailAttempt(). String: " + uniqueString); } MessageCount++; }).Start(); } catch (Exception exc) { BLIO.Log("BLOnlineDatabase.InsertEmailAttempt() failed: exception occured: " + exc.ToString()); BLIO.WriteError(exc, "BLOnlineDatabase.InsertEmailAttempt() failed: exception occured: " + exc.ToString(), false); } }
/// <summary> /// Inserts the contents of the local errorlog.txt into the database /// </summary> /// <param name="uniqueString">The unique user identifier</param> /// <param name="logContents">The contents of errorlog.txt</param> /// <param name="lineCount">The amount of lines in errorlog.txt</param> public static void InsertLocalErrorLog(string uniqueString, string logContents, int lineCount) { try { new Thread(() => { //Don't do anything without internet if (!BLIO.HasInternetAccess()) { return; } if (!string.IsNullOrWhiteSpace(uniqueString)) { DLOnlineDatabase.InsertLocalErrorLog(uniqueString, logContents, lineCount); } else { BLIO.Log("Invalid uniqueString version string parameter in BLOnlineDatabase.InsertLocalErrorLog(). String: " + uniqueString); } }).Start(); } catch (Exception exc) { BLIO.Log("BLOnlineDatabase.InsertLocalErrorLog() failed: exception occured: " + exc.ToString()); BLIO.WriteError(exc, "BLOnlineDatabase.InsertLocalErrorLog() failed: exception occured: " + exc.ToString(), false); } }
/// <summary> /// Inserts a user into the database to keep track of how many users RemindMe has (after version 2.6.02) /// </summary> /// <param name="uniqueString"></param> public static void InsertOrUpdateUser(string uniqueString) { new Thread(() => { try { //Don't do anything without internet if (!BLIO.HasInternetAccess()) return; if (BLIO.LastLogMessage != null && !BLIO.LastLogMessage.Contains("Updating user")) BLIO.Log("Updating user"); if (!string.IsNullOrWhiteSpace(uniqueString)) DLOnlineDatabase.InsertOrUpdateUser(uniqueString, IOVariables.RemindMeVersion); else BLIO.Log("Invalid uniqueString version string parameter in BLOnlineDatabase.InsertUser(). String: " + uniqueString); } catch (Exception exc) { BLIO.Log("BLOnlineDatabase.InsertUser() failed: exception occured: " + exc.GetType().ToString()); BLIO.WriteError(exc, "BLOnlineDatabase.InsertUser() failed: exception occured: " + exc.ToString(), false); } }).Start(); }
/// <summary> /// Checks if all reminders are functioning and not causing problems /// </summary> /// <returns>A list of corrupt reminders. null if none are found</returns> public static List <Reminder> CheckForCorruptedReminders() { BLIO.Log("Checking for corrupted reminders..."); List <Reminder> corruptReminders = new List <Reminder>(); foreach (Reminder rem in GetReminders()) { Exception ex = IsValidReminder(rem); if (ex != null) { BLIO.Log("Reminder with ID " + rem.Id + " Caused an exception: " + ex.Message + ". \r\nMarking this reminder as corrupted."); rem.Corrupted = 1; BLIO.Log("Pushing corrupted reminder to the db."); EditReminder(rem); corruptReminders.Add(rem); } } BLIO.Log("Checking for corrupted reminders complete."); if (corruptReminders.Count > 0) { return(corruptReminders); } else { return(null); } }
/// <summary> /// Export a list of reminders to a .remindme file /// </summary> /// <param name="reminders"></param> /// <param name="path"></param> /// <returns></returns> public static Exception ExportReminders(List <Reminder> reminders, string path) { try { if (!string.IsNullOrEmpty(path)) { SerializeRemindersToFile(reminders, path + "\\Backup reminders " + DateTime.Now.Hour + "-" + DateTime.Now.Minute + "-" + DateTime.Now.Second + ".remindme"); } new Thread(() => { //Log an entry to the database, for data! try { BLOnlineDatabase.ExportCount++; } catch (ArgumentException ex) { BLIO.Log("Exception at BLOnlineDatabase.ExportCount++. -> " + ex.Message); BLIO.WriteError(ex, ex.Message, true); } }).Start(); return(null); } catch (UnauthorizedAccessException ex) { return(ex); } catch (Exception ex) { return(ex); } }
/// <summary> /// Logs an exception to the online database /// </summary> /// <param name="ex">The exception that is going to be logged</param> /// <param name="exceptionDate">The date the exception is logged at</param> public static void AddException(Exception ex, DateTime exceptionDate, string pathToSystemLog, string customMessage = null) { new Thread(() => { try { //Don't do anything without internet if (!BLIO.HasInternetAccess()) return; //Don't log these kind of exceptions if (ex is System.Data.Entity.Core.EntityException || ex is System.Data.Entity.Core.EntityCommandExecutionException || ex is System.Data.SqlClient.SqlException) { BLIO.Log("AddException() Skipped. Exception is " + ex.GetType().ToString()); return; } //Write the system log contents to the .txt file, so that the database record contains the latest system log info BLIO.DumpLogTxt(); if (ex != null && ex.Message != null && ex.StackTrace != null && exceptionDate != null) DLOnlineDatabase.AddException(ex, exceptionDate, pathToSystemLog, customMessage); else BLIO.Log("BLOnlineDatabase.AddException() failed: parameter(s) null"); } catch (Exception exc) { BLIO.Log("BLOnlineDatabase.AddException() failed: exception occured: " + exc.GetType().ToString()); BLIO.WriteError(exc, "BLOnlineDatabase.AddException() failed: exception occured: " + exc.ToString(), false); } }).Start(); }
/// <summary> /// Gets an reminder with the matching unique id. /// </summary> /// <param name="id">The unique id</param> /// <returns>Reminder that matches the given id. null if no reminder was found</returns> public static Reminder GetReminderById(long id) { BLIO.Log("BLReminder.GetReminderById(" + id + ")"); if (id != -1) { return(DLReminders.GetReminderById(id)); } else { return(null); } }
/// <summary> /// Gets an reminder with the matching unique id. /// </summary> /// <param name="id">The unique id</param> /// <returns>Reminder that matches the given id. null if no reminder was found</returns> public static Reminder GetReminderById(long id) { BLIO.Log("BLReminder.GetReminderById(" + id + ")"); if (id != -1) { Reminder reminder = DLReminders.GetReminderById(id); GC.Collect(); return(reminder); } else { return(null); } }
/// <summary> /// Serializes the provided list of reminder objects to a file located at the given path /// </summary> /// <param name="reminders">The list of reminders you want serialized</param> /// <param name="pathToRemindMeFile">The path to the file that will contain the serialized reminder objects</param> /// <returns>True if succesfull, false if not</returns> public static bool SerializeRemindersToFile(List <Reminder> reminders, string pathToRemindMeFile) { BLIO.Log("Beginning reminder serialization..."); // Create a hashtable of values that will eventually be serialized. Hashtable hashReminders = new Hashtable(); foreach (Reminder rem in reminders) { rem.Hide = 0; //Un-hide the reminder when putting it into a .remindme file hashReminders.Add(rem.Id, rem); } BLIO.Log(reminders.Count + " reminders hashed"); // To serialize the hashtable and its key/value pairs, // you must first open a stream for writing. // In this case, use a file stream. FileStream fs = new FileStream(pathToRemindMeFile, FileMode.Create); // Construct a BinaryFormatter and use it to serialize the data to the stream. BinaryFormatter formatter = new BinaryFormatter(); //Finally, add the language tag of the current machine running RemindMe to it hashReminders.Add("LANGUAGE_CODE", CultureInfo.CurrentCulture.IetfLanguageTag); try { BLIO.Log("Serializing reminders..."); formatter.Serialize(fs, hashReminders); BLIO.Log("Reminders succesfully serialized"); } catch (SerializationException) { BLIO.Log("Could not serialize reminder(s)"); return(false); } finally { fs.Close(); } //Force the list in DLReminders to sync again. In this method some reminders could have their Hide property set from 1 to 0. //Since the reference is passed, changing the reminder here will also change the reminder in the list of DLReminders, hence the change. NotifyChange(); return(true); }
/// <summary> /// Gets the amount of minutes from a bunifu textbox string. Includes formats like h, for example 1h30 returns 90 /// </summary> /// <param name="tb"></param> /// <returns></returns> public static int GetTextboxMinutes(Control tb) { try { int timerMinutes = 0; //Text without the 'm'. We know the number after 'h' is in minutes, no need to keep it in the string string tbText = tb.Text.ToLower().Replace("m", ""); if (tbText.Contains('h')) { BLIO.Log("Reminder popup contains 'h'. Checking what's before it"); //Get the tbPrompt number of the 'h' in the text int index = tbText.IndexOf('h'); //Now get all the text before it(should be a numer) and multiply by 60 because the user input hours BLIO.Log("Parsing hours...."); timerMinutes += Convert.ToInt32(tbText.Substring(0, index)) * 60; //Now get the number after the 'h' , which should be minutes, and add it to timerMinutes //But, first check if there is actually something after the 'h' if (tbText.Length > index + 1)//+1 because .Length starts from 1, index starts from 0 { BLIO.Log("Parsing minutes...."); timerMinutes += Convert.ToInt32(tbText.Substring(index + 1, tbText.Length - (index + 1))); } } else { timerMinutes = Convert.ToInt32(tbText); } return(timerMinutes); } catch { return(-1); } }
public static Exception SendEmail(string subject, string message, bool includeLog = true) { BLIO.Log("Entered SendEmail()"); MailMessage mes = new MailMessage("RemindMeUser_" + Environment.UserName + "@gmail.com", "*****@*****.**", subject, ("RemindMe Version " + IOVariables.RemindMeVersion + "\r\n" + message)); BLIO.Log("New MailMessage object created"); // Create the file attachment for this e-mail message. if (includeLog) { BLIO.Log("Include log = true. Creating attachment...."); string path = BLIO.GetLogTxtPath(); Attachment data = new Attachment(path, MediaTypeNames.Application.Octet); // Add time stamp information for the file. ContentDisposition disposition = data.ContentDisposition; disposition.CreationDate = System.IO.File.GetCreationTime(path); disposition.ModificationDate = System.IO.File.GetLastWriteTime(path); disposition.ReadDate = System.IO.File.GetLastAccessTime(path); // Add the file attachment to this e-mail message. mes.Attachments.Add(data); BLIO.Log("Attachment created and added to the MailMessage"); } Exception returnException = null; BLIO.Log("Getting domain names/servers...."); string domainName = GetDomainName(mes.To[0].Address); IPAddress[] servers = GetMailExchangeServer(domainName); if (servers == null) { return(new NullReferenceException()); } int count = 0; foreach (IPAddress server in servers) { try { count++; BLIO.Log(count + ": attempting to create SmtpClient...."); SmtpClient client = new SmtpClient(server.ToString(), SmtpPort); BLIO.Log(count + ": SmtpClient created. Attempting to send the E-mail...."); client.Send(mes); BLIO.Log(count + ": Success! E-mail sent."); return(null); } catch (Exception ex) { BLIO.Log(count + ": Could not send the e-mail :( an exception happened..... Exception type: " + ex.GetType().ToString() + "\r\n Message: \r\n" + ex.Message); returnException = ex; continue; } } return(returnException); }
/// <summary> /// Gives a new value to a reminder based on it's repeating type, and inserts it into the database /// </summary> /// <param name="rem"></param> public static void UpdateReminder(Reminder rem) { if (rem != null) { BLIO.Log("Updating reminder with id " + rem.Id); //Enable the reminder again rem.Enabled = 1; if (rem.RepeatType == ReminderRepeatType.WORKDAYS.ToString()) //Add days to the reminder so that the next date will be a new workday { rem.Date = BLDateTime.GetNextReminderWorkDay(rem, true).ToString(); } if (rem.RepeatType == ReminderRepeatType.DAILY.ToString()) //Add a day to the reminder { UpdateReminderDateDaily(rem, true); } if (rem.RepeatType == ReminderRepeatType.MONTHLY.ToString()) { if (rem.Date.Split(',').Length > 1) { List <DateTime> reminderDates = new List <DateTime>(); foreach (string date in rem.Date.Split(',')) //go through each date. with monthly reminders, it can have multiple dates, seperated by comma's { if (Convert.ToDateTime(date) < DateTime.Now) //get the next day of the monthly day of the date. example: 10-6-2017 -> 10-7-2017 BUT 31-1-2017 -> 31-3-2017, since february doesnt have 31 days { reminderDates.Add(Convert.ToDateTime(BLDateTime.GetDateForNextDayOfMonth(Convert.ToDateTime(date)).ToShortDateString() + " " + Convert.ToDateTime(date).ToShortTimeString())); } else { reminderDates.Add(Convert.ToDateTime(date)); //Date in the future? good! do nothing with it. } } //have to make sure the first date is in front. reminderDates.Sort(); //Now, we're going to put the (sorted) dates in a string string newDateString = ""; foreach (DateTime date in reminderDates) { if (rem.UpdateTime == 0) { newDateString += date.ToString() + ","; } else { newDateString += date.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + ","; } } rem.Date = newDateString.Remove(newDateString.Length - 1, 1); } else {//There's only one date in this string. if (rem.UpdateTime == 0) { rem.Date = BLDateTime.GetDateForNextDayOfMonth(Convert.ToDateTime(rem.Date)).ToShortDateString() + " " + Convert.ToDateTime(rem.Date).ToShortTimeString(); } else { rem.Date = BLDateTime.GetDateForNextDayOfMonth(Convert.ToDateTime(rem.Date)).ToShortDateString() + " " + DateTime.Now.ToShortTimeString(); } } } if (rem.RepeatType == ReminderRepeatType.MULTIPLE_DAYS.ToString()) { if (rem.UpdateTime == 0) { rem.Date = Convert.ToDateTime(BLDateTime.GetEarliestDateFromListOfStringDays(rem.RepeatDays)).ToShortDateString() + " " + Convert.ToDateTime(rem.Date).ToShortTimeString(); } else { rem.Date = Convert.ToDateTime(BLDateTime.GetEarliestDateFromListOfStringDays(rem.RepeatDays)).ToShortDateString() + " " + DateTime.Now.ToShortTimeString(); } } if (rem.EveryXCustom != null) { while (Convert.ToDateTime(rem.Date) < DateTime.Now) { //The user has a custom reminder, every x minutes,hours,days,weeks, or months switch (rem.RepeatType.ToLower()) { case "minutes": rem.Date = Convert.ToDateTime(rem.Date).AddMinutes((double)rem.EveryXCustom).ToString(); break; case "hours": rem.Date = Convert.ToDateTime(rem.Date).AddHours((double)rem.EveryXCustom).ToString(); break; case "days": rem.Date = Convert.ToDateTime(rem.Date).AddDays((double)rem.EveryXCustom).ToString(); if (rem.UpdateTime == 1) { rem.Date = Convert.ToDateTime(rem.Date).ToShortDateString() + " " + DateTime.Now.ToShortTimeString(); } break; case "weeks": rem.Date = Convert.ToDateTime(rem.Date).AddDays((double)rem.EveryXCustom * 7).ToString(); if (rem.UpdateTime == 1) { rem.Date = Convert.ToDateTime(rem.Date).ToShortDateString() + " " + DateTime.Now.ToShortTimeString(); } break; case "months": rem.Date = Convert.ToDateTime(rem.Date).AddMonths((int)rem.EveryXCustom).ToString(); if (rem.UpdateTime == 1) { rem.Date = Convert.ToDateTime(rem.Date).ToShortDateString() + " " + DateTime.Now.ToShortTimeString(); } break; } } } if (rem.RepeatType == ReminderRepeatType.NONE.ToString()) { if (rem.Date.Split(',').Length > 1) //multiple dates seperated by comma's { string newDateString = ""; //The new date1,date2,date3 string that we will assign to the reminder string[] dateArray = rem.Date.Split(','); dateArray = dateArray.Where(s => Convert.ToDateTime(s) > DateTime.Now).ToArray(); //remove all elements from the array that already happened if (dateArray.Length == 0) { DLReminders.ArchiveReminder(rem); return; } foreach (string date in dateArray) { newDateString += date + ","; } newDateString = newDateString.Remove(newDateString.Length - 1, 1); //remove the last ',' rem.Date = newDateString; } else//it had one date, and that date caused this popup. Let's delete the reminder. { DLReminders.ArchiveReminder(rem); return; } } //finally, Write the changes to the database DLReminders.EditReminder(rem); BLIO.Log("Reminder updated"); } else { throw new ArgumentNullException("parameter rem in UpdateReminder is null."); } }
/// <summary> /// forces the database to refresh the list /// </summary> public static void NotifyChange() { BLIO.Log("BLReminder.NotifyChange()"); DLReminders.NotifyChange(); }