public static bool TryLoadMsflPriceInfo( string stockName, string stockSymbol, string strFilePath, out MSFL.MSFLPriceRecord[] msflPriceRecordArray ) { msflPriceRecordArray = new MSFL.MSFLPriceRecord[0]; if ( Directory.Exists( strFilePath ) == false ) return false; byte dirNumber = 0; int iErr = MSFL.MSFL1_OpenDirectory( strFilePath, ref dirNumber, MSFL.MSFL_DIR_FORCE_USER_IN ); if ( iErr != (int)MSFL.MSFL_ERR.MSFL_NO_ERR ) return false; MSFL.MSFLDirectoryStatus msflDirectoryStatus = new MSFL.MSFLDirectoryStatus(); msflDirectoryStatus.dwTotalSize = (uint)Marshal.SizeOf( msflDirectoryStatus ); iErr = MSFL.MSFL1_GetDirectoryStatus( dirNumber, string.Empty, ref msflDirectoryStatus ); if ( iErr != (int)MSFL.MSFL_ERR.MSFL_NO_ERR ) return false; if ( msflDirectoryStatus.bExists == false || msflDirectoryStatus.bOpen == false || msflDirectoryStatus.bMetaStockDir == false ) return false; MSFL.MSFLSecurityInfo msflSecurityInfo = new MSFL.MSFLSecurityInfo(); msflSecurityInfo.dwTotalSize = (uint)Marshal.SizeOf( msflSecurityInfo ); iErr = MSFL.MSFL1_GetFirstSecurityInfo( dirNumber, ref msflSecurityInfo ); while ( iErr == (int)MSFL.MSFL_ERR.MSFL_NO_ERR || iErr == (int)MSFL.MSFL_Messages.MSFL_MSG_LAST_SECURITY_IN_DIR ) { if ( msflSecurityInfo.szName == stockName && msflSecurityInfo.szSymbol == stockSymbol ) { iErr = MSFL.MSFL1_LockSecurity( msflSecurityInfo.hSecurity, MSFL.MSFL_LOCK_PREV_WRITE_LOCK ); if ( iErr != (int)MSFL.MSFL_ERR.MSFL_NO_ERR ) break; ushort wPriceRecCount = 0; iErr = MSFL.MSFL1_GetDataRecordCount( msflSecurityInfo.hSecurity, ref wPriceRecCount ); if ( iErr != (int)MSFL.MSFL_ERR.MSFL_NO_ERR ) break; if ( wPriceRecCount > 0 ) { iErr = MSFL.MSFL1_SeekBeginData( msflSecurityInfo.hSecurity ); if ( iErr != (int)MSFL.MSFL_ERR.MSFL_NO_ERR ) break; MSFL.DateTime sDateTime = new MSFL.DateTime(); msflPriceRecordArray = new MSFL.MSFLPriceRecord[wPriceRecCount]; iErr = MSFL.MSFL2_ReadMultipleRecs( msflSecurityInfo.hSecurity, msflPriceRecordArray, ref sDateTime, ref wPriceRecCount, (int)MSFL.MSFL_FIND.MSFL_FIND_USE_CURRENT_POS ); if ( iErr != (int)MSFL.MSFL_ERR.MSFL_NO_ERR ) break; // Unlock the security (we're done using it) iErr = MSFL.MSFL1_UnlockSecurity( msflSecurityInfo.hSecurity ); iErr = MSFL.MSFL1_CloseDirectory( dirNumber ); return true; } break; } if ( iErr == (int)MSFL.MSFL_Messages.MSFL_MSG_LAST_SECURITY_IN_DIR ) break; iErr = MSFL.MSFL1_GetNextSecurityInfo( msflSecurityInfo.hSecurity, ref msflSecurityInfo ); } MSFL.MSFL1_CloseDirectory( dirNumber ); return false; }
public static bool TryLoadMsflSecurityInfo( string strFilePath, out MSFL.MSFLSecurityInfo[] msflSecurityInfoArray ) { msflSecurityInfoArray = new MSFL.MSFLSecurityInfo[0]; if ( Directory.Exists( strFilePath ) == false ) return false; byte dirNumber = 0; int iErr = MSFL.MSFL1_OpenDirectory( strFilePath, ref dirNumber, MSFL.MSFL_DIR_FORCE_USER_IN ); if ( iErr != (int)MSFL.MSFL_ERR.MSFL_NO_ERR ) return false; MSFL.MSFLDirectoryStatus msflDirectoryStatus = new MSFL.MSFLDirectoryStatus(); msflDirectoryStatus.dwTotalSize = (uint)Marshal.SizeOf( msflDirectoryStatus ); iErr = MSFL.MSFL1_GetDirectoryStatus( dirNumber, string.Empty, ref msflDirectoryStatus ); if ( iErr != (int)MSFL.MSFL_ERR.MSFL_NO_ERR ) return false; if ( msflDirectoryStatus.bExists == false || msflDirectoryStatus.bOpen == false || msflDirectoryStatus.bMetaStockDir == false ) return false; List<MSFL.MSFLSecurityInfo> msflSecurityInfoList = new List<MSFL.MSFLSecurityInfo>(); MSFL.MSFLSecurityInfo msflSecurityInfo = new MSFL.MSFLSecurityInfo(); msflSecurityInfo.dwTotalSize = (uint)Marshal.SizeOf( msflSecurityInfo ); iErr = MSFL.MSFL1_GetFirstSecurityInfo( dirNumber, ref msflSecurityInfo ); while ( iErr == (int)MSFL.MSFL_ERR.MSFL_NO_ERR || iErr == (int)MSFL.MSFL_Messages.MSFL_MSG_LAST_SECURITY_IN_DIR ) { msflSecurityInfoList.Add( msflSecurityInfo ); if ( iErr == (int)MSFL.MSFL_Messages.MSFL_MSG_LAST_SECURITY_IN_DIR ) break; msflSecurityInfo = new MSFL.MSFLSecurityInfo(); msflSecurityInfo.dwTotalSize = (uint)Marshal.SizeOf( msflSecurityInfo ); iErr = MSFL.MSFL1_GetNextSecurityInfo( msflSecurityInfo.hSecurity, ref msflSecurityInfo ); } MSFL.MSFL1_CloseDirectory( dirNumber ); msflSecurityInfoArray = msflSecurityInfoList.ToArray(); return true; }