// 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 Rauchy.Regionerate.ServiceLayer.Components;
using Rauchy.Regionerate.ServiceLayer.Components.Services;
namespace Rauchy.Regionerate.Presentation.Console
{
///
/// A utility that activates Regionerate's service by command-line.
///
internal class Program
{
#region Methods (3)
private static void DoFile( Arguments arguments )
{
DocumentService service;
if ( arguments.UseDefaultCodeLayout )
{
service = new DocumentService();
}
else
{
service = new DocumentService( arguments.CustomCodeLayoutPath );
}
Document document = new FileDocument( arguments.TargetFile );
service.Process( document );
}
private static void DoProject( Arguments arguments )
{
ProjectService service;
if ( arguments.UseDefaultCodeLayout )
{
service = new CSharpProjectService( arguments.IgnoredFiles );
}
else
{
service = new CSharpProjectService( arguments.CustomCodeLayoutPath, arguments.IgnoredFiles );
}
service.Process( arguments.TargetFile );
}
private static void DoSolution( Arguments arguments )
{
SolutionService service;
if ( arguments.UseDefaultCodeLayout )
{
service = new SolutionService( arguments.IgnoredProjects, arguments.IgnoredFiles );
}
else
{
service = new SolutionService( arguments.CustomCodeLayoutPath, arguments.IgnoredProjects,
arguments.IgnoredFiles );
}
service.Process( arguments.TargetFile );
}
private static void Main( string[] args )
{
try
{
UserInterface.ShowHeader();
Arguments arguments;
if ( Arguments.TryParse( args ) )
{
arguments = Arguments.Parse( args );
if ( arguments.ShowHelp )
{
UserInterface.ShowSyntax();
return;
}
UserInterface.Load( arguments );
}
else
{
UserInterface.ShowSyntax();
return;
}
switch ( ( int )arguments.TargetType )
{
case ( int )TargetType.File:
DoFile( arguments );
break;
case ( int )TargetType.Project:
DoProject( arguments );
break;
case ( int )TargetType.Solution:
DoSolution( arguments );
break;
}
}
catch ( Exception ex )
{
System.Console.WriteLine( "The following exception has been raised:" );
System.Console.WriteLine( "{0} at {1}.", ex.Message, ex.TargetSite );
}
finally
{
UserInterface.ShowFooter();
}
}
#endregion
}
}