mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-30 11:38:32 -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
|
@ -57,6 +57,10 @@
|
|||
</StartupObject>
|
||||
</PropertyGroup>
|
||||
<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">
|
||||
<HintPath>..\packages\Common.Logging.3.0.0\lib\net40\Common.Logging.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
|
@ -187,6 +191,7 @@
|
|||
<Compile Include="Models\SearchMusicViewModel.cs" />
|
||||
<Compile Include="Models\SearchMovieViewModel.cs" />
|
||||
<Compile Include="Modules\BaseModule.cs" />
|
||||
<Compile Include="Start\StartupOptions.cs" />
|
||||
<Compile Include="Validators\HeadphonesValidator.cs" />
|
||||
<Compile Include="Validators\PushoverSettingsValidator.cs" />
|
||||
<Compile Include="Validators\PushbulletSettingsValidator.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<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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
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"?>
|
||||
<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.Core" version="3.0.0" targetFramework="net452" />
|
||||
<package id="Dapper" version="1.42" targetFramework="net46" />
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue