update sqlite

This commit is contained in:
Luke Pulverenti 2016-05-01 17:48:37 -04:00
parent 324c6dc8db
commit a4d1c9e6e4
29 changed files with 224 additions and 150 deletions

View File

@ -19,12 +19,6 @@ namespace MediaBrowser.Controller.Notifications
/// Occurs when [notifications marked read]. /// Occurs when [notifications marked read].
/// </summary> /// </summary>
event EventHandler<NotificationReadEventArgs> NotificationsMarkedRead; event EventHandler<NotificationReadEventArgs> NotificationsMarkedRead;
/// <summary>
/// Opens the connection to the repository
/// </summary>
/// <returns>Task.</returns>
Task Initialize();
/// <summary> /// <summary>
/// Gets the notifications. /// Gets the notifications.

View File

@ -11,12 +11,6 @@ namespace MediaBrowser.Controller.Persistence
/// </summary> /// </summary>
public interface IDisplayPreferencesRepository : IRepository public interface IDisplayPreferencesRepository : IRepository
{ {
/// <summary>
/// Opens the connection to the repository
/// </summary>
/// <returns>Task.</returns>
Task Initialize();
/// <summary> /// <summary>
/// Saves display preferences for an item /// Saves display preferences for an item
/// </summary> /// </summary>

View File

@ -13,12 +13,6 @@ namespace MediaBrowser.Controller.Persistence
/// </summary> /// </summary>
public interface IItemRepository : IRepository public interface IItemRepository : IRepository
{ {
/// <summary>
/// Opens the connection to the repository
/// </summary>
/// <returns>Task.</returns>
Task Initialize();
/// <summary> /// <summary>
/// Saves an item /// Saves an item
/// </summary> /// </summary>

View File

@ -11,12 +11,6 @@ namespace MediaBrowser.Controller.Persistence
/// </summary> /// </summary>
public interface IUserDataRepository : IRepository public interface IUserDataRepository : IRepository
{ {
/// <summary>
/// Opens the connection to the repository
/// </summary>
/// <returns>Task.</returns>
Task Initialize();
/// <summary> /// <summary>
/// Saves the user data. /// Saves the user data.
/// </summary> /// </summary>

View File

@ -21,11 +21,5 @@ namespace MediaBrowser.Controller.Providers
/// <param name="cancellationToken">The cancellation token.</param> /// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns> /// <returns>Task.</returns>
Task SaveMetadataStatus(MetadataStatus status, CancellationToken cancellationToken); Task SaveMetadataStatus(MetadataStatus status, CancellationToken cancellationToken);
/// <summary>
/// Initializes this instance.
/// </summary>
/// <returns>Task.</returns>
Task Initialize();
} }
} }

View File

@ -27,11 +27,11 @@ namespace MediaBrowser.Server.Implementations.Activity
_appPaths = appPaths; _appPaths = appPaths;
} }
public async Task Initialize() public async Task Initialize(IDbConnector dbConnector)
{ {
var dbFile = Path.Combine(_appPaths.DataPath, "activitylog.db"); var dbFile = Path.Combine(_appPaths.DataPath, "activitylog.db");
_connection = await SqliteExtensions.ConnectToDb(dbFile, Logger).ConfigureAwait(false); _connection = await dbConnector.Connect(dbFile).ConfigureAwait(false);
string[] queries = { string[] queries = {

View File

@ -78,9 +78,6 @@
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Data.SQLite">
<HintPath>..\ThirdParty\System.Data.SQLite.ManagedOnly\1.0.94.0\System.Data.SQLite.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp" /> <Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" /> <Reference Include="System.Data" />
<Reference Include="System.Net" /> <Reference Include="System.Net" />
@ -261,6 +258,8 @@
<Compile Include="Notifications\IConfigurableNotificationService.cs" /> <Compile Include="Notifications\IConfigurableNotificationService.cs" />
<Compile Include="Persistence\BaseSqliteRepository.cs" /> <Compile Include="Persistence\BaseSqliteRepository.cs" />
<Compile Include="Persistence\CleanDatabaseScheduledTask.cs" /> <Compile Include="Persistence\CleanDatabaseScheduledTask.cs" />
<Compile Include="Persistence\DataExtensions.cs" />
<Compile Include="Persistence\IDbConnector.cs" />
<Compile Include="Persistence\MediaStreamColumns.cs" /> <Compile Include="Persistence\MediaStreamColumns.cs" />
<Compile Include="Social\SharingManager.cs" /> <Compile Include="Social\SharingManager.cs" />
<Compile Include="Social\SharingRepository.cs" /> <Compile Include="Social\SharingRepository.cs" />
@ -275,7 +274,6 @@
<Compile Include="Notifications\InternalNotificationService.cs" /> <Compile Include="Notifications\InternalNotificationService.cs" />
<Compile Include="Notifications\NotificationConfigurationFactory.cs" /> <Compile Include="Notifications\NotificationConfigurationFactory.cs" />
<Compile Include="Notifications\NotificationManager.cs" /> <Compile Include="Notifications\NotificationManager.cs" />
<Compile Include="Persistence\SqliteExtensions.cs" />
<Compile Include="Persistence\SqliteFileOrganizationRepository.cs" /> <Compile Include="Persistence\SqliteFileOrganizationRepository.cs" />
<Compile Include="Notifications\SqliteNotificationsRepository.cs" /> <Compile Include="Notifications\SqliteNotificationsRepository.cs" />
<Compile Include="Persistence\SqliteProviderInfoRepository.cs" /> <Compile Include="Persistence\SqliteProviderInfoRepository.cs" />

View File

@ -32,11 +32,11 @@ namespace MediaBrowser.Server.Implementations.Notifications
_appPaths = appPaths; _appPaths = appPaths;
} }
public async Task Initialize() public async Task Initialize(IDbConnector dbConnector)
{ {
var dbFile = Path.Combine(_appPaths.DataPath, "notifications.db"); var dbFile = Path.Combine(_appPaths.DataPath, "notifications.db");
_connection = await SqliteExtensions.ConnectToDb(dbFile, Logger).ConfigureAwait(false); _connection = await dbConnector.Connect(dbFile).ConfigureAwait(false);
string[] queries = { string[] queries = {

View File

@ -3,16 +3,12 @@ using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Serialization; using MediaBrowser.Model.Serialization;
using System; using System;
using System.Data; using System.Data;
using System.Data.SQLite;
using System.IO; using System.IO;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace MediaBrowser.Server.Implementations.Persistence namespace MediaBrowser.Server.Implementations.Persistence
{ {
/// <summary> static class DataExtensions
/// Class SQLiteExtensions
/// </summary>
static class SqliteExtensions
{ {
/// <summary> /// <summary>
/// Determines whether the specified conn is open. /// Determines whether the specified conn is open.
@ -28,11 +24,11 @@ namespace MediaBrowser.Server.Implementations.Persistence
{ {
return (IDataParameter)cmd.Parameters[index]; return (IDataParameter)cmd.Parameters[index];
} }
public static IDataParameter Add(this IDataParameterCollection paramCollection, IDbCommand cmd, string name, DbType type) public static IDataParameter Add(this IDataParameterCollection paramCollection, IDbCommand cmd, string name, DbType type)
{ {
var param = cmd.CreateParameter(); var param = cmd.CreateParameter();
param.ParameterName = name; param.ParameterName = name;
param.DbType = type; param.DbType = type;
@ -48,11 +44,11 @@ namespace MediaBrowser.Server.Implementations.Persistence
param.ParameterName = name; param.ParameterName = name;
paramCollection.Add(param); paramCollection.Add(param);
return param; return param;
} }
/// <summary> /// <summary>
/// Gets a stream from a DataReader at a given ordinal /// Gets a stream from a DataReader at a given ordinal
/// </summary> /// </summary>
@ -122,38 +118,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
} }
} }
/// <summary>
/// Connects to db.
/// </summary>
/// <param name="dbPath">The db path.</param>
/// <param name="logger">The logger.</param>
/// <returns>Task{IDbConnection}.</returns>
/// <exception cref="System.ArgumentNullException">dbPath</exception>
public static async Task<IDbConnection> ConnectToDb(string dbPath, ILogger logger)
{
if (string.IsNullOrEmpty(dbPath))
{
throw new ArgumentNullException("dbPath");
}
logger.Info("Sqlite {0} opening {1}", SQLiteConnection.SQLiteVersion, dbPath);
var connectionstr = new SQLiteConnectionStringBuilder
{
PageSize = 4096,
CacheSize = 2000,
SyncMode = SynchronizationModes.Full,
DataSource = dbPath,
JournalMode = SQLiteJournalModeEnum.Wal
};
var connection = new SQLiteConnection(connectionstr.ConnectionString);
await connection.OpenAsync().ConfigureAwait(false);
return connection;
}
public static void Attach(IDbConnection db, string path, string alias) public static void Attach(IDbConnection db, string path, string alias)
{ {
using (var cmd = db.CreateCommand()) using (var cmd = db.CreateCommand())

View File

@ -0,0 +1,10 @@
using System.Data;
using System.Threading.Tasks;
namespace MediaBrowser.Server.Implementations.Persistence
{
public interface IDbConnector
{
Task<IDbConnection> Connect(string dbPath);
}
}

View File

@ -52,11 +52,11 @@ namespace MediaBrowser.Server.Implementations.Persistence
/// Opens the connection to the database /// Opens the connection to the database
/// </summary> /// </summary>
/// <returns>Task.</returns> /// <returns>Task.</returns>
public async Task Initialize() public async Task Initialize(IDbConnector dbConnector)
{ {
var dbFile = Path.Combine(_appPaths.DataPath, "displaypreferences.db"); var dbFile = Path.Combine(_appPaths.DataPath, "displaypreferences.db");
_connection = await SqliteExtensions.ConnectToDb(dbFile, Logger).ConfigureAwait(false); _connection = await dbConnector.Connect(dbFile).ConfigureAwait(false);
string[] queries = { string[] queries = {

View File

@ -35,11 +35,11 @@ namespace MediaBrowser.Server.Implementations.Persistence
/// Opens the connection to the database /// Opens the connection to the database
/// </summary> /// </summary>
/// <returns>Task.</returns> /// <returns>Task.</returns>
public async Task Initialize() public async Task Initialize(IDbConnector dbConnector)
{ {
var dbFile = Path.Combine(_appPaths.DataPath, "fileorganization.db"); var dbFile = Path.Combine(_appPaths.DataPath, "fileorganization.db");
_connection = await SqliteExtensions.ConnectToDb(dbFile, Logger).ConfigureAwait(false); _connection = await dbConnector.Connect(dbFile).ConfigureAwait(false);
string[] queries = { string[] queries = {

View File

@ -39,11 +39,11 @@ namespace MediaBrowser.Server.Implementations.Persistence
/// Opens the connection to the database /// Opens the connection to the database
/// </summary> /// </summary>
/// <returns>Task.</returns> /// <returns>Task.</returns>
public async Task Initialize() public async Task Initialize(IDbConnector dbConnector)
{ {
var dbFile = Path.Combine(_appPaths.DataPath, "refreshinfo.db"); var dbFile = Path.Combine(_appPaths.DataPath, "refreshinfo.db");
_connection = await SqliteExtensions.ConnectToDb(dbFile, Logger).ConfigureAwait(false); _connection = await dbConnector.Connect(dbFile).ConfigureAwait(false);
string[] queries = { string[] queries = {

View File

@ -37,11 +37,11 @@ namespace MediaBrowser.Server.Implementations.Persistence
/// Opens the connection to the database /// Opens the connection to the database
/// </summary> /// </summary>
/// <returns>Task.</returns> /// <returns>Task.</returns>
public async Task Initialize() public async Task Initialize(IDbConnector dbConnector)
{ {
var dbFile = Path.Combine(_appPaths.DataPath, "userdata_v2.db"); var dbFile = Path.Combine(_appPaths.DataPath, "userdata_v2.db");
_connection = await SqliteExtensions.ConnectToDb(dbFile, Logger).ConfigureAwait(false); _connection = await dbConnector.Connect(dbFile).ConfigureAwait(false);
string[] queries = { string[] queries = {

View File

@ -43,12 +43,12 @@ namespace MediaBrowser.Server.Implementations.Persistence
/// Opens the connection to the database /// Opens the connection to the database
/// </summary> /// </summary>
/// <returns>Task.</returns> /// <returns>Task.</returns>
public async Task Initialize() public async Task Initialize(IDbConnector dbConnector)
{ {
var dbFile = Path.Combine(_appPaths.DataPath, "users.db"); var dbFile = Path.Combine(_appPaths.DataPath, "users.db");
_connection = await SqliteExtensions.ConnectToDb(dbFile, Logger).ConfigureAwait(false); _connection = await dbConnector.Connect(dbFile).ConfigureAwait(false);
string[] queries = { string[] queries = {
"create table if not exists users (guid GUID primary key, data BLOB)", "create table if not exists users (guid GUID primary key, data BLOB)",

View File

@ -27,11 +27,11 @@ namespace MediaBrowser.Server.Implementations.Security
_appPaths = appPaths; _appPaths = appPaths;
} }
public async Task Initialize() public async Task Initialize(IDbConnector dbConnector)
{ {
var dbFile = Path.Combine(_appPaths.DataPath, "authentication.db"); var dbFile = Path.Combine(_appPaths.DataPath, "authentication.db");
_connection = await SqliteExtensions.ConnectToDb(dbFile, Logger).ConfigureAwait(false); _connection = await dbConnector.Connect(dbFile).ConfigureAwait(false);
string[] queries = { string[] queries = {

View File

@ -26,11 +26,11 @@ namespace MediaBrowser.Server.Implementations.Social
/// Opens the connection to the database /// Opens the connection to the database
/// </summary> /// </summary>
/// <returns>Task.</returns> /// <returns>Task.</returns>
public async Task Initialize() public async Task Initialize(IDbConnector dbConnector)
{ {
var dbFile = Path.Combine(_appPaths.DataPath, "shares.db"); var dbFile = Path.Combine(_appPaths.DataPath, "shares.db");
_connection = await SqliteExtensions.ConnectToDb(dbFile, Logger).ConfigureAwait(false); _connection = await dbConnector.Connect(dbFile).ConfigureAwait(false);
string[] queries = { string[] queries = {

View File

@ -39,11 +39,11 @@ namespace MediaBrowser.Server.Implementations.Sync
_appPaths = appPaths; _appPaths = appPaths;
} }
public async Task Initialize() public async Task Initialize(IDbConnector dbConnector)
{ {
var dbFile = Path.Combine(_appPaths.DataPath, "sync14.db"); var dbFile = Path.Combine(_appPaths.DataPath, "sync14.db");
_connection = await SqliteExtensions.ConnectToDb(dbFile, Logger).ConfigureAwait(false); _connection = await dbConnector.Connect(dbFile).ConfigureAwait(false);
string[] queries = { string[] queries = {

View File

@ -76,12 +76,17 @@
<Reference Include="MediaBrowser.IsoMounting.Linux"> <Reference Include="MediaBrowser.IsoMounting.Linux">
<HintPath>..\ThirdParty\MediaBrowser.IsoMounting.Linux\MediaBrowser.IsoMounting.Linux.dll</HintPath> <HintPath>..\ThirdParty\MediaBrowser.IsoMounting.Linux\MediaBrowser.IsoMounting.Linux.dll</HintPath>
</Reference> </Reference>
<Reference Include="System.Data" />
<Reference Include="System.Data.SQLite">
<HintPath>..\ThirdParty\System.Data.SQLite.ManagedOnly\1.0.94.0\System.Data.SQLite.dll</HintPath>
</Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="..\SharedVersion.cs"> <Compile Include="..\SharedVersion.cs">
<Link>Properties\SharedVersion.cs</Link> <Link>Properties\SharedVersion.cs</Link>
</Compile> </Compile>
<Compile Include="Native\BaseMonoApp.cs" /> <Compile Include="Native\BaseMonoApp.cs" />
<Compile Include="Native\SqliteExtensions.cs" />
<Compile Include="Networking\CertificateGenerator.cs" /> <Compile Include="Networking\CertificateGenerator.cs" />
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />

View File

@ -9,6 +9,7 @@ using System.Collections.Generic;
using System.Reflection; using System.Reflection;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using MediaBrowser.Controller.Power; using MediaBrowser.Controller.Power;
using MediaBrowser.Server.Implementations.Persistence;
using MediaBrowser.Server.Startup.Common.FFMpeg; using MediaBrowser.Server.Startup.Common.FFMpeg;
using OperatingSystem = MediaBrowser.Server.Startup.Common.OperatingSystem; using OperatingSystem = MediaBrowser.Server.Startup.Common.OperatingSystem;
@ -17,9 +18,12 @@ namespace MediaBrowser.Server.Mono.Native
public abstract class BaseMonoApp : INativeApp public abstract class BaseMonoApp : INativeApp
{ {
protected StartupOptions StartupOptions { get; private set; } protected StartupOptions StartupOptions { get; private set; }
protected BaseMonoApp(StartupOptions startupOptions) protected ILogger Logger { get; private set; }
protected BaseMonoApp(StartupOptions startupOptions, ILogger logger)
{ {
StartupOptions = startupOptions; StartupOptions = startupOptions;
Logger = logger;
} }
/// <summary> /// <summary>
@ -227,6 +231,11 @@ namespace MediaBrowser.Server.Mono.Native
throw new NotImplementedException(); throw new NotImplementedException();
} }
public IDbConnector GetDbConnector()
{
return new DbConnector(Logger);
}
public static FFMpegInstallInfo GetInfo(NativeEnvironment environment) public static FFMpegInstallInfo GetInfo(NativeEnvironment environment)
{ {
var info = new FFMpegInstallInfo(); var info = new FFMpegInstallInfo();

View File

@ -1,4 +1,5 @@
using MediaBrowser.Server.Startup.Common; using MediaBrowser.Model.Logging;
using MediaBrowser.Server.Startup.Common;
namespace MediaBrowser.Server.Mono.Native namespace MediaBrowser.Server.Mono.Native
{ {
@ -7,8 +8,8 @@ namespace MediaBrowser.Server.Mono.Native
/// </summary> /// </summary>
internal class NativeApp : BaseMonoApp internal class NativeApp : BaseMonoApp
{ {
public NativeApp(StartupOptions startupOptions) public NativeApp(StartupOptions startupOptions, ILogger logger)
: base(startupOptions) : base(startupOptions, logger)
{ {
} }

View File

@ -0,0 +1,62 @@
using System;
using System.Data;
using System.Data.SQLite;
using System.Threading.Tasks;
using MediaBrowser.Model.Logging;
using MediaBrowser.Server.Implementations.Persistence;
namespace MediaBrowser.Server.Mono.Native
{
/// <summary>
/// Class SQLiteExtensions
/// </summary>
static class SqliteExtensions
{
/// <summary>
/// Connects to db.
/// </summary>
/// <param name="dbPath">The db path.</param>
/// <param name="logger">The logger.</param>
/// <returns>Task{IDbConnection}.</returns>
/// <exception cref="System.ArgumentNullException">dbPath</exception>
public static async Task<IDbConnection> ConnectToDb(string dbPath, ILogger logger)
{
if (string.IsNullOrEmpty(dbPath))
{
throw new ArgumentNullException("dbPath");
}
logger.Info("Sqlite {0} opening {1}", SQLiteConnection.SQLiteVersion, dbPath);
var connectionstr = new SQLiteConnectionStringBuilder
{
PageSize = 4096,
CacheSize = 2000,
SyncMode = SynchronizationModes.Full,
DataSource = dbPath,
JournalMode = SQLiteJournalModeEnum.Wal
};
var connection = new SQLiteConnection(connectionstr.ConnectionString);
await connection.OpenAsync().ConfigureAwait(false);
return connection;
}
}
public class DbConnector : IDbConnector
{
private readonly ILogger _logger;
public DbConnector(ILogger logger)
{
_logger = logger;
}
public Task<IDbConnection> Connect(string dbPath)
{
return SqliteExtensions.ConnectToDb(dbPath, _logger);
}
}
}

View File

@ -79,7 +79,7 @@ namespace MediaBrowser.Server.Mono
var fileSystem = new ManagedFileSystem(new PatternsLogger(logManager.GetLogger("FileSystem")), false, false); var fileSystem = new ManagedFileSystem(new PatternsLogger(logManager.GetLogger("FileSystem")), false, false);
fileSystem.AddShortcutHandler(new MbLinkShortcutHandler(fileSystem)); fileSystem.AddShortcutHandler(new MbLinkShortcutHandler(fileSystem));
var nativeApp = new NativeApp(options); var nativeApp = new NativeApp(options, logManager.GetLogger("App"));
_appHost = new ApplicationHost(appPaths, logManager, options, fileSystem, "emby.mono.zip", nativeApp); _appHost = new ApplicationHost(appPaths, logManager, options, fileSystem, "emby.mono.zip", nativeApp);

View File

@ -410,13 +410,16 @@ namespace MediaBrowser.Server.Startup.Common
UserRepository = await GetUserRepository().ConfigureAwait(false); UserRepository = await GetUserRepository().ConfigureAwait(false);
RegisterSingleInstance(UserRepository); RegisterSingleInstance(UserRepository);
DisplayPreferencesRepository = new SqliteDisplayPreferencesRepository(LogManager, JsonSerializer, ApplicationPaths); var displayPreferencesRepo = new SqliteDisplayPreferencesRepository(LogManager, JsonSerializer, ApplicationPaths);
DisplayPreferencesRepository = displayPreferencesRepo;
RegisterSingleInstance(DisplayPreferencesRepository); RegisterSingleInstance(DisplayPreferencesRepository);
ItemRepository = new SqliteItemRepository(ApplicationPaths, JsonSerializer, LogManager); var itemRepo = new SqliteItemRepository(ServerConfigurationManager, JsonSerializer, LogManager);
ItemRepository = itemRepo;
RegisterSingleInstance(ItemRepository); RegisterSingleInstance(ItemRepository);
ProviderRepository = new SqliteProviderInfoRepository(LogManager, ApplicationPaths); var providerRepo = new SqliteProviderInfoRepository(LogManager, ApplicationPaths);
ProviderRepository = providerRepo;
RegisterSingleInstance(ProviderRepository); RegisterSingleInstance(ProviderRepository);
FileOrganizationRepository = await GetFileOrganizationRepository().ConfigureAwait(false); FileOrganizationRepository = await GetFileOrganizationRepository().ConfigureAwait(false);
@ -541,7 +544,7 @@ namespace MediaBrowser.Server.Startup.Common
RegisterSingleInstance(NativeApp.GetPowerManagement()); RegisterSingleInstance(NativeApp.GetPowerManagement());
var sharingRepo = new SharingRepository(LogManager, ApplicationPaths); var sharingRepo = new SharingRepository(LogManager, ApplicationPaths);
await sharingRepo.Initialize().ConfigureAwait(false); await sharingRepo.Initialize(NativeApp.GetDbConnector()).ConfigureAwait(false);
RegisterSingleInstance<ISharingManager>(new SharingManager(sharingRepo, ServerConfigurationManager, LibraryManager, this)); RegisterSingleInstance<ISharingManager>(new SharingManager(sharingRepo, ServerConfigurationManager, LibraryManager, this));
RegisterSingleInstance<ISsdpHandler>(new SsdpHandler(LogManager.GetLogger("SsdpHandler"), ServerConfigurationManager, this)); RegisterSingleInstance<ISsdpHandler>(new SsdpHandler(LogManager.GetLogger("SsdpHandler"), ServerConfigurationManager, this));
@ -557,9 +560,11 @@ namespace MediaBrowser.Server.Startup.Common
SubtitleEncoder = new SubtitleEncoder(LibraryManager, LogManager.GetLogger("SubtitleEncoder"), ApplicationPaths, FileSystemManager, MediaEncoder, JsonSerializer, HttpClient, MediaSourceManager); SubtitleEncoder = new SubtitleEncoder(LibraryManager, LogManager.GetLogger("SubtitleEncoder"), ApplicationPaths, FileSystemManager, MediaEncoder, JsonSerializer, HttpClient, MediaSourceManager);
RegisterSingleInstance(SubtitleEncoder); RegisterSingleInstance(SubtitleEncoder);
await ConfigureDisplayPreferencesRepositories().ConfigureAwait(false); await displayPreferencesRepo.Initialize(NativeApp.GetDbConnector()).ConfigureAwait(false);
await ConfigureItemRepositories().ConfigureAwait(false); await itemRepo.Initialize(NativeApp.GetDbConnector()).ConfigureAwait(false);
await providerRepo.Initialize(NativeApp.GetDbConnector()).ConfigureAwait(false);
((LibraryManager)LibraryManager).ItemRepository = ItemRepository;
await ConfigureUserDataRepositories().ConfigureAwait(false); await ConfigureUserDataRepositories().ConfigureAwait(false);
await ConfigureNotificationsRepository().ConfigureAwait(false); await ConfigureNotificationsRepository().ConfigureAwait(false);
progress.Report(100); progress.Report(100);
@ -658,7 +663,7 @@ namespace MediaBrowser.Server.Startup.Common
{ {
var repo = new SqliteUserRepository(LogManager, ApplicationPaths, JsonSerializer); var repo = new SqliteUserRepository(LogManager, ApplicationPaths, JsonSerializer);
await repo.Initialize().ConfigureAwait(false); await repo.Initialize(NativeApp.GetDbConnector()).ConfigureAwait(false);
return repo; return repo;
} }
@ -677,7 +682,7 @@ namespace MediaBrowser.Server.Startup.Common
{ {
var repo = new SqliteFileOrganizationRepository(LogManager, ServerConfigurationManager.ApplicationPaths); var repo = new SqliteFileOrganizationRepository(LogManager, ServerConfigurationManager.ApplicationPaths);
await repo.Initialize().ConfigureAwait(false); await repo.Initialize(NativeApp.GetDbConnector()).ConfigureAwait(false);
return repo; return repo;
} }
@ -686,7 +691,7 @@ namespace MediaBrowser.Server.Startup.Common
{ {
var repo = new AuthenticationRepository(LogManager, ServerConfigurationManager.ApplicationPaths); var repo = new AuthenticationRepository(LogManager, ServerConfigurationManager.ApplicationPaths);
await repo.Initialize().ConfigureAwait(false); await repo.Initialize(NativeApp.GetDbConnector()).ConfigureAwait(false);
return repo; return repo;
} }
@ -695,7 +700,7 @@ namespace MediaBrowser.Server.Startup.Common
{ {
var repo = new ActivityRepository(LogManager, ServerConfigurationManager.ApplicationPaths); var repo = new ActivityRepository(LogManager, ServerConfigurationManager.ApplicationPaths);
await repo.Initialize().ConfigureAwait(false); await repo.Initialize(NativeApp.GetDbConnector()).ConfigureAwait(false);
return repo; return repo;
} }
@ -704,7 +709,7 @@ namespace MediaBrowser.Server.Startup.Common
{ {
var repo = new SyncRepository(LogManager, JsonSerializer, ServerConfigurationManager.ApplicationPaths); var repo = new SyncRepository(LogManager, JsonSerializer, ServerConfigurationManager.ApplicationPaths);
await repo.Initialize().ConfigureAwait(false); await repo.Initialize(NativeApp.GetDbConnector()).ConfigureAwait(false);
return repo; return repo;
} }
@ -717,35 +722,13 @@ namespace MediaBrowser.Server.Startup.Common
{ {
var repo = new SqliteNotificationsRepository(LogManager, ApplicationPaths); var repo = new SqliteNotificationsRepository(LogManager, ApplicationPaths);
await repo.Initialize().ConfigureAwait(false); await repo.Initialize(NativeApp.GetDbConnector()).ConfigureAwait(false);
NotificationsRepository = repo; NotificationsRepository = repo;
RegisterSingleInstance(NotificationsRepository); RegisterSingleInstance(NotificationsRepository);
} }
/// <summary>
/// Configures the repositories.
/// </summary>
/// <returns>Task.</returns>
private async Task ConfigureDisplayPreferencesRepositories()
{
await DisplayPreferencesRepository.Initialize().ConfigureAwait(false);
}
/// <summary>
/// Configures the item repositories.
/// </summary>
/// <returns>Task.</returns>
private async Task ConfigureItemRepositories()
{
await ItemRepository.Initialize().ConfigureAwait(false);
await ProviderRepository.Initialize().ConfigureAwait(false);
((LibraryManager)LibraryManager).ItemRepository = ItemRepository;
}
/// <summary> /// <summary>
/// Configures the user data repositories. /// Configures the user data repositories.
/// </summary> /// </summary>
@ -754,7 +737,7 @@ namespace MediaBrowser.Server.Startup.Common
{ {
var repo = new SqliteUserDataRepository(LogManager, ApplicationPaths); var repo = new SqliteUserDataRepository(LogManager, ApplicationPaths);
await repo.Initialize().ConfigureAwait(false); await repo.Initialize(NativeApp.GetDbConnector()).ConfigureAwait(false);
((UserDataManager)UserDataManager).Repository = repo; ((UserDataManager)UserDataManager).Repository = repo;
} }

View File

@ -3,6 +3,7 @@ using MediaBrowser.Model.Logging;
using System.Collections.Generic; using System.Collections.Generic;
using System.Reflection; using System.Reflection;
using MediaBrowser.Controller.Power; using MediaBrowser.Controller.Power;
using MediaBrowser.Server.Implementations.Persistence;
using MediaBrowser.Server.Startup.Common.FFMpeg; using MediaBrowser.Server.Startup.Common.FFMpeg;
namespace MediaBrowser.Server.Startup.Common namespace MediaBrowser.Server.Startup.Common
@ -104,5 +105,7 @@ namespace MediaBrowser.Server.Startup.Common
FFMpegInstallInfo GetFfmpegInstallInfo(); FFMpegInstallInfo GetFfmpegInstallInfo();
void LaunchUrl(string url); void LaunchUrl(string url);
IDbConnector GetDbConnector();
} }
} }

View File

@ -13,6 +13,8 @@
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir> <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<TargetFrameworkProfile /> <TargetFrameworkProfile />
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget> <PlatformTarget>AnyCPU</PlatformTarget>
@ -81,9 +83,9 @@
<Reference Include="System.Configuration" /> <Reference Include="System.Configuration" />
<Reference Include="System.Configuration.Install" /> <Reference Include="System.Configuration.Install" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Data.SQLite, Version=1.0.94.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL"> <Reference Include="System.Data.SQLite, Version=1.0.101.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <HintPath>..\packages\System.Data.SQLite.Core.1.0.101.0\lib\net46\System.Data.SQLite.dll</HintPath>
<HintPath>..\packages\System.Data.SQLite.Core.1.0.94.0\lib\net45\System.Data.SQLite.dll</HintPath> <Private>True</Private>
</Reference> </Reference>
<Reference Include="System.Drawing" /> <Reference Include="System.Drawing" />
<Reference Include="System.ServiceProcess" /> <Reference Include="System.ServiceProcess" />
@ -112,6 +114,7 @@
</Compile> </Compile>
<Compile Include="MainStartup.cs" /> <Compile Include="MainStartup.cs" />
<Compile Include="Native\LnkShortcutHandler.cs" /> <Compile Include="Native\LnkShortcutHandler.cs" />
<Compile Include="Native\SqliteExtensions.cs" />
<Compile Include="Native\Standby.cs" /> <Compile Include="Native\Standby.cs" />
<Compile Include="Native\ServerAuthorization.cs" /> <Compile Include="Native\ServerAuthorization.cs" />
<Compile Include="Native\WindowsApp.cs" /> <Compile Include="Native\WindowsApp.cs" />
@ -156,14 +159,6 @@
</EmbeddedResource> </EmbeddedResource>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="..\packages\System.Data.SQLite.Core.1.0.94.0\build\net45\x64\SQLite.Interop.dll">
<Link>x64\SQLite.Interop.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="..\packages\System.Data.SQLite.Core.1.0.94.0\build\net45\x86\SQLite.Interop.dll">
<Link>x86\SQLite.Interop.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="..\Tools\Installation\MediaBrowser.InstallUtil.dll"> <Content Include="..\Tools\Installation\MediaBrowser.InstallUtil.dll">
<Link>MediaBrowser.InstallUtil.dll</Link> <Link>MediaBrowser.InstallUtil.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
@ -1116,6 +1111,13 @@
<PostBuildEvent> <PostBuildEvent>
</PostBuildEvent> </PostBuildEvent>
</PropertyGroup> </PropertyGroup>
<Import Project="..\packages\System.Data.SQLite.Core.1.0.101.0\build\net46\System.Data.SQLite.Core.targets" Condition="Exists('..\packages\System.Data.SQLite.Core.1.0.101.0\build\net46\System.Data.SQLite.Core.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\System.Data.SQLite.Core.1.0.101.0\build\net46\System.Data.SQLite.Core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\System.Data.SQLite.Core.1.0.101.0\build\net46\System.Data.SQLite.Core.targets'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild"> <Target Name="BeforeBuild">
@ -1123,5 +1125,4 @@
<Target Name="AfterBuild"> <Target Name="AfterBuild">
</Target> </Target>
--> -->
<Import Project="..\packages\System.Data.SQLite.Core.1.0.94.0\build\net45\System.Data.SQLite.Core.targets" Condition="Exists('..\packages\System.Data.SQLite.Core.1.0.94.0\build\net45\System.Data.SQLite.Core.targets')" />
</Project> </Project>

View File

@ -0,0 +1,62 @@
using System;
using System.Data;
using System.Data.SQLite;
using System.Threading.Tasks;
using MediaBrowser.Model.Logging;
using MediaBrowser.Server.Implementations.Persistence;
namespace MediaBrowser.ServerApplication.Native
{
/// <summary>
/// Class SQLiteExtensions
/// </summary>
static class SqliteExtensions
{
/// <summary>
/// Connects to db.
/// </summary>
/// <param name="dbPath">The db path.</param>
/// <param name="logger">The logger.</param>
/// <returns>Task{IDbConnection}.</returns>
/// <exception cref="System.ArgumentNullException">dbPath</exception>
public static async Task<IDbConnection> ConnectToDb(string dbPath, ILogger logger)
{
if (string.IsNullOrEmpty(dbPath))
{
throw new ArgumentNullException("dbPath");
}
logger.Info("Sqlite {0} opening {1}", SQLiteConnection.SQLiteVersion, dbPath);
var connectionstr = new SQLiteConnectionStringBuilder
{
PageSize = 4096,
CacheSize = 2000,
SyncMode = SynchronizationModes.Full,
DataSource = dbPath,
JournalMode = SQLiteJournalModeEnum.Wal
};
var connection = new SQLiteConnection(connectionstr.ConnectionString);
await connection.OpenAsync().ConfigureAwait(false);
return connection;
}
}
public class DbConnector : IDbConnector
{
private readonly ILogger _logger;
public DbConnector(ILogger logger)
{
_logger = logger;
}
public Task<IDbConnection> Connect(string dbPath)
{
return SqliteExtensions.ConnectToDb(dbPath, _logger);
}
}
}

View File

@ -10,6 +10,7 @@ using System.Reflection;
using System.Windows.Forms; using System.Windows.Forms;
using CommonIO; using CommonIO;
using MediaBrowser.Controller.Power; using MediaBrowser.Controller.Power;
using MediaBrowser.Server.Implementations.Persistence;
using MediaBrowser.Server.Startup.Common.FFMpeg; using MediaBrowser.Server.Startup.Common.FFMpeg;
using OperatingSystem = MediaBrowser.Server.Startup.Common.OperatingSystem; using OperatingSystem = MediaBrowser.Server.Startup.Common.OperatingSystem;
@ -191,6 +192,11 @@ namespace MediaBrowser.ServerApplication.Native
} }
} }
public IDbConnector GetDbConnector()
{
return new DbConnector(_logger);
}
/// <summary> /// <summary>
/// Processes the exited. /// Processes the exited.
/// </summary> /// </summary>

View File

@ -3,5 +3,5 @@
<package id="CommonIO" version="1.0.0.9" targetFramework="net45" /> <package id="CommonIO" version="1.0.0.9" targetFramework="net45" />
<package id="ImageMagickSharp" version="1.0.0.18" targetFramework="net45" /> <package id="ImageMagickSharp" version="1.0.0.18" targetFramework="net45" />
<package id="Patterns.Logging" version="1.0.0.2" targetFramework="net45" /> <package id="Patterns.Logging" version="1.0.0.2" targetFramework="net45" />
<package id="System.Data.SQLite.Core" version="1.0.94.0" targetFramework="net45" requireReinstallation="true" /> <package id="System.Data.SQLite.Core" version="1.0.101.0" targetFramework="net46" />
</packages> </packages>