Exemple #1
0
        public void GenerateReportForObfucsationResult(ObfuscationResult obfuscationResult, string path)
        {
            StringBuilder report = new StringBuilder();
            report.AppendLine("");
            report.AppendLine("==========================================================");
            report.AppendLine("                      DAFUSCATOR                          ");
            report.AppendLine("==========================================================");
            report.AppendLine("");
            report.AppendLine("Report Type: Database Obfuscation Result Report");
            report.AppendLine("Report Date: " + DateTime.Now.Date);
            report.AppendLine("Database: " + obfuscationResult.DatabaseName);
            report.AppendLine("");
            report.AppendLine("Database Obfuscation Start: " + obfuscationResult.StartTimeStamp);
            report.AppendLine("Database Obfuscation Stop: " + obfuscationResult.FinsihedTimeStamp);
            report.AppendLine("Database Obfuscation Elapsed: " + obfuscationResult.TimeElapsed);
            report.AppendLine("");
            report.AppendLine("");

            var sorted = from r in obfuscationResult.TablesProcessed
                                     orderby r.Key
                                     select r;

            foreach (var d in sorted)
            {
                report.AppendLine(string.Format("{0}: {1}", d.Key, d.Value));
            }

            report.AppendLine("");
            report.AppendLine("                     Errors                               ");
            report.AppendLine("----------------------------------------------------------");
            report.AppendLine("");

            foreach (var d in obfuscationResult.ErroredTables)
            {
                report.AppendLine(string.Format("{0}: {1}", d.Key, d.Value));
                report.AppendLine("");
            }

            if (File.Exists(path))
                File.Delete(path);

            using (StreamWriter writer = new StreamWriter(path))
            {
                writer.Write(report.ToString());
            }
        }
Exemple #2
0
        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;
        }
Exemple #3
0
        public ObfuscationResult ObfuscateTable(ConnectionString connectionString, Table table)
        {
            ObfuscationResult result = new ObfuscationResult();
            result.DatabaseName = connectionString.DatabaseName;
            result.StartTimeStamp = DateTime.Now;

            if (table.AreAnyGeneratorsActive)
            {
                Table newTable = _dataGenerationService.GenerateDataForTable(connectionString, table, true);
                string sql = _sqlGenerationService.GenerateUpdateSqlForTable(newTable, false);

                if (String.IsNullOrEmpty(sql) == false)
                {
                    _eventAggregator.SendMessage<StatusUpdateEvent>(new StatusUpdateEvent(string.Format("Processing SQL query for table: {0}", table.FullTableName)));
                    int rowsProcessed = _databaseInteractionService.ProcessSql(connectionString, sql);

                    result.TablesProcessed.Add(table.FullTableName, rowsProcessed);
                }
            }

            result.FinsihedTimeStamp = DateTime.Now;
            return result;
        }