Server.ScriptCompiler.Display C# (CSharp) Méthode

Display() public static méthode

public static Display ( CompilerResults results ) : void
results System.CodeDom.Compiler.CompilerResults
Résultat void
		public static void Display( CompilerResults results )
		{
			if( results.Errors.Count > 0 )
			{
				Dictionary<string, List<CompilerError>> errors = new Dictionary<string, List<CompilerError>>( results.Errors.Count, StringComparer.OrdinalIgnoreCase );
				Dictionary<string, List<CompilerError>> warnings = new Dictionary<string, List<CompilerError>>( results.Errors.Count, StringComparer.OrdinalIgnoreCase );

				foreach( CompilerError e in results.Errors )
				{
					string file = e.FileName;

					// Ridiculous. FileName is null if the warning/error is internally generated in csc.
					if ( string.IsNullOrEmpty( file ) ) {
						Console.WriteLine( "ScriptCompiler: {0}: {1}", e.ErrorNumber, e.ErrorText );
						continue;
					}

					Dictionary<string, List<CompilerError>> table = (e.IsWarning ? warnings : errors);

					List<CompilerError> list = null;
					table.TryGetValue( file, out list );

					if( list == null )
						table[file] = list = new List<CompilerError>();

					list.Add( e );
				}

				if( errors.Count > 0 )
					Console.WriteLine( "failed ({0} errors, {1} warnings)", errors.Count, warnings.Count );
				else
					Console.WriteLine( "done ({0} errors, {1} warnings)", errors.Count, warnings.Count );

				string scriptRoot = Path.GetFullPath( Path.Combine( Core.BaseDirectory, "Scripts" + Path.DirectorySeparatorChar ) );
				Uri scriptRootUri = new Uri( scriptRoot );

				Utility.PushColor( ConsoleColor.Yellow );

				if( warnings.Count > 0 )
					Console.WriteLine( "Warnings:" );

				foreach( KeyValuePair<string, List<CompilerError>> kvp in warnings )
				{
					string fileName = kvp.Key;
					List<CompilerError> list = kvp.Value;

					string fullPath = Path.GetFullPath( fileName );
					string usedPath = Uri.UnescapeDataString( scriptRootUri.MakeRelativeUri( new Uri( fullPath ) ).OriginalString );

					Console.WriteLine( " + {0}:", usedPath );

					Utility.PushColor( ConsoleColor.DarkYellow );

					foreach( CompilerError e in list )
						Console.WriteLine( "    {0}: Line {1}: {3}", e.ErrorNumber, e.Line, e.Column, e.ErrorText );

					Utility.PopColor();
				}

				Utility.PopColor();

				Utility.PushColor( ConsoleColor.Red );

				if( errors.Count > 0 )
					Console.WriteLine( "Errors:" );

				foreach( KeyValuePair<string, List<CompilerError>> kvp in errors )
				{
					string fileName = kvp.Key;
					List<CompilerError> list = kvp.Value;

					string fullPath = Path.GetFullPath( fileName );
					string usedPath = Uri.UnescapeDataString( scriptRootUri.MakeRelativeUri( new Uri( fullPath ) ).OriginalString );

					Console.WriteLine( " + {0}:", usedPath );

					Utility.PushColor( ConsoleColor.DarkRed );

					foreach( CompilerError e in list )
						Console.WriteLine( "    {0}: Line {1}: {3}", e.ErrorNumber, e.Line, e.Column, e.ErrorText );

					Utility.PopColor();
				}

				Utility.PopColor();
			}
			else
			{
				Console.WriteLine( "done (0 errors, 0 warnings)" );
			}
		}