diff --git a/PlexRequests.Helpers/LoggingHelper.cs b/PlexRequests.Helpers/LoggingHelper.cs index 03a80d3db..ce9497a8b 100644 --- a/PlexRequests.Helpers/LoggingHelper.cs +++ b/PlexRequests.Helpers/LoggingHelper.cs @@ -61,7 +61,7 @@ namespace PlexRequests.Helpers return dumpTarget.ToString(); } - public static void ConfigureLogging(string connectionString) + public static void ConfigureLogging(string connectionString) { LogManager.ThrowExceptions = true; // Step 1. Create configuration object diff --git a/PlexRequests.UI/PlexRequests.UI.csproj b/PlexRequests.UI/PlexRequests.UI.csproj index 176b1b0fe..45668bc1a 100644 --- a/PlexRequests.UI/PlexRequests.UI.csproj +++ b/PlexRequests.UI/PlexRequests.UI.csproj @@ -57,6 +57,10 @@ + + ..\packages\CommandLineParser.2.0.275-beta\lib\net45\CommandLine.dll + True + ..\packages\Common.Logging.3.0.0\lib\net40\Common.Logging.dll True @@ -187,6 +191,7 @@ + diff --git a/PlexRequests.UI/Program.cs b/PlexRequests.UI/Program.cs index fb906e349..471085c19 100644 --- a/PlexRequests.UI/Program.cs +++ b/PlexRequests.UI/Program.cs @@ -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(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(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; + } } } diff --git a/PlexRequests.UI/Start/StartupOptions.cs b/PlexRequests.UI/Start/StartupOptions.cs new file mode 100644 index 000000000..a911a00b3 --- /dev/null +++ b/PlexRequests.UI/Start/StartupOptions.cs @@ -0,0 +1,56 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: StartupOptions.cs +// Created By: Jamie Rees +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// ************************************************************************/ +#endregion +using System.Text; + +using CommandLine; + +namespace PlexRequests.UI.Start +{ + public class StartupOptions + { + /// + /// Gets or sets the base URL. + /// + /// + /// The base URL. + /// + [Option('b',"base", Required = false, HelpText = "Provide a base url for Plex Requests")] + public string BaseUrl { get; set; } + + /// + /// Gets or sets the port. + /// + /// + /// The port. + /// + [Option('p', "port", Required = false, HelpText = "Provide a port for Plex Requests to run on. You can also change this in the settings page in the UI", Default = 3579)] + public int Port { get; set; } + + + + } +} \ No newline at end of file diff --git a/PlexRequests.UI/packages.config b/PlexRequests.UI/packages.config index 63d5b6c2b..196008837 100644 --- a/PlexRequests.UI/packages.config +++ b/PlexRequests.UI/packages.config @@ -1,5 +1,6 @@  +