2010-09-23 06:19:47 +03:00
|
|
|
using System;
|
2010-09-24 05:19:55 +03:00
|
|
|
using System.IO;
|
|
|
|
using System.Web;
|
2010-09-23 06:19:47 +03:00
|
|
|
using Ninject;
|
2010-10-02 22:01:43 +03:00
|
|
|
using NLog.Config;
|
|
|
|
using NLog.Targets;
|
2010-09-28 07:25:41 +03:00
|
|
|
using NzbDrone.Core.Providers;
|
2010-10-05 09:21:18 +03:00
|
|
|
using NzbDrone.Core.Repository;
|
|
|
|
using NzbDrone.Core.Repository.Episode;
|
2010-09-23 06:19:47 +03:00
|
|
|
using SubSonic.DataProviders;
|
|
|
|
using SubSonic.Repository;
|
2010-10-02 22:01:43 +03:00
|
|
|
using NLog;
|
2010-09-23 06:19:47 +03:00
|
|
|
|
|
|
|
namespace NzbDrone.Core
|
|
|
|
{
|
2010-10-05 09:21:18 +03:00
|
|
|
public static class CentralDispatch
|
2010-09-23 06:19:47 +03:00
|
|
|
{
|
|
|
|
public static void BindKernel(IKernel kernel)
|
|
|
|
{
|
2010-09-28 06:04:39 +03:00
|
|
|
string connectionString = String.Format("Data Source={0};Version=3;", Path.Combine(AppPath, "nzbdrone.db"));
|
2010-09-24 05:19:55 +03:00
|
|
|
var provider = ProviderFactory.GetProvider(connectionString, "System.Data.SQLite");
|
2010-09-23 06:19:47 +03:00
|
|
|
|
2010-09-28 07:25:41 +03:00
|
|
|
kernel.Bind<ISeriesProvider>().To<SeriesProvider>();
|
2010-10-05 09:21:18 +03:00
|
|
|
kernel.Bind<ISeasonProvider>().To<SeasonProvider>();
|
|
|
|
kernel.Bind<IEpisodeProvider>().To<EpisodeProvider>();
|
2010-09-28 07:25:41 +03:00
|
|
|
kernel.Bind<IDiskProvider>().To<DiskProvider>();
|
|
|
|
kernel.Bind<ITvDbProvider>().To<TvDbProvider>();
|
2010-10-05 09:21:18 +03:00
|
|
|
kernel.Bind<IConfigProvider>().To<ConfigProvider>().InSingletonScope();
|
|
|
|
kernel.Bind<IRepository>().ToMethod(c => new SimpleRepository(provider, SimpleRepositoryOptions.RunMigrations)).InSingletonScope();
|
|
|
|
|
|
|
|
ForceMigration(kernel.Get<IRepository>());
|
2010-09-23 06:19:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public static String AppPath
|
|
|
|
{
|
2010-10-05 09:21:18 +03:00
|
|
|
get
|
|
|
|
{
|
|
|
|
if (HttpContext.Current != null)
|
|
|
|
{
|
|
|
|
return new DirectoryInfo(HttpContext.Current.Server.MapPath("\\")).FullName;
|
|
|
|
}
|
|
|
|
return Directory.GetCurrentDirectory();
|
|
|
|
}
|
|
|
|
|
2010-10-02 22:01:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void ConfigureNlog()
|
|
|
|
{
|
|
|
|
// Step 1. Create configuration object
|
|
|
|
var config = new LoggingConfiguration();
|
|
|
|
|
|
|
|
// Step 2. Create targets and add them to the configuration
|
|
|
|
var consoleTarget = new DebuggerTarget();
|
|
|
|
config.AddTarget("console", consoleTarget);
|
|
|
|
|
|
|
|
FileTarget fileTarget = new FileTarget();
|
|
|
|
config.AddTarget("file", fileTarget);
|
|
|
|
|
|
|
|
// Step 3. Set target properties
|
|
|
|
consoleTarget.Layout = "${logger} ${message}";
|
|
|
|
fileTarget.FileName = "${basedir}/test.log";
|
|
|
|
fileTarget.Layout = "${message}";
|
|
|
|
|
|
|
|
// Step 4. Define rules
|
|
|
|
LoggingRule rule1 = new LoggingRule("*", LogLevel.Trace, consoleTarget);
|
|
|
|
config.LoggingRules.Add(rule1);
|
|
|
|
|
|
|
|
LoggingRule rule2 = new LoggingRule("*", LogLevel.Trace, fileTarget);
|
|
|
|
config.LoggingRules.Add(rule2);
|
|
|
|
|
|
|
|
// Step 5. Activate the configuration
|
|
|
|
NLog.LogManager.Configuration = config;
|
|
|
|
|
|
|
|
Logger logger = LogManager.GetCurrentClassLogger();
|
|
|
|
logger.Trace("trace log message");
|
|
|
|
logger.Debug("debug log message");
|
|
|
|
logger.Info("info log message");
|
|
|
|
logger.Warn("warn log message");
|
|
|
|
logger.Error("error log message");
|
|
|
|
logger.Fatal("fatal log message");
|
2010-09-23 06:19:47 +03:00
|
|
|
}
|
2010-10-05 09:21:18 +03:00
|
|
|
|
|
|
|
private static void ForceMigration(IRepository repository)
|
|
|
|
{
|
|
|
|
repository.GetPaged<Series>(0, 1);
|
|
|
|
repository.GetPaged<EpisodeInfo>(0, 1);
|
|
|
|
repository.GetPaged<Series>(0, 1);
|
|
|
|
}
|
2010-09-23 06:19:47 +03:00
|
|
|
}
|
2010-09-28 08:58:49 +03:00
|
|
|
}
|