123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- //---------------------------------------------------------------------------
- #pragma hdrstop
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #include <assert.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <memory.h>
- #include <Systobj.h>
- #include <winsock.h>
- #include <time.h>
- #include <Buttons.hpp>
- #include <Classes.hpp>
- #include <ComCtrls.hpp>
- #include <Controls.hpp>
- #include <Chart.hpp>
- #include <DB.hpp>
- #include <DBClient.hpp>
- #include <DBGrids.hpp>
- #include <DBXpress.hpp>
- #include <Dialogs.hpp>
- #include <ExtCtrls.hpp>
- #include <FMTBcd.hpp>
- #include <Forms.hpp>
- #include <Graphics.hpp>
- #include <Grids.hpp>
- #include <jpeg.hpp>
- #include <Mask.hpp>
- #include <Menus.hpp>
- #include <Messages.hpp>
- #include <OleCtrls.hpp>
- #include <Outline.hpp>
- #include <Provider.hpp>
- #include <SqlExpr.hpp>
- #include <StdCtrls.hpp>
- #include <System.hpp>
- #include <SysUtils.hpp>
- #include <Types.hpp>
- #include <Windows.hpp>
- #include <inifiles.hpp>
- //---------------------------------------------------------------------------
- #include "AppGlobalF.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- //---------------------------------------------------------------------------
- /*
- ******************************************************************************
- * Global variables
- ******************************************************************************
- */
- APP_CONFIG g_AppCfg;
- LOG_INFO g_LogCfg;
- TITSLog *ITSLog = NULL;
- TITSLog *FDbLog = NULL;
- bool LOGIN_CHECK = false;
- bool LOAD_DB = false;
- /**
- * TODO: 20220816: 종료처리를 위해 플래그 추가
- **/
- bool APP_EXIT = false;
- SYSTEM_INFORMATION *g_SysInfo;
- //---------------------------------------------------------------------------
- bool APP_LoadConfigInfo()
- {
- String sCfgFile;
- TIniFile *pIniFile = NULL;
- sCfgFile = g_sCfgDir + g_sAppName + ".ini";
- g_AppCfg.sConfigFile = sCfgFile;
- DATABASE_INFO *pDb;
- try
- {
- String sTmp;
- pIniFile = new TIniFile(sCfgFile);
- g_AppCfg.sTitle = pIniFile->ReadString("APPLICATION", "TITLE", "VMS Communication Server");
- g_AppCfg.sSystemId = pIniFile->ReadString("APPLICATION", "SYSTEMID", "VMS01");
- g_AppCfg.sProcessId = pIniFile->ReadString("APPLICATION", "PROCESSID", "30101");
- g_AppCfg.nProcessId = g_AppCfg.sProcessId.ToIntDef(0);
- g_AppCfg.nProcessPort = pIniFile->ReadInteger("APPLICATION", "PROCESSPORT", 5301);;
- g_AppCfg.bSendCenterComm = false;
- g_AppCfg.DownloadBitmap = (bool)pIniFile->ReadInteger("APPLICATION", "DOWNLOADBITMAP", 0);
- LOGIN_CHECK = (bool)pIniFile->ReadInteger("APPLICATION", "LOGINCHECK", 1);
- LOAD_DB = pIniFile->ReadString("APPLICATION", "LOADDB", "1").ToIntDef(1) == 1 ? true : false;
- g_sFtpDir = pIniFile->ReadString("APPLICATION", "FTPHOMEDIR", g_sFtpDir);
- if (g_sFtpDir.SubString(g_sFtpDir.Length(), 1) != "\\")
- g_sFtpDir += "\\";
- g_AppCfg.sManagerApp= pIniFile->ReadString("APPLICATION", "MANAGERAPP", "");
- if (g_AppCfg.sManagerApp != "")
- {
- if (!FileExists(g_AppCfg.sManagerApp))
- {
- g_AppCfg.sManagerApp = "";
- }
- }
- g_AppCfg.nTrafficCycleTime = pIniFile->ReadInteger("APPLICATION", "TrafficCycleTime", 300);
- if (g_AppCfg.nTrafficCycleTime < 60) g_AppCfg.nTrafficCycleTime = 60;
- g_AppCfg.nTrafficBasisTime = pIniFile->ReadInteger("APPLICATION", "TrafficBasisTime", 60);
- g_AppCfg.nSaveFormType = pIniFile->ReadInteger("APPLICATION", "SaveFormType", 0);
- if (g_AppCfg.nSaveFormType < 0 || g_AppCfg.nSaveFormType > 2) g_AppCfg.nSaveFormType = 0;
- g_AppCfg.nDefaultFillColor = pIniFile->ReadInteger("APPLICATION", "DefaultFillColor", 0);
- g_AppCfg.MaxMemory = pIniFile->ReadInteger("RESOURCE", "MAXMEMORY", 512);
- g_AppCfg.MaxHandle = pIniFile->ReadInteger("RESOURCE", "MAXHANDLE", 0);
- g_AppCfg.MaxThread = pIniFile->ReadInteger("RESOURCE", "MAXTHREAD", 4096);
- g_AppCfg.MaxGdi = pIniFile->ReadInteger("RESOURCE", "MAXGDI", 0);
- g_AppCfg.RcRestart = (bool)pIniFile->ReadInteger("RESOURCE", "RESTART", 0);
- g_AppCfg.comm.nCenterPort = pIniFile->ReadInteger("COMMUNICATION", "CENTERPORT", 6000);
- g_AppCfg.comm.nListenPort = pIniFile->ReadInteger("COMMUNICATION", "LISTENPORT", 6020);
- g_AppCfg.comm.sLocalDomain = pIniFile->ReadString ("COMMUNICATION", "LOCALDOMAIN", "VMS_SERVER");
- g_AppCfg.comm.nClientPort = pIniFile->ReadInteger("COMMUNICATION", "CLIENTPORT", 355);
- g_AppCfg.comm.sLoginUser = pIniFile->ReadString ("COMMUNICATION", "LOGINUSER", "ysvms");
- g_AppCfg.comm.sLoginPswd = pIniFile->ReadString ("COMMUNICATION", "LOGINPSWD", "ysvms");
- g_AppCfg.comm.nConnectWait = pIniFile->ReadInteger("COMMUNICATION", "CONNECTWAIT", 60);
- g_AppCfg.comm.nCmdTimeOut = pIniFile->ReadInteger("COMMUNICATION", "CMDTIMEOUT", 5);
- g_AppCfg.comm.nWatchDogTime = pIniFile->ReadInteger("COMMUNICATION", "WATCHDOGTIME", 30);
- g_AppCfg.comm.nPollingTime = pIniFile->ReadInteger("COMMUNICATION", "POLLINGTIME", 20);
- if (g_AppCfg.comm.nPollingTime < 10) g_AppCfg.comm.nPollingTime = 10;
- if (g_AppCfg.comm.nPollingTime > 90) g_AppCfg.comm.nPollingTime = 90;
- g_AppCfg.nCenterCommLogLevel = pIniFile->ReadInteger("COMMUNICATION", "CenterCommLogLevel", 0);
- if (g_AppCfg.comm.nConnectWait < 30) g_AppCfg.comm.nConnectWait = 30;
- if (g_AppCfg.comm.nConnectWait > 60) g_AppCfg.comm.nConnectWait = 60;
- if (g_AppCfg.comm.nCmdTimeOut < 5) g_AppCfg.comm.nCmdTimeOut = 5;
- if (g_AppCfg.comm.nWatchDogTime < 30) g_AppCfg.comm.nWatchDogTime = 30;
- g_AppCfg.comm.nWatchDogTime += 5; // 5초정도를 더 추가해 준다(딜레이발생할 경우)
- pDb = &g_AppCfg.db;
- pDb->sProvider = pIniFile->ReadString("DATABASE", "PROVIDER", "");
- pDb->sServerName = pIniFile->ReadString("DATABASE", "SERVERNAME", "");
- pDb->sCatalog = pIniFile->ReadString("DATABASE", "CATALOG", "");
- pDb->sUserName = pIniFile->ReadString("DATABASE", "USERNAME", "");
- pDb->sPassword = pIniFile->ReadString("DATABASE", "PASSWORD", "");
- pDb->MakeConnString();
- try
- {
- g_AppCfg.nMaxLogLines = pIniFile->ReadInteger("LOG", "LOGLINE", 200);
- if (g_AppCfg.nMaxLogLines > 1000) g_AppCfg.nMaxLogLines = 1000;
- if (g_AppCfg.nMaxLogLines < 0) g_AppCfg.nMaxLogLines = 100;
- g_AppCfg.sLogDay = pIniFile->ReadString ("LOG", "LOGDAY", "");
- g_LogCfg.Info = (bool)pIniFile->ReadInteger("LOG", "INFO", 1);
- g_LogCfg.Data = (bool)pIniFile->ReadInteger("LOG", "DATA", 0);
- g_LogCfg.Error = (bool)pIniFile->ReadInteger("LOG", "ERROR", 1);
- g_LogCfg.Warning = (bool)pIniFile->ReadInteger("LOG", "WARNING", 1);
- g_LogCfg.Debug = (bool)pIniFile->ReadInteger("LOG", "DEBUG", 0);
- g_LogCfg.Detail = (bool)pIniFile->ReadInteger("LOG", "DETAIL", 0);
- g_LogCfg.Detail = 0;
- } catch(Exception &e) {}
- g_AppCfg.bThrExit = false;
- }
- __finally
- {
- if (pIniFile) delete pIniFile;
- pIniFile = NULL;
- }
- return true;
- }
- //---------------------------------------------------------------------------
- int ITSUtil_Trace(const char *lpszFormat, ...)
- {
- static HWND m_TraceHandle = 0;
- int nBuf;
- char szBuffer[4097];
- va_list args;
- DWORD dwError = GetLastError();
- if (m_TraceHandle == 0)
- {
- //m_TraceHandle = ::FindWindow(L"TFormTrace", NULL);
- //m_TraceHandle = FindWindow(NULL, (LPCTSTR)"Trace");
- m_TraceHandle = FindWindow(NULL, "TracePlus");
- }
- if (!m_TraceHandle)
- return -1;
- memset(szBuffer, 0x00, sizeof(szBuffer));
- va_start(args, lpszFormat);
- nBuf = vsprintf(szBuffer, lpszFormat, args);
- va_end(args);
- if (nBuf < 0) return -1;
- //wsprintf(szBuffer + strlen(szBuffer), "|14|%s|%d|%d|%d|%d|%s|%s", process, level, mode, color, m.line, m.func, m.file);
- //sprintf(szBuffer + strlen(szBuffer), "|14|%s|%d|%d|%d|%d|%s|%s", lpszFileName, 0, 3, 0, nLineNo, " ", lpszFileName);
- nBuf = strlen(szBuffer);
- COPYDATASTRUCT cds;
- cds.dwData = 0;
- cds.cbData = nBuf + 1;
- cds.lpData = (void *)szBuffer;
- int iLength = ::SendMessage(m_TraceHandle, WM_COPYDATA, (WPARAM)NULL, (LPARAM)&cds);
- if(iLength == 0)
- {
- m_TraceHandle = 0;
- dwError = GetLastError();
- }
- return 0;
- }
- //---------------------------------------------------------------------------
|