void OfflineLocalisationDialog::MakeLayout() { this->setWindowTitle("Offline Localisation"); QVBoxLayout *buttonsLayout = new QVBoxLayout(); QPushButton *openFileButton = new QPushButton("&Open Log..."); connect(openFileButton,SIGNAL(clicked()), this, SLOT(OpenLogFiles())); buttonsLayout->addWidget(openFileButton); QPushButton *runSimulationButton = new QPushButton("&Run simulation"); connect(runSimulationButton,SIGNAL(clicked()), this, SLOT(BeginSimulation())); buttonsLayout->addWidget(runSimulationButton); QPushButton *saveLogButton = new QPushButton("Save &Log..."); saveLogButton->setEnabled(false); connect(m_offline_loc,SIGNAL(SimDataChanged(bool)), saveLogButton, SLOT(setEnabled(bool))); connect(saveLogButton,SIGNAL(clicked()), this, SLOT(SaveAsLocalisationLog())); buttonsLayout->addWidget(saveLogButton); QPushButton *saveReportButton = new QPushButton("Save Report..."); saveReportButton->setEnabled(false); connect(m_offline_loc,SIGNAL(SimDataChanged(bool)), saveReportButton, SLOT(setEnabled(bool))); //connect(runSimulationButton,SIGNAL(pressed()), this, SLOT(BeginSimulation())); buttonsLayout->addWidget(saveReportButton); QVBoxLayout *displayLayout = new QVBoxLayout(); QLabel *fileLabel = new QLabel("Log files"); displayLayout->addWidget(fileLabel); m_fileListDisplay = new QTextBrowser(this); m_fileListDisplay->setWordWrapMode(QTextOption::NoWrap); displayLayout->addWidget(m_fileListDisplay); QHBoxLayout *overallLayout = new QHBoxLayout(); overallLayout->addLayout(buttonsLayout); overallLayout->addLayout(displayLayout,1); m_progressBar = new QProgressDialog("Runing localisation...","Cancel",0, m_offline_loc->NumberOfLogFrames(),this); m_progressBar->setWindowModality(Qt::WindowModal); m_progressBar->setValue(0); m_progressBar->setMinimumDuration(100); connect(m_offline_loc, SIGNAL(updateProgress(int,int)), this, SLOT(DiplayProgress(int,int))); connect(m_offline_loc, SIGNAL(finished()), this, SLOT(CompleteSimulation())); connect(m_progressBar, SIGNAL(canceled()), this, SLOT(CancelProgress())); connect(m_reader, SIGNAL(OpenLogFilesChanged(std::vector<QFileInfo>)), this, SLOT(SetOpenFileList(std::vector<QFileInfo>))); setLayout(overallLayout); }
void main(int argc, char *argv[]) { ifstream bcpInfile; // local import file holding records to bcp to x_import table int hndl; // file handle char szXfrFile[128]; // holds name of delimited import file char szTmpFile[128]; // holds name of renamed delimited import file char szXfrLocalFile[128]; // holds name of delimited import file with local dir prepended int intBcpCount; // number of rows bcp'd // Open import log and import error log files if ( !OpenLogFiles() ) return; if ( argc >= 7 ) szSystem = argv[7]; else szSystem = ""; // Check if user wants help or if incorrect args entered if ( !CheckArgs(argc, argv) ) return; // Create transfer filenames wsprintf(szXfrFile, "%s_cags.xfr", argv[7] ); wsprintf(szTmpFile, "%s_cags.yyy", argv[7] ); // Connect to database and init db structures if ( !DBConnect(argv[1], argv[2], argv[3]) ) return; // // Check if local wms_cags.xfr exists to BCP records into import table // wsprintf(szXfrLocalFile, "%s%s", "./transfer/", szXfrFile ); if ( FileSize(szXfrLocalFile) > -1 ) // file exists { // Open local wms_cags.xfr bcpInfile.open(szXfrLocalFile, ios::nocreate, filebuf::sh_none); if ( !bcpInfile.is_open() ) { // Failed open so get out and retry on next run errfile << ERROR_PREFIX << "failed to open bcp input file" << endl; return; } else { // Call bcp routines to move data from import file into x_import table // Note: If migrated to another RDBMS most changes will be to this function if ( (intBcpCount = BCPInRecords(bcpInfile, argv[7])) != -1 ) { // Delete local import file now that its records are in import table bcpInfile.close(); f_deletefile(szXfrLocalFile); logfile << INFO_PREFIX << "successfull BCP of " << intBcpCount << " records into import table" << endl; } else { // Failed bcp so don't delete and get out to retry on next run bcpInfile.close(); errfile << ERROR_PREFIX << "failed BCP of import file to import table" << endl; return; } } } else { if ( FileSize(szXfrLocalFile) == -1 ) logfile << WARNING_PREFIX << "no records to import from " << szXfrLocalFile << " this run" << endl; else errfile << ERROR_PREFIX << "error opening local import file " << szXfrLocalFile << endl; } // // Logon to ftp server to get remote wms_cags.xfr to be bcp'd next import run // hndl = ftp_login(argv[4], argv[5], argv[6], ""); if ( hndl == -1 ) { errfile << ERROR_PREFIX << "failed ftp_login" << endl; return; } // Set current remote transfer directory if ( ftp_cd(hndl, argv[8]) == -1 ) { errfile << ERROR_PREFIX << "failed ftp_cd to " << argv[8] << endl; return; } // Check for no left over records from prior import and new records to import if ( !ftp_exist(hndl, szTmpFile) && ftp_exist(hndl, szXfrFile) ) { // If so, then rename prior to ftp_get to prevent contention with remote site if ( ftp_rename(hndl, szXfrFile, szTmpFile) == -1 ) { // ftp_rename failed so just log message and try again next invocation errfile << ERROR_PREFIX << "failed ftp_remame of " << szXfrFile << " to " << szTmpFile << " will retry next run" << endl; return; } } // Check for either left over records or new records in tmp file to import if ( ftp_exist(hndl, szTmpFile) ) { // If so, then ftp them to local directory if ( ftp_get(hndl, szTmpFile, szXfrLocalFile) == -1 ) { // ftp_get failed so do nothing here and retry next invovation errfile << ERROR_PREFIX << "failed ftp_get of " << szTmpFile << " will retry next run" << endl; } else { if ( ftp_delete(hndl, szTmpFile) == -1 ) { // ftp_delete failed so delete local to prevent re-importing next invocation f_deletefile(szXfrLocalFile); errfile << ERROR_PREFIX << "failed ftp_delete of " << szTmpFile << endl; } else { // successfull FTP logfile << INFO_PREFIX << "successfull FTP from remote site to " << szXfrLocalFile << endl; } } } else logfile << WARNING_PREFIX << "no records to ftp from remote site this run" << endl; // Close opened objects if ( !logfile.is_open() ) logfile.close(); if ( !errfile.is_open() ) errfile.close(); dbexit(); // close database connection ftp_quit(hndl); // close ftp connection }