Ejemplo n.º 1
0
//This function was added to CGrandDataFile to recursively retrieve a list of *.BID files in
//a directory.  It reads the file header to populate the CList of tFileRecords that is converted to
//a safe array used by ImportManager.  This was flagrantly stolen from Kelly Michel and modified to
//search for and read in *.BID files. hn 6/8/2005
// 5-Jul-2005 SFK Removed dead code for readability
// 11-Jul-2005 SFK	Copied from GRAND Import and modified for binary
void CBinaryDataFile::GetCompleteFileList(short FacilityID, CList<tFileRecord, tFileRecord> *pFileList, 
									   const CString& Directory,  bool IncludeSubdirs)
{
	//USES_CONVERSION;

	CFileFind Finder;
	BOOL bWorking;
	CString  FileName;
	tFileRecord FileRecord;

	CString DirWithFileMask;
	DirWithFileMask.Format("%s\\*.*", Directory);
	bWorking = Finder.FindFile(DirWithFileMask);

	
	//If this is an "archive" directory, then skip it completely, and everything that may be underneath it.
	int StartSubDirName = Directory.ReverseFind('\\');
	if(StartSubDirName != -1)
	{
		CString SubDirName = Directory.Mid(StartSubDirName + 1);
		if(SubDirName.CompareNoCase("Archive")) //If SubDirName is not Archive...
		{
			do
			{
				bWorking = Finder.FindNextFile();
				
				if(!Finder.IsDots())
				{
					if(Finder.IsDirectory() && IncludeSubdirs)
					{
						//Recurse.
						GetCompleteFileList(FacilityID, pFileList, Finder.GetFilePath(), IncludeSubdirs);
					}
					else //if(Finder.IsNormal())
					{
 						FileName = Finder.GetFileName(); 
						CString Ext = FileName.Mid(FileName.GetLength() - 3, 3);
						if(!Ext.CompareNoCase("BNY"))
						{
							FileRecord.File.bstrVal = (Finder.GetFilePath()).AllocSysString();

							//****************************************************************
							//Open the file and get info on the data in the file.  Load that
							//file data into the FileRecord structure.
							//****************************************************************
							CString err;
							//If we are not able to read the *.BNY header, we fail
							CString cs(FileRecord.File.bstrVal);
							if (!ReadHeader (cs,&err))
							//if (!ReadHeader (W2T(FileRecord.File.bstrVal),&err))
							{
								if (mpFile) CloseDataFile();
							}
							else
							//Otherwise, save the file date and station ID read.
							{
								SYSTEMTIME sysTime;
								COleDateTime fileDate = GetFileDate ();
								fileDate.GetAsSystemTime (sysTime);
								SystemTimeToVariantTime (&sysTime,&FileRecord.Date.date);
								FileRecord.StationID.lVal = (long) GetStationID ();
								pFileList->AddTail (FileRecord);
								CloseDataFile ();
							}
						}
					}
				}		
			}
			while(bWorking != 0);
		}
	}

}
Ejemplo n.º 2
0
CLogManager::CLogManager()
{
	uint32 nVal;
	const char* s;

	//FocpLogFileSize
	s = GetEnvVar("FocpLogFileSize");
	nVal = FOCP_LOG_MAXFILE;
	if(s)
	{
		nVal = atoi(s);
		if(nVal < FOCP_LOG_MINFILE)
			nVal = FOCP_LOG_MINFILE;
		else if(nVal > FOCP_LOG_MAXFILE)
			nVal = FOCP_LOG_MAXFILE;
	}
	m_nLogFileSize = nVal*1048576;

	//FocpLogFileSize
	s = GetEnvVar("FocpLogFileNo");
	nVal = FOCP_LOG_FILENO;
	if(s)
	{
		nVal = atoi(s);
		if(nVal < 9)
			nVal = 9;
		else if(nVal > FOCP_LOG_FILENO)
			nVal = FOCP_LOG_FILENO;
	}
	m_nLogFileNo = nVal;

	m_nDmn = 0;
	m_nAin = 0;
	m_sHostIp[0] = '\0';
	GetHostIpList(m_sHostIp);

	m_bHold = true;

	m_bLocked = false;

	char sDate[20];
	GetFileDate(sDate);
	GetProgramFileName(m_sHome);
	m_sApp = GetAppName(m_sHome);
	GetAppHome(m_sHome, m_sApp);
	sprintf(m_sName, "%s%s", m_sApp, sDate);

	m_pFile = NULL;
	m_nFileId = 0;

	m_nSocket = socket(AF_INET, SOCK_DGRAM, 0);

	//FocpLogServerPort
	uint16 nPort = 2269;
	s = GetEnvVar("FocpLogServerPort");
	if(s)
	{
		nVal = atoi(s);
		if(nVal && nVal <= 65535)
			nPort = (uint16)nVal;
	}

	uint32 nAddr;
	s =  GetEnvVar("FocpLogServerAddr");
	if(s)
	{
		nAddr = inet_addr(s);
		if(nAddr == (uint32)(-1))
		{
			m_oMutex.Enter();
			struct hostent *hptr = gethostbyname(s);
			if(hptr)
				nAddr = *(uint32*)(hptr->h_addr_list[0]);
			else
				nAddr = inet_addr("127.0.01");
			m_oMutex.Leave();
		}
	}
	else
		nAddr = inet_addr("127.0.0.1");

	m_oServerAddr.sin_family = AF_INET;
	m_oServerAddr.sin_port = htons(nPort);
	m_oServerAddr.sin_addr.s_addr = nAddr;
}