static void Main(string[] args) { //upd 2018-04-22 if (args.Length < 1) { Console.WriteLine("Invalid arguments. Usage: "); Console.WriteLine("MySQLDumper DATABASE_NAME"); return; } string dbName = args[0]; Process proc = new Process(); ProcessStartInfo startInfo = new ProcessStartInfo(); string path = Environment.GetEnvironmentVariable("DB_BACKUPS_PATH"); string tm = CUtilTime.GeDateString(DateTime.Now); string dirName = String.Format("{0}\\{1}\\{2}\\{3}", path, DateTime.Now.Year.ToString("D4"), DateTime.Now.Month.ToString("D2"), tm); CUtil.CreateDirIfNotExist(dirName); if (Directory.Exists(dirName)) { Directory.CreateDirectory(dirName); } string tmCurrent = CUtilTime.GetDateTimeString(DateTime.Now); string fname = String.Format("{0}\\fulldump_{1}.sql", dirName, tmCurrent); startInfo.FileName = @"C:\Program Files\MySQL\MySQL Server 5.7\bin\mysqldump.exe"; startInfo.Arguments = String.Format(@"--user=root --password=profinvest --routines --complete-insert {0} --result-file {1}", dbName, fname); proc.StartInfo = startInfo; proc.Start(); }
private void GenerateBossReport() { Log("Step 5 - GenerateBossReport"); List <Dictionary <string, object> > sessions = _dbCommunicator.GetSessionsBossReportNotSent(_stockExchId); Log("Found sessions: " + sessions.Count); foreach (var session in sessions) { int idSession = (int)session["id"]; CReportDataBoss reportDataBoss = new CReportDataBoss(); reportDataBoss.SetSessionBeginEnd(session); DateTime currMonthBegin = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1); List <Dictionary <string, object> > dataMinMaxAccountOp = _dbCommunicator.GetMinMaxAccountOp(currMonthBegin); reportDataBoss.GenAccountsBeginEnd(dataMinMaxAccountOp); reportDataBoss.GenAllAccountsMoney(_dbCommunicator.GetAllAccountsMoneyCurrent()); reportDataBoss.GetAllAccountsSumsOfSession(_dbCommunicator.GetAllAccountsSumBySession(idSession)); reportDataBoss.GenWalletChange(_dbCommunicator.GetWalletChange()); _pdfGeneratorBoss = new CPDFGeneratorBoss(reportDataBoss); string dirName = GetDirectory(reportDataBoss.DtSessionEnd); CUtil.CreateDirIfNotExist(dirName); //changed 2018_03_20 //string filePathBossReport = dirName + "\\" + "propcompany.pdf"; string filePathBossReport = String.Format(@"{0}\propcompany_{1}_{2}_{3}_{4}-{5}-{6}.pdf", dirName, //0 reportDataBoss.DtSessionEnd.Year, //1 reportDataBoss.DtSessionEnd.Month.ToString("D2"), //2 reportDataBoss.DtSessionEnd.Day.ToString("D2"), //3 reportDataBoss.DtSessionEnd.Hour.ToString("D2"), //4 reportDataBoss.DtSessionEnd.Minute.ToString("D2"), //5 reportDataBoss.DtSessionEnd.Second.ToString("D2") //6 ); _pdfGeneratorBoss.GeneratePDFReport(filePathBossReport); List <Dictionary <string, object> > _listBosses = _dbCommunicator.GetBossReportList(); foreach (Dictionary <string, object> user in _listBosses) { string mail = (string)user["email"]; _mailer.SendMail(toAddress: mail, title: "Отчет проп-компании", stContent: "Высылаем отчет проп-компании", fileName: filePathBossReport); } _dbCommunicator.UpdateReportBossSent(idSession); Log("Successfully processed session " + idSession); } Log("GenerateBossReport was finished"); }
private void GenerateAccountsReports() { Log("GenerateAccountsReports was started"); //Get list of latest calcs for each trader which are were not report-processed. var lstLatestCalcedVM = _dbCommunicator.GetLatestCalcedVmData(_stockExchId); foreach (var dataLatestCalcedVMVal in lstLatestCalcedVM) { try { int currVmCalcId = (int)dataLatestCalcedVMVal["max_clearing_calced_vm_id"]; Log("Porocessing " + currVmCalcId); Log("Step 1 - preparing data for report"); var dataClearingCalsSummary = _dbCommunicator.GetPoslogClearingCalsSummary(currVmCalcId); if (IsDBNullCalcedVMVal(dataLatestCalcedVMVal) || IsDBNullSummaryVMVal(dataClearingCalsSummary[0])) { Log("Incorrect data. Continue."); continue; } CReportDataAccounts repDataAccounts = new CReportDataAccounts(_useRealServer, _client); repDataAccounts.GenStockExchResultsTable(StockExchName, dataLatestCalcedVMVal, dataClearingCalsSummary[0]); repDataAccounts.GenFooterTotalResultsTable(dataClearingCalsSummary[0]); var dataClearingCalsInstrumentsSummary = _dbCommunicator.GetPoslogClearingCalsInstrumentsSummary(currVmCalcId); repDataAccounts.GenDataInstrumentsResultsTable(dataClearingCalsInstrumentsSummary); var dataClearingCalsInstruments = _dbCommunicator.GetPoslogClearingCalsInstruments(currVmCalcId); //repData was set 2017-08-18 repDataAccounts.SetSessionBeginEnd(dataLatestCalcedVMVal); repDataAccounts.GenListVMDynamics(dataClearingCalsInstruments); var currentMonthOperations = _dbCommunicator.GetCurrentMonthOperations((int)dataLatestCalcedVMVal["account_trade_Id"], (DateTime)dataLatestCalcedVMVal["DtEnd"]); repDataAccounts.GenAccountOperationsTable(currentMonthOperations); // repData.SetSessionBeginEnd(dataLatestCalcedVMVal); // was before 2017-08-18 repDataAccounts.GenPoslogTable(dataClearingCalsInstruments); _pdfGeneratorAccounts = new CPDFGeneratorAccounts(repDataAccounts, _useRealServer, _stockExchId); string dirName = GetDirectory(repDataAccounts.DtSessionEnd); string filePath = dirName + "\\" + ((int)dataLatestCalcedVMVal["account_trade_Id"]).ToString("D3") + ".pdf"; CUtil.CreateDirIfNotExist(dirName); Log("Step 2 - generating PDF file"); _pdfGeneratorAccounts.GeneratePDFFile(filePath); Log("Step 3 - sending report by e-mail"); string stDt = ((DateTime)dataLatestCalcedVMVal["DtEnd"]).ToString("dd.MM.yyyy"); _mailer.SendMail( toAddress: dataLatestCalcedVMVal["email"].ToString(), title: "Торговый отчет за " + stDt, stContent: "Высылаем торговый отчет за " + stDt, fileName: filePath ); Log("Step 4 - updating send report flag"); _dbCommunicator.UpdateReportSent((int)dataLatestCalcedVMVal["max_clearing_calced_vm_id"]); } catch (Exception e) { Error("Error processing report", e); } } }