cleaned up app startup logic.

fixed update app issue.
pull/4/head
kay.one 11 years ago
parent b1e5646d7d
commit a4a58c59f1

@ -17,6 +17,14 @@ namespace NzbDrone.Common.EnvironmentInfo
public const string UNINSTALL_SERVICE = "u";
public const string HELP = "?";
static StartupArguments()
{
if (RuntimeInfo.IsProduction)
{
Instance = new StartupArguments("");
}
}
public StartupArguments(params string[] args)
{
Flags = new HashSet<string>();

@ -0,0 +1,15 @@
using NzbDrone.Host;
namespace NzbDrone.Console
{
public class ConsoleAlerts : IUserAlert
{
public void Alert(string message)
{
System.Console.WriteLine();
System.Console.WriteLine(message);
System.Console.WriteLine("Press enter to continue");
System.Console.ReadLine();
}
}
}

@ -1,5 +1,6 @@
using System;
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Host;
namespace NzbDrone.Console
{
@ -9,13 +10,15 @@ namespace NzbDrone.Console
{
try
{
Host.Bootstrap.Start(new StartupArguments(args));
Bootstrap.Start(new StartupArguments(args), new ConsoleAlerts());
}
catch (TerminateApplicationException)
{
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
System.Console.WriteLine("Press enter to exit...");
System.Console.ReadLine();
}

@ -83,6 +83,10 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Newtonsoft.Json.5.0.6\lib\net40\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="NLog, Version=2.0.1.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\NLog.2.0.1.2\lib\net40\NLog.dll</HintPath>
</Reference>
<Reference Include="Owin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f0ebd12fd5e55cc5, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Owin.1.0\lib\net40\Owin.dll</HintPath>
@ -94,6 +98,7 @@
<Compile Include="..\NzbDrone.Common\Properties\SharedAssemblyInfo.cs">
<Link>Properties\SharedAssemblyInfo.cs</Link>
</Compile>
<Compile Include="ConsoleAlerts.cs" />
<Compile Include="ConsoleApp.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>

@ -5,5 +5,6 @@
<package id="Microsoft.Owin" version="1.1.0-beta2" targetFramework="net40" />
<package id="Microsoft.Owin.Hosting" version="1.1.0-beta2" targetFramework="net40" />
<package id="Newtonsoft.Json" version="5.0.6" targetFramework="net40" />
<package id="NLog" version="2.0.1.2" targetFramework="net40" />
<package id="Owin" version="1.0" targetFramework="net40" />
</packages>

@ -1,6 +1,4 @@
using System;
using System.Diagnostics;
using System.Reflection;
using System.Reflection;
using NLog;
using NzbDrone.Common.Composition;
using NzbDrone.Common.EnvironmentInfo;
@ -12,54 +10,27 @@ namespace NzbDrone.Host
{
public static class Bootstrap
{
public static IContainer Start(StartupArguments args)
public static IContainer Start(StartupArguments args, IUserAlert userAlert)
{
var logger = LogManager.GetLogger("AppMain");
try
{
GlobalExceptionHandlers.Register();
IgnoreCertErrorPolicy.Register();
logger.Info("Starting NzbDrone Console. Version {0}", Assembly.GetExecutingAssembly().GetName().Version);
//Check if full version .NET is installed.
try
{
Assembly.Load("System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
}
catch (Exception)
{
logger.Error("It looks like you don't have full version of .NET Framework installed. Press any key and you will be directed to the download page.");
Console.Read();
GlobalExceptionHandlers.Register();
IgnoreCertErrorPolicy.Register();
try
{
Process.Start("http://www.microsoft.com/download/en/details.aspx?id=17851");
}
catch (Exception e)
{
logger.Warn("Oops. can't start default browser. Please visit http://www.microsoft.com/download/en/details.aspx?id=17851 to download .NET Framework 4.");
Console.ReadLine();
}
logger.Info("Starting NzbDrone Console. Version {0}", Assembly.GetExecutingAssembly().GetName().Version);
return null;
}
var container = MainAppContainerBuilder.BuildContainer(args);
DbFactory.RegisterDatabase(container);
container.Resolve<Router>().Route();
if (!PlatformValidation.IsValidate(userAlert))
{
throw new TerminateApplicationException();
}
var container = MainAppContainerBuilder.BuildContainer(args);
DbFactory.RegisterDatabase(container);
container.Resolve<Router>().Route();
return container;
}
catch (Exception e)
{
logger.FatalException("Epic Fail " + e.Message, e);
throw;
}
return container;
}
}
}

@ -0,0 +1,7 @@
namespace NzbDrone.Host
{
public interface IUserAlert
{
void Alert(string message);
}
}

@ -121,6 +121,8 @@
</Compile>
<Compile Include="AccessControl\FirewallAdapter.cs" />
<Compile Include="AccessControl\UrlAclAdapter.cs" />
<Compile Include="IUserAlert.cs" />
<Compile Include="PlatformValidation.cs" />
<Compile Include="MainAppContainerBuilder.cs" />
<Compile Include="ApplicationModes.cs" />
<Compile Include="Bootstrap.cs" />
@ -132,6 +134,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="PriorityMonitor.cs" />
<Compile Include="Router.cs" />
<Compile Include="TerminateApplicationException.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />

@ -0,0 +1,55 @@
using System;
using System.Diagnostics;
using System.Reflection;
using NLog;
using NzbDrone.Common.EnvironmentInfo;
namespace NzbDrone.Host
{
public static class PlatformValidation
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
public static bool IsValidate(IUserAlert userAlert)
{
if (OsInfo.IsMono)
{
return true;
}
if (!IsAssemblyAvailable("System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"))
{
userAlert.Alert("It looks like you don't have full version of .NET Framework installed. You will now be directed the download page.");
try
{
Process.Start("http://www.microsoft.com/en-ca/download/details.aspx?id=30653");
}
catch (Exception e)
{
userAlert.Alert("Oops. can't start default browser. Please visit http://www.microsoft.com/en-ca/download/details.aspx?id=30653 to download .NET Framework 4.5.");
}
return false;
}
return true;
}
private static bool IsAssemblyAvailable(string assemblyString)
{
try
{
Assembly.Load(assemblyString);
return true;
}
catch (Exception e)
{
Logger.Warn("Couldn't load {0}", e.Message);
return false;
}
}
}
}

@ -0,0 +1,8 @@
using System;
namespace NzbDrone.Host
{
public class TerminateApplicationException : ApplicationException
{
}
}

@ -9,7 +9,7 @@ using NzbDrone.Update.UpdateEngine;
namespace NzbDrone.Update.Test
{
[TestFixture]
public class ProgramFixture : TestBase<Program>
public class ProgramFixture : TestBase<UpdateApp>
{

@ -52,7 +52,7 @@
<Link>Properties\SharedAssemblyInfo.cs</Link>
</Compile>
<Compile Include="AppType.cs" />
<Compile Include="Program.cs" />
<Compile Include="UpdateApp.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UpdateContainerBuilder.cs" />
<Compile Include="UpdateEngine\BackupAndRestore.cs" />

@ -10,7 +10,7 @@ using NzbDrone.Update.UpdateEngine;
namespace NzbDrone.Update
{
public class Program
public class UpdateApp
{
private readonly IInstallUpdateService _installUpdateService;
private readonly IProcessProvider _processProvider;
@ -18,7 +18,7 @@ namespace NzbDrone.Update
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
public Program(IInstallUpdateService installUpdateService, IProcessProvider processProvider)
public UpdateApp(IInstallUpdateService installUpdateService, IProcessProvider processProvider)
{
_installUpdateService = installUpdateService;
_processProvider = processProvider;
@ -38,7 +38,7 @@ namespace NzbDrone.Update
_container = UpdateContainerBuilder.Build();
logger.Info("Updating NzbDrone to version {0}", BuildInfo.Version);
_container.Resolve<Program>().Start(args);
_container.Resolve<UpdateApp>().Start(args);
}
catch (Exception e)
{

@ -0,0 +1,13 @@
using System.Windows.Forms;
using NzbDrone.Host;
namespace NzbDrone
{
public class MessageBoxUserAlert : IUserAlert
{
public void Alert(string message)
{
MessageBox.Show(text: message, buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Warning, caption: "NzbDrone");
}
}
}

@ -96,6 +96,7 @@
<Compile Include="..\NzbDrone.Common\Properties\SharedAssemblyInfo.cs">
<Link>Properties\SharedAssemblyInfo.cs</Link>
</Compile>
<Compile Include="MessageBoxUserAlert.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>

@ -1,6 +1,7 @@
using System;
using System.Windows.Forms;
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Host;
using NzbDrone.SysTray;
namespace NzbDrone
@ -11,10 +12,13 @@ namespace NzbDrone
{
try
{
var container = Host.Bootstrap.Start(new StartupArguments(args));
var container = Bootstrap.Start(new StartupArguments(args), new MessageBoxUserAlert());
container.Register<ISystemTrayApp, SystemTrayApp>();
container.Resolve<ISystemTrayApp>().Start();
}
catch (TerminateApplicationException)
{
}
catch (Exception e)
{
var message = string.Format("{0}: {1}", e.GetType().Name, e.Message);

Loading…
Cancel
Save