Exemplo n.º 1
0
Arquivo: Task.cs Projeto: jmclain/Nmp
		/////////////////////////////////////////////////////////////////////////////
		
		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;
		}
Exemplo n.º 2
0
Arquivo: Host.cs Projeto: jmclain/Nmp
		/////////////////////////////////////////////////////////////////////////////

		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();
				}

			}
		}