// Copyright (c) 2007 Omer Rauchwerger (a.k.a rauchy) (omer@rauchy.net)
// All rights reserved.
//
// This file is part of Regionerate.
//
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License,
// or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
using System;
using System.Reflection;
using Rauchy.Regionerate.Shared.Components;
namespace Rauchy.Regionerate.Presentation.Console
{
///
/// Provides user interface services for the console application.
///
internal class UserInterface
{
#region Fields (3)
private static int _criticalWarnings;
private static int _lineCounter;
private static int _nonCriticalWarnings;
#endregion
#region Methods (7)
private static void CountWarning( string text, Output.WarningLevel level )
{
switch ( level )
{
case Output.WarningLevel.NonCritical:
_nonCriticalWarnings++;
break;
case Output.WarningLevel.Critical:
_criticalWarnings++;
break;
}
}
private static void DisplayWarning( string text, Output.WarningLevel level )
{
System.Console.WriteLine( "[#{0}] ({1}) {2} warning: {3}.", ++_lineCounter, DateTime.Now.ToLongTimeString(),
level, text );
}
///
/// Prompts the user about the accepted arguments and attaches to the output accordingly.
///
/// The arguments.
public static void Load( Arguments arguments )
{
System.Console.Write( "Target file: {0}, ", arguments.TargetFile );
System.Console.Write( "Type: {0}, ", arguments.TargetType );
System.Console.WriteLine( "Code Layout: {0}.",
arguments.UseDefaultCodeLayout ? "Default" : arguments.CustomCodeLayoutPath );
if ( arguments.NoInfo )
{
System.Console.WriteLine( "Information prompting disabled." );
}
else
{
Output.OnInformationSubmitted += Output_OnInformationSubmitted;
}
if ( arguments.NoWarn )
{
System.Console.WriteLine( "Warning prompting disabled." );
}
else
{
Output.OnWarningSubmitted += DisplayWarning;
}
// Register to the OnWarningSubmitted anyway, even if the user does not want
// to receive warnings, in order to count them.
Output.OnWarningSubmitted += CountWarning;
System.Console.WriteLine();
}
private static void Output_OnInformationSubmitted( string text )
{
System.Console.WriteLine( "[#{0}] ({1}) Information: {2}.", ++_lineCounter, DateTime.Now.ToLongTimeString(),
text );
}
public static void ShowFooter()
{
string header =
string.Format( "\nOperation completed with {0} critical warnings and {1} non-critical warnings.\n",
_criticalWarnings, _nonCriticalWarnings );
System.Console.WriteLine( Environment.NewLine );
for ( int i = 0; i < header.Length; i++ )
{
System.Console.Write( "=" );
}
System.Console.WriteLine( Environment.NewLine );
System.Console.WriteLine( header );
}
///
/// Shows the header.
///
public static void ShowHeader()
{
string header =
string.Format( "\nRegionerate command line utility v{0} by Omer Rauchwerger (omer@rauchy.net)",
Assembly.GetExecutingAssembly().GetName( false ).Version );
System.Console.WriteLine( header );
for ( int i = 0; i < header.Length; i++ )
{
System.Console.Write( "=" );
}
System.Console.WriteLine( Environment.NewLine );
}
///
/// Shows the syntax.
///
public static void ShowSyntax()
{
System.Console.WriteLine( "Required syntax:\n" );
System.Console.WriteLine(
"In order to run the command line utility, you must specify your target by using the -target argument as follows:" );
System.Console.WriteLine( "rgn -target:Calculator.csproj" );
System.Console.WriteLine( "The target can be a code file, project file or solution file.\n" );
System.Console.WriteLine(
"Besides the -target argument, you can also specify which Code Layout you want to use using the -layout argument as follows:" );
System.Console.WriteLine( "rgn -target:Calculator.csproj -layout:My Special Layout.xml" );
System.Console.WriteLine( "If you won't use the -layout argument, the default Code Layout will be used.\n" );
System.Console.WriteLine(
"If you are running on projects or solutions, you may wish to ignore certain files or projects inside them." );
System.Console.WriteLine( "To do so, use the -ignoreFiles and -ignoreProjects arguments as follows:" );
System.Console.WriteLine(
"rgn -target:Calculator.csproj -ignoreFiles:\"AssemblyInfo.cs|MainForm.cs|MainWindow.cs\"" );
System.Console.WriteLine( "rgn -target:MathLib.sln -ignoreProjects:\"Calculator.csproj|Graphs.csproj\"" );
System.Console.WriteLine( "Ignored values should be separated by the '|' delimiter." );
System.Console.WriteLine( "Ignored values will be searched as part of the file/project name, so:" );
System.Console.WriteLine( "rgn -target:Calculator.csproj -ignoreFiles:\"Main\"" );
System.Console.WriteLine(
"Will ignore all files that contain the word \"Main\" in their name, e.g: \"MainForm.cs\" and \"MainWindow.cs\"\n" );
System.Console.WriteLine(
"You can disable information prompts by using the -noinfo argument and disable warning prompts by using the -nowarn argument, for example:" );
System.Console.WriteLine( "rgn -target:Calculator.csproj -noinfo -nowarn" );
System.Console.WriteLine(
"This will Regionerate the Calculator project in silent mode, only fatal exceptions will be brought to your attentions." );
}
#endregion
}
}