1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-14 11:23:42 +02:00
Sonarr/NzbDrone/Program.cs

119 lines
3.3 KiB
C#
Raw Normal View History

2010-10-14 09:29:01 +03:00
using System;
using System.Diagnostics;
using System.Threading;
2010-10-15 10:10:44 +03:00
using Exceptioneer.WindowsFormsClient;
2010-10-14 09:29:01 +03:00
using NLog;
2010-09-23 06:19:47 +03:00
2010-10-10 22:00:07 +03:00
namespace NzbDrone
2010-09-23 06:19:47 +03:00
{
2011-04-10 05:44:01 +03:00
internal static class Program
2010-09-23 06:19:47 +03:00
{
2010-10-14 09:29:01 +03:00
private static readonly Logger Logger = LogManager.GetLogger("Application");
2011-04-10 05:44:01 +03:00
private static void Main()
2010-10-14 09:29:01 +03:00
{
Logger.Info(Process.GetCurrentProcess().Id);
2010-10-14 09:29:01 +03:00
try
{
Thread.CurrentThread.Name = "Host";
2010-10-14 09:29:01 +03:00
AppDomain.CurrentDomain.UnhandledException += ((s, e) => AppDomainException(e));
2010-10-15 10:10:44 +03:00
AppDomain.CurrentDomain.ProcessExit += ProgramExited;
AppDomain.CurrentDomain.DomainUnload += ProgramExited;
2011-04-25 06:51:18 +03:00
Process.GetCurrentProcess().EnableRaisingEvents = true;
2011-04-10 05:44:01 +03:00
Process.GetCurrentProcess().Exited += ProgramExited;
2010-10-14 09:29:01 +03:00
2010-10-15 10:10:44 +03:00
Config.ConfigureNlog();
2010-10-14 09:29:01 +03:00
2010-10-15 10:10:44 +03:00
Logger.Info("Starting NZBDrone. Start-up Path:'{0}'", Config.ProjectRoot);
2010-10-14 09:29:01 +03:00
2011-04-22 09:46:26 +03:00
IISController.StopServer();
IISController.StartServer();
2010-10-14 09:29:01 +03:00
2010-10-15 10:10:44 +03:00
#if DEBUG
Attach();
#endif
if (Environment.UserInteractive)
{
try
{
Logger.Info("Starting default browser. {0}", IISController.AppUrl);
Process.Start(IISController.AppUrl);
}
catch (Exception e)
{
Logger.ErrorException("Failed to open URL in default browser.", e);
}
while (true)
{
Console.ReadLine();
}
}
}
catch (Exception e)
{
AppDomainException(e);
}
Console.WriteLine("Press enter to exit.");
Console.ReadLine();
}
2011-05-27 09:01:07 +03:00
#if DEBUG
private static void Attach()
{
if (Debugger.IsAttached)
{
Logger.Info("Trying to attach to debugger");
var count = 0;
while (true)
{
try
{
ProcessAttacher.Attach();
Logger.Info("Debugger Attached");
return;
}
catch (Exception e)
{
count++;
if (count > 20)
{
Logger.WarnException("Unable to attach to debugger", e);
return;
}
Thread.Sleep(100);
}
2010-10-15 10:10:44 +03:00
}
2010-10-14 09:29:01 +03:00
}
}
2011-05-27 09:01:07 +03:00
#endif
2010-10-14 09:29:01 +03:00
private static void AppDomainException(object excepion)
{
Console.WriteLine("EPIC FAIL: {0}", excepion);
Logger.Fatal("EPIC FAIL: {0}", excepion);
#if Release
2010-10-15 10:10:44 +03:00
new Client
{
ApiKey = "43BBF60A-EB2A-4C1C-B09E-422ADF637265",
ApplicationName = "NZBDrone",
CurrentException = excepion as Exception
}.Submit();
#endif
2010-09-23 06:19:47 +03:00
2011-04-22 09:46:26 +03:00
IISController.StopServer();
2010-10-14 09:29:01 +03:00
}
2010-09-23 06:19:47 +03:00
2011-04-10 05:44:01 +03:00
private static void ProgramExited(object sender, EventArgs e)
2010-10-14 09:29:01 +03:00
{
2011-04-22 09:46:26 +03:00
IISController.StopServer();
2010-10-14 09:29:01 +03:00
}
2010-09-23 06:19:47 +03:00
}
2011-04-10 05:44:01 +03:00
}