Lidarr/NzbDrone/Program.cs

93 lines
2.4 KiB
C#
Raw Normal View History

2010-10-14 06:29:01 +00:00
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Threading;
2010-10-15 07:10:44 +00:00
using Exceptioneer.WindowsFormsClient;
2010-10-14 06:29:01 +00:00
using NLog;
using NLog.Config;
using NLog.Targets;
2010-09-23 03:19:47 +00:00
2010-10-10 19:00:07 +00:00
namespace NzbDrone
2010-09-23 03:19:47 +00:00
{
2010-10-14 06:29:01 +00:00
static class Program
2010-09-23 03:19:47 +00:00
{
2010-10-07 22:17:24 +00:00
2010-10-14 06:29:01 +00:00
private static readonly Logger Logger = LogManager.GetLogger("Application");
static void Main()
{
Logger.Info(Process.GetCurrentProcess().Id);
2010-10-14 06:29:01 +00:00
try
{
Thread.CurrentThread.Name = "Host";
2010-10-14 06:29:01 +00:00
AppDomain.CurrentDomain.UnhandledException += ((s, e) => AppDomainException(e));
2010-10-15 07:10:44 +00:00
AppDomain.CurrentDomain.ProcessExit += ProgramExited;
AppDomain.CurrentDomain.DomainUnload += ProgramExited;
System.Diagnostics.Process.GetCurrentProcess().Exited += ProgramExited;
2010-10-14 06:29:01 +00:00
2010-10-15 07:10:44 +00:00
Config.ConfigureNlog();
2010-10-14 06:29:01 +00:00
2010-10-15 07:10:44 +00:00
Logger.Info("Starting NZBDrone. Start-up Path:'{0}'", Config.ProjectRoot);
2010-10-14 06:29:01 +00:00
2010-10-15 07:10:44 +00:00
IISController.KillOrphaned();
IISController.StartIIS();
2010-10-14 06:29:01 +00:00
2010-10-15 07:10:44 +00:00
System.Diagnostics.Process.Start(IISController.AppUrl);
2010-10-14 06:29:01 +00:00
2010-10-15 07:10:44 +00:00
#if DEBUG
//Manually Attach debugger to IISExpress
if (Debugger.IsAttached)
{
try
{
ProcessAttacher.Attach();
}
catch (Exception e)
{
Logger.Warn("Unable to attach to debugger", e);
}
2010-10-15 07:10:44 +00:00
}
#endif
2010-10-14 06:29:01 +00:00
}
catch (Exception e)
{
AppDomainException(e);
}
2010-10-15 07:10:44 +00:00
Console.Write("Press Enter At Any Time To Exit...");
2010-10-14 06:29:01 +00:00
Console.ReadLine();
2010-10-15 07:10:44 +00:00
IISController.StopIIS();
2010-10-14 06:29:01 +00:00
}
private static void AppDomainException(object excepion)
{
Console.WriteLine("EPIC FAIL: {0}", excepion);
Logger.Fatal("EPIC FAIL: {0}", excepion);
2010-10-15 07:10:44 +00:00
new Client
2010-10-14 06:29:01 +00:00
{
2010-10-15 07:10:44 +00:00
ApiKey = "43BBF60A-EB2A-4C1C-B09E-422ADF637265",
ApplicationName = "NZBDrone",
CurrentException = excepion as Exception
}.Submit();
2010-09-23 03:19:47 +00:00
2010-10-15 07:10:44 +00:00
IISController.StopIIS();
2010-10-14 06:29:01 +00:00
}
2010-09-23 03:19:47 +00:00
2010-10-15 07:10:44 +00:00
static void ProgramExited(object sender, EventArgs e)
2010-10-14 06:29:01 +00:00
{
2010-10-15 07:10:44 +00:00
IISController.StopIIS();
2010-10-14 06:29:01 +00:00
}
2010-09-23 03:19:47 +00:00
}
}
2010-10-14 06:29:01 +00:00