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].
/// </summary>
event EventHandler<NotificationReadEventArgs> NotificationsMarkedRead;
/// <summary>
/// Opens the connection to the repository
/// </summary>
/// <returns>Task.</returns>
Task Initialize();
/// <summary>
/// Gets the notifications.

View File

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

View File

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

View File

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

View File

@ -21,11 +21,5 @@ namespace MediaBrowser.Controller.Providers
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns>
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;
}
public async Task Initialize()
public async Task Initialize(IDbConnector dbConnector)
{
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 = {

View File

@ -78,9 +78,6 @@
</Reference>
<Reference Include="System" />
<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="System.Data" />
<Reference Include="System.Net" />
@ -261,6 +258,8 @@
<Compile Include="Notifications\IConfigurableNotificationService.cs" />
<Compile Include="Persistence\BaseSqliteRepository.cs" />
<Compile Include="Persistence\CleanDatabaseScheduledTask.cs" />
<Compile Include="Persistence\DataExtensions.cs" />
<Compile Include="Persistence\IDbConnector.cs" />
<Compile Include="Persistence\MediaStreamColumns.cs" />
<Compile Include="Social\SharingManager.cs" />
<Compile Include="Social\SharingRepository.cs" />
@ -275,7 +274,6 @@
<Compile Include="Notifications\InternalNotificationService.cs" />
<Compile Include="Notifications\NotificationConfigurationFactory.cs" />
<Compile Include="Notifications\NotificationManager.cs" />
<Compile Include="Persistence\SqliteExtensions.cs" />
<Compile Include="Persistence\SqliteFileOrganizationRepository.cs" />
<Compile Include="Notifications\SqliteNotificationsRepository.cs" />
<Compile Include="Persistence\SqliteProviderInfoRepository.cs" />

View File

@ -32,11 +32,11 @@ namespace MediaBrowser.Server.Implementations.Notifications
_appPaths = appPaths;
}
public async Task Initialize()
public async Task Initialize(IDbConnector dbConnector)
{
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 = {

View File

@ -3,16 +3,12 @@ using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Serialization;
using System;
using System.Data;
using System.Data.SQLite;
using System.IO;
using System.Threading.Tasks;
namespace MediaBrowser.Server.Implementations.Persistence
{
/// <summary>
/// Class SQLiteExtensions
/// </summary>
static class SqliteExtensions
static class DataExtensions
{
/// <summary>
/// Determines whether the specified conn is open.
@ -28,11 +24,11 @@ namespace MediaBrowser.Server.Implementations.Persistence
{
return (IDataParameter)cmd.Parameters[index];
}
public static IDataParameter Add(this IDataParameterCollection paramCollection, IDbCommand cmd, string name, DbType type)
{
var param = cmd.CreateParameter();
param.ParameterName = name;
param.DbType = type;
@ -48,11 +44,11 @@ namespace MediaBrowser.Server.Implementations.Persistence
param.ParameterName = name;
paramCollection.Add(param);
return param;
}
/// <summary>
/// Gets a stream from a DataReader at a given ordinal
/// </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)
{
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
/// </summary>
/// <returns>Task.</returns>
public async Task Initialize()
public async Task Initialize(IDbConnector dbConnector)
{
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 = {

View File

@ -35,11 +35,11 @@ namespace MediaBrowser.Server.Implementations.Persistence
/// Opens the connection to the database
/// </summary>
/// <returns>Task.</returns>
public async Task Initialize()
public async Task Initialize(IDbConnector dbConnector)
{
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 = {

View File

@ -39,11 +39,11 @@ namespace MediaBrowser.Server.Implementations.Persistence
/// Opens the connection to the database
/// </summary>
/// <returns>Task.</returns>
public async Task Initialize()
public async Task Initialize(IDbConnector dbConnector)
{
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 = {

View File

@ -37,11 +37,11 @@ namespace MediaBrowser.Server.Implementations.Persistence
/// Opens the connection to the database
/// </summary>
/// <returns>Task.</returns>
public async Task Initialize()
public async Task Initialize(IDbConnector dbConnector)
{
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 = {

View File

@ -43,12 +43,12 @@ namespace MediaBrowser.Server.Implementations.Persistence
/// Opens the connection to the database
/// </summary>
/// <returns>Task.</returns>
public async Task Initialize()
public async Task Initialize(IDbConnector dbConnector)
{
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 = {
"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;
}
public async Task Initialize()
public async Task Initialize(IDbConnector dbConnector)
{
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 = {

View File

@ -26,11 +26,11 @@ namespace MediaBrowser.Server.Implementations.Social
/// Opens the connection to the database
/// </summary>
/// <returns>Task.</returns>
public async Task Initialize()
public async Task Initialize(IDbConnector dbConnector)
{
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 = {

View File

@ -39,11 +39,11 @@ namespace MediaBrowser.Server.Implementations.Sync
_appPaths = appPaths;
}
public async Task Initialize()
public async Task Initialize(IDbConnector dbConnector)
{
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 = {

View File

@ -76,12 +76,17 @@
<Reference Include="MediaBrowser.IsoMounting.Linux">
<HintPath>..\ThirdParty\MediaBrowser.IsoMounting.Linux\MediaBrowser.IsoMounting.Linux.dll</HintPath>
</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>
<Compile Include="..\SharedVersion.cs">
<Link>Properties\SharedVersion.cs</Link>
</Compile>
<Compile Include="Native\BaseMonoApp.cs" />
<Compile Include="Native\SqliteExtensions.cs" />
<Compile Include="Networking\CertificateGenerator.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />

View File

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

View File

@ -410,13 +410,16 @@ namespace MediaBrowser.Server.Startup.Common
UserRepository = await GetUserRepository().ConfigureAwait(false);
RegisterSingleInstance(UserRepository);
DisplayPreferencesRepository = new SqliteDisplayPreferencesRepository(LogManager, JsonSerializer, ApplicationPaths);
var displayPreferencesRepo = new SqliteDisplayPreferencesRepository(LogManager, JsonSerializer, ApplicationPaths);
DisplayPreferencesRepository = displayPreferencesRepo;
RegisterSingleInstance(DisplayPreferencesRepository);
ItemRepository = new SqliteItemRepository(ApplicationPaths, JsonSerializer, LogManager);
var itemRepo = new SqliteItemRepository(ServerConfigurationManager, JsonSerializer, LogManager);
ItemRepository = itemRepo;
RegisterSingleInstance(ItemRepository);
ProviderRepository = new SqliteProviderInfoRepository(LogManager, ApplicationPaths);
var providerRepo = new SqliteProviderInfoRepository(LogManager, ApplicationPaths);
ProviderRepository = providerRepo;
RegisterSingleInstance(ProviderRepository);
FileOrganizationRepository = await GetFileOrganizationRepository().ConfigureAwait(false);
@ -541,7 +544,7 @@ namespace MediaBrowser.Server.Startup.Common
RegisterSingleInstance(NativeApp.GetPowerManagement());
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<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);
RegisterSingleInstance(SubtitleEncoder);
await ConfigureDisplayPreferencesRepositories().ConfigureAwait(false);
await ConfigureItemRepositories().ConfigureAwait(false);
await displayPreferencesRepo.Initialize(NativeApp.GetDbConnector()).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 ConfigureNotificationsRepository().ConfigureAwait(false);
progress.Report(100);
@ -658,7 +663,7 @@ namespace MediaBrowser.Server.Startup.Common
{
var repo = new SqliteUserRepository(LogManager, ApplicationPaths, JsonSerializer);
await repo.Initialize().ConfigureAwait(false);
await repo.Initialize(NativeApp.GetDbConnector()).ConfigureAwait(false);
return repo;
}
@ -677,7 +682,7 @@ namespace MediaBrowser.Server.Startup.Common
{
var repo = new SqliteFileOrganizationRepository(LogManager, ServerConfigurationManager.ApplicationPaths);
await repo.Initialize().ConfigureAwait(false);
await repo.Initialize(NativeApp.GetDbConnector()).ConfigureAwait(false);
return repo;
}
@ -686,7 +691,7 @@ namespace MediaBrowser.Server.Startup.Common
{
var repo = new AuthenticationRepository(LogManager, ServerConfigurationManager.ApplicationPaths);
await repo.Initialize().ConfigureAwait(false);
await repo.Initialize(NativeApp.GetDbConnector()).ConfigureAwait(false);
return repo;
}
@ -695,7 +700,7 @@ namespace MediaBrowser.Server.Startup.Common
{
var repo = new ActivityRepository(LogManager, ServerConfigurationManager.ApplicationPaths);
await repo.Initialize().ConfigureAwait(false);
await repo.Initialize(NativeApp.GetDbConnector()).ConfigureAwait(false);
return repo;
}
@ -704,7 +709,7 @@ namespace MediaBrowser.Server.Startup.Common
{
var repo = new SyncRepository(LogManager, JsonSerializer, ServerConfigurationManager.ApplicationPaths);
await repo.Initialize().ConfigureAwait(false);
await repo.Initialize(NativeApp.GetDbConnector()).ConfigureAwait(false);
return repo;
}
@ -717,35 +722,13 @@ namespace MediaBrowser.Server.Startup.Common
{
var repo = new SqliteNotificationsRepository(LogManager, ApplicationPaths);
await repo.Initialize().ConfigureAwait(false);
await repo.Initialize(NativeApp.GetDbConnector()).ConfigureAwait(false);
NotificationsRepository = repo;
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>
/// Configures the user data repositories.
/// </summary>
@ -754,7 +737,7 @@ namespace MediaBrowser.Server.Startup.Common
{
var repo = new SqliteUserDataRepository(LogManager, ApplicationPaths);
await repo.Initialize().ConfigureAwait(false);
await repo.Initialize(NativeApp.GetDbConnector()).ConfigureAwait(false);
((UserDataManager)UserDataManager).Repository = repo;
}

View File

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

View File

@ -13,6 +13,8 @@
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<TargetFrameworkProfile />
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@ -81,9 +83,9 @@
<Reference Include="System.Configuration" />
<Reference Include="System.Configuration.Install" />
<Reference Include="System.Core" />
<Reference Include="System.Data.SQLite, Version=1.0.94.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\System.Data.SQLite.Core.1.0.94.0\lib\net45\System.Data.SQLite.dll</HintPath>
<Reference Include="System.Data.SQLite, Version=1.0.101.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
<HintPath>..\packages\System.Data.SQLite.Core.1.0.101.0\lib\net46\System.Data.SQLite.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Drawing" />
<Reference Include="System.ServiceProcess" />
@ -112,6 +114,7 @@
</Compile>
<Compile Include="MainStartup.cs" />
<Compile Include="Native\LnkShortcutHandler.cs" />
<Compile Include="Native\SqliteExtensions.cs" />
<Compile Include="Native\Standby.cs" />
<Compile Include="Native\ServerAuthorization.cs" />
<Compile Include="Native\WindowsApp.cs" />
@ -156,14 +159,6 @@
</EmbeddedResource>
</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">
<Link>MediaBrowser.InstallUtil.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
@ -1116,6 +1111,13 @@
<PostBuildEvent>
</PostBuildEvent>
</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.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
@ -1123,5 +1125,4 @@
<Target Name="AfterBuild">
</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>

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

View File

@ -3,5 +3,5 @@
<package id="CommonIO" version="1.0.0.9" 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="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>