public void WriteData(T record) { string[] dataArray; bool isWriteHeader = false; if (!CommonMethods.IsFileExistsAndNotEmpty(_filePath) && _isHeaderAvailable && _headers != null) { isWriteHeader = true; } using (var reader = new StreamWriter(_filePath, true)) { if (isWriteHeader) { reader.WriteLine(string.Join(_delimeter, _headers)); } dataArray = DsvConverter.ModelToStringArray(record, _headers); reader.WriteLine(string.Join(_delimeter, dataArray)); reader.Close(); } _dsvReader?.AddDataRecord(dataArray); }
public void UploadTable(string connectionString, List <string> setupSql, Table tableInfo, DataTable uploadData, List <string> postSql) { string tempFile = Path.GetTempFileName() + ".csv"; try { DsvConverter.WriteDatableDsv(uploadData, tempFile, BulkUploadDelimiter); using (var connection = new MySqlConnection(connectionString)) { connection.Open(); foreach (var sql in setupSql) { connection.Execute(sql); } BulkCopy(connection, tableInfo.temp_name, tempFile); foreach (var sql in postSql) { connection.Execute(sql); } } } finally { if (File.Exists(tempFile)) { File.Delete(tempFile); } } }
public int BulkCopy(string connectionString, Table tableInfo, DataTable sourceTable) { string tempFile = Path.GetTempFileName() + ".csv"; try { DsvConverter.WriteDatableDsv(sourceTable, tempFile, BulkUploadDelimiter); using (var connection = new MySqlConnection(connectionString)) { connection.Open(); var recordsCount = BulkCopy(connection, tableInfo.temp_name, tempFile); return(recordsCount); } } finally { if (File.Exists(tempFile)) { File.Delete(tempFile); } } }
public void Refresh() { if (CommonMethods.IsFileExistsAndNotEmpty(_filePath)) { using (var reader = new StreamReader(_filePath)) { List <T> data = new List <T>(); int lineNumber = 0; while (!reader.EndOfStream) { lineNumber++; string line = reader.ReadLine(); string[] values = line.Split(new string[] { _delimeter }, StringSplitOptions.None); if (lineNumber == 1 && _isHeaderAvailableInFile) { if (Headers == null) { Headers = values; } } else { data.Add(DsvConverter.StringArrayToModel <T>(values, Headers)); } } _data = data; reader.Close(); } } else { _data = new List <T>(); } }
internal void AddDataRecord(string[] dataLine) { _data.Add(DsvConverter.StringArrayToModel <T>(dataLine, Headers)); }