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