forked from DbUp/DbUp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request DbUp#81 from dia0369/master
Support for selection of sql file encoding
- Loading branch information
Showing
4 changed files
with
203 additions
and
98 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
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 |
---|---|---|
@@ -1,73 +1,75 @@ | ||
| ||
using System.IO; | ||
using System.Text; | ||
|
||
namespace DbUp.Engine | ||
{ | ||
/// <summary> | ||
/// Represents a SQL Server script that comes from an embedded resource in an assembly. | ||
/// </summary> | ||
public class SqlScript | ||
{ | ||
private readonly string contents; | ||
private readonly string name; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="SqlScript"/> class. | ||
/// </summary> | ||
/// <param name="name">The name.</param> | ||
/// <param name="contents">The contents.</param> | ||
public SqlScript(string name, string contents) | ||
{ | ||
this.name = name; | ||
this.contents = contents; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the contents of the script. | ||
/// </summary> | ||
/// <value></value> | ||
public virtual string Contents | ||
{ | ||
get { return contents; } | ||
} | ||
|
||
/// <summary> | ||
/// Gets the name of the script. | ||
/// </summary> | ||
/// <value></value> | ||
public string Name | ||
{ | ||
get { return name; } | ||
} | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="path"></param> | ||
/// <returns></returns> | ||
public static SqlScript FromFile(string path) | ||
{ | ||
using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read)) | ||
{ | ||
var fileName = new FileInfo(path).Name; | ||
return FromStream(fileName, fileStream); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="scriptName"></param> | ||
/// <param name="stream"></param> | ||
/// <returns></returns> | ||
public static SqlScript FromStream(string scriptName, Stream stream) | ||
{ | ||
using (var resourceStreamReader = new StreamReader(stream, Encoding.Default, true)) | ||
{ | ||
string c = resourceStreamReader.ReadToEnd(); | ||
return new SqlScript(scriptName, c); | ||
} | ||
} | ||
} | ||
| ||
using System.IO; | ||
using System.Text; | ||
|
||
namespace DbUp.Engine | ||
{ | ||
/// <summary> | ||
/// Represents a SQL Server script that comes from an embedded resource in an assembly. | ||
/// </summary> | ||
public class SqlScript | ||
{ | ||
private readonly string contents; | ||
private readonly string name; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="SqlScript"/> class. | ||
/// </summary> | ||
/// <param name="name">The name.</param> | ||
/// <param name="contents">The contents.</param> | ||
public SqlScript(string name, string contents) | ||
{ | ||
this.name = name; | ||
this.contents = contents; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the contents of the script. | ||
/// </summary> | ||
/// <value></value> | ||
public virtual string Contents | ||
{ | ||
get { return contents; } | ||
} | ||
|
||
/// <summary> | ||
/// Gets the name of the script. | ||
/// </summary> | ||
/// <value></value> | ||
public string Name | ||
{ | ||
get { return name; } | ||
} | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="path"></param> | ||
/// <param name="encoding"></param> | ||
/// <returns></returns> | ||
public static SqlScript FromFile(string path, Encoding encoding) | ||
{ | ||
using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read)) | ||
{ | ||
var fileName = new FileInfo(path).Name; | ||
return FromStream(fileName, fileStream, encoding); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="scriptName"></param> | ||
/// <param name="stream"></param> | ||
/// <param name="encoding"></param> | ||
/// <returns></returns> | ||
public static SqlScript FromStream(string scriptName, Stream stream, Encoding encoding) | ||
{ | ||
using (var resourceStreamReader = new StreamReader(stream, encoding, true)) | ||
{ | ||
string c = resourceStreamReader.ReadToEnd(); | ||
return new SqlScript(scriptName, c); | ||
} | ||
} | ||
} | ||
} |
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