You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Readarr/NzbDrone/Program.cs

116 lines
3.2 KiB

14 years ago
using System;
using System.Diagnostics;
using System.Threading;
using Exceptioneer.WindowsFormsClient;
14 years ago
using NLog;
14 years ago
namespace NzbDrone
14 years ago
{
internal static class Program
14 years ago
{
14 years ago
private static readonly Logger Logger = LogManager.GetLogger("Application");
private static void Main()
14 years ago
{
Logger.Info(Process.GetCurrentProcess().Id);
14 years ago
try
{
Thread.CurrentThread.Name = "Host";
14 years ago
AppDomain.CurrentDomain.UnhandledException += ((s, e) => AppDomainException(e));
AppDomain.CurrentDomain.ProcessExit += ProgramExited;
AppDomain.CurrentDomain.DomainUnload += ProgramExited;
Process.GetCurrentProcess().EnableRaisingEvents = true;
Process.GetCurrentProcess().Exited += ProgramExited;
14 years ago
Config.ConfigureNlog();
14 years ago
Logger.Info("Starting NZBDrone. Start-up Path:'{0}'", Config.ProjectRoot);
14 years ago
IISController.StopServer();
IISController.StartServer();
14 years ago
#if DEBUG
Attach();
#endif
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();
}
#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);
}
}
14 years ago
}
}
#endif
14 years ago
private static void AppDomainException(object excepion)
{
Console.WriteLine("EPIC FAIL: {0}", excepion);
Logger.Fatal("EPIC FAIL: {0}", excepion);
#if Release
new Client
{
ApiKey = "43BBF60A-EB2A-4C1C-B09E-422ADF637265",
ApplicationName = "NZBDrone",
CurrentException = excepion as Exception
}.Submit();
#endif
14 years ago
IISController.StopServer();
14 years ago
}
14 years ago
private static void ProgramExited(object sender, EventArgs e)
14 years ago
{
IISController.StopServer();
14 years ago
}
14 years ago
}
}