private void btnValidateGeneral_Click(object sender, RoutedEventArgs e) { MessageFolder = ""; try { //try writing to selected path string tmpFile = Path.Combine(General.LocalFolder, "test.txt"); File.WriteAllText(tmpFile, "File created to check write access for this folder."); //try deleting from selected path File.Delete(tmpFile); GeneralSettingHelper generalHelper = new GeneralSettingHelper(); generalHelper.SaveConfig(General); RaisePropertyChanged("General"); MessageFolder = "Settings successfully updated"; } catch (Exception ex) { string message = Functions.GetErrorFromException(ex); MessageBox.Show("The selected path is not writable. Make sure the path is writable. \n" + message, "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); } }
//Email, Local Folder, AWS S3 private void LoadOtherSettings() { try { AWSS3Helper awsHelper = new AWSS3Helper(); AWSS3 = awsHelper.GetConfig(); if (AWSS3 == null) { AWSS3 = new AWSS3Setting(); } EmailHelper emailHelper = new EmailHelper(); Email = emailHelper.GetConfig(); if (Email == null) { Email = new EmailSetting(); } GeneralSettingHelper generalHelper = new GeneralSettingHelper(); General = generalHelper.GetConfig(); if (General == null) { General = new GeneralSetting(); } } catch (Exception ex) { string message = Functions.GetErrorFromException(ex); MessageBox.Show("A problem occurred while loading settings. \n" + message, "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); } }
private void btnUninstallService_Click(object sender, RoutedEventArgs e) { try { //Stop the service ServiceController service = new ServiceController("Runtime Backup Service", "."); if (service != null && service.Status != ServiceControllerStatus.Stopped) service.Stop(); //Remove Registry Entry ProcessStartInfo startInfoDelete = new ProcessStartInfo { FileName = "sc.exe", Arguments = "delete \"Runtime Backup Service\"", CreateNoWindow = true, UseShellExecute = true }; Process processDelete = new Process() { StartInfo = startInfoDelete }; processDelete.Start(); } catch (Exception ex) { string message = Functions.GetErrorFromException(ex); MessageBox.Show("Failed to uninstall the service. \n" + message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } //update status anyways //sometimes service is already uninstalled and above attempt will fail. So need to update status try { ServiceStatus = "Background service is not installed"; ServiceColor = "LightGray"; GeneralSettingHelper generalHelper = new GeneralSettingHelper(); GeneralSetting generalSetting = generalHelper.GetConfig(); if (generalSetting != null) { generalSetting.ServiceInstalled = false; generalHelper.SaveConfig(generalSetting); } btnInstallService.Visibility = Visibility.Visible; btnUnInstallService.Visibility = Visibility.Collapsed; } catch (Exception ex) { string message = Functions.GetErrorFromException(ex); MessageBox.Show("Failed to update service status. \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 btnInstallService_Click(object sender, RoutedEventArgs e) { try { string servicePath = EnVar.AppPath + "rbs.exe"; if (!File.Exists(servicePath)) { MessageBox.Show("Unable to find service. Try reinstalling the application.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } ProcessStartInfo startInfoRegistry = new ProcessStartInfo { FileName = "sc.exe", Arguments = "create \"Runtime Backup Service\" binpath=\"" + servicePath + "\" start=auto ", CreateNoWindow = true, UseShellExecute = true }; Process processRegistry = new Process() { StartInfo = startInfoRegistry }; processRegistry.Start(); await Task.Delay(2000); //Start the service ServiceController service = new ServiceController("Runtime Backup Service", "."); if (service != null && service.Status != ServiceControllerStatus.Running) service.Start(); } catch (Exception ex) { string message = Functions.GetErrorFromException(ex); MessageBox.Show("Failed to install the service. \n" + message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } try { ServiceStatus = "Service is installed"; ServiceColor = "Green"; GeneralSettingHelper generalHelper = new GeneralSettingHelper(); GeneralSetting generalSetting = generalHelper.GetConfig(); if (generalSetting != null) { generalSetting.ServiceInstalled = true; generalHelper.SaveConfig(generalSetting); } btnInstallService.Visibility = Visibility.Collapsed; btnUnInstallService.Visibility = Visibility.Visible; } catch (Exception ex) { string message = Functions.GetErrorFromException(ex); MessageBox.Show("Failed to update service status. \n" + message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }