示例#1
0
        private static void PerformTask(Options options)
        {
            if (!String.IsNullOrEmpty(options.ProjectFile))
            {
                IDatabaseProjectService databaseProjectService = ObjectLocator.GetInstance <IDatabaseProjectService>();
                IEventAggregator        eventAggregator        = ObjectLocator.GetInstance <IEventAggregator>();

                Console.WriteLine(string.Format("Loading the Dafuscator project: {0}", options.ProjectFile));
                Database         db = databaseProjectService.GetDatabaseProject(options.ProjectFile);
                ConnectionString connetionString;

                if (!String.IsNullOrEmpty(options.ConnectionString))
                {
                    connetionString = new ConnectionString(options.ConnectionString);
                }
                else
                {
                    connetionString = db.ConnectionString;
                }
                db.ConnectionString = connetionString;
                eventAggregator.AddListener <StatusUpdateEvent>(e => Console.WriteLine(string.Format("{0}: {1}", DateTime.Now, e.Message)));

                if (!String.IsNullOrEmpty(options.ExportFile))
                {
                    Console.WriteLine(string.Format("Started exporting the Dafuscator project to {0}", options.ExportFile));
                    IExportService exportService = ObjectLocator.GetInstance <IExportService>();
                    exportService.ExportTables(db.Tables, options.ExportFile, connetionString);

                    Console.WriteLine("Finished exporting the Dafuscator project.");
                }
                else
                {
                    Console.WriteLine(string.Format("Started the obfuscation of the {0} database.", db.ConnectionString.DatabaseName));

                    IRunService    runService    = ObjectLocator.GetInstance <IRunService>();
                    IReportService reportService = ObjectLocator.GetInstance <IReportService>();

                    ObfuscationResult result = runService.ObfuscateDatabase(db);

                    string path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
                    path = path + "\\Dafuscator";

                    if (Directory.Exists(path) == false)
                    {
                        Directory.CreateDirectory(path);
                    }

                    path = path +
                           string.Format("\\DatabaseObfuscationReport_{0}_{1}_{2}-{3}_{4}.txt", DateTime.Now.Month, DateTime.Now.Day,
                                         DateTime.Now.Year, DateTime.Now.Hour, DateTime.Now.Minute);

                    reportService.GenerateReportForObfucsationResult(result, path);

                    Console.WriteLine("Finished the obfuscation process in {0}", result.TimeElapsed);
                }
            }
        }
示例#2
0
        private static void RunObfuscate(object sender, ExecutedRoutedEventArgs e)
        {
            if (UIContext.Database != null)
            {
                BackgroundWorker worker = new BackgroundWorker();

                MainWindow mainWindow = (MainWindow)sender;
                mainWindow.loadingAnimation.Visibility = Visibility.Visible;

                worker.DoWork += delegate(object s, DoWorkEventArgs args)
                {
                    IRunService runService = ObjectLocator.GetInstance <IRunService>();

                    ObfuscationResult result = runService.ObfuscateDatabase(UIContext.Database);

                    args.Result = result;
                };

                worker.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs args)
                {
                    mainWindow.loadingAnimation.Visibility = Visibility.Collapsed;
                    ObfuscationResult result = args.Result as ObfuscationResult;

                    MessageBox.Show(mainWindow, string.Format("Finished database obfuscation in {0}", result.TimeElapsed), "Database Obfuscation Finished",
                                    MessageBoxButton.OK, MessageBoxImage.Information);

                    IReportService reportService = ObjectLocator.GetInstance <IReportService>();

                    //string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
                    //path = path.Replace("file:\\", "");

                    string path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
                    path = path + "\\Dafuscator";

                    if (Directory.Exists(path) == false)
                    {
                        Directory.CreateDirectory(path);
                    }

                    path = path +
                           string.Format("\\DatabaseObfuscationReport_{0}_{1}_{2}-{3}_{4}.txt", DateTime.Now.Month, DateTime.Now.Day,
                                         DateTime.Now.Year, DateTime.Now.Hour, DateTime.Now.Minute);

                    reportService.GenerateReportForObfucsationResult(result, path);
                };

                worker.RunWorkerAsync();
            }
            else
            {
                MessageBox.Show("There is no open database project, cannot obfuscate database.", "Error Saving", MessageBoxButton.OK,
                                MessageBoxImage.Exclamation);
            }
        }