private void MySQLDeleteColumn_Click(object sender, RoutedEventArgs e) { try { var rowData = ((Hyperlink)e.OriginalSource).DataContext as DatabaseViewModel; if (rowData == null) { return; } MessageBoxResult result = MessageBox.Show("Are you sure you want to delete this backup?", "Confirm Action", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.No) { return; } MYSQLHelper helper = new MYSQLHelper(); helper.DeleteConfig(rowData.Id); MessageBox.Show("Backup was successfully deleted.", "Information", MessageBoxButton.OK, MessageBoxImage.Information); LoadMySQL(); } catch (Exception ex) { string message = Functions.GetErrorFromException(ex); MessageBox.Show("A problem occurred while opening edit dialog.\n" + message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
private void LoadMySQL() { try { MYSQLHelper helper = new MYSQLHelper(); List <MYSQLBackup> items = helper.GetConfigList(); if (items != null && items.Count > 0) { MySQLList = (from t in items select new DatabaseViewModel { Id = t.Id, ServerName = t.ServerName, DatabaseName = t.DatabaseName, _backuptime = t.BackupTime, _lastBackup = t.LastBackupTime, }).ToList(); MySQLList.ForEach(a => a.BackupTime = a._backuptime.ToString("HH:mm")); MySQLList.ForEach(a => a.LastBackup = a._lastBackup == null ? "Never" : ((DateTime)a._lastBackup).ToString("MMM dd, yyyy HH:mm")); } else { MySQLList = new List <DatabaseViewModel>(); } } catch (Exception ex) { string message = Functions.GetErrorFromException(ex); MessageBox.Show("An error occurred while loading MSSQL backup configuration. \n" + message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
public winMySQL(string _editId = "") { InitializeComponent(); DataContext = this; EditId = _editId; //load settings if editing if (!string.IsNullOrWhiteSpace(EditId)) { try { MYSQLHelper helper = new MYSQLHelper(); MYSQLBackup backup = helper.GetConfig(EditId); if (backup == null) { MessageBox.Show("Settings were not found.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } ServerName = backup.ServerName; DatabaseName = backup.DatabaseName; Username = backup.Username; Password = backup.Password; BackupIsActive = backup.IsActive; BackupTime = backup.BackupTime; } catch (Exception ex) { string message = Functions.GetErrorFromException(ex); MessageBox.Show("A problem occurred while loading backup details.\n" + message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } }
private void GenerateSummary() { AwsS3SettingColor = "LightGray"; EmailSettingColor = "LightGray"; ServiceColor = "LightGray"; try { MSSQLHelper mssqlHelper = new MSSQLHelper(); List<MSSQLBackup> sqlitems = mssqlHelper.GetConfigList(); MSSQLCount = sqlitems != null ? sqlitems.Count() : 0; MYSQLHelper mysqlHelper = new MYSQLHelper(); List<MYSQLBackup> mysqlitems = mysqlHelper.GetConfigList(); MySQLCount = mysqlitems != null ? mysqlitems.Count() : 0; FolderHelper folderHelper = new FolderHelper(); List<FolderBackup> folderitems = folderHelper.GetConfigList(); FolderCount = folderitems != null ? folderitems.Count() : 0; AWSS3Helper awsHelper = new AWSS3Helper(); AWSS3Setting awsSetting = awsHelper.GetConfig(); if (awsSetting == null) { AwsS3SettingStatus = "AWS S3 settings not defined"; } else if (awsSetting.IsValid == false) { AwsS3SettingStatus = "AWS S3 settings are not valid"; } else if (awsSetting.IsActive == false) { AwsS3SettingStatus = "AWS S3 settings are not active"; } else { AwsS3SettingStatus = "AWS S3 settings are valid & active"; AwsS3SettingColor = "Green"; } EmailHelper emailHelper = new EmailHelper(); EmailSetting emailSetting = emailHelper.GetConfig(); if (emailSetting == null) { EmailSettingStatus = "E-Mail settings are not defined"; } else if (emailSetting.IsValid == false) { EmailSettingStatus = "E-Mail settings are not valid"; } else { EmailSettingStatus = "Email settings are valid & active"; EmailSettingColor = "Green"; } ServiceStatus = "Background service is not installed"; GeneralSettingHelper generalHelper = new GeneralSettingHelper(); GeneralSetting generalSetting = generalHelper.GetConfig(); if (generalSetting != null && generalSetting.ServiceInstalled == true) { ServiceStatus = "Background service is installed"; ServiceColor = "Green"; btnInstallService.Visibility = Visibility.Collapsed; btnUnInstallService.Visibility = Visibility.Visible; } } catch (Exception ex) { string message = Functions.GetErrorFromException(ex); MessageBox.Show("An error occurred. \n" + message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
private async void btnSave_Click(object sender, RoutedEventArgs e) { //validations if (string.IsNullOrWhiteSpace(ServerName)) { Message = "Server name cannot be empty"; return; } if (string.IsNullOrWhiteSpace(DatabaseName)) { Message = "Database name cannot be empty"; return; } if (string.IsNullOrWhiteSpace(Username)) { Message = "Username cannot be empty"; return; } if (string.IsNullOrWhiteSpace(Password)) { Message = "Password cannot be empty"; return; } if (BackupTime == null) { Message = "Backup time cannot be empty"; return; } //Try connecting try { btnSave.IsEnabled = false; Message = "Please wait while checking connection..."; MYSQLHelper helper = new MYSQLHelper(ServerName, DatabaseName, Username, Password); string tempFile = Path.Combine(EnVar.AppTempPath, Functions.RandomString(10) + "_test_backup.sqldump"); bool Result = await helper.BackupDatabase(tempFile); btnSave.IsEnabled = true; Message = ""; if (Result == false) { Message = "Could not connect to database server. \n" + helper.Message; return; } if (File.Exists(tempFile)) { File.Delete(tempFile); } //connection successful, save settings //delete if editing if (!string.IsNullOrWhiteSpace(EditId)) { helper.DeleteConfig(EditId); } helper.AddConfig(new MYSQLBackup { Id = Functions.RandomString(20), ServerName = ServerName, DatabaseName = DatabaseName, Username = Username, Password = Password, BackupTime = (DateTime)BackupTime, CreatedOn = DateTime.UtcNow, IsActive = BackupIsActive, }); Close(); } catch (Exception ex) { string message = Functions.GetErrorFromException(ex); MessageBox.Show("A problem occurred while connecting to server.\n" + message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }