2011-10-07 05:37:41 +02:00
using System ;
2011-10-15 02:41:09 +02:00
using System.Diagnostics ;
2013-01-30 03:21:45 +01:00
using System.IO ;
2013-07-09 02:47:09 +02:00
using NzbDrone.Common.EnvironmentInfo ;
2011-10-07 05:37:41 +02:00
2011-10-23 07:26:43 +02:00
namespace NzbDrone.Common
2011-10-07 05:37:41 +02:00
{
2013-04-16 06:52:41 +02:00
public interface IConsoleService
2011-10-07 05:37:41 +02:00
{
2013-04-16 06:52:41 +02:00
bool IsConsoleApplication { get ; }
void WaitForClose ( ) ;
void PrintHelp ( ) ;
void PrintServiceAlreadyExist ( ) ;
2013-07-09 02:47:09 +02:00
void PrintServiceDoesNotExist ( ) ;
2013-04-16 06:52:41 +02:00
}
public class ConsoleService : IConsoleService
{
public bool IsConsoleApplication
2013-01-30 03:21:45 +01:00
{
get { return Console . In ! = StreamReader . Null ; }
}
2013-04-16 06:52:41 +02:00
public void WaitForClose ( )
2011-10-07 05:37:41 +02:00
{
while ( true )
{
2011-10-13 04:24:30 +02:00
Console . ReadLine ( ) ;
2011-10-07 05:37:41 +02:00
}
}
2011-10-09 04:16:11 +02:00
2013-04-16 06:52:41 +02:00
public void PrintHelp ( )
2011-10-09 04:16:11 +02:00
{
2011-10-15 02:41:09 +02:00
Console . WriteLine ( ) ;
Console . WriteLine ( " Usage: {0} <command> " , Process . GetCurrentProcess ( ) . MainModule . ModuleName ) ;
Console . WriteLine ( " Commands:" ) ;
2013-08-14 06:02:56 +02:00
Console . WriteLine ( " /{0} Install the application as a Windows Service ({1})." , StartupArguments . INSTALL_SERVICE , ServiceProvider . NZBDRONE_SERVICE_NAME ) ;
Console . WriteLine ( " /{0} Uninstall already installed Windows Service ({1})." , StartupArguments . UNINSTALL_SERVICE , ServiceProvider . NZBDRONE_SERVICE_NAME ) ;
2013-07-09 02:47:09 +02:00
Console . WriteLine ( " /{0} Don't open NzbDrone in a browser" , StartupArguments . NO_BROWSER ) ;
2011-10-15 02:41:09 +02:00
Console . WriteLine ( " <No Arguments> Run application in console mode." ) ;
2011-10-09 04:16:11 +02:00
}
2011-10-14 03:22:51 +02:00
2013-04-16 06:52:41 +02:00
public void PrintServiceAlreadyExist ( )
2011-10-14 03:22:51 +02:00
{
2011-10-26 19:15:47 +02:00
Console . WriteLine ( "A service with the same name ({0}) already exists. Aborting installation" , ServiceProvider . NZBDRONE_SERVICE_NAME ) ;
2011-10-14 03:22:51 +02:00
}
2011-10-15 02:41:09 +02:00
2013-07-09 02:47:09 +02:00
public void PrintServiceDoesNotExist ( )
2011-10-15 02:41:09 +02:00
{
2011-10-26 19:15:47 +02:00
Console . WriteLine ( "Can't find service ({0})" , ServiceProvider . NZBDRONE_SERVICE_NAME ) ;
2011-10-15 02:41:09 +02:00
}
2011-10-07 05:37:41 +02:00
}
2011-10-07 08:57:43 +02:00
}