Skip to content

Commit

Permalink
Merge pull request #1 from rhwy/master
Browse files Browse the repository at this point in the history
adjustments for april 11 dump
  • Loading branch information
SamSaffron committed May 15, 2011
2 parents b57b851 + 6788114 commit 4ce9081
Show file tree
Hide file tree
Showing 18 changed files with 862 additions and 60 deletions.
21 changes: 20 additions & 1 deletion Importer.cs
Expand Up @@ -41,7 +41,17 @@ class Importer {
copy.BatchSize = NotifyPerRows;

// TODO: Extract this further up
var validator = targetTable == "Comments" ? CommentsValidator : (ColumnValidator)null;
var validator = (ColumnValidator)null;

if (targetTable.ToLower() == "comments")
{
validator = CommentsValidator;
}
if (targetTable.ToLower() == "posts")
{
validator = ViewCountValidator;
}
//targetTable == "Comments" ? CommentsValidator : (ColumnValidator)null;

var dumpReader = new DumpReader(filename, targetTable, connection, validator);
copy.WriteToServer(dumpReader);
Expand All @@ -53,6 +63,15 @@ class Importer {
return "-1";
}
return value;
}

string ViewCountValidator(string name, string value)
{
if (name == "ViewCount" && value == "")
{
return "0";
}
return value;
}

void copy_SqlRowsCopied(object sender, SqlRowsCopiedEventArgs e) {
Expand Down
62 changes: 48 additions & 14 deletions MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 36 additions & 8 deletions MainForm.cs
Expand Up @@ -17,6 +17,8 @@ namespace SoSlow {
public partial class MainForm : Form {

Settings settings;
StringBuilder importLog = new StringBuilder();
string logFilePath = Path.Combine(Environment.CurrentDirectory,"import.log");

public MainForm() {
InitializeComponent();
Expand All @@ -26,20 +28,20 @@ public partial class MainForm : Form {
SetProgressMessage("");
progressBar1.Visible = false;

location.Text = settings.DataLocation;
locationEdit.Text = settings.DataLocation;
connectionString.Text = settings.ConnectionString;
}

private void selectLocation_Click(object sender, EventArgs e) {
var result = folderBrowserDialog1.ShowDialog();
if (result == DialogResult.OK) {
location.Text = folderBrowserDialog1.SelectedPath;
locationEdit.Text = folderBrowserDialog1.SelectedPath;
}
}

protected override void OnClosing(CancelEventArgs e) {
if (settings != null) {
settings.DataLocation = location.Text;
settings.DataLocation = locationEdit.Text;
settings.ConnectionString = connectionString.Text;
settings.Save();
}
Expand All @@ -51,23 +53,29 @@ public partial class MainForm : Form {
Invoke((MethodInvoker)(() => SetProgressMessage(message)));
} else {
progressMessage.Text = message;
string line = string.Format("[{0}] ",DateTime.Now.ToLongTimeString()) + progressMessage.Text;
importLog.AppendLine(line);
File.AppendAllText(logFilePath,line+Environment.NewLine);
}
}

string baseProgressMessage = "";
string baseProgressMessage = string.Empty;

void SetProgress(int count) {
if (InvokeRequired) {
Invoke((MethodInvoker)(() => SetProgress(count)));
} else {
progressMessage.Text = baseProgressMessage + string.Format("{0} rows imported", count);
string line = string.Format("[{0}] ", DateTime.Now.ToLongTimeString()) + progressMessage.Text;
importLog.AppendLine(line);
File.AppendAllText(logFilePath, line + Environment.NewLine);
}
}

private void import_Click(object sender, EventArgs e) {

import.Enabled = false;

File.Delete(logFilePath);
// reset db and open connection

SqlConnection cnn = new SqlConnection(connectionString.Text);
Expand All @@ -81,7 +89,7 @@ public partial class MainForm : Form {

foreach (var file in files) {
Importer importer = new Importer(
Path.Combine(location.Text, string.Format("{0}.xml",file)),
Path.Combine(locationEdit.Text, string.Format("{0}.xml",file)),
TitleCase(file),
cnn
);
Expand All @@ -90,6 +98,7 @@ public partial class MainForm : Form {
}

ThreadPool.QueueUserWorkItem(_ => {
DateTime startTime = DateTime.Now;
foreach (var importer in importers) {
baseProgressMessage = "Importing " + importer.TargetTable + " ";
Expand All @@ -101,8 +110,10 @@ public partial class MainForm : Form {
baseProgressMessage = "Impoting tag refs";
ImportTagRefs(cnn);
SetProgressMessage("Done !");
TimeSpan duration = DateTime.Now - startTime;
SetProgressMessage(string.Format("Import Done (duration : {0} min)",duration.TotalMinutes));
EnableImportButton();
ShowViewReporttButton();
});

}
Expand Down Expand Up @@ -142,7 +153,17 @@ public partial class MainForm : Form {
import.Enabled = true;
}
}

private void ShowViewReporttButton()
{
if (InvokeRequired)
{
Invoke((MethodInvoker)( () => ShowViewReporttButton() ));
}
else
{
btnViewReport.Visible = true;
}
}
private string LoadResource(string resource) {

using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resource)) {
Expand All @@ -153,6 +174,13 @@ public partial class MainForm : Form {

void importer_Progress(object sender, ProgressEventArgs e) {
SetProgress(e.RowsImported);
}

private void btnViewReport_Click(object sender, EventArgs e)
{
ReportLog log = new ReportLog();
log.UpdateContent(importLog.ToString());
log.ShowDialog();
}


Expand Down
21 changes: 11 additions & 10 deletions Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Properties/Settings.settings
Expand Up @@ -3,7 +3,7 @@
<Profiles />
<Settings>
<Setting Name="ConnectionString" Type="System.String" Scope="User">
<Value Profile="(Default)" />
<Value Profile="(Default)">Data Source=.;Initial Catalog=StackExchange_Database;Integrated Security=SSPI;</Value>
</Setting>
<Setting Name="DataLocation" Type="System.String" Scope="User">
<Value Profile="(Default)" />
Expand Down

0 comments on commit 4ce9081

Please sign in to comment.