///////////////////////////////////////////////////////////////////////////// private bool ProcessFiles( NmpEvaluator nmp ) { // ****** string [] fileList = SourceFiles.Split( ';' ); if( 0 == fileList.Length ) { Log.LogError( "SourceFiles is empty", null ); return false; } // ****** int fileCount = 0; foreach( string fileName in fileList ) { if( ! File.Exists(fileName) ) { Log.LogError( "the source file \"{0}\" could not be located", fileName ); return false; } // ****** try { string result = nmp.Evaluate( nmp.GetFileContext( fileName ), true ); // ****** if( ! Errors && result.Length > 0 ) { if( 0 == fileCount++ ) { File.WriteAllText( OutputFile, result ); } else { File.AppendAllText( OutputFile, result ); } } } catch ( Exception ex ) { // // report error here // #if EXREPORTING // ref dll #endif Log.LogErrorFromException( ex ); return false; } } // ****** return true; }
///////////////////////////////////////////////////////////////////////////// protected Tuple<string, string, bool, string> EvaluateFile( string fileName, NmpStringArray defines ) { // ****** if( null != macroTracer ) { macroTracer.BeginSession( Path.GetFileName( fileName ), Path.GetDirectoryName( fileName ) ); } // ****** try { if( ! File.Exists(fileName) ) { Die( "input file does not exist: {0}", fileName ); } // ****** using( var mp = new NmpEvaluator(this) ) { foreach( var kvp in defines ) { var key = kvp.Key; if( !string.IsNullOrEmpty( key ) && '-' == key [ 0 ] ) { // // v3 have not added undef back to evaluator // continue; } // ****** mp.AddTextMacro( key, kvp.Value, null ); } // ****** string result = mp.Evaluate( mp.GetFileContext(fileName), true ); return new Tuple<string,string, bool, string>(result, mp.FileExt, mp.NoOutputFile, mp.OutputEncoding); } } // // catch error and report here // #if EXREPORTING // ref dll #endif finally { // ****** if( null != macroTracer ) { macroTracer.EndSession(); } } }
///////////////////////////////////////////////////////////////////////////// public NmpResult Evaluate( IDictionary vsBuildPaths, IDictionary projProperties, string text, string inputFileName ) { // ****** string inputFullPath = Path.GetFullPath( inputFileName ).ToLower(); // ****** NmpResult evalResult = new NmpResult(); evalResult.InputText = text; evalResult.FileName = inputFullPath; // ****** var host = new CustomToolHost( evalResult.Messages ); using( var nmp = new NmpEvaluator(host) ) { if( ! string.IsNullOrEmpty(inputFullPath) ) { nmp.ChangeRootDirectory( inputFileName ); } // ****** if( null != vsBuildPaths ) { AddObjectMacro( VSBUILD_PATHS_MACRO_NAME, new NmpArray(vsBuildPaths) ); } if( null != projProperties ) { AddObjectMacro( VSPROJECT_PROPERTIES, new NmpArray(projProperties) ); AddMacros( nmp, vsBuildPaths ); } // ****** var evx = nmp.GetStringContext( text ); evx.SetFileInfo( inputFullPath ); // ****** bool errors = false; string result = string.Empty; try { evalResult.MacroResult = nmp.Evaluate( evx, true ); evalResult.FileExt = nmp.FileExt; } catch ( CustomToolEvaluatorDieException ) { // // this is an exception we've created for as a generic terminal error // which simply causes us to return // errors = true; } // // catch error and report here // #if EXREPORTING // ref dll #endif //catch ( Exception ex ) { // throw; //} // ****** evalResult.Errors = errors; return evalResult; } }