2010-09-23 05:19:47 +02:00
|
|
|
|
using System;
|
2010-09-24 04:19:55 +02:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Web;
|
2010-09-23 05:19:47 +02:00
|
|
|
|
using Ninject;
|
2010-10-02 21:01:43 +02:00
|
|
|
|
using NLog.Config;
|
|
|
|
|
using NLog.Targets;
|
2010-10-08 05:35:04 +02:00
|
|
|
|
using NzbDrone.Core.Entities;
|
|
|
|
|
using NzbDrone.Core.Entities.Episode;
|
2010-09-28 06:25:41 +02:00
|
|
|
|
using NzbDrone.Core.Providers;
|
2010-10-10 21:00:07 +02:00
|
|
|
|
using NzbDrone.Core.Providers.Fakes;
|
2010-09-23 05:19:47 +02:00
|
|
|
|
using SubSonic.DataProviders;
|
|
|
|
|
using SubSonic.Repository;
|
2010-10-02 21:01:43 +02:00
|
|
|
|
using NLog;
|
2010-09-23 05:19:47 +02:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core
|
|
|
|
|
{
|
2010-10-05 08:21:18 +02:00
|
|
|
|
public static class CentralDispatch
|
2010-09-23 05:19:47 +02:00
|
|
|
|
{
|
2010-10-10 21:00:07 +02:00
|
|
|
|
private static IKernel _kernel;
|
|
|
|
|
private static readonly Object kernelLock = new object();
|
|
|
|
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
2010-10-08 00:17:24 +02:00
|
|
|
|
|
2010-10-10 21:00:07 +02:00
|
|
|
|
public static void BindKernel()
|
2010-09-23 05:19:47 +02:00
|
|
|
|
{
|
2010-10-10 21:00:07 +02:00
|
|
|
|
lock (kernelLock)
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug("Binding Ninject's Kernel");
|
|
|
|
|
_kernel = new StandardKernel();
|
|
|
|
|
|
|
|
|
|
string connectionString = String.Format("Data Source={0};Version=3;", Path.Combine(AppPath, "nzbdrone.db"));
|
|
|
|
|
var provider = ProviderFactory.GetProvider(connectionString, "System.Data.SQLite");
|
2010-10-15 09:10:44 +02:00
|
|
|
|
provider.Log = new Instrumentation.NlogWriter();
|
2010-10-10 21:00:07 +02:00
|
|
|
|
provider.LogParams = true;
|
|
|
|
|
|
|
|
|
|
_kernel.Bind<ISeriesProvider>().To<SeriesProvider>().InSingletonScope();
|
|
|
|
|
_kernel.Bind<ISeasonProvider>().To<SeasonProvider>();
|
|
|
|
|
_kernel.Bind<IEpisodeProvider>().To<EpisodeProvider>();
|
|
|
|
|
_kernel.Bind<IDiskProvider>().To<DiskProvider>();
|
|
|
|
|
_kernel.Bind<ITvDbProvider>().To<TvDbProvider>();
|
|
|
|
|
_kernel.Bind<IConfigProvider>().To<ConfigProvider>().InSingletonScope();
|
2010-10-12 04:49:27 +02:00
|
|
|
|
_kernel.Bind<INotificationProvider>().To<NotificationProvider>().InSingletonScope();
|
2010-10-10 21:00:07 +02:00
|
|
|
|
_kernel.Bind<IRepository>().ToMethod(c => new SimpleRepository(provider, SimpleRepositoryOptions.RunMigrations)).InSingletonScope();
|
|
|
|
|
|
|
|
|
|
ForceMigration(_kernel.Get<IRepository>());
|
|
|
|
|
}
|
2010-09-23 05:19:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String AppPath
|
|
|
|
|
{
|
2010-10-05 08:21:18 +02:00
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (HttpContext.Current != null)
|
|
|
|
|
{
|
|
|
|
|
return new DirectoryInfo(HttpContext.Current.Server.MapPath("\\")).FullName;
|
|
|
|
|
}
|
|
|
|
|
return Directory.GetCurrentDirectory();
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-02 21:01:43 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-10-10 21:00:07 +02:00
|
|
|
|
public static IKernel NinjectKernel
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (_kernel == null)
|
|
|
|
|
{
|
|
|
|
|
BindKernel();
|
|
|
|
|
}
|
|
|
|
|
return _kernel;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-10-02 21:01:43 +02:00
|
|
|
|
|
2010-10-05 08:21:18 +02:00
|
|
|
|
private static void ForceMigration(IRepository repository)
|
|
|
|
|
{
|
|
|
|
|
repository.GetPaged<Series>(0, 1);
|
|
|
|
|
repository.GetPaged<EpisodeInfo>(0, 1);
|
|
|
|
|
}
|
2010-09-23 05:19:47 +02:00
|
|
|
|
}
|
2010-09-28 07:58:49 +02:00
|
|
|
|
}
|