public void GenerateObfuscationReportForDatabase(Database database, string path) { List<IGeneratorInfo> generatorInfos = ObjectLocator.GetAllInstances<IGeneratorInfo>(); StringBuilder report = new StringBuilder(); report.AppendLine(""); report.AppendLine("=========================================================="); report.AppendLine(" DAFUSCATOR "); report.AppendLine("=========================================================="); report.AppendLine(""); report.AppendLine("Report Type: Obfuscated Columns Report"); report.AppendLine("Report Date: " + DateTime.Now); report.AppendLine("Database: " + database.ConnectionString.DatabaseName); report.AppendLine(""); foreach (Table t in database.Tables) { List<Column> activeColumns = t.Columns.Where(x => x.GeneratorType != null && x.GeneratorType.Value != SystemConstants.DefaultGuid).ToList(); if (activeColumns.Count > 0 || t.HandlerType != TableHandlerTypes.None) { report.AppendLine("Table: " + t.FullTableName); report.AppendLine("---------------------------------"); if (t.HandlerType == TableHandlerTypes.None) { foreach (Column c in activeColumns) { report.AppendLine(string.Format(" Column: {0} Generator: {1}", c.Name, generatorInfos.Where(x => x.Id == c.GeneratorType.Value).First().Name)); } } else { if (t.HandlerType == TableHandlerTypes.Delete) report.AppendLine(string.Format(" All records in the table will be deleted.")); else report.AppendLine(string.Format(" Table will be dropped from the Database.")); } report.AppendLine(""); report.AppendLine(""); } } if (File.Exists(path)) File.Delete(path); using (StreamWriter writer = new StreamWriter(path)) { writer.Write(report.ToString()); } }
public ObfuscationResult ObfuscateDatabase(Database database) { ObfuscationResult result = new ObfuscationResult(); result.DatabaseName = database.ConnectionString.DatabaseName; result.StartTimeStamp = DateTime.Now; try { Func<Table, ObfuscationWorker> getAndProcessObfuscationWorker = table => { var obfuscationWorker = new ObfuscationWorker( _sqlGenerationService, _dataGenerationService, _databaseInteractionService, _eventAggregator, database.ConnectionString, table); obfuscationWorker.Process(); return obfuscationWorker; }; IEnumerable<ObfuscationWorker> obfuscationWorkers; obfuscationWorkers = database.Tables .AsParallel() .Select(getAndProcessObfuscationWorker); foreach (ObfuscationWorker worker in obfuscationWorkers) { if (worker.ErrorOccured) result.ErroredTables.Add(worker.Table.FullTableName, worker.ErrorString); else result.TablesProcessed.Add(worker.Table.FullTableName, worker.RowsProcessed); } } catch (Exception ex) { Logging.LogException(ex); throw; } result.FinsihedTimeStamp = DateTime.Now; return result; }
public Database RefreshDatabaseProject(Database database) { Database db = new Database(); try { db.ConnectionString = database.ConnectionString; db.Tables = new NotifyList<Table>(_databaseInteractionService.GetTablesFromDatabase(database.ConnectionString)); foreach (Table t in db.Tables) { Table oldTable = database.Tables.Where(x => x.FullTableName == t.FullTableName).SingleOrDefault(); if (oldTable != null) { t.HandlerType = oldTable.HandlerType; t.RecordCount = oldTable.RecordCount; foreach (Column c in t.Columns) { Column oldColumn = oldTable.Columns.Where(x => x.Name == c.Name).SingleOrDefault(); if (oldColumn != null) { c.GeneratorType = oldColumn.GeneratorType; c.GeneratorData = oldColumn.GeneratorData; } } } } } catch (Exception ex) { Logging.LogException(ex); throw; } return db; }
public Database SaveDatabaseProject(Database databaseProject, string path) { if (File.Exists(path)) File.Delete(path); // Clear out all the generated data, so we don't serialize that out foreach (Table t in databaseProject.Tables) foreach (Column c in t.Columns) c.Data = new List<string>(); string plainTextObjectData; plainTextObjectData = objectSerializationProvider.Serialize(databaseProject); string encryptedObjectData; encryptedObjectData = encryptionProvider.Encrypt(plainTextObjectData, encryptionInfo); using (StreamWriter writer = new StreamWriter(path)) { writer.Write(encryptedObjectData); } return GetDatabaseProject(path); }
private void newWindow_ConnectButtonClick(object sender, RoutedEventArgs e) { if (newWindow.IsFormValid()) { BackgroundWorker worker = new BackgroundWorker(); newWindow.loadingAnimation.Visibility = Visibility.Visible; IDatabaseInteractionService dbService = ObjectLocator.GetInstance<IDatabaseInteractionService>(); worker.DoWork += delegate(object s, DoWorkEventArgs args) { ConnectionString connectionString = args.Argument as ConnectionString; bool valid = dbService.TestConnection(connectionString); args.Result = valid; if (valid) { if (newWindow.IsUpdateOnly) { UIContext.Database.ConnectionString = connectionString; } else { Database db = new Database(); db.ConnectionString = connectionString; UIContext.Database = db; RefreshData(); } } }; worker.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs args) { if (args.Result != null && !(bool)args.Result) { newWindow.loadingAnimation.Visibility = Visibility.Collapsed; MessageBox.Show( "There was a problem connecting to the database\r\nusing the information you supplied.\r\n\r\nPlease checking the information and retry.", "Database Connection Error", MessageBoxButton.OK, MessageBoxImage.Asterisk); } else if (args.Result != null) { newWindow.ResetForm(); newWindow.Visibility = Visibility.Collapsed; newWindow.loadingAnimation.Visibility = Visibility.Collapsed; ColumnsGrid.Visibility = Visibility.Visible; } }; worker.RunWorkerAsync(newWindow.GetConnectionString()); } }
public Database SaveDatabaseProject(Database databaseProject, string path) { return _databaseProjectRepository.SaveDatabaseProject(databaseProject, path); }