Skip to content

Commit

Permalink
adding viewcount validator for '11 april dump bug, adding some log, c…
Browse files Browse the repository at this point in the history
…hanging the colors
  • Loading branch information
rhwy committed Apr 9, 2011
1 parent b57b851 commit 6788114
Show file tree
Hide file tree
Showing 18 changed files with 862 additions and 60 deletions.
21 changes: 20 additions & 1 deletion Importer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,17 @@ public void Import() {
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 @@ string CommentsValidator(string name, string value) {
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
Original file line number Diff line number Diff line change
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 MainForm() {
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 @@ void SetProgressMessage(string message) {
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 @@ private void import_Click(object sender, EventArgs e) {

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 @@ private void import_Click(object sender, EventArgs e) {
}

ThreadPool.QueueUserWorkItem(_ => {
DateTime startTime = DateTime.Now;
foreach (var importer in importers) {
baseProgressMessage = "Importing " + importer.TargetTable + " ";
Expand All @@ -101,8 +110,10 @@ private void import_Click(object sender, EventArgs e) {
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 @@ private void EnableImportButton() {
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 @@ private string LoadResource(string resource) {

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
Original file line number Diff line number Diff line change
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
Loading

0 comments on commit 6788114

Please sign in to comment.