2010-09-23 03:19:47 +00:00
|
|
|
|
using System;
|
2010-10-17 17:22:48 +00:00
|
|
|
|
using System.Diagnostics;
|
2011-06-18 01:46:22 +00:00
|
|
|
|
using System.Linq;
|
2010-09-23 03:19:47 +00:00
|
|
|
|
using Ninject;
|
2011-04-10 02:44:01 +00:00
|
|
|
|
using NLog;
|
2011-11-13 07:27:16 +00:00
|
|
|
|
using NzbDrone.Common;
|
2011-05-23 23:29:14 +00:00
|
|
|
|
using NzbDrone.Core.Datastore;
|
2010-10-24 07:46:58 +00:00
|
|
|
|
using NzbDrone.Core.Instrumentation;
|
2010-09-28 04:25:41 +00:00
|
|
|
|
using NzbDrone.Core.Providers;
|
2011-10-01 07:04:06 +00:00
|
|
|
|
using NzbDrone.Core.Providers.Core;
|
2011-04-29 06:06:13 +00:00
|
|
|
|
using NzbDrone.Core.Providers.ExternalNotification;
|
2011-04-19 00:12:06 +00:00
|
|
|
|
using NzbDrone.Core.Providers.Indexer;
|
2011-04-20 07:44:13 +00:00
|
|
|
|
using NzbDrone.Core.Providers.Jobs;
|
2011-06-15 02:31:41 +00:00
|
|
|
|
using PetaPoco;
|
2011-11-13 07:27:16 +00:00
|
|
|
|
using LogConfiguration = NzbDrone.Core.Instrumentation.LogConfiguration;
|
2010-09-23 03:19:47 +00:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core
|
|
|
|
|
{
|
2011-11-08 20:12:54 +00:00
|
|
|
|
public class CentralDispatch
|
2010-09-23 03:19:47 +00:00
|
|
|
|
{
|
2011-11-08 20:12:54 +00:00
|
|
|
|
private readonly Object KernelLock = new object();
|
2010-10-10 19:00:07 +00:00
|
|
|
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
2010-10-07 22:17:24 +00:00
|
|
|
|
|
2011-11-08 20:12:54 +00:00
|
|
|
|
public CentralDispatch()
|
2011-04-10 02:44:01 +00:00
|
|
|
|
{
|
2011-11-08 20:12:54 +00:00
|
|
|
|
InitializeApp();
|
2011-04-10 02:44:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-11-08 20:12:54 +00:00
|
|
|
|
public StandardKernel Kernel { get; private set; }
|
|
|
|
|
|
|
|
|
|
private void InitializeApp()
|
2011-05-23 23:29:14 +00:00
|
|
|
|
{
|
|
|
|
|
BindKernel();
|
2011-05-27 02:12:28 +00:00
|
|
|
|
|
2011-11-08 20:12:54 +00:00
|
|
|
|
Kernel.Get<LogConfiguration>().Setup();
|
2011-10-12 02:24:43 +00:00
|
|
|
|
|
2011-11-08 20:12:54 +00:00
|
|
|
|
var mainConnectionString = Kernel.Get<Connection>().MainConnectionString;
|
2011-05-27 02:12:28 +00:00
|
|
|
|
|
2011-11-03 05:04:14 +00:00
|
|
|
|
MigrationsHelper.Run(mainConnectionString, true);
|
2011-10-12 02:24:43 +00:00
|
|
|
|
|
2011-11-08 20:12:54 +00:00
|
|
|
|
LogConfiguration.RegisterDatabaseLogger(Kernel.Get<DatabaseTarget>());
|
2011-11-13 18:16:31 +00:00
|
|
|
|
LogConfiguration.Reload();
|
2011-05-27 02:12:28 +00:00
|
|
|
|
|
2011-11-08 20:12:54 +00:00
|
|
|
|
Kernel.Get<QualityProvider>().SetupDefaultProfiles();
|
|
|
|
|
Kernel.Get<QualityTypeProvider>().SetupDefault();
|
|
|
|
|
Kernel.Get<ConfigFileProvider>().CreateDefaultConfigFile();
|
2011-05-23 23:29:14 +00:00
|
|
|
|
|
2011-07-28 07:21:49 +00:00
|
|
|
|
BindExternalNotifications();
|
2011-05-23 23:29:14 +00:00
|
|
|
|
BindIndexers();
|
|
|
|
|
BindJobs();
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-08 20:12:54 +00:00
|
|
|
|
private void BindKernel()
|
2010-09-23 03:19:47 +00:00
|
|
|
|
{
|
2011-04-10 00:14:51 +00:00
|
|
|
|
lock (KernelLock)
|
2010-10-10 19:00:07 +00:00
|
|
|
|
{
|
|
|
|
|
Logger.Debug("Binding Ninject's Kernel");
|
2011-11-08 20:12:54 +00:00
|
|
|
|
Kernel = new StandardKernel();
|
2010-10-10 19:00:07 +00:00
|
|
|
|
|
2011-11-08 20:12:54 +00:00
|
|
|
|
var connection = Kernel.Get<Connection>();
|
2010-10-10 19:00:07 +00:00
|
|
|
|
|
2011-11-08 20:12:54 +00:00
|
|
|
|
Kernel.Bind<IDatabase>().ToMethod(c => connection.GetMainPetaPocoDb()).InTransientScope();
|
|
|
|
|
Kernel.Bind<IDatabase>().ToMethod(c => connection.GetLogPetaPocoDb(false)).WhenInjectedInto<DatabaseTarget>().InSingletonScope();
|
|
|
|
|
Kernel.Bind<IDatabase>().ToMethod(c => connection.GetLogPetaPocoDb()).WhenInjectedInto<LogProvider>().InSingletonScope();
|
2011-10-23 21:53:24 +00:00
|
|
|
|
|
2011-11-08 20:12:54 +00:00
|
|
|
|
Kernel.Bind<JobProvider>().ToSelf().InSingletonScope();
|
2010-10-10 19:00:07 +00:00
|
|
|
|
}
|
2010-09-23 03:19:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-11-08 20:12:54 +00:00
|
|
|
|
private void BindIndexers()
|
2011-04-19 00:12:06 +00:00
|
|
|
|
{
|
2011-11-08 20:12:54 +00:00
|
|
|
|
Kernel.Bind<IndexerBase>().To<NzbsOrg>();
|
|
|
|
|
Kernel.Bind<IndexerBase>().To<NzbMatrix>();
|
|
|
|
|
Kernel.Bind<IndexerBase>().To<NzbsRUs>();
|
|
|
|
|
Kernel.Bind<IndexerBase>().To<Newzbin>();
|
2011-05-27 06:03:57 +00:00
|
|
|
|
|
2011-11-08 20:12:54 +00:00
|
|
|
|
var indexers = Kernel.GetAll<IndexerBase>();
|
|
|
|
|
Kernel.Get<IndexerProvider>().InitializeIndexers(indexers.ToList());
|
2011-04-19 00:12:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-11-08 20:12:54 +00:00
|
|
|
|
private void BindJobs()
|
2011-04-20 02:17:28 +00:00
|
|
|
|
{
|
2011-11-08 20:12:54 +00:00
|
|
|
|
Kernel.Bind<IJob>().To<RssSyncJob>().InSingletonScope();
|
|
|
|
|
Kernel.Bind<IJob>().To<ImportNewSeriesJob>().InSingletonScope();
|
|
|
|
|
Kernel.Bind<IJob>().To<UpdateInfoJob>().InSingletonScope();
|
|
|
|
|
Kernel.Bind<IJob>().To<DiskScanJob>().InSingletonScope();
|
|
|
|
|
Kernel.Bind<IJob>().To<DeleteSeriesJob>().InSingletonScope();
|
|
|
|
|
Kernel.Bind<IJob>().To<EpisodeSearchJob>().InSingletonScope();
|
|
|
|
|
Kernel.Bind<IJob>().To<RenameEpisodeJob>().InSingletonScope();
|
|
|
|
|
Kernel.Bind<IJob>().To<PostDownloadScanJob>().InSingletonScope();
|
|
|
|
|
Kernel.Bind<IJob>().To<UpdateSceneMappingsJob>().InSingletonScope();
|
|
|
|
|
Kernel.Bind<IJob>().To<SeasonSearchJob>().InSingletonScope();
|
|
|
|
|
Kernel.Bind<IJob>().To<RenameSeasonJob>().InSingletonScope();
|
|
|
|
|
Kernel.Bind<IJob>().To<SeriesSearchJob>().InSingletonScope();
|
|
|
|
|
Kernel.Bind<IJob>().To<RenameSeriesJob>().InSingletonScope();
|
|
|
|
|
Kernel.Bind<IJob>().To<BacklogSearchJob>().InSingletonScope();
|
|
|
|
|
Kernel.Bind<IJob>().To<BannerDownloadJob>().InSingletonScope();
|
|
|
|
|
Kernel.Bind<IJob>().To<ConvertEpisodeJob>().InSingletonScope();
|
|
|
|
|
|
|
|
|
|
Kernel.Get<JobProvider>().Initialize();
|
|
|
|
|
Kernel.Get<WebTimer>().StartTimer(30);
|
2011-04-20 02:17:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-11-08 20:12:54 +00:00
|
|
|
|
private void BindExternalNotifications()
|
2011-04-29 06:06:13 +00:00
|
|
|
|
{
|
2011-11-10 04:14:19 +00:00
|
|
|
|
Kernel.Bind<ExternalNotificationBase>().To<Xbmc>();
|
2011-11-08 20:12:54 +00:00
|
|
|
|
Kernel.Bind<ExternalNotificationBase>().To<Smtp>();
|
|
|
|
|
Kernel.Bind<ExternalNotificationBase>().To<Twitter>();
|
|
|
|
|
Kernel.Bind<ExternalNotificationBase>().To<Providers.ExternalNotification.Growl>();
|
2011-11-10 04:14:19 +00:00
|
|
|
|
Kernel.Bind<ExternalNotificationBase>().To<Prowl>();
|
2011-07-28 07:21:49 +00:00
|
|
|
|
|
2011-11-08 20:12:54 +00:00
|
|
|
|
var notifiers = Kernel.GetAll<ExternalNotificationBase>();
|
|
|
|
|
Kernel.Get<ExternalNotificationProvider>().InitializeNotifiers(notifiers.ToList());
|
2011-04-29 06:06:13 +00:00
|
|
|
|
}
|
2011-04-22 02:23:31 +00:00
|
|
|
|
|
2010-10-17 17:22:48 +00:00
|
|
|
|
/// <summary>
|
2011-04-20 01:20:20 +00:00
|
|
|
|
/// Forces IISExpress process to exit with the host application
|
2010-10-17 17:22:48 +00:00
|
|
|
|
/// </summary>
|
2011-11-08 20:12:54 +00:00
|
|
|
|
public void DedicateToHost()
|
2010-10-17 17:22:48 +00:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2011-11-13 20:31:02 +00:00
|
|
|
|
var pid = new EnviromentProvider().NzbDroneProcessIdFromEnviroment;
|
2011-06-13 03:45:22 +00:00
|
|
|
|
|
|
|
|
|
Logger.Debug("Attaching to parent process ({0}) for automatic termination.", pid);
|
|
|
|
|
|
|
|
|
|
var hostProcess = Process.GetProcessById(Convert.ToInt32(pid));
|
2010-10-17 17:22:48 +00:00
|
|
|
|
|
|
|
|
|
hostProcess.EnableRaisingEvents = true;
|
|
|
|
|
hostProcess.Exited += (delegate
|
2011-04-10 02:44:01 +00:00
|
|
|
|
{
|
|
|
|
|
Logger.Info("Host has been terminated. Shutting down web server.");
|
|
|
|
|
ShutDown();
|
|
|
|
|
});
|
2010-10-17 17:22:48 +00:00
|
|
|
|
|
2011-06-13 03:45:22 +00:00
|
|
|
|
Logger.Debug("Successfully Attached to host. Process [{0}]", hostProcess.ProcessName);
|
2010-10-17 17:22:48 +00:00
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Logger.Fatal(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void ShutDown()
|
|
|
|
|
{
|
|
|
|
|
Logger.Info("Shutting down application.");
|
2011-11-07 06:26:21 +00:00
|
|
|
|
WebTimer.Stop();
|
2010-10-17 17:22:48 +00:00
|
|
|
|
Process.GetCurrentProcess().Kill();
|
|
|
|
|
}
|
2010-09-23 03:19:47 +00:00
|
|
|
|
}
|
2011-11-10 04:14:19 +00:00
|
|
|
|
}
|