Skip to content

Commit e657a38

Browse files
Merge pull request #4 from Twinfield/EP-DEVLEAD-3700
[EP-DEVLEAD-3700] Use SqlBulkCopy to create snapshots and restore
2 parents 69a79e0 + 7b2685d commit e657a38

16 files changed

Lines changed: 612 additions & 1016 deletions

DataFresh.Common/AssemblyInfo.cs

Lines changed: 46 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,57 @@
11
using System.Reflection;
2-
using System.Runtime.CompilerServices;
3-
4-
//
5-
// General Information about an assembly is controlled through the following
6-
// set of attributes. Change these attribute values to modify the information
7-
// associated with an assembly.
8-
//
2+
3+
//
4+
// General Information about an assembly is controlled through the following
5+
// set of attributes. Change these attribute values to modify the information
6+
// associated with an assembly.
7+
//
98
[assembly: AssemblyTitle("")]
109
[assembly: AssemblyDescription("")]
1110
[assembly: AssemblyConfiguration("")]
1211
[assembly: AssemblyCompany("")]
1312
[assembly: AssemblyProduct("")]
1413
[assembly: AssemblyCopyright("")]
1514
[assembly: AssemblyTrademark("")]
16-
[assembly: AssemblyCulture("")]
17-
18-
//
19-
// Version information for an assembly consists of the following four values:
20-
//
21-
// Major Version
22-
// Minor Version
23-
// Build Number
24-
// Revision
25-
//
26-
// You can specify all the values or you can default the Revision and Build Numbers
27-
// by using the '*' as shown below:
28-
29-
[assembly: AssemblyVersion("1.0.*")]
30-
31-
//
32-
// In order to sign your assembly you must specify a key to use. Refer to the
33-
// Microsoft .NET Framework documentation for more information on assembly signing.
34-
//
35-
// Use the attributes below to control which key is used for signing.
36-
//
37-
// Notes:
38-
// (*) If no key is specified, the assembly is not signed.
39-
// (*) KeyName refers to a key that has been installed in the Crypto Service
40-
// Provider (CSP) on your machine. KeyFile refers to a file which contains
41-
// a key.
42-
// (*) If the KeyFile and the KeyName values are both specified, the
43-
// following processing occurs:
44-
// (1) If the KeyName can be found in the CSP, that key is used.
45-
// (2) If the KeyName does not exist and the KeyFile does exist, the key
46-
// in the KeyFile is installed into the CSP and used.
47-
// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility.
48-
// When specifying the KeyFile, the location of the KeyFile should be
49-
// relative to the project output directory which is
50-
// %Project Directory%\obj\<configuration>. For example, if your KeyFile is
51-
// located in the project directory, you would specify the AssemblyKeyFile
52-
// attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]
53-
// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework
54-
// documentation for more information on this.
55-
//
15+
[assembly: AssemblyCulture("")]
16+
17+
//
18+
// Version information for an assembly consists of the following four values:
19+
//
20+
// Major Version
21+
// Minor Version
22+
// Build Number
23+
// Revision
24+
//
25+
// You can specify all the values or you can default the Revision and Build Numbers
26+
// by using the '*' as shown below:
27+
28+
[assembly: AssemblyVersion("1.0.*")]
29+
30+
//
31+
// In order to sign your assembly you must specify a key to use. Refer to the
32+
// Microsoft .NET Framework documentation for more information on assembly signing.
33+
//
34+
// Use the attributes below to control which key is used for signing.
35+
//
36+
// Notes:
37+
// (*) If no key is specified, the assembly is not signed.
38+
// (*) KeyName refers to a key that has been installed in the Crypto Service
39+
// Provider (CSP) on your machine. KeyFile refers to a file which contains
40+
// a key.
41+
// (*) If the KeyFile and the KeyName values are both specified, the
42+
// following processing occurs:
43+
// (1) If the KeyName can be found in the CSP, that key is used.
44+
// (2) If the KeyName does not exist and the KeyFile does exist, the key
45+
// in the KeyFile is installed into the CSP and used.
46+
// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility.
47+
// When specifying the KeyFile, the location of the KeyFile should be
48+
// relative to the project output directory which is
49+
// %Project Directory%\obj\<configuration>. For example, if your KeyFile is
50+
// located in the project directory, you would specify the AssemblyKeyFile
51+
// attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]
52+
// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework
53+
// documentation for more information on this.
54+
//
5655
[assembly: AssemblyDelaySign(false)]
5756
[assembly: AssemblyKeyFile("")]
5857
[assembly: AssemblyKeyName("")]

DataFresh/AssemblyInfo.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
using System.Reflection;
2-
[assembly: AssemblyVersion("1.0.0.0")]
3-
[assembly: AssemblyTitleAttribute("dataFresh")]
4-
[assembly: DataFresh.AssemblyResourceEncrpytion(false)]
2+
[assembly: AssemblyVersion("2.0.0.0")]
3+
[assembly: AssemblyTitle("dataFresh")]

DataFresh/DataFresh.csproj

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,19 +90,15 @@
9090
<Compile Include="IDataFresh.cs">
9191
<SubType>Code</SubType>
9292
</Compile>
93-
<Compile Include="ResourceManagement.cs">
94-
<SubType>Code</SubType>
95-
</Compile>
9693
<Compile Include="SqlDataFresh.cs">
9794
<SubType>Code</SubType>
9895
</Compile>
9996
<Compile Include="SqlDataFreshException.cs">
10097
<SubType>Code</SubType>
10198
</Compile>
10299
<Content Include="Readme.txt" />
103-
<EmbeddedResource Include="Resources\PrepareDataFresh.sql" />
104-
<EmbeddedResource Include="Resources\RemoveDataFresh.sql" />
105100
</ItemGroup>
101+
<ItemGroup />
106102
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
107103
<PropertyGroup>
108104
<PreBuildEvent />

DataFresh/DataFreshConsole.cs

Lines changed: 57 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,43 @@
1-
// EntropyZero dataFresh Copyright (C) 2007 EntropyZero Consulting, LLC.
2-
// Please visit us on the web: http://blogs.ent0.com/
3-
//
4-
// This library is free software; you can redistribute it and/or modify
5-
// it under the terms of the GNU Lesser General Public License as
6-
// published by the Free Software Foundation; either version 2.1 of the
7-
// License, or (at your option) any later version.
8-
//
9-
// This library is distributed in the hope that it will be useful, but
10-
// WITHOUT ANY WARRANTY; without even the implied warranty of
11-
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12-
// Lesser General Public License for more details.
13-
//
14-
// You should have received a copy of the GNU Lesser General Public
15-
// License along with this library; if not, write to:
16-
// Free Software Foundation, Inc.,
17-
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18-
1+
// EntropyZero dataFresh Copyright (C) 2007 EntropyZero Consulting, LLC.
2+
// Please visit us on the web: http://blogs.ent0.com/
3+
//
4+
// This library is free software; you can redistribute it and/or modify
5+
// it under the terms of the GNU Lesser General Public License as
6+
// published by the Free Software Foundation; either version 2.1 of the
7+
// License, or (at your option) any later version.
8+
//
9+
// This library is distributed in the hope that it will be useful, but
10+
// WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
// Lesser General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Lesser General Public
15+
// License along with this library; if not, write to:
16+
// Free Software Foundation, Inc.,
17+
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18+
1919
using System;
2020
using System.Collections.Specialized;
21-
using System.IO;
2221
using System.Text;
2322

2423
namespace DataFresh
2524
{
2625
public class DataFreshConsole
2726
{
28-
private StringBuilder results = new StringBuilder();
29-
30-
public NameValueCollection arguments = new NameValueCollection();
31-
public string connectionString = string.Empty;
27+
readonly StringBuilder results = new StringBuilder();
3228

33-
public string Results
29+
public DataFreshConsole()
3430
{
35-
get { return results.ToString(); }
31+
ConnectionString = string.Empty;
32+
Arguments = new NameValueCollection();
3633
}
3734

35+
public string Results => results.ToString();
36+
37+
public NameValueCollection Arguments { get; }
38+
39+
public string ConnectionString { get; set; }
40+
3841
public void Start(string[] args)
3942
{
4043
ConsoleWrite("DataFresh provided by Entropy Zero Consulting");
@@ -45,55 +48,26 @@ public void Start(string[] args)
4548
return;
4649
}
4750

48-
for (int i = 0; i < args.Length; i = i + 2)
49-
{
50-
this.arguments.Add(args[i].Replace("-", ""), args[i + 1]);
51-
//ConsoleWrite(args[i] + ": " +args[i+1]);
52-
}
51+
for (var i = 0; i < args.Length; i += 2)
52+
Arguments.Add(args[i].Replace("-", ""), args[i + 1]);
5353

54-
if (!CheckForRequiredArguments(this.arguments))
54+
if (!CheckForRequiredArguments(Arguments))
5555
{
5656
return;
5757
}
5858

59-
connectionString = string.Format(@"user id={0};password={1};Initial Catalog={2};Data Source={3};",
60-
this.arguments["u"],
61-
this.arguments["p"],
62-
this.arguments["d"],
63-
this.arguments["s"]);
64-
65-
SqlDataFresh dataFresh = new SqlDataFresh(connectionString, true);
59+
ConnectionString =
60+
$@"user id={Arguments["u"]};password={Arguments["p"]};Initial Catalog={Arguments["d"]};Data Source={Arguments["s"]};";
6661

67-
string snapshotPath = this.arguments["sp"];
62+
var dataFresh = new SqlDataFresh(ConnectionString, true);
6863

69-
if (snapshotPath != null)
70-
{
71-
snapshotPath = snapshotPath.Replace("\"", "");
72-
if (!snapshotPath.EndsWith(@"\"))
73-
{
74-
snapshotPath += @"\";
75-
}
76-
77-
ConsoleWrite("snapshotPath = {0}", snapshotPath);
78-
string fullPath = Path.GetFullPath(snapshotPath);
79-
ConsoleWrite("fullPath = {0}", fullPath);
80-
dataFresh.SnapshotPath = new DirectoryInfo(snapshotPath);
81-
}
82-
83-
string command = this.arguments["c"].ToUpper();
64+
var command = Arguments["c"].ToUpper();
8465
switch (command)
8566
{
8667
case "PREPARE":
87-
bool ignoreSnapshot = false;
88-
string ignoreSnapshotArgument = arguments["ignoresnapshot"];
89-
if(ignoreSnapshotArgument != null)
90-
{
91-
if(ignoreSnapshotArgument == "1")
92-
{
93-
ignoreSnapshot = true;
94-
}
95-
}
96-
dataFresh.PrepareDatabaseforDataFresh(!ignoreSnapshot);
68+
var ignoreSnapshotArgument = Arguments["ignoresnapshot"];
69+
var ignoreSnapshot = (ignoreSnapshotArgument != null && ignoreSnapshotArgument == "1");
70+
dataFresh.PrepareDatabaseForDataFresh(!ignoreSnapshot);
9771
break;
9872
case "REFRESH":
9973
dataFresh.RefreshTheDatabase();
@@ -107,44 +81,39 @@ public void Start(string[] args)
10781
case "SNAPSHOT":
10882
dataFresh.CreateSnapshot();
10983
break;
110-
case "FOO":
111-
//no nothing
84+
case "FOO":
85+
//no nothing
11286
break;
11387
default:
11488
ConsoleWrite("Command '{0}' was not recognized", command);
11589
break;
11690
}
11791
}
11892

119-
private void ConsoleWrite(string message, params object[] args)
93+
void ConsoleWrite(string message, params object[] args)
12094
{
12195
results.AppendFormat(message, args);
12296
results.AppendFormat(Environment.NewLine);
12397

12498
Console.Out.WriteLine(message, args);
12599
}
126100

127-
private bool CheckForRequiredArguments(NameValueCollection myArgs)
101+
bool CheckForRequiredArguments(NameValueCollection myArgs)
128102
{
129-
if (
130-
myArgs == null ||
131-
myArgs["c"] == null ||
132-
myArgs["s"] == null ||
133-
myArgs["d"] == null ||
134-
myArgs["u"] == null ||
135-
myArgs["p"] == null
136-
)
137-
{
138-
ConsoleWrite("Missing required arguments.");
139-
WriteUsage();
140-
return false;
141-
}
142-
return true;
103+
if (myArgs?["c"] != null
104+
&& myArgs["s"] != null
105+
&& myArgs["d"] != null
106+
&& myArgs["u"] != null
107+
&& myArgs["p"] != null) return true;
108+
109+
ConsoleWrite("Missing required arguments.");
110+
WriteUsage();
111+
return false;
143112
}
144113

145-
private void WriteUsage()
114+
void WriteUsage()
146115
{
147-
string usageText = @"
116+
const string usageText = @"
148117
Usage:
149118
150119
DataFreshUtil.exe
@@ -156,7 +125,6 @@ private void WriteUsage()
156125
157126
Options:
158127
159-
-sp specify path on server where snapshot files are located
160128
-ignoresnapshot 1: ignore snapshot during prepare
161129
0: (default) will create snapshot
162130
@@ -174,7 +142,7 @@ SNAPSHOT create a snapshot of your database
174142

175143
public static DataFreshConsole Execute(string command, string username, string password, string server, string database, params string[] options)
176144
{
177-
string[] args = new string[]
145+
var args = new[]
178146
{
179147
"-c", command,
180148
"-u", username,
@@ -185,12 +153,12 @@ public static DataFreshConsole Execute(string command, string username, string p
185153

186154
if (options != null && options.Length > 1)
187155
{
188-
string argsString = string.Join("|", args);
189-
string optionsString = string.Join("|", options);
156+
var argsString = string.Join("|", args);
157+
var optionsString = string.Join("|", options);
190158
args = string.Format(argsString + "|" + optionsString).Split('|');
191159
}
192160

193-
DataFreshConsole console = new DataFreshConsole();
161+
var console = new DataFreshConsole();
194162
console.Start(args);
195163
return console;
196164
}

0 commit comments

Comments
 (0)