-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace Northwind database with scripts
- Loading branch information
1 parent
d046f92
commit 6f4e16c
Showing
21 changed files
with
142 additions
and
17 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -16,5 +16,5 @@ _[Ss]cripts | |
*.psess | ||
*.orig | ||
*.pdb | ||
TrippinDB.mdf | ||
TrippinDB_log.ldf | ||
*.mdf | ||
*.ldf |
Binary file not shown.
Binary file removed
BIN
-3.38 MB
src/Microsoft.Restier.Samples.Northwind.EF7/App_Data/Northwind_log.ldf
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
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
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
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
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
95 changes: 95 additions & 0 deletions
95
src/Microsoft.Restier.Samples.Northwind/Models/SqlLoader.cs
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,95 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Microsoft.Restier.Samples.Northwind.Models | ||
{ | ||
internal class SqlLoader | ||
{ | ||
private static readonly string[] possibleSqlCmdExePaths = | ||
{ | ||
@"%ProgramFiles%\Microsoft SQL Server\110\Tools\Binn\SQLCMD.EXE", | ||
@"%ProgramW6432%\Microsoft SQL Server\110\Tools\Binn\SQLCMD.EXE", | ||
@"%ProgramFiles%\Microsoft SQL Server\120\Tools\Binn\SQLCMD.EXE", | ||
@"%ProgramW6432%\Microsoft SQL Server\120\Tools\Binn\SQLCMD.EXE" | ||
}; | ||
|
||
private readonly IList<KeyValuePair<string, string>> _options = new List<KeyValuePair<string, string>>(); | ||
|
||
public void SetDatabaseEngine(string dbName) | ||
{ | ||
AddOption("-S", dbName); | ||
} | ||
|
||
public void AddScriptArgument(string argName, string argValue) | ||
{ | ||
AddOption("-v", string.Format("{0}=\"{1}\"", argName, argValue)); | ||
} | ||
|
||
public void AddScript(string scriptName) | ||
{ | ||
AddOption("-i", scriptName); | ||
} | ||
|
||
public void Reset() | ||
{ | ||
_options.Clear(); | ||
} | ||
|
||
public void Execute(string workingDirectory) | ||
{ | ||
var sqlCmdExePath = possibleSqlCmdExePaths.Select(Environment.ExpandEnvironmentVariables).First(File.Exists); | ||
|
||
var argumentStringBuilder = new StringBuilder(); | ||
foreach (var option in _options) | ||
{ | ||
argumentStringBuilder.Append(string.Format("{0} {1} ", option.Key, option.Value)); | ||
} | ||
|
||
var start = new ProcessStartInfo() | ||
{ | ||
FileName = sqlCmdExePath, | ||
WorkingDirectory = workingDirectory, | ||
Arguments = argumentStringBuilder.ToString(), | ||
UseShellExecute = false, | ||
CreateNoWindow = true | ||
}; | ||
|
||
Process.Start(start).WaitForExit(); | ||
} | ||
|
||
public static string GetDatabaseDirectory(string subDir) | ||
{ | ||
var dataDirectory = AppDomain.CurrentDomain.GetData("DataDirectory") as string; | ||
if (string.IsNullOrEmpty(dataDirectory)) | ||
{ | ||
dataDirectory = Environment.CurrentDirectory; | ||
} | ||
|
||
if (!string.IsNullOrEmpty(subDir)) | ||
{ | ||
dataDirectory = Path.Combine(dataDirectory, subDir); | ||
} | ||
|
||
return AddTrailingSlash(dataDirectory); | ||
} | ||
|
||
private void AddOption(string key, string value) | ||
{ | ||
_options.Add(new KeyValuePair<string, string>(key, value)); | ||
} | ||
|
||
private static string AddTrailingSlash(string path) | ||
{ | ||
if (path.EndsWith("\\")) | ||
{ | ||
return path; | ||
} | ||
|
||
return path + "\\"; | ||
} | ||
} | ||
} |
Binary file removed
BIN
-5.38 MB
test/Microsoft.Restier.Samples.Northwind.EF7.Tests/App_Data/Northwind.mdf
Binary file not shown.
Binary file removed
BIN
-3.38 MB
test/Microsoft.Restier.Samples.Northwind.EF7.Tests/App_Data/Northwind_log.ldf
Binary file not shown.
Binary file added
BIN
+3.45 MB
test/Microsoft.Restier.Samples.Northwind.EF7.Tests/App_Data/instnwdb.sql
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
Binary file removed
BIN
-5.38 MB
test/Microsoft.Restier.Samples.Northwind.Tests/App_Data/Northwind.mdf
Binary file not shown.
Binary file removed
BIN
-3.38 MB
test/Microsoft.Restier.Samples.Northwind.Tests/App_Data/Northwind_log.ldf
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