public static void GeneratePendingRequestsCSV_MarkAsPaid_AndReturn(GridView gridview, bool markAsPaid = true) { string fileName = "PendingPayoutsRequestsExport_" + AppSettings.ServerTime.ToString("yyyy_MM_dd") + ".csv"; try { string content = DBArchiverAPI.ExportToCSVString( @"SELECT pr.PaymentAddress, pr.Amount, pr.Username, FORMAT(pr.RequestDate,'MM/dd/yyyy') AS [RequestDate], pr.PaymentProcessor FROM [PayoutRequests] AS pr " + GetPayoutRequestsSQLConditions() + " ORDER BY pr.[RequestDate] DESC"); if (markAsPaid) { MarkAllRequestsAsPaid(); } HttpContext.Current.Response.Clear(); HttpContext.Current.Response.Buffer = true; HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + fileName); HttpContext.Current.Response.Charset = ""; HttpContext.Current.Response.ContentType = "application/text"; HttpContext.Current.Response.Output.Write(content); HttpContext.Current.Response.Flush(); HttpContext.Current.Response.End(); } catch (Exception ex) { ErrorLogger.Log("Error while exporting CSV to file: " + ex.Message); throw new MsgException(ex.Message); } }
protected static void ArchiveHistoryLogs() { DateTime date = DateTime.Now.AddDays(-AppSettings.DBArchiver.HistoryLogsKeptForDays); string wherePart = "WHERE Date < '" + date.ToDBString() + "'"; //Archive to file string archiveQuery = "SELECT * FROM History " + wherePart; DBArchiverAPI.ExportToCSV(archiveQuery, date, HistoryFileName); //Delete from DB string deleteQuery = "DELETE FROM History " + wherePart; using (var bridge = ParserPool.Acquire(Database.Client)) { bridge.Instance.ExecuteRawCommandNonQuery(deleteQuery); } }
protected static void ArchiveOfferwallsLogs() { DateTime date = DateTime.Now.AddDays(-AppSettings.DBArchiver.OfferwallsLogsKeptForDays); string wherePart = "WHERE DateAdded < '" + date.ToDBString() + "'"; int recordsInEachBatch = 8000; int batches = (int)TableHelper.SelectScalar("SELECT COUNT(*) FROM OfferwallsLogs " + wherePart) / recordsInEachBatch; string archiveQuery = "SELECT TOP " + recordsInEachBatch + " * FROM OfferwallsLogs " + wherePart; string deleteQuery = string.Format(@"WITH CTE AS ({0}) DELETE FROM CTE", archiveQuery); for (int i = 0; i < batches; i++) { //Archive to file DBArchiverAPI.ExportToCSV(archiveQuery, date, OfferwallsLogsFileName, i); //Delete from DB using (var bridge = ParserPool.Acquire(Database.Client)) { bridge.Instance.ExecuteRawCommandNonQuery(deleteQuery); } } }
public static void GenerateAndReturn() { string fileName = "EmailExport_" + AppSettings.ServerTime.ToString("yyyy_MM_dd") + ".csv"; try { string content = DBArchiverAPI.ExportToCSVString("SELECT firstname, secondname, username, email, country FROM users", false); HttpContext.Current.Response.Clear(); HttpContext.Current.Response.Buffer = true; HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + fileName); HttpContext.Current.Response.Charset = ""; HttpContext.Current.Response.ContentType = "application/text"; HttpContext.Current.Response.Output.Write(content); HttpContext.Current.Response.Flush(); HttpContext.Current.Response.End(); } catch (Exception ex) { ErrorLogger.Log("Error while exporting CSV to file: " + ex.Message); throw new MsgException(ex.Message); } }