[2228] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.ComponentModel;
|
---|
| 4 | using System.Data;
|
---|
| 5 | using System.Drawing;
|
---|
| 6 | using System.Linq;
|
---|
| 7 | using System.Text;
|
---|
| 8 | using System.Windows.Forms;
|
---|
[2286] | 9 | using System.IO;
|
---|
| 10 | using HeuristicLab.Core;
|
---|
| 11 | using HeuristicLab.DataAnalysis;
|
---|
[2312] | 12 | using HeuristicLab.Modeling.Database.SQLServerCompact;
|
---|
[2228] | 13 |
|
---|
| 14 | namespace CedmaExporter {
|
---|
| 15 | public partial class CedmaExporterForm : Form {
|
---|
[2286] | 16 | private BackgroundWorker worker;
|
---|
[2228] | 17 | public CedmaExporterForm() {
|
---|
| 18 | InitializeComponent();
|
---|
[2286] | 19 | }
|
---|
[2228] | 20 |
|
---|
[2286] | 21 | private void exportButton_Click(object sender, EventArgs e) {
|
---|
[2228] | 22 | var dialog = new OpenFileDialog();
|
---|
| 23 | DialogResult result;
|
---|
[2286] | 24 | result = dialog.ShowDialog();
|
---|
| 25 | if (result == DialogResult.OK) {
|
---|
| 26 | string fileName = dialog.FileName;
|
---|
| 27 | exportButton.Enabled = false;
|
---|
| 28 | cancelButton.Enabled = true;
|
---|
| 29 | worker = new BackgroundWorker();
|
---|
| 30 | worker.WorkerReportsProgress = true;
|
---|
| 31 | worker.WorkerSupportsCancellation = true;
|
---|
| 32 | worker.DoWork += CreateWorkerDelegate(worker, fileName);
|
---|
| 33 | worker.ProgressChanged += new ProgressChangedEventHandler(worker_ProgressChanged);
|
---|
| 34 | worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);
|
---|
| 35 | worker.RunWorkerAsync();
|
---|
| 36 | }
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | private DoWorkEventHandler CreateWorkerDelegate(BackgroundWorker worker, string fileName) {
|
---|
| 40 | return (sender, args) => {
|
---|
| 41 | string inputFileName = fileName;
|
---|
[2312] | 42 | string outputFileName = fileName.Replace(".sdf", "") + ".txt";
|
---|
| 43 | string sqlCompactConnectionString = "sqlite:rdf:Data Source=\"" + inputFileName + "\"";
|
---|
[2286] | 44 | using (StreamWriter writer = File.CreateText(outputFileName)) {
|
---|
[2312] | 45 | DatabaseService database = new DatabaseService("Data Source=" + fileName);
|
---|
| 46 | database.Connect();
|
---|
| 47 | var models = database.GetAllModels();
|
---|
| 48 | var dataset = database.GetDataset();
|
---|
| 49 | CedmaExporter.WriteColumnHeaders(writer);
|
---|
| 50 | List<string> inputVariables = CedmaExporter.WriteVariableImpactHeaders(database, writer);
|
---|
| 51 | writer.WriteLine();
|
---|
| 52 | int i = 0;
|
---|
| 53 | var exporter = new ModelExporter(dataset, Path.GetDirectoryName(outputFileName), true);
|
---|
| 54 | var allModels = database.GetAllModels();
|
---|
| 55 | foreach (HeuristicLab.Modeling.Database.IModel m in allModels) {
|
---|
| 56 | CedmaExporter.WriteModel(m, ++i, database, writer, inputVariables, exporter);
|
---|
| 57 | worker.ReportProgress((i * 100) / allModels.Count());
|
---|
| 58 | if (worker.CancellationPending) return;
|
---|
[2286] | 59 | }
|
---|
[2228] | 60 | }
|
---|
[2286] | 61 | };
|
---|
[2228] | 62 | }
|
---|
[2286] | 63 |
|
---|
| 64 | void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
|
---|
| 65 | exportButton.Enabled = true;
|
---|
| 66 | cancelButton.Enabled = false;
|
---|
| 67 | progressBar.Value = 0;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | void worker_ProgressChanged(object sender, ProgressChangedEventArgs e) {
|
---|
| 71 | progressBar.Value = e.ProgressPercentage;
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | private void cancelButton_Click(object sender, EventArgs e) {
|
---|
| 75 | worker.CancelAsync();
|
---|
| 76 | }
|
---|
[2228] | 77 | }
|
---|
| 78 | }
|
---|