@ -1,9 +1,6 @@
using System ;
using System.Diagnostics ;
using System.IO ;
using System.Linq ;
using System.Reflection ;
using System.Web.Hosting ;
using Ninject ;
using NLog ;
using NzbDrone.Core.Datastore ;
@ -17,111 +14,104 @@ using PetaPoco;
namespace NzbDrone.Core
{
public static class CentralDispatch
public class CentralDispatch
{
private static StandardKernel _kernel ;
private static readonly Object KernelLock = new object ( ) ;
private readonly Object KernelLock = new object ( ) ;
private static readonly Logger Logger = LogManager . GetCurrentClassLogger ( ) ;
public static StandardKernel NinjectKernel
public CentralDispatch ( )
{
get
{
if ( _kernel = = null )
{
InitializeApp ( ) ;
}
return _kernel ;
}
InitializeApp ( ) ;
}
public static void InitializeApp ( )
public StandardKernel Kernel { get ; private set ; }
private void InitializeApp ( )
{
BindKernel ( ) ;
_k ernel. Get < LogConfiguration > ( ) . Setup ( ) ;
K ernel. Get < LogConfiguration > ( ) . Setup ( ) ;
var mainConnectionString = _k ernel. Get < Connection > ( ) . MainConnectionString ;
var mainConnectionString = K ernel. Get < Connection > ( ) . MainConnectionString ;
MigrationsHelper . Run ( mainConnectionString , true ) ;
LogConfiguration . RegisterDatabaseLogger ( _k ernel. Get < DatabaseTarget > ( ) ) ;
LogConfiguration . RegisterDatabaseLogger ( K ernel. Get < DatabaseTarget > ( ) ) ;
_k ernel. Get < QualityProvider > ( ) . SetupDefaultProfiles ( ) ;
_k ernel. Get < QualityTypeProvider > ( ) . SetupDefault ( ) ;
_k ernel. Get < ConfigFileProvider > ( ) . CreateDefaultConfigFile ( ) ;
K ernel. Get < QualityProvider > ( ) . SetupDefaultProfiles ( ) ;
K ernel. Get < QualityTypeProvider > ( ) . SetupDefault ( ) ;
K ernel. Get < ConfigFileProvider > ( ) . CreateDefaultConfigFile ( ) ;
BindExternalNotifications ( ) ;
BindIndexers ( ) ;
BindJobs ( ) ;
}
private static void BindKernel ( )
private void BindKernel ( )
{
lock ( KernelLock )
{
Logger . Debug ( "Binding Ninject's Kernel" ) ;
_k ernel = new StandardKernel ( ) ;
K ernel = new StandardKernel ( ) ;
var connection = _k ernel. Get < Connection > ( ) ;
var connection = K ernel. Get < Connection > ( ) ;
_k ernel. Bind < IDatabase > ( ) . ToMethod ( c = > connection . GetMainPetaPocoDb ( ) ) . InTransientScope ( ) ;
_k ernel. Bind < IDatabase > ( ) . ToMethod ( c = > connection . GetLogPetaPocoDb ( false ) ) . WhenInjectedInto < DatabaseTarget > ( ) . InSingletonScope ( ) ;
_k ernel. Bind < IDatabase > ( ) . ToMethod ( c = > connection . GetLogPetaPocoDb ( ) ) . WhenInjectedInto < LogProvider > ( ) . InSingletonScope ( ) ;
K ernel. Bind < IDatabase > ( ) . ToMethod ( c = > connection . GetMainPetaPocoDb ( ) ) . InTransientScope ( ) ;
K ernel. Bind < IDatabase > ( ) . ToMethod ( c = > connection . GetLogPetaPocoDb ( false ) ) . WhenInjectedInto < DatabaseTarget > ( ) . InSingletonScope ( ) ;
K ernel. Bind < IDatabase > ( ) . ToMethod ( c = > connection . GetLogPetaPocoDb ( ) ) . WhenInjectedInto < LogProvider > ( ) . InSingletonScope ( ) ;
_k ernel. Bind < JobProvider > ( ) . ToSelf ( ) . InSingletonScope ( ) ;
K ernel. Bind < JobProvider > ( ) . ToSelf ( ) . InSingletonScope ( ) ;
}
}
private static void BindIndexers ( )
private void BindIndexers ( )
{
_k ernel. Bind < IndexerBase > ( ) . To < NzbsOrg > ( ) ;
_k ernel. Bind < IndexerBase > ( ) . To < NzbMatrix > ( ) ;
_k ernel. Bind < IndexerBase > ( ) . To < NzbsRUs > ( ) ;
_k ernel. Bind < IndexerBase > ( ) . To < Newzbin > ( ) ;
K ernel. Bind < IndexerBase > ( ) . To < NzbsOrg > ( ) ;
K ernel. Bind < IndexerBase > ( ) . To < NzbMatrix > ( ) ;
K ernel. Bind < IndexerBase > ( ) . To < NzbsRUs > ( ) ;
K ernel. Bind < IndexerBase > ( ) . To < Newzbin > ( ) ;
var indexers = _k ernel. GetAll < IndexerBase > ( ) ;
_k ernel. Get < IndexerProvider > ( ) . InitializeIndexers ( indexers . ToList ( ) ) ;
var indexers = K ernel. GetAll < IndexerBase > ( ) ;
K ernel. Get < IndexerProvider > ( ) . InitializeIndexers ( indexers . ToList ( ) ) ;
}
private static void BindJobs ( )
private void BindJobs ( )
{
_k ernel. Bind < IJob > ( ) . To < RssSyncJob > ( ) . InSingletonScope ( ) ;
_k ernel. Bind < IJob > ( ) . To < ImportNewSeriesJob > ( ) . InSingletonScope ( ) ;
_k ernel. Bind < IJob > ( ) . To < UpdateInfoJob > ( ) . InSingletonScope ( ) ;
_k ernel. Bind < IJob > ( ) . To < DiskScanJob > ( ) . InSingletonScope ( ) ;
_k ernel. Bind < IJob > ( ) . To < DeleteSeriesJob > ( ) . InSingletonScope ( ) ;
_k ernel. Bind < IJob > ( ) . To < EpisodeSearchJob > ( ) . InSingletonScope ( ) ;
_k ernel. Bind < IJob > ( ) . To < RenameEpisodeJob > ( ) . InSingletonScope ( ) ;
_k ernel. Bind < IJob > ( ) . To < PostDownloadScanJob > ( ) . InSingletonScope ( ) ;
_k ernel. Bind < IJob > ( ) . To < UpdateSceneMappingsJob > ( ) . InSingletonScope ( ) ;
_k ernel. Bind < IJob > ( ) . To < SeasonSearchJob > ( ) . InSingletonScope ( ) ;
_k ernel. Bind < IJob > ( ) . To < RenameSeasonJob > ( ) . InSingletonScope ( ) ;
_k ernel. Bind < IJob > ( ) . To < SeriesSearchJob > ( ) . InSingletonScope ( ) ;
_k ernel. Bind < IJob > ( ) . To < RenameSeriesJob > ( ) . InSingletonScope ( ) ;
_k ernel. Bind < IJob > ( ) . To < BacklogSearchJob > ( ) . InSingletonScope ( ) ;
_k ernel. Bind < IJob > ( ) . To < BannerDownloadJob > ( ) . InSingletonScope ( ) ;
_k ernel. Bind < IJob > ( ) . To < ConvertEpisodeJob > ( ) . InSingletonScope ( ) ;
_k ernel. Get < JobProvider > ( ) . Initialize ( ) ;
_k ernel. Get < WebTimer > ( ) . StartTimer ( 30 ) ;
K ernel. Bind < IJob > ( ) . To < RssSyncJob > ( ) . InSingletonScope ( ) ;
K ernel. Bind < IJob > ( ) . To < ImportNewSeriesJob > ( ) . InSingletonScope ( ) ;
K ernel. Bind < IJob > ( ) . To < UpdateInfoJob > ( ) . InSingletonScope ( ) ;
K ernel. Bind < IJob > ( ) . To < DiskScanJob > ( ) . InSingletonScope ( ) ;
K ernel. Bind < IJob > ( ) . To < DeleteSeriesJob > ( ) . InSingletonScope ( ) ;
K ernel. Bind < IJob > ( ) . To < EpisodeSearchJob > ( ) . InSingletonScope ( ) ;
K ernel. Bind < IJob > ( ) . To < RenameEpisodeJob > ( ) . InSingletonScope ( ) ;
K ernel. Bind < IJob > ( ) . To < PostDownloadScanJob > ( ) . InSingletonScope ( ) ;
K ernel. Bind < IJob > ( ) . To < UpdateSceneMappingsJob > ( ) . InSingletonScope ( ) ;
K ernel. Bind < IJob > ( ) . To < SeasonSearchJob > ( ) . InSingletonScope ( ) ;
K ernel. Bind < IJob > ( ) . To < RenameSeasonJob > ( ) . InSingletonScope ( ) ;
K ernel. Bind < IJob > ( ) . To < SeriesSearchJob > ( ) . InSingletonScope ( ) ;
K ernel. Bind < IJob > ( ) . To < RenameSeriesJob > ( ) . InSingletonScope ( ) ;
K ernel. Bind < IJob > ( ) . To < BacklogSearchJob > ( ) . InSingletonScope ( ) ;
K ernel. Bind < IJob > ( ) . To < BannerDownloadJob > ( ) . InSingletonScope ( ) ;
K ernel. Bind < IJob > ( ) . To < ConvertEpisodeJob > ( ) . InSingletonScope ( ) ;
K ernel. Get < JobProvider > ( ) . Initialize ( ) ;
K ernel. Get < WebTimer > ( ) . StartTimer ( 30 ) ;
}
private static void BindExternalNotifications ( )
private void BindExternalNotifications ( )
{
_kernel . Bind < ExternalNotificationBase > ( ) . To < Xbmc > ( ) ;
_kernel . Bind < ExternalNotificationBase > ( ) . To < Smtp > ( ) ;
_kernel . Bind < ExternalNotificationBase > ( ) . To < Twitter > ( ) ;
_kernel . Bind < ExternalNotificationBase > ( ) . To < Providers . ExternalNotification . Growl > ( ) ;
Kernel . Bind < ExternalNotificationBase > ( ) . To < Smtp > ( ) ;
Kernel . Bind < ExternalNotificationBase > ( ) . To < Twitter > ( ) ;
Kernel . Bind < ExternalNotificationBase > ( ) . To < Providers . ExternalNotification . Growl > ( ) ;
var notifiers = _k ernel. GetAll < ExternalNotificationBase > ( ) ;
_k ernel. Get < ExternalNotificationProvider > ( ) . InitializeNotifiers ( notifiers . ToList ( ) ) ;
var notifiers = K ernel. GetAll < ExternalNotificationBase > ( ) ;
K ernel. Get < ExternalNotificationProvider > ( ) . InitializeNotifiers ( notifiers . ToList ( ) ) ;
}
/// <summary>
/// Forces IISExpress process to exit with the host application
/// </summary>
public static void DedicateToHost ( )
public void DedicateToHost ( )
{
try
{