started to remove iisexpress.

This commit is contained in:
Keivan Beigi 2013-02-18 17:13:42 -08:00
parent 40f3a8663d
commit 68128809c9
39 changed files with 383 additions and 820 deletions

View File

@ -0,0 +1,45 @@
using System;
using AutoMapper;
using NzbDrone.Api.QualityProfiles;
using NzbDrone.Api.QualityType;
using NzbDrone.Api.Resolvers;
using NzbDrone.Api.Series;
using NzbDrone.Core.Repository.Quality;
namespace NzbDrone.Api
{
public static class AutomapperBootstraper
{
public static void InitializeAutomapper()
{
//QualityProfiles
Mapper.CreateMap<QualityProfile, QualityProfileModel>()
.ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.QualityProfileId))
.ForMember(dest => dest.Qualities,
opt => opt.ResolveUsing<AllowedToQualitiesResolver>().FromMember(src => src.Allowed));
Mapper.CreateMap<QualityProfileModel, QualityProfile>()
.ForMember(dest => dest.QualityProfileId, opt => opt.MapFrom(src => src.Id))
.ForMember(dest => dest.Allowed,
opt => opt.ResolveUsing<QualitiesToAllowedResolver>().FromMember(src => src.Qualities));
Mapper.CreateMap<QualityTypes, QualityProfileType>()
.ForMember(dest => dest.Allowed, opt => opt.Ignore());
//QualityTypes
Mapper.CreateMap<Core.Repository.Quality.QualityType, QualityTypeModel>()
.ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.QualityTypeId));
Mapper.CreateMap<QualityTypeModel, Core.Repository.Quality.QualityType>()
.ForMember(dest => dest.QualityTypeId, opt => opt.MapFrom(src => src.Id));
//Series
Mapper.CreateMap<Core.Repository.Series, SeriesResource>()
.ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.SeriesId))
.ForMember(dest => dest.CustomStartDate, opt => opt.ResolveUsing<NullableDatetimeToString>().FromMember(src => src.CustomStartDate))
.ForMember(dest => dest.BacklogSetting, opt => opt.MapFrom(src => (Int32)src.BacklogSetting))
.ForMember(dest => dest.NextAiring, opt => opt.ResolveUsing<NextAiringResolver>());
}
}
}

View File

@ -1,128 +0,0 @@
using System;
using System.Linq;
using AutoMapper;
using Autofac;
using NLog;
using Nancy.Bootstrapper;
using Nancy.Bootstrappers.Autofac;
using Nancy.Conventions;
using Nancy.Diagnostics;
using NzbDrone.Api.ErrorManagment;
using NzbDrone.Api.Extentions;
using NzbDrone.Api.QualityProfiles;
using NzbDrone.Api.QualityType;
using NzbDrone.Api.Resolvers;
using NzbDrone.Api.Series;
using NzbDrone.Core;
using NzbDrone.Core.Helpers;
using NzbDrone.Core.Repository.Quality;
using ErrorPipeline = NzbDrone.Api.ErrorManagment.ErrorPipeline;
namespace NzbDrone.Api
{
public class Bootstrapper : AutofacNancyBootstrapper
{
private readonly Logger _logger;
public Bootstrapper()
{
_logger = LogManager.GetCurrentClassLogger();
}
protected override Nancy.IRootPathProvider RootPathProvider
{
get
{
return new RootPathProvider();
}
}
protected override void ApplicationStartup(ILifetimeScope container, IPipelines pipelines)
{
InitializeAutomapper();
}
public static void InitializeAutomapper()
{
//QualityProfiles
Mapper.CreateMap<QualityProfile, QualityProfileModel>()
.ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.QualityProfileId))
.ForMember(dest => dest.Qualities,
opt => opt.ResolveUsing<AllowedToQualitiesResolver>().FromMember(src => src.Allowed));
Mapper.CreateMap<QualityProfileModel, QualityProfile>()
.ForMember(dest => dest.QualityProfileId, opt => opt.MapFrom(src => src.Id))
.ForMember(dest => dest.Allowed,
opt => opt.ResolveUsing<QualitiesToAllowedResolver>().FromMember(src => src.Qualities));
Mapper.CreateMap<QualityTypes, QualityProfileType>()
.ForMember(dest => dest.Allowed, opt => opt.Ignore());
//QualityTypes
Mapper.CreateMap<Core.Repository.Quality.QualityType, QualityTypeModel>()
.ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.QualityTypeId));
Mapper.CreateMap<QualityTypeModel, Core.Repository.Quality.QualityType>()
.ForMember(dest => dest.QualityTypeId, opt => opt.MapFrom(src => src.Id));
//Series
Mapper.CreateMap<Core.Repository.Series, SeriesResource>()
.ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.SeriesId))
.ForMember(dest => dest.CustomStartDate, opt => opt.ResolveUsing<NullableDatetimeToString>().FromMember(src => src.CustomStartDate))
.ForMember(dest => dest.BacklogSetting, opt => opt.MapFrom(src => (Int32)src.BacklogSetting))
.ForMember(dest => dest.NextAiring, opt => opt.ResolveUsing<NextAiringResolver>());
}
protected override ILifetimeScope GetApplicationContainer()
{
_logger.Info("Starting NzbDrone API");
var builder = new ContainerBuilder();
builder.RegisterCoreServices();
builder.RegisterAssemblyTypes(typeof(Bootstrapper).Assembly)
.AsImplementedInterfaces()
.SingleInstance();
builder.RegisterType<ErrorPipeline>().AsSelf().SingleInstance();
var container = builder.Build();
ApplicationPipelines.OnError.AddItemToEndOfPipeline(container.Resolve<ErrorPipeline>().HandleException);
return container;
}
protected override NancyInternalConfiguration InternalConfiguration
{
get
{
var internalConfig = NancyInternalConfiguration.Default;
internalConfig.StatusCodeHandlers.Add(typeof(ErrorHandler));
internalConfig.Serializers.Add(typeof(NancyJsonSerializer));
return internalConfig;
}
}
protected override DiagnosticsConfiguration DiagnosticsConfiguration
{
get { return new DiagnosticsConfiguration { Password = @"password" }; }
}
protected override void ConfigureConventions(Nancy.Conventions.NancyConventions nancyConventions)
{
base.ConfigureConventions(nancyConventions);
Conventions.StaticContentsConventions.Add(StaticContentConventionBuilder.AddDirectory("static", @"NzbDrone.Backbone",new string[]{".css",".js",".html",".htm",".jpg",".jpeg",".icon",".gif",".png",".woff",".ttf"}));
}
}
}

View File

@ -0,0 +1,23 @@
using System.Linq;
using System.Reflection;
using Autofac;
namespace NzbDrone.Api
{
public static class ContainerExtensions
{
public static void RegisterApiServices(this ContainerBuilder containerBuilder)
{
var apiAssembly = Assembly.Load("NzbDrone.Api");
containerBuilder.RegisterAssemblyTypes(apiAssembly)
.AsImplementedInterfaces()
.SingleInstance();
containerBuilder.RegisterAssemblyTypes(apiAssembly)
.AsSelf()
.SingleInstance();
}
}
}

View File

@ -4,9 +4,8 @@ using Nancy;
using Nancy.Responses; using Nancy.Responses;
using Newtonsoft.Json; using Newtonsoft.Json;
using NzbDrone.Api.Extentions; using NzbDrone.Api.Extentions;
using NzbDrone.Api.QualityType;
namespace NzbDrone.Api.ErrorManagment namespace NzbDrone.Api.ErrorManagement
{ {
public abstract class ApiException : Exception public abstract class ApiException : Exception
{ {

View File

@ -2,9 +2,8 @@
using Nancy; using Nancy;
using Nancy.ErrorHandling; using Nancy.ErrorHandling;
using NzbDrone.Api.Extentions; using NzbDrone.Api.Extentions;
using NzbDrone.Api.QualityType;
namespace NzbDrone.Api.ErrorManagment namespace NzbDrone.Api.ErrorManagement
{ {
public class ErrorHandler : IStatusCodeHandler public class ErrorHandler : IStatusCodeHandler
{ {

View File

@ -1,6 +1,6 @@
using System.Linq; using System.Linq;
namespace NzbDrone.Api.ErrorManagment namespace NzbDrone.Api.ErrorManagement
{ {
public class ErrorModel public class ErrorModel
{ {

View File

@ -4,7 +4,7 @@ using NLog;
using Nancy; using Nancy;
using NzbDrone.Api.Extentions; using NzbDrone.Api.Extentions;
namespace NzbDrone.Api.ErrorManagment namespace NzbDrone.Api.ErrorManagement
{ {
public class ErrorPipeline public class ErrorPipeline
{ {

View File

@ -0,0 +1,122 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Autofac;
using NLog;
using Nancy.Bootstrapper;
using Nancy.Bootstrappers.Autofac;
using Nancy.Conventions;
using Nancy.Diagnostics;
using NzbDrone.Api.ErrorManagement;
using NzbDrone.Api.Extentions;
using NzbDrone.Common;
using NzbDrone.Core;
using NzbDrone.Core.Lifecycle;
using NzbDrone.Core.Providers.Core;
using SignalR;
namespace NzbDrone.Api
{
public class NancyBootstrapper : AutofacNancyBootstrapper
{
private readonly Logger _logger;
public NancyBootstrapper()
{
_logger = LogManager.GetCurrentClassLogger();
}
protected override Nancy.IRootPathProvider RootPathProvider
{
get
{
return new RootPathProvider();
}
}
protected override void ApplicationStartup(ILifetimeScope container, IPipelines pipelines)
{
_logger.Info("Starting NzbDrone API");
AutomapperBootstraper.InitializeAutomapper();
SignalRBootstraper.InitializeAutomapper(container);
RegisterReporting(container);
KickoffInitilizables(container);
ApplicationPipelines.OnError.AddItemToEndOfPipeline(container.Resolve<ErrorPipeline>().HandleException);
}
private void KickoffInitilizables(ILifetimeScope container)
{
var initilizables = container.Resolve<IEnumerable<IInitializable>>();
foreach (var initializable in initilizables)
{
_logger.Debug("Initializing {0}", initializable.GetType().Name);
try
{
initializable.Init();
}
catch (Exception e)
{
_logger.FatalException("An error occurred while initializing " + initializable.GetType().Name, e);
throw;
}
}
}
private void RegisterReporting(ILifetimeScope container)
{
EnvironmentProvider.UGuid = container.Resolve<ConfigProvider>().UGuid;
ReportingService.RestProvider = container.Resolve<RestProvider>();
ReportingService.SetupExceptronDriver();
}
protected override ILifetimeScope GetApplicationContainer()
{
_logger.Debug("Initializing Service Container");
var builder = new ContainerBuilder();
builder.RegisterCoreServices();
builder.RegisterApiServices();
var container = builder.Build();
return container;
}
protected override NancyInternalConfiguration InternalConfiguration
{
get
{
var internalConfig = NancyInternalConfiguration.Default;
internalConfig.StatusCodeHandlers.Add(typeof(ErrorHandler));
internalConfig.Serializers.Add(typeof(NancyJsonSerializer));
return internalConfig;
}
}
protected override DiagnosticsConfiguration DiagnosticsConfiguration
{
get { return new DiagnosticsConfiguration { Password = @"password" }; }
}
protected override void ConfigureConventions(NancyConventions nancyConventions)
{
base.ConfigureConventions(nancyConventions);
Conventions.StaticContentsConventions.Add(StaticContentConventionBuilder.AddDirectory("static", @"NzbDrone.Backbone", new string[] { ".css", ".js", ".html", ".htm", ".jpg", ".jpeg", ".icon", ".gif", ".png", ".woff", ".ttf" }));
}
}
public static class SignalRBootstraper
{
public static void InitializeAutomapper(ILifetimeScope container)
{
GlobalHost.DependencyResolver = new AutofacSignalrDependencyResolver(container.BeginLifetimeScope("SignalR"));
}
}
}

View File

@ -86,6 +86,14 @@
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\NLog.2.0.0.2000\lib\net40\NLog.dll</HintPath> <HintPath>..\packages\NLog.2.0.0.2000\lib\net40\NLog.dll</HintPath>
</Reference> </Reference>
<Reference Include="SignalR, Version=0.5.1.10822, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\SignalR.Server.0.5.3\lib\net40\SignalR.dll</HintPath>
</Reference>
<Reference Include="SignalR.Hosting.Common, Version=0.5.1.10822, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\SignalR.Hosting.Common.0.5.3\lib\net40\SignalR.Hosting.Common.dll</HintPath>
</Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />
@ -99,6 +107,8 @@
</Reference> </Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="AutomapperBootstraper.cs" />
<Compile Include="ContainerExtentions.cs" />
<Compile Include="Directories\DirectoryModule.cs" /> <Compile Include="Directories\DirectoryModule.cs" />
<Compile Include="Extentions\NancyJsonSerializer.cs" /> <Compile Include="Extentions\NancyJsonSerializer.cs" />
<Compile Include="Extentions\Serializer.cs" /> <Compile Include="Extentions\Serializer.cs" />
@ -112,11 +122,11 @@
<Compile Include="Series\SeriesResource.cs" /> <Compile Include="Series\SeriesResource.cs" />
<Compile Include="Series\SeriesModule.cs" /> <Compile Include="Series\SeriesModule.cs" />
<Compile Include="Series\SeriesLookupModule.cs" /> <Compile Include="Series\SeriesLookupModule.cs" />
<Compile Include="ErrorManagment\ApiException.cs" /> <Compile Include="ErrorManagement\ApiException.cs" />
<Compile Include="Bootstrapper.cs" /> <Compile Include="NancyBootstrapper.cs" />
<Compile Include="ErrorManagment\ErrorHandler.cs" /> <Compile Include="ErrorManagement\ErrorHandler.cs" />
<Compile Include="ErrorManagment\ErrorModel.cs" /> <Compile Include="ErrorManagement\ErrorModel.cs" />
<Compile Include="ErrorManagment\ErrorPipeline.cs" /> <Compile Include="ErrorManagement\ErrorPipeline.cs" />
<Compile Include="Exceptions\InvalidApiKeyException.cs" /> <Compile Include="Exceptions\InvalidApiKeyException.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="NzbDroneApiModule.cs" /> <Compile Include="NzbDroneApiModule.cs" />

View File

@ -8,4 +8,6 @@
<package id="Nancy.Bootstrappers.Autofac" version="0.16.1" targetFramework="net40" /> <package id="Nancy.Bootstrappers.Autofac" version="0.16.1" targetFramework="net40" />
<package id="Newtonsoft.Json" version="4.5.11" targetFramework="net40" /> <package id="Newtonsoft.Json" version="4.5.11" targetFramework="net40" />
<package id="NLog" version="2.0.0.2000" targetFramework="net40" /> <package id="NLog" version="2.0.0.2000" targetFramework="net40" />
<package id="SignalR.Hosting.Common" version="0.5.3" targetFramework="net40" />
<package id="SignalR.Server" version="0.5.3" targetFramework="net40" />
</packages> </packages>

View File

@ -1,7 +1,6 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Threading;
namespace NzbDrone.Common namespace NzbDrone.Common
{ {

View File

@ -0,0 +1,69 @@
using System;
using System.Linq;
using NLog;
using Nancy.Bootstrapper;
using Nancy.Hosting.Self;
namespace NzbDrone.Common
{
public interface IHostController
{
bool ServerStarted { get; }
string AppUrl { get; }
void StartServer();
void RestartServer();
void StopServer();
}
public class HostController : IHostController
{
private readonly ConfigFileProvider _configFileProvider;
private readonly INancyBootstrapper _bootstrapper;
private readonly Logger _logger;
private NancyHost _host;
public bool ServerStarted { get; private set; }
public HostController(ConfigFileProvider configFileProvider, INancyBootstrapper bootstrapper, Logger logger)
{
_configFileProvider = configFileProvider;
_bootstrapper = bootstrapper;
_logger = logger;
}
public void StartServer()
{
_host = new NancyHost(new Uri(AppUrl), _bootstrapper);
}
public string AppUrl
{
get { return string.Format("http://localhost:{0}/", _configFileProvider.Port); }
}
public void RestartServer()
{
_logger.Warn("Attempting to restart server.");
if (_host != null)
{
StopServer();
}
StartServer();
}
public void StopServer()
{
if (_host == null) return;
_logger.Info("Attempting to stop Nancy host");
_host.Stop();
_host = null;
_logger.Info("Host has stopped");
}
}
}

View File

@ -1,127 +0,0 @@
using System.Linq;
using System;
using System.Diagnostics;
using NLog;
namespace NzbDrone.Common
{
public class IISProvider
{
private static readonly Logger IISLogger = LogManager.GetCurrentClassLogger();
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private readonly ConfigFileProvider _configFileProvider;
private readonly ProcessProvider _processProvider;
private readonly EnvironmentProvider _environmentProvider;
public int IISProcessId { get; private set; }
public bool ServerStarted { get; private set; }
public void StartServer()
{
Logger.Info("Preparing IISExpress Server...");
var startInfo = new ProcessStartInfo();
startInfo.FileName = _environmentProvider.GetIISExe();
startInfo.Arguments = String.Format("/config:\"{0}\" /trace:i", _environmentProvider.GetIISConfigPath());
startInfo.WorkingDirectory = _environmentProvider.ApplicationPath;
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
startInfo.CreateNoWindow = true;
startInfo.EnvironmentVariables[EnvironmentProvider.NZBDRONE_PATH] = _environmentProvider.ApplicationPath;
startInfo.EnvironmentVariables[EnvironmentProvider.NZBDRONE_PID] = Process.GetCurrentProcess().Id.ToString();
try
{
_configFileProvider.UpdateIISConfig(_environmentProvider.GetIISConfigPath());
}
catch (Exception e)
{
Logger.ErrorException("An error has occurred while trying to update the config file.", e);
}
var iisProcess = _processProvider.Start(startInfo);
IISProcessId = iisProcess.Id;
iisProcess.OutputDataReceived += (OnOutputDataReceived);
iisProcess.ErrorDataReceived += (OnErrorDataReceived);
iisProcess.BeginErrorReadLine();
iisProcess.BeginOutputReadLine();
ServerStarted = true;
iisProcess.EnableRaisingEvents = true;
iisProcess.Exited += IIS_EXITED;
}
public IISProvider(ConfigFileProvider configFileProvider, ProcessProvider processProvider, EnvironmentProvider environmentProvider)
{
_configFileProvider = configFileProvider;
_processProvider = processProvider;
_environmentProvider = environmentProvider;
}
public IISProvider()
{
}
public string AppUrl
{
get { return string.Format("http://localhost:{0}/", _configFileProvider.Port); }
}
private static void OnErrorDataReceived(object sender, DataReceivedEventArgs e)
{
if (e == null || String.IsNullOrWhiteSpace(e.Data))
return;
IISLogger.Error(e.Data);
}
public void RestartServer()
{
ServerStarted = false;
Logger.Warn("Attempting to restart server.");
StopServer();
StartServer();
}
public virtual void StopServer()
{
_processProvider.Kill(IISProcessId);
Logger.Info("Finding orphaned IIS Processes.");
foreach (var process in _processProvider.GetProcessByName("IISExpress"))
{
Logger.Info("[{0}]IIS Process found. Path:{1}", process.Id, process.StartPath);
if (DiskProvider.PathEquals(process.StartPath, _environmentProvider.GetIISExe()))
{
Logger.Info("[{0}]Process is considered orphaned.", process.Id);
_processProvider.Kill(process.Id);
}
else
{
Logger.Info("[{0}]Process has a different start-up path. skipping.", process.Id);
}
}
}
public void IIS_EXITED(object obj, EventArgs args)
{
RestartServer();
}
private void OnOutputDataReceived(object s, DataReceivedEventArgs e)
{
if (e == null || String.IsNullOrWhiteSpace(e.Data) || e.Data.StartsWith("Request started:") ||
e.Data.StartsWith("Request ended:") || e.Data == ("IncrementMessages called"))
return;
Console.WriteLine(e.Data);
}
}
}

View File

@ -65,6 +65,12 @@
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Exceptron.Client.1.0.7\lib\net20\Exceptron.Client.dll</HintPath> <HintPath>..\packages\Exceptron.Client.1.0.7\lib\net20\Exceptron.Client.dll</HintPath>
</Reference> </Reference>
<Reference Include="Nancy">
<HintPath>..\packages\Nancy.0.16.1\lib\net40\Nancy.dll</HintPath>
</Reference>
<Reference Include="Nancy.Hosting.Self">
<HintPath>..\packages\Nancy.Hosting.Self.0.16.1\lib\net40\Nancy.Hosting.Self.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> <Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Newtonsoft.Json.4.5.11\lib\net40\Newtonsoft.Json.dll</HintPath> <HintPath>..\packages\Newtonsoft.Json.4.5.11\lib\net40\Newtonsoft.Json.dll</HintPath>
@ -103,6 +109,7 @@
<Compile Include="EnsureThat\Resources\ExceptionMessages.Designer.cs" /> <Compile Include="EnsureThat\Resources\ExceptionMessages.Designer.cs" />
<Compile Include="EnsureThat\StringExtensions.cs" /> <Compile Include="EnsureThat\StringExtensions.cs" />
<Compile Include="EnsureThat\TypeParam.cs" /> <Compile Include="EnsureThat\TypeParam.cs" />
<Compile Include="HostController.cs" />
<Compile Include="StringExtention.cs" /> <Compile Include="StringExtention.cs" />
<Compile Include="HttpProvider.cs" /> <Compile Include="HttpProvider.cs" />
<Compile Include="ConfigFileProvider.cs" /> <Compile Include="ConfigFileProvider.cs" />
@ -110,7 +117,6 @@
<Compile Include="Contract\ReportBase.cs" /> <Compile Include="Contract\ReportBase.cs" />
<Compile Include="Contract\ParseErrorReport.cs" /> <Compile Include="Contract\ParseErrorReport.cs" />
<Compile Include="NlogTargets\RemoteTarget.cs" /> <Compile Include="NlogTargets\RemoteTarget.cs" />
<Compile Include="IISProvider.cs" />
<Compile Include="Model\AuthenticationType.cs" /> <Compile Include="Model\AuthenticationType.cs" />
<Compile Include="PathExtentions.cs" /> <Compile Include="PathExtentions.cs" />
<Compile Include="DiskProvider.cs" /> <Compile Include="DiskProvider.cs" />

View File

@ -1,7 +1,4 @@
 namespace NzbDrone.Common
using System.IO;
namespace NzbDrone.Common
{ {
public static class StringExtention public static class StringExtention
{ {

View File

@ -10,18 +10,18 @@ namespace NzbDrone.Common.SysTray
{ {
private readonly ConfigFileProvider _configFileProvider; private readonly ConfigFileProvider _configFileProvider;
private readonly ProcessProvider _processProvider; private readonly ProcessProvider _processProvider;
private readonly IISProvider _iisProvider; private readonly HostController _hostController;
private readonly EnvironmentProvider _environmentProvider; private readonly EnvironmentProvider _environmentProvider;
private readonly NotifyIcon _trayIcon = new NotifyIcon(); private readonly NotifyIcon _trayIcon = new NotifyIcon();
private readonly ContextMenu _trayMenu = new ContextMenu(); private readonly ContextMenu _trayMenu = new ContextMenu();
public SysTrayApp(ConfigFileProvider configFileProvider, ProcessProvider processProvider, public SysTrayApp(ConfigFileProvider configFileProvider, ProcessProvider processProvider,
IISProvider iisProvider, EnvironmentProvider environmentProvider) HostController hostController, EnvironmentProvider environmentProvider)
{ {
_configFileProvider = configFileProvider; _configFileProvider = configFileProvider;
_processProvider = processProvider; _processProvider = processProvider;
_iisProvider = iisProvider; _hostController = hostController;
_environmentProvider = environmentProvider; _environmentProvider = environmentProvider;
} }
@ -73,7 +73,7 @@ namespace NzbDrone.Common.SysTray
private void LaunchBrowser(object sender, EventArgs e) private void LaunchBrowser(object sender, EventArgs e)
{ {
_processProvider.Start(_iisProvider.AppUrl); _processProvider.Start(_hostController.AppUrl);
} }
} }
} }

View File

@ -2,6 +2,8 @@
<packages> <packages>
<package id="Autofac" version="3.0.1" targetFramework="net40" /> <package id="Autofac" version="3.0.1" targetFramework="net40" />
<package id="Exceptron.Client" version="1.0.7" targetFramework="net40" /> <package id="Exceptron.Client" version="1.0.7" targetFramework="net40" />
<package id="Nancy" version="0.16.1" targetFramework="net40" />
<package id="Nancy.Hosting.Self" version="0.16.1" targetFramework="net40" />
<package id="Newtonsoft.Json" version="4.5.11" targetFramework="net40" /> <package id="Newtonsoft.Json" version="4.5.11" targetFramework="net40" />
<package id="NLog" version="2.0.0.2000" /> <package id="NLog" version="2.0.0.2000" />
</packages> </packages>

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection;
using Autofac; using Autofac;
using FluentAssertions; using FluentAssertions;
using NCrunch.Framework; using NCrunch.Framework;
@ -15,15 +16,20 @@ using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test namespace NzbDrone.Core.Test
{ {
[Ignore]
[TestFixture] [TestFixture]
[ExclusivelyUses("REAL_LOG_FILE")] [ExclusivelyUses("REAL_LOG_FILE")]
[Serial] [Serial]
class CentralDispatchFixture : CoreTest class CentralDispatchFixture : CoreTest
{ {
readonly IList<string> indexers = typeof(CentralDispatch).Assembly.GetTypes().Where(t => t.IsSubclassOf(typeof(IndexerBase))).Select(c => c.ToString()).ToList(); static readonly Assembly NzbDroneCore = Assembly.Load("NzbDrone.Core");
readonly IList<string> jobs = typeof(CentralDispatch).Assembly.GetTypes().Where(t => t.GetInterfaces().Contains(typeof(IJob))).Select(c => c.ToString()).ToList();
readonly IList<Type> extNotifications = typeof(CentralDispatch).Assembly.GetTypes().Where(t => t.IsSubclassOf(typeof(ExternalNotificationBase))).ToList(); readonly IList<string> indexers = NzbDroneCore.GetTypes().Where(t => t.IsSubclassOf(typeof(IndexerBase))).Select(c => c.ToString()).ToList();
readonly IList<Type> metadata = typeof(CentralDispatch).Assembly.GetTypes().Where(t => t.IsSubclassOf(typeof(MetadataBase))).ToList(); readonly IList<string> jobs = NzbDroneCore.GetTypes().Where(t => t.GetInterfaces().Contains(typeof(IJob))).Select(c => c.ToString()).ToList();
readonly IList<Type> extNotifications = NzbDroneCore.GetTypes().Where(t => t.IsSubclassOf(typeof(ExternalNotificationBase))).ToList();
readonly IList<Type> metadata = NzbDroneCore.GetTypes().Where(t => t.IsSubclassOf(typeof(MetadataBase))).ToList();
private readonly IContainer kernel; private readonly IContainer kernel;
@ -35,10 +41,6 @@ namespace NzbDrone.Core.Test
} }
InitLogging(); InitLogging();
var dispatch = new CentralDispatch();
kernel = dispatch.BuildContainer();
WebTimer.Stop();
} }
[Test] [Test]
@ -50,7 +52,7 @@ namespace NzbDrone.Core.Test
[Test] [Test]
public void Resolve_all_providers() public void Resolve_all_providers()
{ {
var providers = typeof(CentralDispatch).Assembly.GetTypes().Where(t => t.Name.EndsWith("Provider")).ToList(); var providers = NzbDroneCore.GetTypes().Where(t => t.Name.EndsWith("Provider")).ToList();
providers.Should().NotBeEmpty(); providers.Should().NotBeEmpty();

View File

@ -1,65 +0,0 @@
using System;
using System.Linq;
using Autofac;
using FluentAssertions;
using NLog;
using NUnit.Framework;
using NzbDrone.Common;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Repository;
using NzbDrone.Core.Test.Framework;
using PetaPoco;
namespace NzbDrone.Core.Test.Integeration
{
[TestFixture(Category = "ServiceIngeneration")]
public class ServiceIntegerationFixture : SqlCeTest
{
private IContainer _container;
[SetUp]
public void Setup()
{
WithRealDb();
var builder = new CentralDispatch().ContainerBuilder;
builder.Register(c => Db)
.As<IDatabase>();
builder.RegisterType<ReferenceDataProvider>().AsSelf();
builder.RegisterType<SceneMappingProvider>().AsSelf();
builder.RegisterType<HttpProvider>().AsSelf();
builder.RegisterType<ConfigProvider>().AsSelf();
_container = builder.Build();
Mocker.GetMock<ConfigProvider>().SetupGet(s => s.ServiceRootUrl)
.Returns("http://services.nzbdrone.com");
}
[Test]
public void should_be_able_to_update_scene_mapping()
{
_container.Resolve<SceneMappingProvider>().UpdateMappings();
var mappings = Db.Fetch<SceneMapping>();
mappings.Should().NotBeEmpty();
mappings.Should().OnlyContain(c => !string.IsNullOrWhiteSpace(c.CleanTitle));
mappings.Should().OnlyContain(c => !string.IsNullOrWhiteSpace(c.SceneName));
mappings.Should().OnlyContain(c => c.SeriesId > 0);
}
[Test]
public void should_be_able_to_get_daily_series_ids()
{
var dailySeries = _container.Resolve<ReferenceDataProvider>().GetDailySeriesIds();
dailySeries.Should().NotBeEmpty();
dailySeries.Should().OnlyContain(c => c > 0);
}
}
}

View File

@ -166,7 +166,6 @@
<Compile Include="ProviderTests\TvRageProviderTests\SearchSeriesFixture.cs" /> <Compile Include="ProviderTests\TvRageProviderTests\SearchSeriesFixture.cs" />
<Compile Include="QualityTypesTest.cs" /> <Compile Include="QualityTypesTest.cs" />
<Compile Include="EpisodeParseResultTest.cs" /> <Compile Include="EpisodeParseResultTest.cs" />
<Compile Include="Integeration\ServiceIntegerationFixture.cs" />
<Compile Include="JobTests\BacklogSearchJobTest.cs" /> <Compile Include="JobTests\BacklogSearchJobTest.cs" />
<Compile Include="JobTests\BannerDownloadJobTest.cs" /> <Compile Include="JobTests\BannerDownloadJobTest.cs" />
<Compile Include="JobTests\RssSyncJobTest.cs" /> <Compile Include="JobTests\RssSyncJobTest.cs" />

View File

@ -1,91 +0,0 @@
using System;
using System.Diagnostics;
using System.Linq;
using Autofac;
using NLog;
using NzbDrone.Common;
using NzbDrone.Core.Instrumentation;
using NzbDrone.Core.Providers.Core;
using SignalR;
namespace NzbDrone.Core
{
public class CentralDispatch
{
private readonly Logger _logger;
private readonly EnvironmentProvider _environmentProvider;
public ContainerBuilder ContainerBuilder { get; private set; }
public CentralDispatch()
{
_logger = LogManager.GetCurrentClassLogger();
_environmentProvider = new EnvironmentProvider();
_logger.Debug("Initializing ContainerBuilder:");
ContainerBuilder = new ContainerBuilder();
}
private void RegisterReporting(IComponentContext container)
{
EnvironmentProvider.UGuid = container.Resolve<ConfigProvider>().UGuid;
ReportingService.RestProvider = container.Resolve<RestProvider>();
ReportingService.SetupExceptronDriver();
}
public void DedicateToHost()
{
try
{
var pid = _environmentProvider.NzbDroneProcessIdFromEnviroment;
_logger.Debug("Attaching to parent process ({0}) for automatic termination.", pid);
var hostProcess = Process.GetProcessById(Convert.ToInt32(pid));
hostProcess.EnableRaisingEvents = true;
hostProcess.Exited += (delegate
{
_logger.Info("Host has been terminated. Shutting down web server.");
ShutDown();
});
_logger.Debug("Successfully Attached to host. Process [{0}]", hostProcess.ProcessName);
}
catch (Exception e)
{
_logger.FatalException("An error has occurred while dedicating to host.", e);
}
}
public IContainer BuildContainer()
{
_logger.Debug("Initializing Components");
ContainerBuilder.RegisterCoreServices();
var container = ContainerBuilder.Build();
container.Resolve<DatabaseTarget>().Register();
LogConfiguration.Reload();
RegisterReporting(container);
container.Resolve<WebTimer>().StartTimer(30);
//SignalR
GlobalHost.DependencyResolver = new AutofacSignalrDependencyResolver(container.BeginLifetimeScope("SignalR"));
return container;
}
private void ShutDown()
{
_logger.Info("Shutting down application...");
WebTimer.Stop();
Process.GetCurrentProcess().Kill();
}
}
}

View File

@ -4,6 +4,7 @@ using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using NLog; using NLog;
using NzbDrone.Core.Lifecycle;
using NzbDrone.Core.Model; using NzbDrone.Core.Model;
using NzbDrone.Core.Model.Notification; using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.Providers; using NzbDrone.Core.Providers;
@ -19,12 +20,13 @@ namespace NzbDrone.Core.Jobs
bool QueueJob(string jobTypeString); bool QueueJob(string jobTypeString);
} }
public class JobController : IJobController public class JobController : IJobController, IInitializable
{ {
private readonly NotificationProvider _notificationProvider; private readonly NotificationProvider _notificationProvider;
private readonly IEnumerable<IJob> _jobs; private readonly IEnumerable<IJob> _jobs;
private readonly IJobRepository _jobRepository; private readonly IJobRepository _jobRepository;
private readonly Logger logger; private readonly Logger _logger;
private Timer _timer;
private Thread _jobThread; private Thread _jobThread;
public Stopwatch StopWatch { get; private set; } public Stopwatch StopWatch { get; private set; }
@ -41,10 +43,16 @@ namespace NzbDrone.Core.Jobs
_notificationProvider = notificationProvider; _notificationProvider = notificationProvider;
_jobs = jobs; _jobs = jobs;
_jobRepository = jobRepository; _jobRepository = jobRepository;
this.logger = logger; _logger = logger;
ResetThread(); ResetThread();
} }
public void Init()
{
_timer = new Timer(c => QueueScheduled());
_timer.Change(0, 60 * 1000);
}
public List<JobQueueItem> Queue public List<JobQueueItem> Queue
{ {
get get
@ -62,7 +70,7 @@ namespace NzbDrone.Core.Jobs
if (_jobThread.IsAlive) if (_jobThread.IsAlive)
{ {
logger.Trace("Queue is already running. Ignoring scheduler's request."); _logger.Trace("Queue is already running. Ignoring scheduler's request.");
return; return;
} }
} }
@ -73,7 +81,7 @@ namespace NzbDrone.Core.Jobs
pendingJobs.ForEach(jobType => QueueJob(jobType, source: JobQueueItem.JobSourceType.Scheduler)); pendingJobs.ForEach(jobType => QueueJob(jobType, source: JobQueueItem.JobSourceType.Scheduler));
logger.Trace("{0} Scheduled tasks have been added to the queue", pendingJobs.Count); _logger.Trace("{0} Scheduled tasks have been added to the queue", pendingJobs.Count);
} }
public virtual void QueueJob(Type jobType, dynamic options = null, JobQueueItem.JobSourceType source = JobQueueItem.JobSourceType.User) public virtual void QueueJob(Type jobType, dynamic options = null, JobQueueItem.JobSourceType source = JobQueueItem.JobSourceType.User)
@ -85,7 +93,7 @@ namespace NzbDrone.Core.Jobs
Source = source Source = source
}; };
logger.Debug("Attempting to queue {0}", queueItem); _logger.Debug("Attempting to queue {0}", queueItem);
lock (_executionLock) lock (_executionLock)
{ {
@ -96,17 +104,17 @@ namespace NzbDrone.Core.Jobs
if (!Queue.Contains(queueItem)) if (!Queue.Contains(queueItem))
{ {
Queue.Add(queueItem); Queue.Add(queueItem);
logger.Trace("Job {0} added to the queue. current items in queue: {1}", queueItem, Queue.Count); _logger.Trace("Job {0} added to the queue. current items in queue: {1}", queueItem, Queue.Count);
} }
else else
{ {
logger.Info("{0} already exists in the queue. Skipping. current items in queue: {1}", queueItem, Queue.Count); _logger.Info("{0} already exists in the queue. Skipping. current items in queue: {1}", queueItem, Queue.Count);
} }
} }
if (_jobThread.IsAlive) if (_jobThread.IsAlive)
{ {
logger.Trace("Queue is already running. No need to start it up."); _logger.Trace("Queue is already running. No need to start it up.");
return; return;
} }
@ -145,7 +153,7 @@ namespace NzbDrone.Core.Jobs
if (Queue.Count != 0) if (Queue.Count != 0)
{ {
job = Queue.OrderBy(c => c.Source).First(); job = Queue.OrderBy(c => c.Source).First();
logger.Trace("Popping {0} from the queue.", job); _logger.Trace("Popping {0} from the queue.", job);
Queue.Remove(job); Queue.Remove(job);
} }
} }
@ -161,7 +169,7 @@ namespace NzbDrone.Core.Jobs
} }
catch (Exception e) catch (Exception e)
{ {
logger.FatalException("An error has occurred while executing job.", e); _logger.FatalException("An error has occurred while executing job.", e);
} }
} }
@ -169,16 +177,16 @@ namespace NzbDrone.Core.Jobs
} }
catch (ThreadAbortException e) catch (ThreadAbortException e)
{ {
logger.Warn(e.Message); _logger.Warn(e.Message);
} }
catch (Exception e) catch (Exception e)
{ {
logger.ErrorException("Error has occurred in queue processor thread", e); _logger.ErrorException("Error has occurred in queue processor thread", e);
} }
finally finally
{ {
StopWatch.Stop(); StopWatch.Stop();
logger.Trace("Finished processing jobs in the queue."); _logger.Trace("Finished processing jobs in the queue.");
} }
} }
@ -187,7 +195,7 @@ namespace NzbDrone.Core.Jobs
var jobImplementation = _jobs.SingleOrDefault(t => t.GetType() == queueItem.JobType); var jobImplementation = _jobs.SingleOrDefault(t => t.GetType() == queueItem.JobType);
if (jobImplementation == null) if (jobImplementation == null)
{ {
logger.Error("Unable to locate implementation for '{0}'. Make sure it is properly registered.", queueItem.JobType); _logger.Error("Unable to locate implementation for '{0}'. Make sure it is properly registered.", queueItem.JobType);
return; return;
} }
@ -196,7 +204,7 @@ namespace NzbDrone.Core.Jobs
{ {
try try
{ {
logger.Debug("Starting {0}. Last execution {1}", queueItem, jobDefinition.LastExecution); _logger.Debug("Starting {0}. Last execution {1}", queueItem, jobDefinition.LastExecution);
var sw = Stopwatch.StartNew(); var sw = Stopwatch.StartNew();
@ -208,7 +216,7 @@ namespace NzbDrone.Core.Jobs
jobDefinition.Success = true; jobDefinition.Success = true;
sw.Stop(); sw.Stop();
logger.Debug("Job {0} successfully completed in {1:0}.{2} seconds.", queueItem, sw.Elapsed.TotalSeconds, sw.Elapsed.Milliseconds / 100, _logger.Debug("Job {0} successfully completed in {1:0}.{2} seconds.", queueItem, sw.Elapsed.TotalSeconds, sw.Elapsed.Milliseconds / 100,
sw.Elapsed.Seconds); sw.Elapsed.Seconds);
} }
catch (ThreadAbortException) catch (ThreadAbortException)
@ -217,7 +225,7 @@ namespace NzbDrone.Core.Jobs
} }
catch (Exception e) catch (Exception e)
{ {
logger.ErrorException("An error has occurred while executing job [" + jobImplementation.Name + "].", e); _logger.ErrorException("An error has occurred while executing job [" + jobImplementation.Name + "].", e);
_notification.Status = ProgressNotificationStatus.Failed; _notification.Status = ProgressNotificationStatus.Failed;
_notification.CurrentMessage = jobImplementation.Name + " Failed."; _notification.CurrentMessage = jobImplementation.Name + " Failed.";
@ -237,7 +245,7 @@ namespace NzbDrone.Core.Jobs
{ {
if (StopWatch.Elapsed.TotalHours > 1) if (StopWatch.Elapsed.TotalHours > 1)
{ {
logger.Warn("Thread job has been running for more than an hour. fuck it!"); _logger.Warn("Thread job has been running for more than an hour. fuck it!");
ResetThread(); ResetThread();
} }
} }
@ -249,8 +257,10 @@ namespace NzbDrone.Core.Jobs
_jobThread.Abort(); _jobThread.Abort();
} }
logger.Trace("resetting queue processor thread"); _logger.Trace("resetting queue processor thread");
_jobThread = new Thread(ProcessQueue) { Name = "JobQueueThread" }; _jobThread = new Thread(ProcessQueue) { Name = "JobQueueThread" };
} }
} }
} }

View File

@ -9,13 +9,13 @@ namespace NzbDrone.Core.Lifecycle
{ {
public class AppRestartJob : IJob public class AppRestartJob : IJob
{ {
private readonly IISProvider _iisProvider; private readonly HostController _hostController;
private static readonly Logger logger = LogManager.GetCurrentClassLogger(); private static readonly Logger logger = LogManager.GetCurrentClassLogger();
public AppRestartJob(IISProvider iisProvider) public AppRestartJob(HostController hostController)
{ {
_iisProvider = iisProvider; _hostController = hostController;
} }
public string Name public string Name
@ -33,7 +33,7 @@ namespace NzbDrone.Core.Lifecycle
notification.CurrentMessage = "Restarting NzbDrone"; notification.CurrentMessage = "Restarting NzbDrone";
logger.Info("Restarting NzbDrone"); logger.Info("Restarting NzbDrone");
_iisProvider.StopServer(); _hostController.StopServer();
} }
} }
} }

View File

@ -592,7 +592,6 @@
<Compile Include="RootFolders\RootFolder.cs" /> <Compile Include="RootFolders\RootFolder.cs" />
<Compile Include="Repository\SceneMapping.cs" /> <Compile Include="Repository\SceneMapping.cs" />
<Compile Include="Repository\Series.cs" /> <Compile Include="Repository\Series.cs" />
<Compile Include="CentralDispatch.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Tvdb\Tvdb.cs" /> <Compile Include="Tvdb\Tvdb.cs" />
<Compile Include="Tvdb\Tvdb.Sync.cs" /> <Compile Include="Tvdb\Tvdb.Sync.cs" />
@ -609,7 +608,6 @@
<Compile Include="Tvdb\TvdbServerTime.cs" /> <Compile Include="Tvdb\TvdbServerTime.cs" />
<Compile Include="Tvdb\TvdbUpdate.cs" /> <Compile Include="Tvdb\TvdbUpdate.cs" />
<Compile Include="Tvdb\TvdbUpdateItems.cs" /> <Compile Include="Tvdb\TvdbUpdateItems.cs" />
<Compile Include="WebTimer.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.0,Profile=Client"> <BootstrapperPackage Include=".NETFramework,Version=v4.0,Profile=Client">

View File

@ -1,51 +0,0 @@
using System;
using System.Web;
using System.Web.Caching;
using NLog;
using NzbDrone.Core.Jobs;
namespace NzbDrone.Core
{
public class WebTimer
{
private readonly JobController _jobProvider;
private static CacheItemRemovedCallback _onCacheRemove;
private static bool _stop;
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
public WebTimer(JobController jobProvider)
{
_jobProvider = jobProvider;
}
//TODO: Fix this so the timer doesn't keep running during unit tests.
public void StartTimer(int secondInterval)
{
_onCacheRemove = DoWork;
HttpRuntime.Cache.Insert(GetType().ToString(), secondInterval, null,
DateTime.Now.AddSeconds(secondInterval), Cache.NoSlidingExpiration,
CacheItemPriority.NotRemovable, _onCacheRemove);
}
public void DoWork(string k, object v, CacheItemRemovedReason r)
{
if (!_stop)
{
_jobProvider.QueueScheduled();
StartTimer(Convert.ToInt32(v));
}
}
public static void Stop()
{
Logger.Info("Stopping Web Timer");
_stop = true;
}
}
}

View File

@ -45,7 +45,6 @@ namespace NzbDrone.Services.Service
ModelBinders.Binders.DefaultBinder = new JsonModelBinder(); ModelBinders.Binders.DefaultBinder = new JsonModelBinder();
InitContainer();
} }
// ReSharper disable InconsistentNaming // ReSharper disable InconsistentNaming
@ -72,7 +71,7 @@ namespace NzbDrone.Services.Service
private void InitContainer() private void InitContainer()
{ {
logger.Info("NzbDrone Starting up."); /*/* logger.Info("NzbDrone Starting up.");
var dispatch = new CentralDispatch(); var dispatch = new CentralDispatch();
@ -81,9 +80,9 @@ namespace NzbDrone.Services.Service
MVCRegistration(dispatch.ContainerBuilder); MVCRegistration(dispatch.ContainerBuilder);
var container = dispatch.ContainerBuilder.Build(); var container = dispatch.ContainerBuilder.Build();#1#
DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); DependencyResolver.SetResolver(new AutofacDependencyResolver(container));*/
} }
private static void MVCRegistration(ContainerBuilder builder) private static void MVCRegistration(ContainerBuilder builder)

View File

@ -125,7 +125,7 @@ namespace NzbDrone.Update.Test
Mocker.Resolve<UpdateProvider>().Start(TARGET_FOLDER); Mocker.Resolve<UpdateProvider>().Start(TARGET_FOLDER);
//Assert //Assert
Mocker.GetMock<IISProvider>().Verify(c => c.StopServer(), Times.Once()); Mocker.GetMock<HostController>().Verify(c => c.StopServer(), Times.Once());
} }
[Test] [Test]

View File

@ -1,5 +1,4 @@
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using NLog; using NLog;
@ -13,17 +12,17 @@ namespace NzbDrone.Update.Providers
private readonly ServiceProvider _serviceProvider; private readonly ServiceProvider _serviceProvider;
private readonly ProcessProvider _processProvider; private readonly ProcessProvider _processProvider;
private readonly EnvironmentProvider _environmentProvider; private readonly EnvironmentProvider _environmentProvider;
private readonly IISProvider _iisProvider; private readonly HostController _hostController;
private static readonly Logger logger = LogManager.GetCurrentClassLogger(); private static readonly Logger logger = LogManager.GetCurrentClassLogger();
public UpdateProvider(DiskProvider diskProvider, ServiceProvider serviceProvider, public UpdateProvider(DiskProvider diskProvider, ServiceProvider serviceProvider,
ProcessProvider processProvider, EnvironmentProvider environmentProvider, IISProvider iisProvider) ProcessProvider processProvider, EnvironmentProvider environmentProvider, HostController hostController)
{ {
_diskProvider = diskProvider; _diskProvider = diskProvider;
_serviceProvider = serviceProvider; _serviceProvider = serviceProvider;
_processProvider = processProvider; _processProvider = processProvider;
_environmentProvider = environmentProvider; _environmentProvider = environmentProvider;
_iisProvider = iisProvider; _hostController = hostController;
} }
public UpdateProvider() public UpdateProvider()
@ -80,7 +79,7 @@ namespace NzbDrone.Update.Providers
} }
logger.Info("Killing all orphan IISExpress processes"); logger.Info("Killing all orphan IISExpress processes");
_iisProvider.StopServer(); _hostController.StopServer();
logger.Info("Creating backup of existing installation"); logger.Info("Creating backup of existing installation");
_diskProvider.CopyDirectory(targetFolder, _environmentProvider.GetUpdateBackUpFolder()); _diskProvider.CopyDirectory(targetFolder, _environmentProvider.GetUpdateBackUpFolder());

View File

@ -97,10 +97,6 @@
<Project>{F2BE0FDF-6E47-4827-A420-DD4EF82407F8}</Project> <Project>{F2BE0FDF-6E47-4827-A420-DD4EF82407F8}</Project>
<Name>NzbDrone.Common</Name> <Name>NzbDrone.Common</Name>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\NzbDrone.Web\NzbDrone.Web.csproj">
<Project>{43BD3BBD-1531-4D8F-9C08-E1CD544AB2CD}</Project>
<Name>NzbDrone.Web</Name>
</ProjectReference>
<ProjectReference Include="..\NzbDrone\NzbDrone.csproj"> <ProjectReference Include="..\NzbDrone\NzbDrone.csproj">
<Project>{D12F7F2F-8A3C-415F-88FA-6DD061A84869}</Project> <Project>{D12F7F2F-8A3C-415F-88FA-6DD061A84869}</Project>
<Name>NzbDrone</Name> <Name>NzbDrone</Name>

View File

@ -11,13 +11,10 @@ EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NzbDrone", "NzbDrone\NzbDrone.csproj", "{D12F7F2F-8A3C-415F-88FA-6DD061A84869}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NzbDrone", "NzbDrone\NzbDrone.csproj", "{D12F7F2F-8A3C-415F-88FA-6DD061A84869}"
ProjectSection(ProjectDependencies) = postProject ProjectSection(ProjectDependencies) = postProject
{FF5EE3B6-913B-47CE-9CEB-11C51B4E1205} = {FF5EE3B6-913B-47CE-9CEB-11C51B4E1205} {FF5EE3B6-913B-47CE-9CEB-11C51B4E1205} = {FF5EE3B6-913B-47CE-9CEB-11C51B4E1205}
{43BD3BBD-1531-4D8F-9C08-E1CD544AB2CD} = {43BD3BBD-1531-4D8F-9C08-E1CD544AB2CD}
EndProjectSection EndProjectSection
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NzbDrone.Core", "NzbDrone.Core\NzbDrone.Core.csproj", "{FF5EE3B6-913B-47CE-9CEB-11C51B4E1205}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NzbDrone.Core", "NzbDrone.Core\NzbDrone.Core.csproj", "{FF5EE3B6-913B-47CE-9CEB-11C51B4E1205}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NzbDrone.Web", "NzbDrone.Web\NzbDrone.Web.csproj", "{43BD3BBD-1531-4D8F-9C08-E1CD544AB2CD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NzbDrone.Core.Test", "NzbDrone.Core.Test\NzbDrone.Core.Test.csproj", "{193ADD3B-792B-4173-8E4C-5A3F8F0237F0}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NzbDrone.Core.Test", "NzbDrone.Core.Test\NzbDrone.Core.Test.csproj", "{193ADD3B-792B-4173-8E4C-5A3F8F0237F0}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NzbDrone.App.Test", "NzbDrone.App.Test\NzbDrone.App.Test.csproj", "{C0EA1A40-91AD-4EEB-BD16-2DDDEBD20AE5}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NzbDrone.App.Test", "NzbDrone.App.Test\NzbDrone.App.Test.csproj", "{C0EA1A40-91AD-4EEB-BD16-2DDDEBD20AE5}"
@ -34,8 +31,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NzbDrone.Common.Test", "Nzb
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NzbDrone.Test.Common", "NzbDrone.Test.Common\NzbDrone.Test.Common.csproj", "{CADDFCE0-7509-4430-8364-2074E1EEFCA2}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NzbDrone.Test.Common", "NzbDrone.Test.Common\NzbDrone.Test.Common.csproj", "{CADDFCE0-7509-4430-8364-2074E1EEFCA2}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NzbDrone.Web.UI.Automation", "NzbDrone.Web.UI.Test\NzbDrone.Web.UI.Automation.csproj", "{3CCD64E1-84DA-4853-B7EF-98B02FD4E39E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServiceInstall", "ServiceHelpers\ServiceInstall\ServiceInstall.csproj", "{6BCE712F-846D-4846-9D1B-A66B858DA755}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServiceInstall", "ServiceHelpers\ServiceInstall\ServiceInstall.csproj", "{6BCE712F-846D-4846-9D1B-A66B858DA755}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServiceUninstall", "ServiceHelpers\ServiceUninstall\ServiceUninstall.csproj", "{700D0B95-95CD-43F3-B6C9-FAA0FC1358D4}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServiceUninstall", "ServiceHelpers\ServiceUninstall\ServiceUninstall.csproj", "{700D0B95-95CD-43F3-B6C9-FAA0FC1358D4}"
@ -124,26 +119,6 @@ Global
{FF5EE3B6-913B-47CE-9CEB-11C51B4E1205}.Services|x64.Build.0 = Release|x64 {FF5EE3B6-913B-47CE-9CEB-11C51B4E1205}.Services|x64.Build.0 = Release|x64
{FF5EE3B6-913B-47CE-9CEB-11C51B4E1205}.Services|x86.ActiveCfg = Release|x86 {FF5EE3B6-913B-47CE-9CEB-11C51B4E1205}.Services|x86.ActiveCfg = Release|x86
{FF5EE3B6-913B-47CE-9CEB-11C51B4E1205}.Services|x86.Build.0 = Release|x86 {FF5EE3B6-913B-47CE-9CEB-11C51B4E1205}.Services|x86.Build.0 = Release|x86
{43BD3BBD-1531-4D8F-9C08-E1CD544AB2CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{43BD3BBD-1531-4D8F-9C08-E1CD544AB2CD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{43BD3BBD-1531-4D8F-9C08-E1CD544AB2CD}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{43BD3BBD-1531-4D8F-9C08-E1CD544AB2CD}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{43BD3BBD-1531-4D8F-9C08-E1CD544AB2CD}.Debug|x64.ActiveCfg = Debug|Any CPU
{43BD3BBD-1531-4D8F-9C08-E1CD544AB2CD}.Debug|x86.ActiveCfg = Debug|x86
{43BD3BBD-1531-4D8F-9C08-E1CD544AB2CD}.Debug|x86.Build.0 = Debug|x86
{43BD3BBD-1531-4D8F-9C08-E1CD544AB2CD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{43BD3BBD-1531-4D8F-9C08-E1CD544AB2CD}.Release|Any CPU.Build.0 = Release|Any CPU
{43BD3BBD-1531-4D8F-9C08-E1CD544AB2CD}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{43BD3BBD-1531-4D8F-9C08-E1CD544AB2CD}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{43BD3BBD-1531-4D8F-9C08-E1CD544AB2CD}.Release|x64.ActiveCfg = Release|Any CPU
{43BD3BBD-1531-4D8F-9C08-E1CD544AB2CD}.Release|x86.ActiveCfg = Release|x86
{43BD3BBD-1531-4D8F-9C08-E1CD544AB2CD}.Release|x86.Build.0 = Release|x86
{43BD3BBD-1531-4D8F-9C08-E1CD544AB2CD}.Services|Any CPU.ActiveCfg = Release|Any CPU
{43BD3BBD-1531-4D8F-9C08-E1CD544AB2CD}.Services|Any CPU.Build.0 = Release|Any CPU
{43BD3BBD-1531-4D8F-9C08-E1CD544AB2CD}.Services|Mixed Platforms.ActiveCfg = Release|Any CPU
{43BD3BBD-1531-4D8F-9C08-E1CD544AB2CD}.Services|Mixed Platforms.Build.0 = Release|Any CPU
{43BD3BBD-1531-4D8F-9C08-E1CD544AB2CD}.Services|x64.ActiveCfg = Release|Any CPU
{43BD3BBD-1531-4D8F-9C08-E1CD544AB2CD}.Services|x86.ActiveCfg = Release|Any CPU
{193ADD3B-792B-4173-8E4C-5A3F8F0237F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {193ADD3B-792B-4173-8E4C-5A3F8F0237F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{193ADD3B-792B-4173-8E4C-5A3F8F0237F0}.Debug|Any CPU.Build.0 = Debug|Any CPU {193ADD3B-792B-4173-8E4C-5A3F8F0237F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{193ADD3B-792B-4173-8E4C-5A3F8F0237F0}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU {193ADD3B-792B-4173-8E4C-5A3F8F0237F0}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
@ -298,24 +273,6 @@ Global
{CADDFCE0-7509-4430-8364-2074E1EEFCA2}.Services|Mixed Platforms.Build.0 = Release|Any CPU {CADDFCE0-7509-4430-8364-2074E1EEFCA2}.Services|Mixed Platforms.Build.0 = Release|Any CPU
{CADDFCE0-7509-4430-8364-2074E1EEFCA2}.Services|x64.ActiveCfg = Release|Any CPU {CADDFCE0-7509-4430-8364-2074E1EEFCA2}.Services|x64.ActiveCfg = Release|Any CPU
{CADDFCE0-7509-4430-8364-2074E1EEFCA2}.Services|x86.ActiveCfg = Release|Any CPU {CADDFCE0-7509-4430-8364-2074E1EEFCA2}.Services|x86.ActiveCfg = Release|Any CPU
{3CCD64E1-84DA-4853-B7EF-98B02FD4E39E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3CCD64E1-84DA-4853-B7EF-98B02FD4E39E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3CCD64E1-84DA-4853-B7EF-98B02FD4E39E}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{3CCD64E1-84DA-4853-B7EF-98B02FD4E39E}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{3CCD64E1-84DA-4853-B7EF-98B02FD4E39E}.Debug|x64.ActiveCfg = Debug|Any CPU
{3CCD64E1-84DA-4853-B7EF-98B02FD4E39E}.Debug|x86.ActiveCfg = Debug|x86
{3CCD64E1-84DA-4853-B7EF-98B02FD4E39E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3CCD64E1-84DA-4853-B7EF-98B02FD4E39E}.Release|Any CPU.Build.0 = Release|Any CPU
{3CCD64E1-84DA-4853-B7EF-98B02FD4E39E}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{3CCD64E1-84DA-4853-B7EF-98B02FD4E39E}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{3CCD64E1-84DA-4853-B7EF-98B02FD4E39E}.Release|x64.ActiveCfg = Release|Any CPU
{3CCD64E1-84DA-4853-B7EF-98B02FD4E39E}.Release|x86.ActiveCfg = Release|x86
{3CCD64E1-84DA-4853-B7EF-98B02FD4E39E}.Services|Any CPU.ActiveCfg = Release|Any CPU
{3CCD64E1-84DA-4853-B7EF-98B02FD4E39E}.Services|Any CPU.Build.0 = Release|Any CPU
{3CCD64E1-84DA-4853-B7EF-98B02FD4E39E}.Services|Mixed Platforms.ActiveCfg = Release|Any CPU
{3CCD64E1-84DA-4853-B7EF-98B02FD4E39E}.Services|Mixed Platforms.Build.0 = Release|Any CPU
{3CCD64E1-84DA-4853-B7EF-98B02FD4E39E}.Services|x64.ActiveCfg = Release|Any CPU
{3CCD64E1-84DA-4853-B7EF-98B02FD4E39E}.Services|x86.ActiveCfg = Release|Any CPU
{6BCE712F-846D-4846-9D1B-A66B858DA755}.Debug|Any CPU.ActiveCfg = Debug|x86 {6BCE712F-846D-4846-9D1B-A66B858DA755}.Debug|Any CPU.ActiveCfg = Debug|x86
{6BCE712F-846D-4846-9D1B-A66B858DA755}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 {6BCE712F-846D-4846-9D1B-A66B858DA755}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
{6BCE712F-846D-4846-9D1B-A66B858DA755}.Debug|Mixed Platforms.Build.0 = Debug|x86 {6BCE712F-846D-4846-9D1B-A66B858DA755}.Debug|Mixed Platforms.Build.0 = Debug|x86
@ -509,7 +466,6 @@ Global
{C0EA1A40-91AD-4EEB-BD16-2DDDEBD20AE5} = {57A04B72-8088-4F75-A582-1158CF8291F7} {C0EA1A40-91AD-4EEB-BD16-2DDDEBD20AE5} = {57A04B72-8088-4F75-A582-1158CF8291F7}
{35388E8E-0CDB-4A84-AD16-E4B6EFDA5D97} = {57A04B72-8088-4F75-A582-1158CF8291F7} {35388E8E-0CDB-4A84-AD16-E4B6EFDA5D97} = {57A04B72-8088-4F75-A582-1158CF8291F7}
{BEC74619-DDBB-4FBA-B517-D3E20AFC9997} = {57A04B72-8088-4F75-A582-1158CF8291F7} {BEC74619-DDBB-4FBA-B517-D3E20AFC9997} = {57A04B72-8088-4F75-A582-1158CF8291F7}
{3CCD64E1-84DA-4853-B7EF-98B02FD4E39E} = {57A04B72-8088-4F75-A582-1158CF8291F7}
{FAFB5948-A222-4CF6-AD14-026BE7564802} = {47697CDB-27B6-4B05-B4F8-0CBE6F6EDF97} {FAFB5948-A222-4CF6-AD14-026BE7564802} = {47697CDB-27B6-4B05-B4F8-0CBE6F6EDF97}
{CADDFCE0-7509-4430-8364-2074E1EEFCA2} = {47697CDB-27B6-4B05-B4F8-0CBE6F6EDF97} {CADDFCE0-7509-4430-8364-2074E1EEFCA2} = {47697CDB-27B6-4B05-B4F8-0CBE6F6EDF97}
{6BCE712F-846D-4846-9D1B-A66B858DA755} = {F9E67978-5CD6-4A5F-827B-4249711C0B02} {6BCE712F-846D-4846-9D1B-A66B858DA755} = {F9E67978-5CD6-4A5F-827B-4249711C0B02}

View File

@ -1,5 +1,6 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> <wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=CheckNamespace/@EntryIndexedValue">ERROR</s:String> <s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=CheckNamespace/@EntryIndexedValue">ERROR</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ClassNeverInstantiated_002EGlobal/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ConvertIfStatementToReturnStatement/@EntryIndexedValue">DO_NOT_SHOW</s:String> <s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ConvertIfStatementToReturnStatement/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/JavaScriptNaming/UserRules/=JS_005FPARAMETER/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb"&gt;&lt;ExtraRule Prefix="" Suffix="" Style="AaBb" /&gt;&lt;/Policy&gt;</s:String> <s:String x:Key="/Default/CodeStyle/Naming/JavaScriptNaming/UserRules/=JS_005FPARAMETER/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb"&gt;&lt;ExtraRule Prefix="" Suffix="" Style="AaBb" /&gt;&lt;/Policy&gt;</s:String>
<s:String x:Key="/Default/Environment/Editor/MatchingBraceHighlighting/Position/@EntryValue">BOTH_SIDES</s:String> <s:String x:Key="/Default/Environment/Editor/MatchingBraceHighlighting/Position/@EntryValue">BOTH_SIDES</s:String>

View File

@ -14,22 +14,20 @@ namespace NzbDrone
private static readonly Logger logger = LogManager.GetCurrentClassLogger(); private static readonly Logger logger = LogManager.GetCurrentClassLogger();
private readonly ConfigFileProvider _configFileProvider; private readonly ConfigFileProvider _configFileProvider;
private readonly DebuggerProvider _debuggerProvider;
private readonly EnvironmentProvider _environmentProvider; private readonly EnvironmentProvider _environmentProvider;
private readonly IISProvider _iisProvider; private readonly HostController _hostController;
private readonly ProcessProvider _processProvider; private readonly ProcessProvider _processProvider;
private readonly MonitoringProvider _monitoringProvider; private readonly MonitoringProvider _monitoringProvider;
private readonly SecurityProvider _securityProvider; private readonly SecurityProvider _securityProvider;
private readonly DiskProvider _diskProvider; private readonly DiskProvider _diskProvider;
public ApplicationServer(ConfigFileProvider configFileProvider, IISProvider iisProvider, public ApplicationServer(ConfigFileProvider configFileProvider, HostController hostController,
DebuggerProvider debuggerProvider, EnvironmentProvider environmentProvider, EnvironmentProvider environmentProvider,
ProcessProvider processProvider, MonitoringProvider monitoringProvider, ProcessProvider processProvider, MonitoringProvider monitoringProvider,
SecurityProvider securityProvider, DiskProvider diskProvider) SecurityProvider securityProvider, DiskProvider diskProvider)
{ {
_configFileProvider = configFileProvider; _configFileProvider = configFileProvider;
_iisProvider = iisProvider; _hostController = hostController;
_debuggerProvider = debuggerProvider;
_environmentProvider = environmentProvider; _environmentProvider = environmentProvider;
_processProvider = processProvider; _processProvider = processProvider;
_monitoringProvider = monitoringProvider; _monitoringProvider = monitoringProvider;
@ -49,7 +47,7 @@ namespace NzbDrone
public virtual void Start() public virtual void Start()
{ {
_iisProvider.StopServer(); _hostController.StopServer();
_securityProvider.MakeAccessible(); _securityProvider.MakeAccessible();
if(_securityProvider.IsCurrentUserAdmin()) if(_securityProvider.IsCurrentUserAdmin())
@ -59,17 +57,16 @@ namespace NzbDrone
_diskProvider.CreateDirectory(tempFiles); _diskProvider.CreateDirectory(tempFiles);
} }
_iisProvider.StartServer(); _hostController.StartServer();
//Todo: verify that IIS is actually started //Todo: verify that IIS is actually started
_debuggerProvider.Attach();
if (_environmentProvider.IsUserInteractive && _configFileProvider.LaunchBrowser) if (_environmentProvider.IsUserInteractive && _configFileProvider.LaunchBrowser)
{ {
try try
{ {
logger.Info("Starting default browser. {0}", _iisProvider.AppUrl); logger.Info("Starting default browser. {0}", _hostController.AppUrl);
_processProvider.Start(_iisProvider.AppUrl); _processProvider.Start(_hostController.AppUrl);
} }
catch (Exception e) catch (Exception e)
{ {
@ -83,7 +80,7 @@ namespace NzbDrone
protected override void OnStop() protected override void OnStop()
{ {
logger.Info("Attempting to stop application."); logger.Info("Attempting to stop application.");
_iisProvider.StopServer(); _hostController.StopServer();
logger.Info("Application has finished stop routine."); logger.Info("Application has finished stop routine.");
} }
} }

View File

@ -1,6 +1,9 @@
using Autofac; using Autofac;
using NLog; using NLog;
using Nancy.Bootstrapper;
using NzbDrone.Api;
using NzbDrone.Common; using NzbDrone.Common;
using NzbDrone.Core.Instrumentation;
using NzbDrone.Providers; using NzbDrone.Providers;
namespace NzbDrone namespace NzbDrone
@ -31,12 +34,15 @@ namespace NzbDrone
builder.RegisterAssemblyTypes(typeof(DiskProvider).Assembly).SingleInstance(); builder.RegisterAssemblyTypes(typeof(DiskProvider).Assembly).SingleInstance();
builder.RegisterType<Router>(); builder.RegisterType<Router>();
builder.RegisterModule<LogInjectionModule>();
builder.RegisterType<NancyBootstrapper>().As<INancyBootstrapper>().SingleInstance();
builder.RegisterType<ApplicationServer>().SingleInstance(); builder.RegisterType<ApplicationServer>().SingleInstance();
builder.RegisterType<ConfigFileProvider>().SingleInstance(); builder.RegisterType<ConfigFileProvider>().SingleInstance();
builder.RegisterType<ConsoleProvider>().SingleInstance(); builder.RegisterType<ConsoleProvider>().SingleInstance();
builder.RegisterType<DebuggerProvider>().SingleInstance();
builder.RegisterType<EnvironmentProvider>().SingleInstance(); builder.RegisterType<EnvironmentProvider>().SingleInstance();
builder.RegisterType<IISProvider>().SingleInstance(); builder.RegisterType<HostController>().SingleInstance();
builder.RegisterType<MonitoringProvider>().SingleInstance(); builder.RegisterType<MonitoringProvider>().SingleInstance();
builder.RegisterType<ProcessProvider>().SingleInstance(); builder.RegisterType<ProcessProvider>().SingleInstance();
builder.RegisterType<ServiceProvider>().SingleInstance(); builder.RegisterType<ServiceProvider>().SingleInstance();

View File

@ -106,8 +106,6 @@
</Compile> </Compile>
<Compile Include="CentralDispatch.cs" /> <Compile Include="CentralDispatch.cs" />
<Compile Include="Model\ApplicationMode.cs" /> <Compile Include="Model\ApplicationMode.cs" />
<Compile Include="Providers\DebuggerProvider.cs" />
<Compile Include="ProcessAttacher.cs" />
<Compile Include="AppMain.cs" /> <Compile Include="AppMain.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Providers\MonitoringProvider.cs" /> <Compile Include="Providers\MonitoringProvider.cs" />
@ -151,6 +149,10 @@
<Project>{F2BE0FDF-6E47-4827-A420-DD4EF82407F8}</Project> <Project>{F2BE0FDF-6E47-4827-A420-DD4EF82407F8}</Project>
<Name>NzbDrone.Common</Name> <Name>NzbDrone.Common</Name>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\NzbDrone.Core\NzbDrone.Core.csproj">
<Project>{FF5EE3B6-913B-47CE-9CEB-11C51B4E1205}</Project>
<Name>NzbDrone.Core</Name>
</ProjectReference>
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup> <PropertyGroup>

View File

@ -104,8 +104,6 @@
</Compile> </Compile>
<Compile Include="CentralDispatch.cs" /> <Compile Include="CentralDispatch.cs" />
<Compile Include="Model\ApplicationMode.cs" /> <Compile Include="Model\ApplicationMode.cs" />
<Compile Include="Providers\DebuggerProvider.cs" />
<Compile Include="ProcessAttacher.cs" />
<Compile Include="AppMain.cs" /> <Compile Include="AppMain.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Providers\MonitoringProvider.cs" /> <Compile Include="Providers\MonitoringProvider.cs" />
@ -149,6 +147,10 @@
<Project>{F2BE0FDF-6E47-4827-A420-DD4EF82407F8}</Project> <Project>{F2BE0FDF-6E47-4827-A420-DD4EF82407F8}</Project>
<Name>NzbDrone.Common</Name> <Name>NzbDrone.Common</Name>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\NzbDrone.Core\NzbDrone.Core.csproj">
<Project>{FF5EE3B6-913B-47CE-9CEB-11C51B4E1205}</Project>
<Name>NzbDrone.Core</Name>
</ProjectReference>
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup> <PropertyGroup>

View File

@ -1,167 +0,0 @@
/* SOURCE: http://lazy.codeplex.com/
* File: http://lazy.codeplex.com/SourceControl/changeset/view/55373#307770
* Author: pablito900
* Licence: GNU General Public License version 2 (GPLv2)
*/
#if DEBUG
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.InteropServices;
using EnvDTE80;
using Process = EnvDTE.Process;
using Thread = System.Threading.Thread;
namespace NzbDrone
{
[DebuggerStepThrough]
public class ProcessAttacher
{
public static void Attach()
{
DTE2 dte2;
try
{
dte2 = (DTE2)Marshal.GetActiveObject("VisualStudio.DTE.10.0");
}
catch (Exception e)
{
dte2 = (DTE2)Marshal.GetActiveObject("VisualStudio.DTE.11.0");
}
var pa = new ProcessAttacher(dte2, "iisexpress", 10);
pa.PessimisticAttachManaged();
// Get an instance of the currently running Visual Studio IDE.
}
#region private
private readonly Dictionary<AttachType, string> _attachTypesMap;
private readonly DTE2 _dte;
private readonly string _processName;
private readonly int _waitTimeout;
#endregion
#region ctor
private ProcessAttacher(DTE2 dte, string processName, int waitTimeout)
{
_processName = processName;
_waitTimeout = waitTimeout;
_dte = dte;
_attachTypesMap = new Dictionary<AttachType, string>
{
{AttachType.Managed, "Managed"}
};
}
#endregion
#region private methods
private AttachResult Attach(AttachType attachType)
{
string engine = _attachTypesMap[attachType];
if (IsBeingDebugged())
{
return AttachResult.BeingDebugged;
}
var dbg = _dte.Debugger as Debugger2;
var trans = dbg.Transports.Item("Default");
var eng = trans.Engines.Item(engine);
Process2 proc = null;
try
{
proc = dbg.GetProcesses(trans, "").Item(_processName) as Process2;
}
catch (Exception)
{
return AttachResult.NotRunning;
}
proc.Attach2(eng);
return AttachResult.Attached;
}
private AttachResult PessimisticAttach(AttachType attachType)
{
var res = Attach(attachType);
var timeout = DateTime.Now.AddSeconds(_waitTimeout);
while (res == AttachResult.NotRunning && timeout > DateTime.Now)
{
res = Attach(attachType);
Thread.Sleep(100);
}
return res;
}
private bool IsBeingDebugged()
{
if (_dte.Debugger.DebuggedProcesses != null)
{
foreach (Process process in _dte.Debugger.DebuggedProcesses)
{
if (process.Name.IndexOf(_processName) != -1)
{
return true;
}
}
}
return false;
}
#endregion
#region public methods
public void OptimisticAttachManaged()
{
Attach(AttachType.Managed);
}
public void PessimisticAttachManaged()
{
PessimisticAttach(AttachType.Managed);
}
#endregion
#region Nested type: AttachResult
private enum AttachResult
{
Attached,
NotRunning,
BeingDebugged
}
#endregion
#region Nested type: AttachType
private enum AttachType
{
Managed,
Native,
ManagedAndNative
}
#endregion
}
}
#endif

View File

@ -1,47 +0,0 @@
using System;
using System.Diagnostics;
using System.Threading;
using NLog;
namespace NzbDrone.Providers
{
[DebuggerStepThroughAttribute]
public class DebuggerProvider
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
public virtual void Attach()
{
#if DEBUG
if (Debugger.IsAttached)
{
Logger.Info("Trying to attach to debugger");
int 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);
}
}
}
#endif
}
}
}

View File

@ -5,7 +5,6 @@ using System.Runtime.Remoting;
using System.Threading; using System.Threading;
using NLog; using NLog;
using NzbDrone.Common; using NzbDrone.Common;
using NzbDrone.Common.Model;
namespace NzbDrone.Providers namespace NzbDrone.Providers
{ {
@ -13,7 +12,7 @@ namespace NzbDrone.Providers
{ {
private static readonly Logger logger = LogManager.GetLogger("Host.MonitoringProvider"); private static readonly Logger logger = LogManager.GetLogger("Host.MonitoringProvider");
private readonly IISProvider _iisProvider; private readonly HostController _hostController;
private readonly ProcessProvider _processProvider; private readonly ProcessProvider _processProvider;
private readonly HttpProvider _httpProvider; private readonly HttpProvider _httpProvider;
private readonly ConfigFileProvider _configFileProvider; private readonly ConfigFileProvider _configFileProvider;
@ -22,11 +21,11 @@ namespace NzbDrone.Providers
private Timer _pingTimer; private Timer _pingTimer;
private Timer _processPriorityCheckTimer; private Timer _processPriorityCheckTimer;
public MonitoringProvider(ProcessProvider processProvider, IISProvider iisProvider, public MonitoringProvider(ProcessProvider processProvider, HostController hostController,
HttpProvider httpProvider, ConfigFileProvider configFileProvider) HttpProvider httpProvider, ConfigFileProvider configFileProvider)
{ {
_processProvider = processProvider; _processProvider = processProvider;
_iisProvider = iisProvider; _hostController = hostController;
_httpProvider = httpProvider; _httpProvider = httpProvider;
_configFileProvider = configFileProvider; _configFileProvider = configFileProvider;
} }
@ -59,7 +58,7 @@ namespace NzbDrone.Providers
_processProvider.SetPriority(currentProcess.Id, ProcessPriorityClass.Normal); _processProvider.SetPriority(currentProcess.Id, ProcessPriorityClass.Normal);
} }
var iisProcess = _processProvider.GetProcessById(_iisProvider.IISProcessId); var iisProcess = _processProvider.GetProcessById(_processProvider.GetCurrentProcess().Id);
if (iisProcess != null && iisProcess.Priority != ProcessPriorityClass.Normal && if (iisProcess != null && iisProcess.Priority != ProcessPriorityClass.Normal &&
iisProcess.Priority != ProcessPriorityClass.AboveNormal) iisProcess.Priority != ProcessPriorityClass.AboveNormal)
{ {
@ -74,13 +73,13 @@ namespace NzbDrone.Providers
public virtual void PingServer(object sender) public virtual void PingServer(object sender)
{ {
if (!_iisProvider.ServerStarted) return; if (!_hostController.ServerStarted) return;
try try
{ {
ICredentials identity = CredentialCache.DefaultCredentials; ICredentials identity = CredentialCache.DefaultCredentials;
_httpProvider.DownloadString(_iisProvider.AppUrl, identity); //This should preload the home page, making the first load faster. _httpProvider.DownloadString(_hostController.AppUrl, identity); //This should preload the home page, making the first load faster.
string response = _httpProvider.DownloadString(_iisProvider.AppUrl + "/health", identity); string response = _httpProvider.DownloadString(_hostController.AppUrl + "/health", identity);
if (!response.Contains("OK")) if (!response.Contains("OK"))
{ {
@ -101,14 +100,14 @@ namespace NzbDrone.Providers
if (_pingFailCounter >= 10) if (_pingFailCounter >= 10)
{ {
_pingFailCounter = 0; _pingFailCounter = 0;
_iisProvider.RestartServer(); _hostController.RestartServer();
} }
} }
} }
private void ProgramExited(object sender, EventArgs e) private void ProgramExited(object sender, EventArgs e)
{ {
_iisProvider.StopServer(); _hostController.StopServer();
} }
public static void AppDomainException(Exception excepion) public static void AppDomainException(Exception excepion)

View File

@ -51,7 +51,7 @@ namespace NzbDrone
case ApplicationMode.Nancy: case ApplicationMode.Nancy:
{ {
var nancyHost = new NancyHost(new Uri("http://localhost:8282"), new Bootstrapper()); var nancyHost = new NancyHost(new Uri("http://localhost:8282"), new NancyBootstrapper());
nancyHost.Start(); nancyHost.Start();