Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jeremiah Peschka
committed
Jul 14, 2013
1 parent
e06a666
commit 047c531
Showing
64 changed files
with
8,054 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 2012 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "soddi", "soddi\soddi.csproj", "{94451A1F-9DBA-438C-956F-CD1C072310B2}" | ||
EndProject | ||
Project("{54435603-DBB4-11D2-8724-00A0C9A8B90C}") = "SODDI_Setup", "SODDI_Setup\SODDI_Setup.vdproj", "{CB758D8A-3B3D-4CC4-AF05-005F60AD6DCC}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Debug|x86 = Debug|x86 | ||
Release|Any CPU = Release|Any CPU | ||
Release|x86 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{94451A1F-9DBA-438C-956F-CD1C072310B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{94451A1F-9DBA-438C-956F-CD1C072310B2}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{94451A1F-9DBA-438C-956F-CD1C072310B2}.Debug|x86.ActiveCfg = Debug|x86 | ||
{94451A1F-9DBA-438C-956F-CD1C072310B2}.Debug|x86.Build.0 = Debug|x86 | ||
{94451A1F-9DBA-438C-956F-CD1C072310B2}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{94451A1F-9DBA-438C-956F-CD1C072310B2}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{94451A1F-9DBA-438C-956F-CD1C072310B2}.Release|x86.ActiveCfg = Release|x86 | ||
{94451A1F-9DBA-438C-956F-CD1C072310B2}.Release|x86.Build.0 = Release|x86 | ||
{CB758D8A-3B3D-4CC4-AF05-005F60AD6DCC}.Debug|Any CPU.ActiveCfg = Debug | ||
{CB758D8A-3B3D-4CC4-AF05-005F60AD6DCC}.Debug|Any CPU.Build.0 = Debug | ||
{CB758D8A-3B3D-4CC4-AF05-005F60AD6DCC}.Debug|x86.ActiveCfg = Debug | ||
{CB758D8A-3B3D-4CC4-AF05-005F60AD6DCC}.Debug|x86.Build.0 = Debug | ||
{CB758D8A-3B3D-4CC4-AF05-005F60AD6DCC}.Release|Any CPU.ActiveCfg = Release | ||
{CB758D8A-3B3D-4CC4-AF05-005F60AD6DCC}.Release|Any CPU.Build.0 = Release | ||
{CB758D8A-3B3D-4CC4-AF05-005F60AD6DCC}.Release|x86.ActiveCfg = Release | ||
{CB758D8A-3B3D-4CC4-AF05-005F60AD6DCC}.Release|x86.Build.0 = Release | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(MercurialSourceControlSolutionProperties) = preSolution | ||
SolutionIsControlled = True | ||
SolutionBindings = <Solution Location In Database> | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,255 @@ | ||
// /*! | ||
// * Project: SODDI v.10 | ||
// * http://skysanders.net/tools/se/ | ||
// * | ||
// * Copyright 2010, Sky Sanders | ||
// * Dual licensed under the MIT or GPL Version 2 licenses. | ||
// * http://skysanders.net/tools/se/LICENSE.TXT | ||
// * | ||
// * Date: April 01 2010 | ||
// */ | ||
|
||
#region | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Data.Common; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Text.RegularExpressions; | ||
using Salient.StackExchange.Import.Loaders; | ||
using Salient.StackExchange.Import.TableTypes; | ||
|
||
#endregion | ||
|
||
namespace Salient.StackExchange.Import.Configuration | ||
{ | ||
public class Configuration | ||
{ | ||
#region ImportOptions enum | ||
|
||
[Flags] | ||
public enum ImportOptions | ||
{ | ||
None = 0, | ||
Indices = 1, | ||
FullText = 2, | ||
Split = 4, | ||
GUI = 8, | ||
FieldCount = 16 | ||
} | ||
|
||
#endregion | ||
|
||
private const int DefaultBatchSize = 5000; | ||
|
||
|
||
public Configuration() | ||
{ | ||
SetDefaults(); | ||
} | ||
|
||
public Configuration(string[] args) | ||
{ | ||
SetDefaults(); | ||
ParseArguments(args); | ||
} | ||
|
||
|
||
public int BatchSize { get; set; } | ||
|
||
public bool FullText | ||
{ | ||
get { return (Options & ImportOptions.FullText) == ImportOptions.FullText; } | ||
set | ||
{ | ||
Options = value | ||
? Options | ImportOptions.FullText | ||
: Options & (ImportOptions)(ImportOptions.FieldCount - ImportOptions.FullText); | ||
} | ||
} | ||
|
||
public bool GUI | ||
{ | ||
get { return (Options & ImportOptions.GUI) == ImportOptions.GUI; } | ||
set | ||
{ | ||
Options = value | ||
? Options | ImportOptions.GUI | ||
: Options & (ImportOptions)(ImportOptions.FieldCount - ImportOptions.GUI); | ||
} | ||
} | ||
|
||
public bool Indices | ||
{ | ||
get { return (Options & ImportOptions.Indices) == ImportOptions.Indices; } | ||
set | ||
{ | ||
Options = value | ||
? Options | ImportOptions.Indices | ||
: Options & (ImportOptions)(ImportOptions.FieldCount - ImportOptions.Indices); | ||
} | ||
} | ||
|
||
internal ImportOptions Options { get; set; } | ||
|
||
public DbProviderInfo Provider { get; set; } | ||
|
||
public string Source { get; set; } | ||
|
||
public bool Split | ||
{ | ||
get { return (Options & ImportOptions.Split) == ImportOptions.Split; } | ||
set | ||
{ | ||
Options = value | ||
? Options | ImportOptions.Split | ||
: Options & (ImportOptions)(ImportOptions.FieldCount - ImportOptions.Split); | ||
} | ||
} | ||
|
||
public string Target { get; set; } | ||
|
||
public List<ImportTarget> Targets { get; set; } | ||
|
||
|
||
public Type[] GetAllTableTypes() | ||
{ | ||
return | ||
typeof(Posts).Assembly.GetTypes().Where( | ||
t => t.Namespace == typeof(Posts).Namespace && (Split || t != typeof(PostTags))).ToArray(); | ||
} | ||
|
||
public string ToString(bool commandLine) | ||
{ | ||
if (commandLine) | ||
{ | ||
string targets = string.Join(" ", Targets.Select(t => t.Name == t.Schema ? t.Name : t.Name + ":" + t.Schema).ToArray()); | ||
DbConnectionStringBuilder csb = new DbConnectionStringBuilder(); | ||
csb.ConnectionString = Provider.ConnectionString; | ||
csb.Add("Provider", Provider.Name); | ||
|
||
|
||
string batch = BatchSize != DefaultBatchSize ? " batch:" + BatchSize : ""; | ||
string cmdLine = string.Format("{7} source:\"{0}\" target:\"{1}\"{2}{3}{4}{5} {6}", Source, | ||
csb.ConnectionString, batch, Indices ? " indices" : "", | ||
FullText ? " fulltext" : "", Split ? " split" : "", targets, | ||
Path.GetFileName(Assembly.GetExecutingAssembly().Location)); | ||
return cmdLine; | ||
} | ||
else | ||
{ | ||
return | ||
string.Format("Source : {0}\r\nTarget : {1}\r\nOptions : {2}", Source, Target, Options); | ||
} | ||
} | ||
|
||
|
||
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) | ||
{ | ||
sites.Add(match.Groups[2].Value); | ||
} | ||
} | ||
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); | ||
} | ||
|
||
public static List<ImportTarget> GetTargets(string source, IEnumerable<string> unparsed) | ||
{ | ||
List<ImportTarget> targets = new List<ImportTarget>(); | ||
foreach (string arg in unparsed) | ||
{ | ||
ImportTarget site = GetSite(source, arg); | ||
if (site != null) | ||
{ | ||
targets.Add(site); | ||
} | ||
} | ||
return targets; | ||
} | ||
|
||
private void ParseArguments(string[] args) | ||
{ | ||
List<string> unparsed = new List<string>(); | ||
|
||
for (int i = 0; i < args.Length; i++) | ||
{ | ||
string value = null; | ||
string arg = args[i].Trim(); | ||
if (arg.IndexOf(":") > -1) | ||
{ | ||
value = arg.Substring(arg.IndexOf(":") + 1).Trim('"', '\''); | ||
arg = arg.Substring(0, arg.IndexOf(":")); | ||
} | ||
switch (arg.ToLowerInvariant()) | ||
{ | ||
case "source": | ||
Source = value; | ||
break; | ||
case "target": | ||
Target = value; | ||
Provider = DbProviders.ParseArg(value); | ||
break; | ||
case "batch": | ||
int batchSize; | ||
if (int.TryParse(value, out batchSize)) | ||
{ | ||
BatchSize = batchSize; | ||
} | ||
break; | ||
case "indices": | ||
Options = Options | ImportOptions.Indices; | ||
break; | ||
case "fulltext": | ||
Options = Options | ImportOptions.FullText; | ||
break; | ||
case "split": | ||
Options = Options | ImportOptions.Split; | ||
break; | ||
case "gui": | ||
Options = Options | ImportOptions.GUI; | ||
break; | ||
default: | ||
unparsed.Add(args[i].Trim()); | ||
break; | ||
} | ||
} | ||
|
||
// unparsed args MUST be sites | ||
// if no sites specified, get them all | ||
if (unparsed.Count == 0 && !string.IsNullOrEmpty(Source)) | ||
{ | ||
unparsed = GetAllSites(Source); | ||
} | ||
|
||
Targets = GetTargets(Source, unparsed); | ||
} | ||
|
||
private void SetDefaults() | ||
{ | ||
Targets = new List<ImportTarget>(); | ||
BatchSize = DefaultBatchSize; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// /*! | ||
// * Project: SODDI v.10 | ||
// * http://skysanders.net/tools/se/ | ||
// * | ||
// * Copyright 2010, Sky Sanders | ||
// * Dual licensed under the MIT or GPL Version 2 licenses. | ||
// * http://skysanders.net/tools/se/LICENSE.TXT | ||
// * | ||
// * Date: April 01 2010 | ||
// */ | ||
|
||
#region | ||
|
||
using System; | ||
using System.Data; | ||
using System.Data.Common; | ||
|
||
#endregion | ||
|
||
namespace Salient.StackExchange.Import.Configuration | ||
{ | ||
public class DbProviderInfo | ||
{ | ||
public DbProviderInfo(DataRow prov) | ||
{ | ||
Name = (string) prov["Name"]; | ||
Description = (string) prov["Description"]; | ||
InvariantName = (string) prov["InvariantName"]; | ||
AssemblyQualifiedName = (string) prov["AssemblyQualifiedName"]; | ||
|
||
Factory = DbProviderFactories.GetFactory(prov); | ||
} | ||
|
||
public string Name { get; set; } | ||
public string Description { get; set; } | ||
public string InvariantName { get; set; } | ||
public string AssemblyQualifiedName { get; set; } | ||
public Type BulkInsertType { get; set; } | ||
public DbProviderFactory Factory { get; private set; } | ||
public String ConnectionString { get; set; } | ||
} | ||
} |
Oops, something went wrong.