Skip to content

Commit

Permalink
Merge pull request #1 from Jorriss/master
Browse files Browse the repository at this point in the history
Add missing commits from move to BrentOzarULTD.
  • Loading branch information
Jorriss committed May 17, 2016
2 parents 3113c51 + e856db9 commit 60d3a6b
Show file tree
Hide file tree
Showing 18 changed files with 589 additions and 279 deletions.
79 changes: 43 additions & 36 deletions soddi/App.config
Original file line number Diff line number Diff line change
@@ -1,38 +1,45 @@
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="Salient.StackExchange.Import.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
</sectionGroup>
</configSections>
<system.data>
<DbProviderFactories>
<clear/>
<add name="System.Data.SqlClient" invariant="System.Data.SqlClient" description=".Net Framework Data Provider for SqlServer" type="System.Data.SqlClient.SqlClientFactory, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<add name="MySql.Data.MySqlClient" invariant="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.2.2.0" description="MySql ADO.Net Provider"/>
<add name="System.Data.SQLite" invariant="System.Data.SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite, Version=1.0.65.0" description="SQLite ADO.Net Provider"/>
</DbProviderFactories>
</system.data>
<userSettings>
<Salient.StackExchange.Import.Properties.Settings>
<setting name="SourceValue" serializeAs="String">
<value/>
</setting>
<setting name="TargetText" serializeAs="String">
<value>data source=c:\temp</value>
</setting>
<setting name="SplitChecked" serializeAs="String">
<value>False</value>
</setting>
<setting name="IndicesChecked" serializeAs="String">
<value>False</value>
</setting>
<setting name="FullTextChecked" serializeAs="String">
<value>False</value>
</setting>
<setting name="ProviderName" serializeAs="String">
<value>System.Data.SQLite</value>
</setting>
</Salient.StackExchange.Import.Properties.Settings>
</userSettings>
<startup/></configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="Salient.StackExchange.Import.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
</sectionGroup>
</configSections>
<system.data>
<DbProviderFactories>
<clear/>
<add name="System.Data.SqlClient" invariant="System.Data.SqlClient" description=".Net Framework Data Provider for SqlServer" type="System.Data.SqlClient.SqlClientFactory, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<!--<add name="MySql.Data.MySqlClient" invariant="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.2.2.0" description="MySql ADO.Net Provider"/>
<add name="System.Data.SQLite" invariant="System.Data.SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite, Version=1.0.65.0" description="SQLite ADO.Net Provider"/>-->
</DbProviderFactories>
</system.data>
<userSettings>
<Salient.StackExchange.Import.Properties.Settings>
<setting name="SourceValue" serializeAs="String">
<value/>
</setting>
<setting name="TargetText" serializeAs="String">
<value/>
</setting>
<setting name="SplitChecked" serializeAs="String">
<value>False</value>
</setting>
<setting name="IndicesChecked" serializeAs="String">
<value>False</value>
</setting>
<setting name="FullTextChecked" serializeAs="String">
<value>False</value>
</setting>
<setting name="FKChecked" serializeAs="String">
<value>False</value>
</setting>
<setting name="ProviderName" serializeAs="String">
<value>System.Data.SqlClient</value>
</setting>
<setting name="DefaultSchema" serializeAs="String">
<value>dbo</value>
</setting>
</Salient.StackExchange.Import.Properties.Settings>
</userSettings>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup>
</configuration>
82 changes: 64 additions & 18 deletions soddi/Configuration/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.Common;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Windows.Forms.VisualStyles;
using Salient.StackExchange.Import.Loaders;
using Salient.StackExchange.Import.TableTypes;

Expand All @@ -37,13 +39,34 @@ public enum ImportOptions
FullText = 2,
Split = 4,
GUI = 8,
FieldCount = 16
FieldCount = 16,
ForeignKeys = 32
}

#endregion

private const int DefaultBatchSize = 5000;

public class StackOverflowFile
{
public string FileName { get; set; }
public bool IsFound { get; set; }
}

public static List<StackOverflowFile> GetStackOverflowFileList()
{
List<StackOverflowFile> fileList = new List<StackOverflowFile>();
fileList.Add(new StackOverflowFile() { FileName = "Badges.xml", IsFound = false });
fileList.Add(new StackOverflowFile() { FileName = "Comments.xml", IsFound = false });
fileList.Add(new StackOverflowFile() { FileName = "PostHistory.xml", IsFound = false });
fileList.Add(new StackOverflowFile() { FileName = "PostLinks.xml", IsFound = false });
fileList.Add(new StackOverflowFile() { FileName = "Posts.xml", IsFound = false });
fileList.Add(new StackOverflowFile() { FileName = "Tags.xml", IsFound = false });
fileList.Add(new StackOverflowFile() { FileName = "Users.xml", IsFound = false });
fileList.Add(new StackOverflowFile() { FileName = "Votes.xml", IsFound = false });

return fileList;
}

public Configuration()
{
Expand All @@ -66,7 +89,7 @@ public bool FullText
{
Options = value
? Options | ImportOptions.FullText
: Options & (ImportOptions)(ImportOptions.FieldCount - ImportOptions.FullText);
: Options & (ImportOptions)(Options - ImportOptions.FullText);
}
}

Expand All @@ -77,7 +100,7 @@ public bool GUI
{
Options = value
? Options | ImportOptions.GUI
: Options & (ImportOptions)(ImportOptions.FieldCount - ImportOptions.GUI);
: Options & (ImportOptions)(Options - ImportOptions.GUI);
}
}

Expand All @@ -88,7 +111,18 @@ public bool Indices
{
Options = value
? Options | ImportOptions.Indices
: Options & (ImportOptions)(ImportOptions.FieldCount - ImportOptions.Indices);
: Options & (ImportOptions)(Options - ImportOptions.Indices);
}
}

public bool ForeignKeys
{
get { return (Options & ImportOptions.ForeignKeys) == ImportOptions.ForeignKeys; }
set
{
Options = value
? Options | ImportOptions.ForeignKeys
: Options & (ImportOptions)(Options - ImportOptions.ForeignKeys);
}
}

Expand Down Expand Up @@ -145,34 +179,43 @@ public string ToString(bool commandLine)
}
}


public static List<string> GetAllSites(string source)
{
List<string> sites = new List<string>();
Regex dirRx = new Regex(@"^(\d+) ([A-Za-z]+)$", RegexOptions.IgnoreCase);
string[] dirs = Directory.GetDirectories(source);
foreach (string dir in dirs)
{
Match match = dirRx.Match(Path.GetFileName(dir));
if (match.Success)
List<StackOverflowFile> soFiles = GetStackOverflowFileList();
foreach (string file in Directory.GetFiles(dir))
{
sites.Add(match.Groups[2].Value);
foreach (StackOverflowFile soFile in soFiles.Where(x => x.FileName == Path.GetFileName(file)))
{
soFile.IsFound = true;
}
}

bool soValid = true;
foreach (StackOverflowFile soFile in soFiles)
{
if (soFile.IsFound == false)
{
soValid = false;
break;
}
}

if (soValid)
{
sites.Add(Path.GetFileName(dir));
}
}
return sites;

}

public static ImportTarget GetSite(string source, string arg)
{
string[] segments = arg.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);

string siteId = segments[0];

string siteSchema = segments.Length > 1 ? segments[1] : siteId;

string[] dirs = Directory.GetDirectories(source, "* " + siteId);

return dirs.Length == 0 ? null : new ImportTarget(segments[0], dirs[0], siteSchema);
return new ImportTarget(arg, Path.Combine(source, arg), Properties.Settings.Default.DefaultSchema);
}

public static List<ImportTarget> GetTargets(string source, IEnumerable<string> unparsed)
Expand Down Expand Up @@ -230,6 +273,9 @@ private void ParseArguments(string[] args)
case "gui":
Options = Options | ImportOptions.GUI;
break;
case "foreignkeys":
Options = Options | ImportOptions.ForeignKeys;
break;
default:
unparsed.Add(args[i].Trim());
break;
Expand Down
Loading

0 comments on commit 60d3a6b

Please sign in to comment.