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