public void ZipTxtDb() { var archiveName = $"DB{DateTime.Now:yyyy-MM-dd-HH-mm-ss}.zip"; var zipFileToCreate = Path.Combine(_mySettings.GetCombinedSetting("BackupPath"), archiveName); var directoryToZip = (string)_mySettings.GetSetting("TemporaryTxtDbPath"); try { using (var zip = new ZipFile()) { zip.Password = "******"; zip.Encryption = EncryptionAlgorithm.WinZipAes256; var filenames = Directory.GetFiles(directoryToZip, "*.txt"); // note: this does not recurse directories! foreach (var filename in filenames) { zip.AddFile(filename, String.Empty); } zip.Comment = $"This zip archive was created on machine '{Dns.GetHostName()}'"; zip.Save(zipFileToCreate); } } catch (Exception ex1) { MessageBox.Show("Exception during database zipping: " + ex1); } }
private void SaveData() { var pp = _mySettings.GetCombinedSetting("DbFileFullPath"); new DbSerializer().EncryptAndSerialize(_db, pp); if (_shellModel.IsDbChanged) { IoC.Get <DbBackuper>().MakeDbTxtCopy(); } }
public void Execute(MainMenuAction action) { switch (action) { case MainMenuAction.SaveDatabase: new DbSerializer().EncryptAndSerialize(_db, _mySettings.GetCombinedSetting("DbFileFullPath")); break; case MainMenuAction.LoadDatabase: _db = new DbSerializer().DecryptAndDeserialize(_mySettings.GetCombinedSetting("DbFileFullPath")); break; case MainMenuAction.ClearDatabase: _dbCleaner.ClearAllTables(_db); break; case MainMenuAction.MakeDatabaseBackup: _dbBackuper.MakeDbTxtCopy(); break; case MainMenuAction.ExportDatabaseToTxt: _dbToTxtSaver.SaveDbInTxt(); break; case MainMenuAction.ImportDatabaseFromTxt: ImportDatabaseFromTxt(); break; case MainMenuAction.RemoveExtraBackups: new DbBackupOrganizer().RemoveIdenticalBackups(); break; case MainMenuAction.RemoveAllNonFirstInMonth: new DbBackupOrganizer().RemoveAllNonFirstInMonth(); break; } }