Skip to content

Instantly share code, notes, and snippets.

View talkingdotnet's full-sized avatar

Talking Dotnet talkingdotnet

View GitHub Profile
public static void SetBoolean(this ISession session, string key, bool value)
{
session.Set(key, BitConverter.GetBytes(value));
}
public static bool? GetBoolean(this ISession session, string key)
{
var data = session.Get(key);
if (data == null)
{
private void PrepareZip(string filePath)
{
FileInfo gZipfile = new FileInfo(filePath);
FileInfo gzipFileName = new FileInfo(string.Concat(gZipfile.FullName, ".gz"));
using (FileStream fileToBeZippedAsStream = gZipfile.OpenRead())
{
using (FileStream gzipTargetAsStream = gzipFileName.Create())
{
using (GZipStream gzipStream = new GZipStream(gzipTargetAsStream, CompressionMode.Compress))
{
private DataTable FetchData(string tableName)
{
using (SqlConnection conn = new SqlConnection(_connectionString))
{
string sQuery = "SELECT * FROM [" + tableName + "]";
using (SqlCommand command = new SqlCommand(sQuery, conn))
{
conn.Open();
command.CommandTimeout = 180;
DataAdapter da = new SqlDataAdapter(command);
private string _connectionString = "";
private string _directoryPath = "";
public DataExtractor(IConfigurationRoot config)
{
_connectionString = config["AppSettings:SQLConnectionString"];
_directoryPath = config["AppSettings:SourceDirectoryPath"];
}
{
"AppSettings": {
"SQLConnectionString": "Server=localhost; Database=SampleDB;user=sa;password=pass@123;Trusted_Connection=False;",
"SourceDirectoryPath": "C:\\Temp",
}
}
public void ExtractData()
{
try
{
DataTable dtList = GetTableList();
DataSet ds = new DataSet();
foreach (DataRow row in dtList.Rows)
{
string tableName = row[0].ToString();
DataTable dtData = FetchData(tableName);
private DataTable GetTableList()
{
DataTable dt;
string sQuery = @"SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'";
using (SqlConnection conn = new SqlConnection(_connectionString))
{
using (SqlCommand command = new SqlCommand(sQuery, conn))
{
conn.Open();
DataAdapter da = new SqlDataAdapter(command);
private object ConvertDataTypes(object col)
{
if (col == null)
return "NULL";
switch (col.GetType().FullName)
{
case "System.Int16":
case "System.Int32":
case "System.Int64":
private string UnZipFile(string filePath)
{
string unZippedFileName = "";
FileInfo fileToDecompress = new FileInfo(filePath);
try
{
using (FileStream originalFileStream = fileToDecompress.OpenRead())
{
string currentFileName = fileToDecompress.FullName;
unZippedFileName = currentFileName.Remove(currentFileName.Length - fileToDecompress.Extension.Length);
private DataSet DeserializeDataset(string filePath)
{
DataSet ds = new DataSet();
try
{
ds.ReadXmlSchema(filePath);
ds.ReadXml(filePath, XmlReadMode.IgnoreSchema);
WriteToConsole("Dataset deserialized successfully.");
}
catch (Exception ex)