Skip to content

Instantly share code, notes, and snippets.

View talkingdotnet's full-sized avatar

Talking Dotnet talkingdotnet

View GitHub Profile
private bool DownloadFile(string url, string filePath)
{
bool bResult = true;
try
{
WebClient Client = new WebClient();
Client.DownloadFile(url, filePath);
WriteToConsole("File Downloaded successfully");
}
catch (Exception ex)
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)
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 object ConvertDataTypes(object col)
{
if (col == null)
return "NULL";
switch (col.GetType().FullName)
{
case "System.Int16":
case "System.Int32":
case "System.Int64":
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);
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);
{
"AppSettings": {
"SQLConnectionString": "Server=localhost; Database=SampleDB;user=sa;password=pass@123;Trusted_Connection=False;",
"SourceDirectoryPath": "C:\\Temp",
}
}
private string _connectionString = "";
private string _directoryPath = "";
public DataExtractor(IConfigurationRoot config)
{
_connectionString = config["AppSettings:SQLConnectionString"];
_directoryPath = config["AppSettings:SourceDirectoryPath"];
}
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 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))
{