sonarr-repo-only/NzbDrone/NzbDroneConsole.cs

54 lines
1.6 KiB
C#
Raw Normal View History

2011-10-11 07:11:05 +00:00
using System;
using System.Collections.Generic;
2011-10-13 02:24:30 +00:00
using System.Diagnostics;
2011-10-11 07:11:05 +00:00
using System.Linq;
using System.Reflection;
2011-10-13 02:24:30 +00:00
using System.Threading;
2011-10-11 07:11:05 +00:00
using NLog;
using Ninject;
using NzbDrone.Model;
namespace NzbDrone
{
public static class NzbDroneConsole
{
private static readonly Logger Logger = LogManager.GetLogger("Host.Main");
2011-10-13 02:24:30 +00:00
public static void Main(string[] args)
2011-10-11 07:11:05 +00:00
{
try
{
2011-10-13 02:24:30 +00:00
//while (!Debugger.IsAttached) Thread.Sleep(100);
2011-10-11 07:11:05 +00:00
Console.WriteLine("Starting NzbDrone Console. Version " + Assembly.GetExecutingAssembly().GetName().Version);
CentralDispatch.ApplicationMode = GetApplicationMode(args);
CentralDispatch.Kernel.Get<Router>().Route();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
Logger.Fatal(e.ToString());
}
}
public static ApplicationMode GetApplicationMode(IEnumerable<string> args)
{
if (args == null) return ApplicationMode.Console;
var cleanArgs = args.Where(c => c != null && !String.IsNullOrWhiteSpace(c)).ToList();
if (cleanArgs.Count == 0) return ApplicationMode.Console;
if (cleanArgs.Count != 1) return ApplicationMode.Help;
var arg = cleanArgs.First().Trim('/', '\\', '-').ToLower();
if (arg == "i") return ApplicationMode.InstallService;
if (arg == "u") return ApplicationMode.UninstallService;
return ApplicationMode.Help;
}
}
}