//Methods public void DateAndTimeCheck() { Dictionary <string, List <string> > schedule = new Dictionary <string, List <string> >(); DateTime conversion; string temp; int x = 2; //Add days and lists with times to schedule dictionary. foreach (string day in weekDays) { command = $"select * from {day};"; commander = new SQLiteCommand(command, connection); reader = commander.ExecuteReader(); List <string> tempTimes = new List <string>(); while (reader.Read()) { for (int i = 0; i < reader.FieldCount; i++) { tempTimes.Add((string)reader[i]); } } schedule.Add(day, tempTimes); } for (int i = 0; i < schedule.Count; i++) { conversion = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second); //Check if it is the right day for example Monday if (schedule.Keys.ElementAt(i).ToLower() == conversion.DayOfWeek.ToString().ToLower()) { //Get the timestamp from the list belonging to the given day. foreach (string time in schedule.Values.ElementAt(i)) { //Trim the string so that it can be converted and compared to a Datetime. temp = time; temp = temp.Remove(2); TimeSpan ts = new TimeSpan(Convert.ToInt32(temp.TrimStart('0')), 0, 0); conversion = conversion.Date + ts; //Check if the current time (DateTime.Now) is larger than the scheduled time (Conversion) and that current time is smaller than conversion + 5 min. if (conversion < DateTime.Now && conversion.AddMinutes(x) > DateTime.Now) { //Run auto backup Backupper auto = new Backupper(BackupType.Automatic, sourceDirs, destDir, ref curatedBackup, connection); } } } } //Set the timer for the next auto backup check in about an hour. SetTimer(); }
private void btn_runBackup_Click(object sender, RoutedEventArgs e) { //Code for the manual backup. if (System.Windows.MessageBox.Show("Unchecked folders will be removed from list of folders to back-up.\nAre you sure you wish to back-up selected folders?", "Confirm backup", MessageBoxButton.OKCancel) == MessageBoxResult.OK) { List <System.Windows.Controls.CheckBox> toRemove = new List <System.Windows.Controls.CheckBox>(); foreach (System.Windows.Controls.CheckBox item in listBox.Items) { if (!(bool)item.IsChecked) { toRemove.Add(item); } } foreach (System.Windows.Controls.CheckBox item in toRemove) { command = $"delete from SourceDirPaths where path = '{item.Content}'"; commander = new SQLiteCommand(command, connection); commander.ExecuteNonQuery(); listBox.Items.Remove(item); } toRemove.Clear(); List <string> sourceDirs = new List <string>(); foreach (System.Windows.Controls.CheckBox checkBox in listBox.Items) { sourceDirs.Add(checkBox.Content.ToString()); } command = $"select * from RepositoryPath;"; commander = new SQLiteCommand(command, connection); reader = commander.ExecuteReader(); while (reader.Read()) { if ((string)reader[0] != txtBox_backupLocation.Text) { command = $"update RepositoryPath set path = '{txtBox_backupLocation.Text}'"; commander = new SQLiteCommand(command, connection); commander.ExecuteNonQuery(); } } Backupper backup = new Backupper(BackupType.Manual, sourceDirs, txtBox_backupLocation.Text, ref curatedBackup, connection); } else { } }