This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private object ConvertDataTypes(object col) | |
{ | |
if (col == null) | |
return "NULL"; | |
switch (col.GetType().FullName) | |
{ | |
case "System.Int16": | |
case "System.Int32": | |
case "System.Int64": |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"AppSettings": { | |
"SQLConnectionString": "Server=localhost; Database=SampleDB;user=sa;password=pass@123;Trusted_Connection=False;", | |
"SourceDirectoryPath": "C:\\Temp", | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private string _connectionString = ""; | |
private string _directoryPath = ""; | |
public DataExtractor(IConfigurationRoot config) | |
{ | |
_connectionString = config["AppSettings:SQLConnectionString"]; | |
_directoryPath = config["AppSettings:SourceDirectoryPath"]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | |
{ |