mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-13 18:16:55 -07:00
Improved the startup of the application. We now properaly parse any args passed into the console.
This commit is contained in:
parent
145e02d2e5
commit
186b18ccb9
5 changed files with 93 additions and 36 deletions
|
@ -61,7 +61,7 @@ namespace PlexRequests.Helpers
|
||||||
return dumpTarget.ToString();
|
return dumpTarget.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ConfigureLogging(string connectionString)
|
public static void ConfigureLogging(string connectionString)
|
||||||
{
|
{
|
||||||
LogManager.ThrowExceptions = true;
|
LogManager.ThrowExceptions = true;
|
||||||
// Step 1. Create configuration object
|
// Step 1. Create configuration object
|
||||||
|
|
|
@ -57,6 +57,10 @@
|
||||||
</StartupObject>
|
</StartupObject>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Reference Include="CommandLine, Version=2.0.275.0, Culture=neutral, PublicKeyToken=de6f01bd326f8c32, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\CommandLineParser.2.0.275-beta\lib\net45\CommandLine.dll</HintPath>
|
||||||
|
<Private>True</Private>
|
||||||
|
</Reference>
|
||||||
<Reference Include="Common.Logging, Version=3.0.0.0, Culture=neutral, PublicKeyToken=af08829b84f0328e, processorArchitecture=MSIL">
|
<Reference Include="Common.Logging, Version=3.0.0.0, Culture=neutral, PublicKeyToken=af08829b84f0328e, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\Common.Logging.3.0.0\lib\net40\Common.Logging.dll</HintPath>
|
<HintPath>..\packages\Common.Logging.3.0.0\lib\net40\Common.Logging.dll</HintPath>
|
||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
|
@ -187,6 +191,7 @@
|
||||||
<Compile Include="Models\SearchMusicViewModel.cs" />
|
<Compile Include="Models\SearchMusicViewModel.cs" />
|
||||||
<Compile Include="Models\SearchMovieViewModel.cs" />
|
<Compile Include="Models\SearchMovieViewModel.cs" />
|
||||||
<Compile Include="Modules\BaseModule.cs" />
|
<Compile Include="Modules\BaseModule.cs" />
|
||||||
|
<Compile Include="Start\StartupOptions.cs" />
|
||||||
<Compile Include="Validators\HeadphonesValidator.cs" />
|
<Compile Include="Validators\HeadphonesValidator.cs" />
|
||||||
<Compile Include="Validators\PushoverSettingsValidator.cs" />
|
<Compile Include="Validators\PushoverSettingsValidator.cs" />
|
||||||
<Compile Include="Validators\PushbulletSettingsValidator.cs" />
|
<Compile Include="Validators\PushbulletSettingsValidator.cs" />
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
56
PlexRequests.UI/Start/StartupOptions.cs
Normal file
56
PlexRequests.UI/Start/StartupOptions.cs
Normal file
|
@ -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
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the base URL.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>
|
||||||
|
/// The base URL.
|
||||||
|
/// </value>
|
||||||
|
[Option('b',"base", Required = false, HelpText = "Provide a base url for Plex Requests")]
|
||||||
|
public string BaseUrl { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the port.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>
|
||||||
|
/// The port.
|
||||||
|
/// </value>
|
||||||
|
[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; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
|
<package id="CommandLineParser" version="2.0.275-beta" targetFramework="net452" />
|
||||||
<package id="Common.Logging" version="3.0.0" targetFramework="net452" />
|
<package id="Common.Logging" version="3.0.0" targetFramework="net452" />
|
||||||
<package id="Common.Logging.Core" version="3.0.0" targetFramework="net452" />
|
<package id="Common.Logging.Core" version="3.0.0" targetFramework="net452" />
|
||||||
<package id="Dapper" version="1.42" targetFramework="net46" />
|
<package id="Dapper" version="1.42" targetFramework="net46" />
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue