@ -40,6 +40,10 @@ using PlexRequests.Store;
using PlexRequests.Store.Repository ;
using System.Diagnostics ;
using CommandLine ;
using PlexRequests.UI.Start ;
namespace PlexRequests.UI
{
class Program
@ -47,37 +51,18 @@ namespace PlexRequests.UI
private static Logger Log = LogManager . GetCurrentClassLogger ( ) ;
static void Main ( string [ ] args )
{
var baseUrl = string . Empty ;
var port = - 1 ;
if ( args . Length > 0 )
{
for ( var i = 0 ; i < args . Length ; i + + )
{
var arg = args [ i ] . ToLowerInvariant ( ) . Substring ( 1 ) ;
switch ( arg )
{
case "base" :
i + + ;
var value = args [ i ] ;
Console . WriteLine ( $"Using a Base URL {args[i]}" ) ;
baseUrl = value ;
break ;
default :
int portResult ;
if ( ! int . TryParse ( args [ i ] , out portResult ) )
{
Console . WriteLine ( "Didn't pass in a valid port" ) ;
Console . ReadLine ( ) ;
Environment . Exit ( 1 ) ;
}
else
{
port = portResult ;
}
break ;
}
}
}
var result = Parser . Default . ParseArguments < StartupOptions > ( args ) ;
var baseUrl = result . MapResult (
o = > o . BaseUrl ,
e = > string . Empty ) ;
var port = result . MapResult (
x = > x . Port ,
e = > - 1 ) ;
PrintToConsole ( "Starting Up! Please wait, this can usually take a few seconds." , ConsoleColor . Yellow ) ;
Log . Trace ( "Getting product version" ) ;
WriteOutVersion ( ) ;
@ -87,7 +72,7 @@ namespace PlexRequests.UI
ConfigureTargets ( cn ) ;
SetupLogging ( ) ;
if ( port = = - 1 )
if ( port = = - 1 | | port = = 3579 )
port = GetStartupPort ( ) ;
var options = new StartOptions ( Debugger . IsAttached ? $"http://localhost:{port}" : $"http://+:{port}" )
@ -98,11 +83,13 @@ namespace PlexRequests.UI
{
using ( WebApp . Start < Startup > ( options ) )
{
Console . WriteLine ( $" Request Plex is running on the following: http://+:{port}/ ") ;
Console . WriteLine ( $" Plex Requests is running on the following: http://+:{port}/{baseUrl} ") ;
PrintToConsole ( "All setup, Plex Requests is now ready!" , ConsoleColor . Yellow ) ;
if ( Type . GetType ( "Mono.Runtime" ) ! = null )
{
Log . Trace ( "We are on Mono!" ) ;
Log . Info ( "We are on Mono!" ) ;
// on mono, processes will usually run as daemons - this allows you to listen
// for termination signals (ctrl+c, shutdown, etc) and finalize correctly
UnixSignal . WaitAny (
@ -110,7 +97,7 @@ namespace PlexRequests.UI
}
else
{
Log . Trace ( "This is not Mono" ) ;
Log . Info ( "This is not Mono" ) ;
Console . WriteLine ( "Press any key to exit" ) ;
Console . ReadLine ( ) ;
}
@ -119,6 +106,7 @@ namespace PlexRequests.UI
catch ( Exception e )
{
Log . Fatal ( e ) ;
Console . WriteLine ( e ) ;
throw ;
}
}
@ -160,5 +148,12 @@ namespace PlexRequests.UI
LoggingHelper . ReconfigureLogLevel ( LogLevel . FromOrdinal ( logSettings . Level ) ) ;
}
}
private static void PrintToConsole ( string message , ConsoleColor colour = ConsoleColor . Gray )
{
Console . ForegroundColor = colour ;
Console . WriteLine ( message ) ;
Console . ForegroundColor = ConsoleColor . Gray ;
}
}
}