Skip to content

Instantly share code, notes, and snippets.

@Zabaa
Created August 23, 2016 20:04
Show Gist options
  • Save Zabaa/d7c7617793abdeaf6c56aa3ecd7c9774 to your computer and use it in GitHub Desktop.
Save Zabaa/d7c7617793abdeaf6c56aa3ecd7c9774 to your computer and use it in GitHub Desktop.
<#@ template language="C#" #>
<#@ output extension=".sql" #>
<#@ assembly name="$(ProjectDir)bin\Debug\SiepaczeKoduSample.Infrastructure.dll" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="SiepaczeKoduSample.Infrastructure" #>
<#
IList<Dictionary> dictionary = TemplateHelper.GetDictionary(@"C:\Users\Zaba\Pictures\SiepaczeKodu\Dictionary.csv");
#>
<#foreach (var item in dictionary)
{
#>
IF NOT EXISTS (SELECT TOP 1 * FROM dbo.Dictionary WHERE [key] = '<#= item.Key #>')
INSERT INTO dbo.Dictionary ([key], [value], [description]) VALUES ( '<#= item.Key #>', '<#= item.Value #>', '<#= item.Description #>')
GO
<#
}
#>
public class TemplateHelper
{
public static IList<Dictionary> GetDictionary(string filePath)
{
IList<Dictionary> dictionary;
var csvConfiguration = new CsvConfiguration
{
Encoding = Encoding.UTF8,
CultureInfo = new System.Globalization.CultureInfo("pl-PL")
};
using (StreamReader reader = File.OpenText(filePath))
{
using(var csv = new CsvReader(reader, csvConfiguration))
{
dictionary = csv.GetRecords<Dictionary>().ToList();
}
}
return dictionary;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment