mono progress - able to start app

pull/702/head
Luke Pulverenti 11 years ago
parent 2d0cc66e6b
commit 2d8152f36a

@ -980,7 +980,7 @@ namespace MediaBrowser.Controller.Entities
var initialCount = _children.Count;
var list = new List<BaseItem>(initialCount);
AddChildrenToList(user, includeLinkedChildren, list, false);
AddChildrenToList(user, includeLinkedChildren, list, false, null);
return list;
}
@ -992,7 +992,9 @@ namespace MediaBrowser.Controller.Entities
/// <param name="includeLinkedChildren">if set to <c>true</c> [include linked children].</param>
/// <param name="list">The list.</param>
/// <param name="recursive">if set to <c>true</c> [recursive].</param>
private bool AddChildrenToList(User user, bool includeLinkedChildren, List<BaseItem> list, bool recursive)
/// <param name="filter">The filter.</param>
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
private bool AddChildrenToList(User user, bool includeLinkedChildren, List<BaseItem> list, bool recursive, Func<BaseItem,bool> filter)
{
var hasLinkedChildren = false;
@ -1000,7 +1002,10 @@ namespace MediaBrowser.Controller.Entities
{
if (child.IsVisible(user))
{
list.Add(child);
if (filter == null || filter(child))
{
list.Add(child);
}
}
if (recursive)
@ -1009,7 +1014,7 @@ namespace MediaBrowser.Controller.Entities
if (folder != null)
{
if (folder.AddChildrenToList(user, includeLinkedChildren, list, true))
if (folder.AddChildrenToList(user, includeLinkedChildren, list, true, filter))
{
hasLinkedChildren = true;
}
@ -1021,6 +1026,11 @@ namespace MediaBrowser.Controller.Entities
{
foreach (var child in GetLinkedChildren())
{
if (filter != null && !filter(child))
{
continue;
}
hasLinkedChildren = true;
if (child.IsVisible(user))
@ -1042,6 +1052,11 @@ namespace MediaBrowser.Controller.Entities
/// <returns>IEnumerable{BaseItem}.</returns>
/// <exception cref="System.ArgumentNullException"></exception>
public IEnumerable<BaseItem> GetRecursiveChildren(User user, bool includeLinkedChildren = true)
{
return GetRecursiveChildren(user, null, true);
}
public IEnumerable<BaseItem> GetRecursiveChildren(User user, Func<BaseItem,bool> filter, bool includeLinkedChildren = true)
{
if (user == null)
{
@ -1051,10 +1066,10 @@ namespace MediaBrowser.Controller.Entities
var initialCount = _lastRecursiveCount == 0 ? _children.Count : _lastRecursiveCount;
var list = new List<BaseItem>(initialCount);
var hasLinkedChildren = AddChildrenToList(user, includeLinkedChildren, list, true);
var hasLinkedChildren = AddChildrenToList(user, includeLinkedChildren, list, true, null);
_lastRecursiveCount = list.Count;
if (includeLinkedChildren && hasLinkedChildren)
{
list = list.Distinct().ToList();
@ -1062,7 +1077,7 @@ namespace MediaBrowser.Controller.Entities
return list;
}
/// <summary>
/// Gets the linked children.
/// </summary>

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

@ -2,7 +2,6 @@
using MediaBrowser.Model.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

@ -14,7 +14,7 @@ namespace MediaBrowser.Controller.Persistence
/// Opens the connection to the repository
/// </summary>
/// <returns>Task.</returns>
void Initialize();
Task Initialize();
/// <summary>
/// Deletes the user.

@ -1,15 +1,12 @@
<Properties>
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug|x86" />
<MonoDevelop.Ide.Workbench ActiveDocument="d:\Development\MediaBrowser\MediaBrowser.Server.Mono\Native\Sqlite.cs">
<MonoDevelop.Ide.Workbench ActiveDocument="d:\Development\MediaBrowser\MediaBrowser.ServerApplication\ApplicationHost.cs">
<Files>
<File FileName="d:\Development\MediaBrowser\MediaBrowser.ServerApplication\ApplicationHost.cs" Line="442" Column="10" />
<File FileName="MediaBrowser.Server.Mono\Native\ServerAuthorization.cs" Line="1" Column="1" />
<File FileName="MediaBrowser.Server.Mono\Native\Autorun.cs" Line="1" Column="1" />
<File FileName="MediaBrowser.Server.Mono\Native\Assemblies.cs" Line="1" Column="1" />
<File FileName="MediaBrowser.Server.Mono\Program.cs" Line="1" Column="1" />
<File FileName="MediaBrowser.Server.Mono\MainWindow.cs" Line="8" Column="12" />
<File FileName="MediaBrowser.Server.Mono\Native\Autorun.cs" Line="17" Column="4" />
<File FileName="MediaBrowser.Server.Mono\Native\ServerAuthorization.cs" Line="23" Column="1" />
<File FileName="MediaBrowser.Server.Mono\FFMpeg\FFMpegDownloader.cs" Line="7" Column="14" />
<File FileName="MediaBrowser.ServerApplication\ApplicationHost.cs" Line="548" Column="61" />
<File FileName="MediaBrowser.Server.Mono\Native\NativeApp.cs" Line="22" Column="13" />
<File FileName="d:\Development\MediaBrowser\MediaBrowser.Server.Mono\Native\Sqlite.cs" Line="21" Column="14" />
</Files>
</MonoDevelop.Ide.Workbench>
<MonoDevelop.Ide.DebuggingService.Breakpoints>

@ -1074,7 +1074,7 @@ namespace MediaBrowser.Server.Implementations.Dto
double totalPercentPlayed = 0;
// Loop through each recursive child
foreach (var child in folder.GetRecursiveChildren(user, true).Where(i => !i.IsFolder).ToList())
foreach (var child in folder.GetRecursiveChildren(user, i => !i.IsFolder))
{
var userdata = _userDataRepository.GetUserData(user.Id, child.GetUserDataKey());

@ -1,4 +1,6 @@
using MediaBrowser.Controller.Notifications;
using System.IO;
using MediaBrowser.Controller;
using MediaBrowser.Controller.Notifications;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Notifications;
using System;
@ -12,15 +14,15 @@ namespace MediaBrowser.Server.Implementations.Persistence
{
public class SqliteNotificationsRepository : INotificationsRepository
{
private readonly IDbConnection _connection;
private IDbConnection _connection;
private readonly ILogger _logger;
private readonly IServerApplicationPaths _appPaths;
private readonly SemaphoreSlim _writeLock = new SemaphoreSlim(1, 1);
public SqliteNotificationsRepository(IDbConnection connection, ILogManager logManager)
public SqliteNotificationsRepository(ILogManager logManager, IServerApplicationPaths appPaths)
{
_connection = connection;
_appPaths = appPaths;
_logger = logManager.GetLogger(GetType().Name);
}
@ -31,8 +33,12 @@ namespace MediaBrowser.Server.Implementations.Persistence
private IDbCommand _replaceNotificationCommand;
private IDbCommand _markReadCommand;
public void Initialize()
public async Task Initialize()
{
var dbFile = Path.Combine(_appPaths.DataPath, "notifications.db");
_connection = await SqliteExtensions.ConnectToDb(dbFile).ConfigureAwait(false);
string[] queries = {
"create table if not exists Notifications (Id GUID NOT NULL, UserId GUID NOT NULL, Date DATETIME NOT NULL, Name TEXT NOT NULL, Description TEXT, Url TEXT, Level TEXT NOT NULL, IsRead BOOLEAN NOT NULL, Category TEXT NOT NULL, RelatedId TEXT, PRIMARY KEY (Id, UserId))",

@ -1,10 +1,12 @@
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Serialization;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
@ -20,6 +22,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
private readonly SemaphoreSlim _writeLock = new SemaphoreSlim(1, 1);
private IDbConnection _connection;
private readonly IServerApplicationPaths _appPaths;
/// <summary>
/// Gets the name of the repository
@ -42,19 +45,19 @@ namespace MediaBrowser.Server.Implementations.Persistence
/// <summary>
/// Initializes a new instance of the <see cref="SqliteUserRepository" /> class.
/// </summary>
/// <param name="connection">The connection.</param>
/// <param name="jsonSerializer">The json serializer.</param>
/// <param name="logManager">The log manager.</param>
/// <param name="appPaths">The app paths.</param>
/// <exception cref="System.ArgumentNullException">appPaths</exception>
public SqliteUserRepository(IDbConnection connection, IJsonSerializer jsonSerializer, ILogManager logManager)
public SqliteUserRepository(IJsonSerializer jsonSerializer, ILogManager logManager, IServerApplicationPaths appPaths)
{
if (jsonSerializer == null)
{
throw new ArgumentNullException("jsonSerializer");
}
_connection = connection;
_jsonSerializer = jsonSerializer;
_appPaths = appPaths;
_logger = logManager.GetLogger(GetType().Name);
}
@ -63,8 +66,12 @@ namespace MediaBrowser.Server.Implementations.Persistence
/// Opens the connection to the database
/// </summary>
/// <returns>Task.</returns>
public void Initialize()
public async Task Initialize()
{
var dbFile = Path.Combine(_appPaths.DataPath, "users.db");
_connection = await SqliteExtensions.ConnectToDb(dbFile).ConfigureAwait(false);
string[] queries = {
"create table if not exists users (guid GUID primary key, data BLOB)",

@ -10,6 +10,8 @@
<RootNamespace>MediaBrowser.Server.Mono</RootNamespace>
<AssemblyName>MediaBrowser.Server.Mono</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<StartupObject>MediaBrowser.Server.Mono.MainClass</StartupObject>
<ApplicationIcon>..\MediaBrowser.ServerApplication\Resources\Images\Icon.ico</ApplicationIcon>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>true</DebugSymbols>
@ -43,6 +45,12 @@
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Data" />
<Reference Include="ServiceStack.Common">
<HintPath>..\packages\ServiceStack.Common.3.9.62\lib\net35\ServiceStack.Common.dll</HintPath>
</Reference>
<Reference Include="ServiceStack.Interfaces">
<HintPath>..\packages\ServiceStack.Common.3.9.62\lib\net35\ServiceStack.Interfaces.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="gtk-gui\gui.stetic">
@ -50,6 +58,9 @@
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Compile Include="..\SharedVersion.cs">
<Link>Properties\SharedVersion.cs</Link>
</Compile>
<Compile Include="gtk-gui\generated.cs" />
<Compile Include="MainWindow.cs" />
<Compile Include="gtk-gui\MainWindow.cs" />
@ -72,7 +83,6 @@
</Compile>
<Compile Include="Native\HttpMessageHandlerFactory.cs" />
<Compile Include="Native\Assemblies.cs" />
<Compile Include="Native\Sqlite.cs" />
<Compile Include="Native\NativeApp.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
@ -112,8 +122,10 @@
</ItemGroup>
<ItemGroup>
<Folder Include="EntryPoints\" />
<Folder Include="Implementations\" />
<Folder Include="Native\" />
<Folder Include="FFMpeg\" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
</ItemGroup>
</Project>

@ -1,4 +1,5 @@

using MediaBrowser.Server.Mono;
namespace MediaBrowser.ServerApplication.Native
{
/// <summary>
@ -11,7 +12,7 @@ namespace MediaBrowser.ServerApplication.Native
/// </summary>
public static void Shutdown()
{
MainClass.Shutdown ();
}
/// <summary>
@ -19,7 +20,7 @@ namespace MediaBrowser.ServerApplication.Native
/// </summary>
public static void Restart()
{
MainClass.Restart ();
}
}
}

@ -1,36 +0,0 @@
using System.Data;
using System.Data.SQLite;
using System.Threading.Tasks;
namespace MediaBrowser.ServerApplication.Native
{
/// <summary>
/// Class Sqlite
/// </summary>
public static class Sqlite
{
/// <summary>
/// Connects to db.
/// </summary>
/// <param name="dbPath">The db path.</param>
/// <returns>Task{IDbConnection}.</returns>
/// <exception cref="System.ArgumentNullException">dbPath</exception>
public static async Task<IDbConnection> OpenDatabase(string dbPath)
{
var connectionstr = new SQLiteConnectionStringBuilder
{
PageSize = 4096,
CacheSize = 4096,
SyncMode = SynchronizationModes.Normal,
DataSource = dbPath,
JournalMode = SQLiteJournalModeEnum.Wal
};
var connection = new SQLiteConnection(connectionstr.ConnectionString);
await connection.OpenAsync().ConfigureAwait(false);
return connection;
}
}
}

@ -1,16 +1,188 @@
using MediaBrowser.Common.Constants;
using MediaBrowser.Common.Implementations.Logging;
using MediaBrowser.Common.Implementations.Updates;
using MediaBrowser.Model.Logging;
using MediaBrowser.Server.Implementations;
using MediaBrowser.ServerApplication;
using Microsoft.Win32;
using System;
using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Windows;
using Gtk;
using System.Threading.Tasks;
namespace MediaBrowser.Server.Mono
{
class MainClass
public class MainClass
{
private static ApplicationHost _appHost;
private static Mutex _singleInstanceMutex;
private static ILogger _logger;
public static void Main (string[] args)
{
Application.Init ();
var appPaths = CreateApplicationPaths();
var logManager = new NlogManager(appPaths.LogDirectoryPath, "server");
logManager.ReloadLogger(LogSeverity.Info);
var logger = _logger = logManager.GetLogger("Main");
BeginLog(logger);
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
bool createdNew;
var runningPath = Process.GetCurrentProcess().MainModule.FileName.Replace(Path.DirectorySeparatorChar.ToString(), string.Empty);
_singleInstanceMutex = new Mutex(true, @"Local\" + runningPath, out createdNew);
if (!createdNew)
{
_singleInstanceMutex = null;
logger.Info("Shutting down because another instance of Media Browser Server is already running.");
return;
}
if (PerformUpdateIfNeeded(appPaths, logger))
{
logger.Info("Exiting to perform application update.");
return;
}
try
{
RunApplication(appPaths, logManager);
}
finally
{
logger.Info("Shutting down");
ReleaseMutex(logger);
_appHost.Dispose();
}
}
private static ServerApplicationPaths CreateApplicationPaths()
{
return new ServerApplicationPaths("D:\\MonoTest");
}
private static void RunApplication(ServerApplicationPaths appPaths, ILogManager logManager)
{
// TODO: Show splash here
SystemEvents.SessionEnding += SystemEvents_SessionEnding;
_appHost = new ApplicationHost(appPaths, logManager);
var task = _appHost.Init();
Task.WaitAll (task);
task = _appHost.RunStartupTasks();
Task.WaitAll (task);
// TODO: Hide splash here
MainWindow win = new MainWindow ();
win.Show ();
Application.Run ();
}
/// <summary>
/// Handles the SessionEnding event of the SystemEvents control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="SessionEndingEventArgs"/> instance containing the event data.</param>
static void SystemEvents_SessionEnding(object sender, SessionEndingEventArgs e)
{
if (e.Reason == SessionEndReasons.SystemShutdown)
{
Shutdown();
}
}
/// <summary>
/// Begins the log.
/// </summary>
/// <param name="logger">The logger.</param>
private static void BeginLog(ILogger logger)
{
logger.Info("Media Browser Server started");
logger.Info("Command line: {0}", string.Join(" ", Environment.GetCommandLineArgs()));
logger.Info("Server: {0}", Environment.MachineName);
logger.Info("Operating system: {0}", Environment.OSVersion.ToString());
}
/// <summary>
/// Handles the UnhandledException event of the CurrentDomain control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="UnhandledExceptionEventArgs"/> instance containing the event data.</param>
static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
var exception = (Exception)e.ExceptionObject;
_logger.ErrorException("UnhandledException", exception);
if (!Debugger.IsAttached)
{
Environment.Exit(System.Runtime.InteropServices.Marshal.GetHRForException(exception));
}
}
/// <summary>
/// Releases the mutex.
/// </summary>
internal static void ReleaseMutex(ILogger logger)
{
if (_singleInstanceMutex == null)
{
return;
}
logger.Debug("Releasing mutex");
_singleInstanceMutex.ReleaseMutex();
_singleInstanceMutex.Close();
_singleInstanceMutex.Dispose();
_singleInstanceMutex = null;
}
/// <summary>
/// Performs the update if needed.
/// </summary>
/// <param name="appPaths">The app paths.</param>
/// <param name="logger">The logger.</param>
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
private static bool PerformUpdateIfNeeded(ServerApplicationPaths appPaths, ILogger logger)
{
return false;
}
public static void Shutdown()
{
Application.Quit ();
}
public static void Restart()
{
// Second instance will start first, so release the mutex and dispose the http server ahead of time
ReleaseMutex (_logger);
_appHost.Dispose();
Application.Quit ();
}
}
}

@ -10,13 +10,4 @@ using System.Runtime.CompilerServices;
[assembly: AssemblyProduct ("")]
[assembly: AssemblyCopyright ("Luke")]
[assembly: AssemblyTrademark ("")]
[assembly: AssemblyCulture ("")]
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
[assembly: AssemblyVersion ("1.0.*")]
// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]
[assembly: AssemblyCulture ("")]

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog" />
</configSections>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets async="true"></targets>
</nlog>
<appSettings>
<add key="DebugProgramDataPath" value="..\..\..\..\ProgramData-Server" />
<add key="ReleaseProgramDataPath" value="%ApplicationData%" />
<add key="ProgramDataFolderName" value="MediaBrowser-Server" />
</appSettings>
</configuration>

@ -55,8 +55,6 @@ namespace MediaBrowser.ServerApplication
public void OnUnhandledException(Exception ex)
{
_logger.ErrorException("UnhandledException", ex);
MessageBox.Show("Unhandled exception: " + ex.Message);
}

@ -53,7 +53,6 @@ using MediaBrowser.ServerApplication.Native;
using MediaBrowser.WebDashboard.Api;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Net.Http;
@ -157,7 +156,7 @@ namespace MediaBrowser.ServerApplication
private ISessionManager SessionManager { get; set; }
private ILiveTvManager LiveTvManager { get; set; }
private ILocalizationManager LocalizationManager { get; set; }
/// <summary>
@ -329,13 +328,9 @@ namespace MediaBrowser.ServerApplication
private async Task<IUserRepository> GetUserRepository()
{
var dbFile = Path.Combine(ApplicationPaths.DataPath, "users.db");
var connection = await ConnectToDb(dbFile).ConfigureAwait(false);
var repo = new SqliteUserRepository(JsonSerializer, LogManager, ApplicationPaths);
var repo = new SqliteUserRepository(connection, JsonSerializer, LogManager);
repo.Initialize();
await repo.Initialize().ConfigureAwait(false);
return repo;
}
@ -346,13 +341,9 @@ namespace MediaBrowser.ServerApplication
/// <returns>Task.</returns>
private async Task ConfigureNotificationsRepository()
{
var dbFile = Path.Combine(ApplicationPaths.DataPath, "notifications.db");
var connection = await ConnectToDb(dbFile).ConfigureAwait(false);
var repo = new SqliteNotificationsRepository(LogManager, ApplicationPaths);
var repo = new SqliteNotificationsRepository(connection, LogManager);
repo.Initialize();
await repo.Initialize().ConfigureAwait(false);
NotificationsRepository = repo;
@ -388,22 +379,6 @@ namespace MediaBrowser.ServerApplication
return UserDataRepository.Initialize();
}
/// <summary>
/// Connects to db.
/// </summary>
/// <param name="dbPath">The db path.</param>
/// <returns>Task{IDbConnection}.</returns>
/// <exception cref="System.ArgumentNullException">dbPath</exception>
private static Task<IDbConnection> ConnectToDb(string dbPath)
{
if (string.IsNullOrEmpty(dbPath))
{
throw new ArgumentNullException("dbPath");
}
return Sqlite.OpenDatabase(dbPath);
}
/// <summary>
/// Dirty hacks
/// </summary>
@ -550,7 +525,7 @@ namespace MediaBrowser.ServerApplication
.Select(LoadAssembly)
.Where(a => a != null)
.ToList();
// Gets all plugin assemblies by first reading all bytes of the .dll and calling Assembly.Load against that
// This will prevent the .dll file from getting locked, and allow us to replace it when needed

@ -314,6 +314,8 @@ namespace MediaBrowser.ServerApplication
{
var exception = (Exception)e.ExceptionObject;
_logger.ErrorException("UnhandledException", ex);
if (_backgroundService == null)
{
_app.OnUnhandledException(exception);

@ -167,14 +167,6 @@
<Reference Include="System" />
<Reference Include="System.Configuration.Install" />
<Reference Include="System.Data" />
<Reference Include="System.Data.SQLite, Version=1.0.88.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=x86">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\System.Data.SQLite.x86.1.0.88.0\lib\net45\System.Data.SQLite.dll</HintPath>
</Reference>
<Reference Include="System.Data.SQLite.Linq, Version=1.0.88.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\System.Data.SQLite.x86.1.0.88.0\lib\net45\System.Data.SQLite.Linq.dll</HintPath>
</Reference>
<Reference Include="System.Drawing" />
<Reference Include="System.Net" />
<Reference Include="System.Net.Http" />
@ -212,7 +204,6 @@
<Compile Include="BackgroundServiceInstaller.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Native\Sqlite.cs" />
<Compile Include="Splash\SplashWindow.xaml.cs">
<DependentUpon>SplashWindow.xaml</DependentUpon>
</Compile>

@ -1,36 +0,0 @@
using System.Data;
using System.Data.SQLite;
using System.Threading.Tasks;
namespace MediaBrowser.ServerApplication.Native
{
/// <summary>
/// Class Sqlite
/// </summary>
public static class Sqlite
{
/// <summary>
/// Connects to db.
/// </summary>
/// <param name="dbPath">The db path.</param>
/// <returns>Task{IDbConnection}.</returns>
/// <exception cref="System.ArgumentNullException">dbPath</exception>
public static async Task<IDbConnection> OpenDatabase(string dbPath)
{
var connectionstr = new SQLiteConnectionStringBuilder
{
PageSize = 4096,
CacheSize = 4096,
SyncMode = SynchronizationModes.Normal,
DataSource = dbPath,
JournalMode = SQLiteJournalModeEnum.Wal
};
var connection = new SQLiteConnection(connectionstr.ConnectionString);
await connection.OpenAsync().ConfigureAwait(false);
return connection;
}
}
}

@ -10,5 +10,4 @@
<package id="ServiceStack.Redis" version="3.9.44" targetFramework="net45" />
<package id="ServiceStack.Text" version="3.9.62" targetFramework="net45" />
<package id="SimpleInjector" version="2.3.5" targetFramework="net45" />
<package id="System.Data.SQLite.x86" version="1.0.88.0" targetFramework="net45" />
</packages>
Loading…
Cancel
Save