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