Skip to content

Commit

Permalink
Merge pull request #2 from devlead/f/refactoring
Browse files Browse the repository at this point in the history
Inital delete support & refactoring
  • Loading branch information
devlead committed Apr 6, 2016
2 parents 05cc0a8 + d430b8f commit d724358
Show file tree
Hide file tree
Showing 15 changed files with 1,194 additions and 364 deletions.
1 change: 1 addition & 0 deletions build.cake
Expand Up @@ -66,6 +66,7 @@ Task("Build")
Information("Building {0}", solution);
MSBuild(solution, settings =>
settings.SetPlatformTarget(PlatformTarget.MSIL)
.UseToolVersion(MSBuildToolVersion.VS2015)
.WithProperty("TreatWarningsAsErrors","true")
.WithTarget("Build")
.SetConfiguration(configuration));
Expand Down
10 changes: 9 additions & 1 deletion build.ps1
Expand Up @@ -9,15 +9,23 @@ $TOOLS_DIR = Join-Path $PSScriptRoot "tools"
$NUGET_EXE = Join-Path $TOOLS_DIR "nuget.exe"
$CAKE_EXE = Join-Path $TOOLS_DIR "Cake/Cake.exe"

# Try download NuGet.exe if not exists
if (!(Test-Path $NUGET_EXE)) {
Invoke-WebRequest -Uri https://dist.nuget.org/win-x86-commandline/latest/nuget.exe -OutFile $NUGET_EXE
}

# Make sure NuGet exists where we expect it.
if (!(Test-Path $NUGET_EXE)) {
Throw "Could not find NuGet.exe"
}

# Save nuget.exe path to environment to be available to child processed
$ENV:NUGET_EXE = $NUGET_EXE

# Restore tools from NuGet.
Push-Location
Set-Location $TOOLS_DIR
Invoke-Expression "$NUGET_EXE install -ExcludeVersion"
Invoke-Expression "$NUGET_EXE install -ExcludeVersion -Source https://api.nuget.org/v3/index.json"
Pop-Location
if ($LASTEXITCODE -ne 0)
{
Expand Down
4 changes: 2 additions & 2 deletions src/SqlBulkSync/SqlBulkSync/App.config
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
</startup>
</configuration>
9 changes: 5 additions & 4 deletions src/SqlBulkSync/SqlBulkSync/Column.cs
@@ -1,10 +1,10 @@
// ----------------------------------------------------------------------------------------------
// Copyright (c) WCOM AB.
// ----------------------------------------------------------------------------------------------
// This source code is subject to terms and conditions of the Microsoft Public License. A
// copy of the license can be found in the LICENSE.md file at the root of this distribution.
// If you cannot locate the Microsoft Public License, please send an email to
// dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
// This source code is subject to terms and conditions of the Microsoft Public License. A
// copy of the license can be found in the LICENSE.md file at the root of this distribution.
// If you cannot locate the Microsoft Public License, please send an email to
// dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
// by the terms of the Microsoft Public License.
// ----------------------------------------------------------------------------------------------
// You must not remove this notice, or any other, from this software.
Expand All @@ -23,5 +23,6 @@ public class Column
public bool IsIdentity { get; set; }
public bool IsPrimary { get; set; }
public bool IsNullable { get; set; }
public string Collation { get; set; }
}
}
1,021 changes: 815 additions & 206 deletions src/SqlBulkSync/SqlBulkSync/Include_T4Include.cs

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions src/SqlBulkSync/SqlBulkSync/Include_T4Include.tt
@@ -1,25 +1,25 @@
<#
// Whenever this file is saved the files in the Includes section is downloaded
// from GitHub (you can download from other websources by changing rootpath)
RootPath = @"https://raw.github.com/";
RootPath = @"https://raw.githubusercontent.com/";
Namespace = "WCOM.SqlBulkSync" ; // The downloaded content is wrapped in this namespace
Includes = new []
{
// Include the basic extension from T4Include
Include (@"mrange/T4Include/master/Extensions/BasicExtensions.cs"),
Include (@"mrange/T4Include/master/Common/SubString.cs"),
Include (@"mrange/T4Include/master/Common/Array.cs"),
Include (@"mrange/T4Include/master/Extensions/ParseExtensions.cs"),
Include (@"mrange/T4Include/master/Extensions/EnumParseExtensions.cs"),
Include (@"mrange/T4Include/master/Reflection/StaticReflection.cs"),
Include (@"mrange/T4Include/master/Reflection/ClassDescriptor.cs"),
Include (@"mrange/T4Include/master/Common/Log.cs"),
Include (@"mrange/T4Include/master/Common/ConsoleLog.cs"),
Include (@"mrange/T4Include/master/Hron/HRONSerializer.cs"),
Include (@"mrange/T4Include/master/Hron/HRONObjectSerializer.cs"),
Include (@"wcomab/T4Include/master/Extensions/BasicExtensions.cs"),
Include (@"wcomab/T4Include/master/Common/SubString.cs"),
Include (@"wcomab/T4Include/master/Common/Array.cs"),
Include (@"wcomab/T4Include/master/Extensions/ParseExtensions.cs"),
Include (@"wcomab/T4Include/master/Extensions/EnumParseExtensions.cs"),
Include (@"wcomab/T4Include/master/Reflection/StaticReflection.cs"),
Include (@"wcomab/T4Include/master/Reflection/ClassDescriptor.cs"),
Include (@"wcomab/T4Include/master/Common/Log.cs"),
Include (@"wcomab/T4Include/master/Common/ConsoleLog.cs"),
Include (@"wcomab/T4Include/master/Hron/HRONSerializer.cs"),
Include (@"wcomab/T4Include/master/Hron/HRONObjectSerializer.cs"),

// Stackexchange Dapper
Include (@"StackExchange/dapper-dot-net/master/Dapper%20NET40/SqlMapper.cs"),
Include (@"StackExchange/dapper-dot-net/bf6404f5d0d7e7eb6f51169ff2672eea0142cb3e/Dapper%20NET40/SqlMapper.cs"),
};
#>

Expand Down
7 changes: 6 additions & 1 deletion src/SqlBulkSync/SqlBulkSync/Program.cs
Expand Up @@ -36,6 +36,11 @@ private static void Main(string[] args)
SyncRunner.Run(syncJobPath);
break;
}
case "PROCESS_GLOBAL_CHANGETRACKING":
{
SyncRunner.Run(globalChangeTracking: true, syncJobPath:syncJobPath);
break;
}
case "CREATETEMPLATE":
{
CreateTemplateFile(syncJobPath);
Expand Down Expand Up @@ -67,7 +72,7 @@ private static void Main(string[] args)
public static void Usage()
{
Log.Info(
"USAGE:\r\n\t{0} PROCESS|CREATETEMPLATE [SyncJobFilePath]",
"USAGE:\r\n\t{0} PROCESS|CREATETEMPLATE|PROCESS_GLOBAL_CHANGETRACKING [SyncJobFilePath]",
Path.GetFileName(Assembly.GetExecutingAssembly().Location)
);
}
Expand Down
34 changes: 22 additions & 12 deletions src/SqlBulkSync/SqlBulkSync/SchemaExtensions.cs
@@ -1,10 +1,10 @@
// ----------------------------------------------------------------------------------------------
// Copyright (c) WCOM AB.
// ----------------------------------------------------------------------------------------------
// This source code is subject to terms and conditions of the Microsoft Public License. A
// copy of the license can be found in the LICENSE.md file at the root of this distribution.
// If you cannot locate the Microsoft Public License, please send an email to
// dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
// This source code is subject to terms and conditions of the Microsoft Public License. A
// copy of the license can be found in the License.md file at the root of this distribution.
// If you cannot locate the Microsoft Public License, please send an email to
// dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
// by the terms of the Microsoft Public License.
// ----------------------------------------------------------------------------------------------
// You must not remove this notice, or any other, from this software.
Expand Down Expand Up @@ -53,7 +53,7 @@ public static void PersistsSourceTargetVersionState(this TableSchema tableSchema
targetStatePath = Path.Combine(
SyncStateDirectory.FullName,
Uri.EscapeDataString(
String.Concat(
string.Concat(
conn.DataSource,
"_",
conn.Database,
Expand Down Expand Up @@ -92,11 +92,12 @@ out errors
return tableVersion;
}

public static TableVersion GetSourceVersion(this SqlConnection conn, string tableName, Column[] columns)
public static TableVersion GetSourceVersion(this SqlConnection conn, string tableName, bool globalChangeTracking, Column[] columns)
{
var tableVersionStatement = SqlStatmentExtenstions.GetTableVersionStatement(tableName, columns);
var tableVersionStatement = SqlStatmentExtenstions.GetTableVersionStatement(tableName, globalChangeTracking, columns);
var result = conn.Query<TableVersion>(
tableVersionStatement
tableVersionStatement,
commandTimeout: 5000
).FirstOrDefault();
return result;
}
Expand All @@ -111,17 +112,26 @@ public static Column[] GetColumns(this IDbConnection sourceConn, string tableNam
c.is_identity AS IsIdentity ,
tn.IsPrimary AS IsPrimary ,
c.is_nullable AS IsNullable ,
QUOTENAME(c.Name) AS QuoteName
QUOTENAME(c.Name) AS QuoteName ,
c.collation_name AS Collation
FROM sys.columns c
INNER JOIN sys.types tp ON c.user_type_id = tp.user_type_id
CROSS APPLY (
SELECT CASE
WHEN tp.name IN('varchar', 'nvarchar')
WHEN tp.name IN('nvarchar')
THEN tp.name +
'(' +
CASE c.max_length
WHEN -1 THEN 'max'
ELSE CAST(c.max_length as nvarchar(max))
ELSE CAST(c.max_length / 2 as nvarchar(max))
END
+')'
WHEN tp.name IN('varchar')
THEN tp.name +
'(' +
CASE c.max_length
WHEN -1 THEN 'max'
ELSE CAST(c.max_length as varchar(max))
END
+')'
WHEN tp.name = 'decimal'
Expand All @@ -134,7 +144,7 @@ ELSE CAST(c.max_length as nvarchar(max))
ELSE tp.name
END AS Type,
CASE WHEN EXISTS(SELECT 1
FROM sys.indexes i
FROM sys.indexes i
INNER JOIN sys.index_columns ic ON i.object_id = ic.object_id AND
i.index_id = ic.index_id AND
c.column_id = ic.column_id
Expand Down
6 changes: 1 addition & 5 deletions src/SqlBulkSync/SqlBulkSync/SqlBulkSync.csproj
Expand Up @@ -9,11 +9,9 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>WCOM.SqlBulkSync</RootNamespace>
<AssemblyName>SqlBulkSync</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -24,7 +22,6 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -34,7 +31,6 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>wcom.ico</ApplicationIcon>
Expand Down

0 comments on commit d724358

Please sign in to comment.