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;
|
2010-10-08 00:17:24 +02:00
|
|
|
|
using NLog.Layouts;
|
2010-10-02 21:01:43 +02:00
|
|
|
|
using NLog.Targets;
|
2010-09-28 06:25:41 +02:00
|
|
|
|
using NzbDrone.Core.Providers;
|
2010-10-05 08:21:18 +02:00
|
|
|
|
using NzbDrone.Core.Repository;
|
|
|
|
|
using NzbDrone.Core.Repository.Episode;
|
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-08 00:17:24 +02:00
|
|
|
|
private static readonly Logger Logger = LogManager.GetLogger("DB");
|
|
|
|
|
|
2010-09-23 05:19:47 +02:00
|
|
|
|
public static void BindKernel(IKernel kernel)
|
|
|
|
|
{
|
2010-09-28 05:04:39 +02:00
|
|
|
|
string connectionString = String.Format("Data Source={0};Version=3;", Path.Combine(AppPath, "nzbdrone.db"));
|
2010-09-24 04:19:55 +02:00
|
|
|
|
var provider = ProviderFactory.GetProvider(connectionString, "System.Data.SQLite");
|
2010-10-08 00:17:24 +02:00
|
|
|
|
provider.Log = new SonicTrace();
|
2010-09-28 06:25:41 +02:00
|
|
|
|
kernel.Bind<ISeriesProvider>().To<SeriesProvider>();
|
2010-10-05 08:21:18 +02:00
|
|
|
|
kernel.Bind<ISeasonProvider>().To<SeasonProvider>();
|
|
|
|
|
kernel.Bind<IEpisodeProvider>().To<EpisodeProvider>();
|
2010-09-28 06:25:41 +02:00
|
|
|
|
kernel.Bind<IDiskProvider>().To<DiskProvider>();
|
|
|
|
|
kernel.Bind<ITvDbProvider>().To<TvDbProvider>();
|
2010-10-05 08:21:18 +02: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 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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void ConfigureNlog()
|
|
|
|
|
{
|
|
|
|
|
// Step 1. Create configuration object
|
|
|
|
|
var config = new LoggingConfiguration();
|
|
|
|
|
|
2010-10-08 00:17:24 +02:00
|
|
|
|
string callSight = "${callsite:className=false:fileName=true:includeSourcePath=false:methodName=true}";
|
|
|
|
|
|
2010-10-02 21:01:43 +02:00
|
|
|
|
// Step 2. Create targets and add them to the configuration
|
2010-10-08 00:17:24 +02:00
|
|
|
|
var debuggerTarget = new DebuggerTarget
|
|
|
|
|
{
|
|
|
|
|
Layout = callSight + "- ${logger}: ${message}"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var consoleTarget = new ColoredConsoleTarget
|
|
|
|
|
{
|
|
|
|
|
Layout = callSight + ": ${message}"
|
|
|
|
|
};
|
2010-10-02 21:01:43 +02:00
|
|
|
|
|
2010-10-08 00:17:24 +02:00
|
|
|
|
|
|
|
|
|
var fileTarget = new FileTarget
|
|
|
|
|
{
|
|
|
|
|
FileName = "${basedir}/test.log",
|
|
|
|
|
Layout = "${message}"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
config.AddTarget("debugger", debuggerTarget);
|
|
|
|
|
config.AddTarget("console", consoleTarget);
|
|
|
|
|
//config.AddTarget("file", fileTarget);
|
2010-10-02 21:01:43 +02:00
|
|
|
|
|
|
|
|
|
// Step 3. Set target properties
|
2010-10-08 00:17:24 +02:00
|
|
|
|
|
|
|
|
|
|
2010-10-02 21:01:43 +02:00
|
|
|
|
|
|
|
|
|
// Step 4. Define rules
|
2010-10-08 00:17:24 +02:00
|
|
|
|
LoggingRule debugRule = new LoggingRule("*", LogLevel.Trace, debuggerTarget);
|
|
|
|
|
LoggingRule fileRule = new LoggingRule("*", LogLevel.Trace, fileTarget);
|
|
|
|
|
LoggingRule consoleRule = new LoggingRule("*", LogLevel.Trace, consoleTarget);
|
2010-10-02 21:01:43 +02:00
|
|
|
|
|
2010-10-08 00:17:24 +02:00
|
|
|
|
//config.LoggingRules.Add(fileRule);
|
|
|
|
|
config.LoggingRules.Add(debugRule);
|
|
|
|
|
config.LoggingRules.Add(consoleRule);
|
2010-10-02 21:01:43 +02:00
|
|
|
|
|
|
|
|
|
// Step 5. Activate the configuration
|
2010-10-08 00:17:24 +02:00
|
|
|
|
LogManager.Configuration = config;
|
2010-09-23 05:19:47 +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
|
|
|
|
}
|