public unsafe static void CompileMap(string strFilename, ref string strCompiledFilename) { m_lstErrorMsgs.Clear(); // start with an empty list of errors so we can detect them. int status = 0; FileStream fileMap = new FileStream(strFilename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); byte[] pTxt = new byte[fileMap.Length]; uint nMapSize = (uint)fileMap.Read(pTxt, 0, (int)fileMap.Length); byte * compiledTable = (byte *)0; UInt32 compiledSize = 0; errFunc dsplyErr = new errFunc(TECkitDllWrapper.DisplayCompilerError); byte[] baName = Encoding.ASCII.GetBytes(strFilename); fixed(byte *lpTxt = pTxt) fixed(byte *lpName = baName) status = TECkit_Compile( lpTxt, nMapSize, (byte)1, // docompression dsplyErr, lpName, &compiledTable, &compiledSize); // any errors occur? if (m_lstErrorMsgs.Count > 0) { // show the compiler errors, but limit it to some value. const int cnTeCkitCompilerMaxErrors = 20; string strErrs = null; int i = 0; int nUpperLimit = Math.Min(m_lstErrorMsgs.Count, cnTeCkitCompilerMaxErrors); while (i < nUpperLimit) { string strErr = m_lstErrorMsgs[i++]; strErrs += strErr + Environment.NewLine; } if (i == cnTeCkitCompilerMaxErrors) { strErrs = String.Format("First {1} errors:{0}{2}", Environment.NewLine, cnTeCkitCompilerMaxErrors, strErrs); } ApplicationException e = new ApplicationException(strErrs); throw e; } else if (status == (int)ErrStatus.NoError) { // put the data from TEC into a managed byte array for the following Write byte[] baOut = new byte[compiledSize]; ECNormalizeData.ByteStarToByteArr(compiledTable, (int)compiledSize, baOut); // save the compiled mapping (but if it fails because it's locked, then // try to save it with a temporary name. FileStream fileTec = null; try { fileTec = File.OpenWrite(strCompiledFilename); } catch (System.IO.IOException) { // temporary filename for temporary CC tables (to check portions of the file at a time) strCompiledFilename = Path.GetTempFileName(); strCompiledFilename = strCompiledFilename.Remove(strCompiledFilename.Length - 3) + "tec"; fileTec = File.OpenWrite(strCompiledFilename); } fileTec.Write(baOut, 0, (int)compiledSize); fileTec.Close(); } }
protected unsafe void CompileMap(string strFilename, ref string strCompiledFilename) { int status = 0; try { FileStream fileMap = new FileStream(strFilename,FileMode.Open,FileAccess.Read,FileShare.ReadWrite); byte [] pTxt = new byte [fileMap.Length]; uint nMapSize = (uint)fileMap.Read(pTxt,0,(int)fileMap.Length); byte* compiledTable = (byte*)0; UInt32 compiledSize = 0; try { // do this in a try/catch so the user can cancel if there are too many // errors. errFunc dsplyErr = new errFunc( TecEncConverter.DisplayCompilerError ); byte [] baName = Encoding.ASCII.GetBytes(Name); fixed (byte* lpTxt = pTxt) fixed (byte* lpName = baName) status = TECkit_Compile( lpTxt, nMapSize, (byte)1, // docompression dsplyErr, lpName, &compiledTable, &compiledSize); } catch { status = (int)ErrStatus.CompilationFailed; } if( status == (int)ErrStatus.NoError ) { // put the data from TEC into a managed byte array for the following Write byte [] baOut = new byte [compiledSize]; ECNormalizeData.ByteStarToByteArr(compiledTable,(int)compiledSize,baOut); // save the compiled mapping (but if it fails because it's locked, then // try to save it with a temporary name. FileStream fileTec = null; try { fileTec = File.OpenWrite(strCompiledFilename); } catch(System.IO.IOException) { // temporary filename for temporary CC tables (to check portions of the file at a time) strCompiledFilename = Path.GetTempFileName(); fileTec = File.OpenWrite(strCompiledFilename); } // get it's last created timestamp DoesFileExist(strCompiledFilename, ref m_timeModifiedTec); fileTec.Write(baOut,0,(int)compiledSize); fileTec.Close(); } } catch { // compiling isn't crucial } if( status != (int)ErrStatus.NoError ) EncConverters.ThrowError(status); }
protected unsafe void CompileMap(string strFilename, ref string strCompiledFilename) { int status = 0; try { FileStream fileMap = new FileStream(strFilename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); byte [] pTxt = new byte [fileMap.Length]; uint nMapSize = (uint)fileMap.Read(pTxt, 0, (int)fileMap.Length); byte * compiledTable = (byte *)0; UInt32 compiledSize = 0; try { // do this in a try/catch so the user can cancel if there are too many // errors. errFunc dsplyErr = new errFunc(TecEncConverter.DisplayCompilerError); byte [] baName = Encoding.ASCII.GetBytes(Name); fixed(byte *lpTxt = pTxt) fixed(byte *lpName = baName) status = TECkit_Compile( lpTxt, nMapSize, (byte)1, // docompression dsplyErr, lpName, &compiledTable, &compiledSize); } catch { status = (int)ErrStatus.CompilationFailed; } if (status == (int)ErrStatus.NoError) { // put the data from TEC into a managed byte array for the following Write byte [] baOut = new byte [compiledSize]; ECNormalizeData.ByteStarToByteArr(compiledTable, (int)compiledSize, baOut); // save the compiled mapping (but if it fails because it's locked, then // try to save it with a temporary name. FileStream fileTec = null; try { fileTec = File.OpenWrite(strCompiledFilename); } catch (System.IO.IOException) { // temporary filename for temporary CC tables (to check portions of the file at a time) strCompiledFilename = Path.GetTempFileName(); fileTec = File.OpenWrite(strCompiledFilename); } // get it's last created timestamp DoesFileExist(strCompiledFilename, ref m_timeModifiedTec); fileTec.Write(baOut, 0, (int)compiledSize); fileTec.Close(); } } catch { // compiling isn't crucial } if (status != (int)ErrStatus.NoError) { EncConverters.ThrowError(status); } }
public unsafe static void CompileMap(string strFilename, ref string strCompiledFilename) { m_lstErrorMsgs.Clear(); // start with an empty list of errors so we can detect them. int status = 0; FileStream fileMap = new FileStream(strFilename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); byte[] pTxt = new byte[fileMap.Length]; uint nMapSize = (uint)fileMap.Read(pTxt, 0, (int)fileMap.Length); byte* compiledTable = (byte*)0; UInt32 compiledSize = 0; errFunc dsplyErr = new errFunc(TECkitDllWrapper.DisplayCompilerError); byte[] baName = Encoding.ASCII.GetBytes(strFilename); fixed (byte* lpTxt = pTxt) fixed (byte* lpName = baName) status = TECkit_Compile( lpTxt, nMapSize, (byte)1, // docompression dsplyErr, lpName, &compiledTable, &compiledSize); // any errors occur? if (m_lstErrorMsgs.Count > 0) { // show the compiler errors, but limit it to some value. const int cnTeCkitCompilerMaxErrors = 20; string strErrs = null; int i = 0; int nUpperLimit = Math.Min(m_lstErrorMsgs.Count, cnTeCkitCompilerMaxErrors); while (i < nUpperLimit) { string strErr = m_lstErrorMsgs[i++]; strErrs += strErr + Environment.NewLine; } if (i == cnTeCkitCompilerMaxErrors) strErrs = String.Format("First {1} errors:{0}{2}", Environment.NewLine, cnTeCkitCompilerMaxErrors, strErrs); ApplicationException e = new ApplicationException(strErrs); throw e; } else if (status == (int)ErrStatus.NoError) { // put the data from TEC into a managed byte array for the following Write byte[] baOut = new byte[compiledSize]; ECNormalizeData.ByteStarToByteArr(compiledTable, (int)compiledSize, baOut); // save the compiled mapping (but if it fails because it's locked, then // try to save it with a temporary name. FileStream fileTec = null; try { fileTec = File.OpenWrite(strCompiledFilename); } catch (System.IO.IOException) { // temporary filename for temporary CC tables (to check portions of the file at a time) strCompiledFilename = Path.GetTempFileName(); strCompiledFilename = strCompiledFilename.Remove(strCompiledFilename.Length - 3) + "tec"; fileTec = File.OpenWrite(strCompiledFilename); } fileTec.Write(baOut, 0, (int)compiledSize); fileTec.Close(); } }