From b6b735f0d1096e16ba2b7de8dd92c42bd09e6262 Mon Sep 17 00:00:00 2001 From: Luke Date: Sat, 19 Nov 2016 13:20:26 -0500 Subject: [PATCH 1/4] update mac project --- MediaBrowser.Server.Mac/MacAppHost.cs | 3 ++- MediaBrowser.Server.Mac/Main.cs | 3 ++- MediaBrowser.Server.Mac/MenuBarIcon.cs | 2 +- MediaBrowser.Server.Mac/Native/MonoFileSystem.cs | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/MediaBrowser.Server.Mac/MacAppHost.cs b/MediaBrowser.Server.Mac/MacAppHost.cs index 054913d4d..342829c10 100644 --- a/MediaBrowser.Server.Mac/MacAppHost.cs +++ b/MediaBrowser.Server.Mac/MacAppHost.cs @@ -3,7 +3,8 @@ using System.Collections.Generic; using System.Reflection; using Emby.Server.Core; using Emby.Server.Core.Data; -using Emby.Server.Core.FFMpeg; +using Emby.Server.Implementations; +using Emby.Server.Implementations.FFMpeg; using MediaBrowser.Model.IO; using MediaBrowser.Model.Logging; using MediaBrowser.Model.System; diff --git a/MediaBrowser.Server.Mac/Main.cs b/MediaBrowser.Server.Mac/Main.cs index fa9f8ae1f..cda6f459a 100644 --- a/MediaBrowser.Server.Mac/Main.cs +++ b/MediaBrowser.Server.Mac/Main.cs @@ -20,6 +20,7 @@ using MonoMac.AppKit; using MonoMac.Foundation; using MonoMac.ObjCRuntime; using Emby.Server.Core; +using Emby.Server.Implementations; using Emby.Common.Implementations.Logging; using Emby.Common.Implementations.EnvironmentInfo; using Emby.Server.Mac.Native; @@ -43,7 +44,7 @@ namespace MediaBrowser.Server.Mac var applicationPath = Assembly.GetEntryAssembly().Location; - var options = new StartupOptions(); + var options = new StartupOptions(Environment.GetCommandLineArgs()); // Allow this to be specified on the command line. var customProgramDataPath = options.GetOption("-programdata"); diff --git a/MediaBrowser.Server.Mac/MenuBarIcon.cs b/MediaBrowser.Server.Mac/MenuBarIcon.cs index 646b5ff69..1b335ce46 100644 --- a/MediaBrowser.Server.Mac/MenuBarIcon.cs +++ b/MediaBrowser.Server.Mac/MenuBarIcon.cs @@ -4,7 +4,7 @@ using MediaBrowser.Model.Logging; using System; using MonoMac.Foundation; using MonoMac.AppKit; -using Emby.Server.Core.Browser; +using Emby.Server.Implementations.Browser; namespace MediaBrowser.Server.Mac { diff --git a/MediaBrowser.Server.Mac/Native/MonoFileSystem.cs b/MediaBrowser.Server.Mac/Native/MonoFileSystem.cs index e71345723..3fb07b8d8 100644 --- a/MediaBrowser.Server.Mac/Native/MonoFileSystem.cs +++ b/MediaBrowser.Server.Mac/Native/MonoFileSystem.cs @@ -6,7 +6,7 @@ namespace Emby.Server.Mac.Native { public class MonoFileSystem : ManagedFileSystem { - public MonoFileSystem(ILogger logger, bool supportsAsyncFileStreams, bool enableManagedInvalidFileNameChars) : base(logger, supportsAsyncFileStreams, enableManagedInvalidFileNameChars, false) + public MonoFileSystem(ILogger logger, bool supportsAsyncFileStreams, bool enableManagedInvalidFileNameChars) : base(logger, supportsAsyncFileStreams, enableManagedInvalidFileNameChars, true) { } From eef52bc70fb2458a15f720a5199cf64d3730a33a Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 19 Nov 2016 13:22:48 -0500 Subject: [PATCH 2/4] update mac project --- MediaBrowser.Server.Mac/Emby.Server.Mac.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MediaBrowser.Server.Mac/Emby.Server.Mac.csproj b/MediaBrowser.Server.Mac/Emby.Server.Mac.csproj index f49716ead..f80513c51 100644 --- a/MediaBrowser.Server.Mac/Emby.Server.Mac.csproj +++ b/MediaBrowser.Server.Mac/Emby.Server.Mac.csproj @@ -108,11 +108,11 @@ True - ..\packages\SQLitePCLRaw.core.1.1.0\lib\net45\SQLitePCLRaw.core.dll + ..\packages\SQLitePCLRaw.core.1.1.1-pre20161109081005\lib\net45\SQLitePCLRaw.core.dll True - ..\packages\SQLitePCLRaw.provider.sqlite3.net45.1.1.0\lib\net45\SQLitePCLRaw.provider.sqlite3.dll + ..\packages\SQLitePCLRaw.provider.sqlite3.net45.1.1.1-pre20161109081005\lib\net45\SQLitePCLRaw.provider.sqlite3.dll True From 9d1b4e1074a530a6ba8652f9940a4d30f66a0dd1 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 19 Nov 2016 15:10:59 -0500 Subject: [PATCH 3/4] update userdata repository --- .../Data/SqliteUserDataRepository.cs | 777 ++++++++---------- 1 file changed, 331 insertions(+), 446 deletions(-) diff --git a/Emby.Server.Implementations/Data/SqliteUserDataRepository.cs b/Emby.Server.Implementations/Data/SqliteUserDataRepository.cs index d1355ce8f..4c73b6c6a 100644 --- a/Emby.Server.Implementations/Data/SqliteUserDataRepository.cs +++ b/Emby.Server.Implementations/Data/SqliteUserDataRepository.cs @@ -1,446 +1,331 @@ -//using System; -//using System.Collections.Generic; -//using System.Globalization; -//using System.IO; -//using System.Text; -//using System.Threading; -//using System.Threading.Tasks; -//using MediaBrowser.Common.Configuration; -//using MediaBrowser.Controller.Entities; -//using MediaBrowser.Controller.Persistence; -//using MediaBrowser.Model.Logging; -//using SQLitePCL.pretty; - -//namespace Emby.Server.Implementations.Data -//{ -// public class SqliteUserDataRepository : BaseSqliteRepository, IUserDataRepository -// { -// private SQLiteDatabaseConnection _connection; - -// public SqliteUserDataRepository(ILogger logger, IApplicationPaths appPaths) -// : base(logger) -// { -// DbFilePath = Path.Combine(appPaths.DataPath, "userdata_v2.db"); -// } - -// protected override bool EnableConnectionPooling -// { -// get { return false; } -// } - -// /// -// /// Gets the name of the repository -// /// -// /// The name. -// public string Name -// { -// get -// { -// return "SQLite"; -// } -// } - -// /// -// /// Opens the connection to the database -// /// -// /// Task. -// public void Initialize(SQLiteDatabaseConnection connection, ReaderWriterLockSlim writeLock) -// { -// WriteLock.Dispose(); -// WriteLock = writeLock; -// _connection = connection; - -// string[] queries = { - -// "create table if not exists UserDataDb.userdata (key nvarchar, userId GUID, rating float null, played bit, playCount int, isFavorite bit, playbackPositionTicks bigint, lastPlayedDate datetime null)", - -// "drop index if exists UserDataDb.idx_userdata", -// "drop index if exists UserDataDb.idx_userdata1", -// "drop index if exists UserDataDb.idx_userdata2", -// "drop index if exists UserDataDb.userdataindex1", - -// "create unique index if not exists UserDataDb.userdataindex on userdata (key, userId)", -// "create index if not exists UserDataDb.userdataindex2 on userdata (key, userId, played)", -// "create index if not exists UserDataDb.userdataindex3 on userdata (key, userId, playbackPositionTicks)", -// "create index if not exists UserDataDb.userdataindex4 on userdata (key, userId, isFavorite)", - -// //pragmas -// "pragma temp_store = memory", - -// "pragma shrink_memory" -// }; - -// _connection.RunQueries(queries); - -// connection.RunInTransaction(db => -// { -// var existingColumnNames = GetColumnNames(db, "userdata"); - -// AddColumn(db, "userdata", "AudioStreamIndex", "int", existingColumnNames); -// AddColumn(db, "userdata", "SubtitleStreamIndex", "int", existingColumnNames); -// }); -// } - -// /// -// /// Saves the user data. -// /// -// /// The user id. -// /// The key. -// /// The user data. -// /// The cancellation token. -// /// Task. -// /// userData -// /// or -// /// cancellationToken -// /// or -// /// userId -// /// or -// /// userDataId -// public Task SaveUserData(Guid userId, string key, UserItemData userData, CancellationToken cancellationToken) -// { -// if (userData == null) -// { -// throw new ArgumentNullException("userData"); -// } -// if (userId == Guid.Empty) -// { -// throw new ArgumentNullException("userId"); -// } -// if (string.IsNullOrEmpty(key)) -// { -// throw new ArgumentNullException("key"); -// } - -// return PersistUserData(userId, key, userData, cancellationToken); -// } - -// public Task SaveAllUserData(Guid userId, IEnumerable userData, CancellationToken cancellationToken) -// { -// if (userData == null) -// { -// throw new ArgumentNullException("userData"); -// } -// if (userId == Guid.Empty) -// { -// throw new ArgumentNullException("userId"); -// } - -// return PersistAllUserData(userId, userData, cancellationToken); -// } - -// /// -// /// Persists the user data. -// /// -// /// The user id. -// /// The key. -// /// The user data. -// /// The cancellation token. -// /// Task. -// public async Task PersistUserData(Guid userId, string key, UserItemData userData, CancellationToken cancellationToken) -// { -// cancellationToken.ThrowIfCancellationRequested(); - -// await WriteLock.WaitAsync(cancellationToken).ConfigureAwait(false); - -// IDbTransaction transaction = null; - -// try -// { -// transaction = _connection.BeginTransaction(); - -// using (var cmd = _connection.CreateCommand()) -// { -// cmd.CommandText = "replace into userdata (key, userId, rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex) values (@key, @userId, @rating,@played,@playCount,@isFavorite,@playbackPositionTicks,@lastPlayedDate,@AudioStreamIndex,@SubtitleStreamIndex)"; - -// cmd.Parameters.Add(cmd, "@key", DbType.String).Value = key; -// cmd.Parameters.Add(cmd, "@userId", DbType.Guid).Value = userId; -// cmd.Parameters.Add(cmd, "@rating", DbType.Double).Value = userData.Rating; -// cmd.Parameters.Add(cmd, "@played", DbType.Boolean).Value = userData.Played; -// cmd.Parameters.Add(cmd, "@playCount", DbType.Int32).Value = userData.PlayCount; -// cmd.Parameters.Add(cmd, "@isFavorite", DbType.Boolean).Value = userData.IsFavorite; -// cmd.Parameters.Add(cmd, "@playbackPositionTicks", DbType.Int64).Value = userData.PlaybackPositionTicks; -// cmd.Parameters.Add(cmd, "@lastPlayedDate", DbType.DateTime).Value = userData.LastPlayedDate; -// cmd.Parameters.Add(cmd, "@AudioStreamIndex", DbType.Int32).Value = userData.AudioStreamIndex; -// cmd.Parameters.Add(cmd, "@SubtitleStreamIndex", DbType.Int32).Value = userData.SubtitleStreamIndex; - -// cmd.Transaction = transaction; - -// cmd.ExecuteNonQuery(); -// } - -// transaction.Commit(); -// } -// catch (OperationCanceledException) -// { -// if (transaction != null) -// { -// transaction.Rollback(); -// } - -// throw; -// } -// catch (Exception e) -// { -// Logger.ErrorException("Failed to save user data:", e); - -// if (transaction != null) -// { -// transaction.Rollback(); -// } - -// throw; -// } -// finally -// { -// if (transaction != null) -// { -// transaction.Dispose(); -// } - -// WriteLock.Release(); -// } -// } - -// /// -// /// Persist all user data for the specified user -// /// -// /// -// /// -// /// -// /// -// private async Task PersistAllUserData(Guid userId, IEnumerable userData, CancellationToken cancellationToken) -// { -// cancellationToken.ThrowIfCancellationRequested(); - -// await WriteLock.WaitAsync(cancellationToken).ConfigureAwait(false); - -// IDbTransaction transaction = null; - -// try -// { -// transaction = _connection.BeginTransaction(); - -// foreach (var userItemData in userData) -// { -// using (var cmd = _connection.CreateCommand()) -// { -// cmd.CommandText = "replace into userdata (key, userId, rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex) values (@key, @userId, @rating,@played,@playCount,@isFavorite,@playbackPositionTicks,@lastPlayedDate,@AudioStreamIndex,@SubtitleStreamIndex)"; - -// cmd.Parameters.Add(cmd, "@key", DbType.String).Value = userItemData.Key; -// cmd.Parameters.Add(cmd, "@userId", DbType.Guid).Value = userId; -// cmd.Parameters.Add(cmd, "@rating", DbType.Double).Value = userItemData.Rating; -// cmd.Parameters.Add(cmd, "@played", DbType.Boolean).Value = userItemData.Played; -// cmd.Parameters.Add(cmd, "@playCount", DbType.Int32).Value = userItemData.PlayCount; -// cmd.Parameters.Add(cmd, "@isFavorite", DbType.Boolean).Value = userItemData.IsFavorite; -// cmd.Parameters.Add(cmd, "@playbackPositionTicks", DbType.Int64).Value = userItemData.PlaybackPositionTicks; -// cmd.Parameters.Add(cmd, "@lastPlayedDate", DbType.DateTime).Value = userItemData.LastPlayedDate; -// cmd.Parameters.Add(cmd, "@AudioStreamIndex", DbType.Int32).Value = userItemData.AudioStreamIndex; -// cmd.Parameters.Add(cmd, "@SubtitleStreamIndex", DbType.Int32).Value = userItemData.SubtitleStreamIndex; - -// cmd.Transaction = transaction; - -// cmd.ExecuteNonQuery(); -// } - -// cancellationToken.ThrowIfCancellationRequested(); -// } - -// transaction.Commit(); -// } -// catch (OperationCanceledException) -// { -// if (transaction != null) -// { -// transaction.Rollback(); -// } - -// throw; -// } -// catch (Exception e) -// { -// Logger.ErrorException("Failed to save user data:", e); - -// if (transaction != null) -// { -// transaction.Rollback(); -// } - -// throw; -// } -// finally -// { -// if (transaction != null) -// { -// transaction.Dispose(); -// } - -// WriteLock.Release(); -// } -// } - -// /// -// /// Gets the user data. -// /// -// /// The user id. -// /// The key. -// /// Task{UserItemData}. -// /// -// /// userId -// /// or -// /// key -// /// -// public UserItemData GetUserData(Guid userId, string key) -// { -// if (userId == Guid.Empty) -// { -// throw new ArgumentNullException("userId"); -// } -// if (string.IsNullOrEmpty(key)) -// { -// throw new ArgumentNullException("key"); -// } - -// using (var cmd = _connection.CreateCommand()) -// { -// cmd.CommandText = "select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where key = @key and userId=@userId"; - -// cmd.Parameters.Add(cmd, "@key", DbType.String).Value = key; -// cmd.Parameters.Add(cmd, "@userId", DbType.Guid).Value = userId; - -// using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult | CommandBehavior.SingleRow)) -// { -// if (reader.Read()) -// { -// return ReadRow(reader); -// } -// } - -// return null; -// } -// } - -// public UserItemData GetUserData(Guid userId, List keys) -// { -// if (userId == Guid.Empty) -// { -// throw new ArgumentNullException("userId"); -// } -// if (keys == null) -// { -// throw new ArgumentNullException("keys"); -// } - -// using (var cmd = _connection.CreateCommand()) -// { -// var index = 0; -// var userdataKeys = new List(); -// var builder = new StringBuilder(); -// foreach (var key in keys) -// { -// var paramName = "@Key" + index; -// userdataKeys.Add("Key =" + paramName); -// cmd.Parameters.Add(cmd, paramName, DbType.String).Value = key; -// builder.Append(" WHEN Key=" + paramName + " THEN " + index); -// index++; -// break; -// } - -// var keyText = string.Join(" OR ", userdataKeys.ToArray()); - -// cmd.CommandText = "select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where userId=@userId AND (" + keyText + ") "; - -// cmd.CommandText += " ORDER BY (Case " + builder + " Else " + keys.Count.ToString(CultureInfo.InvariantCulture) + " End )"; -// cmd.CommandText += " LIMIT 1"; - -// cmd.Parameters.Add(cmd, "@userId", DbType.Guid).Value = userId; - -// using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult | CommandBehavior.SingleRow)) -// { -// if (reader.Read()) -// { -// return ReadRow(reader); -// } -// } - -// return null; -// } -// } - -// /// -// /// Return all user-data associated with the given user -// /// -// /// -// /// -// public IEnumerable GetAllUserData(Guid userId) -// { -// if (userId == Guid.Empty) -// { -// throw new ArgumentNullException("userId"); -// } - -// using (var cmd = _connection.CreateCommand()) -// { -// cmd.CommandText = "select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where userId=@userId"; - -// cmd.Parameters.Add(cmd, "@userId", DbType.Guid).Value = userId; - -// using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult)) -// { -// while (reader.Read()) -// { -// yield return ReadRow(reader); -// } -// } -// } -// } - -// /// -// /// Read a row from the specified reader into the provided userData object -// /// -// /// -// private UserItemData ReadRow(IDataReader reader) -// { -// var userData = new UserItemData(); - -// userData.Key = reader.GetString(0); -// userData.UserId = reader.GetGuid(1); - -// if (!reader.IsDBNull(2)) -// { -// userData.Rating = reader.GetDouble(2); -// } - -// userData.Played = reader.GetBoolean(3); -// userData.PlayCount = reader.GetInt32(4); -// userData.IsFavorite = reader.GetBoolean(5); -// userData.PlaybackPositionTicks = reader.GetInt64(6); - -// if (!reader.IsDBNull(7)) -// { -// userData.LastPlayedDate = reader.GetDateTime(7).ToUniversalTime(); -// } - -// if (!reader.IsDBNull(8)) -// { -// userData.AudioStreamIndex = reader.GetInt32(8); -// } - -// if (!reader.IsDBNull(9)) -// { -// userData.SubtitleStreamIndex = reader.GetInt32(9); -// } - -// return userData; -// } - -// protected override void Dispose(bool dispose) -// { -// // handled by library database -// } - -// protected override void CloseConnection() -// { -// // handled by library database -// } -// } -//} \ No newline at end of file +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using MediaBrowser.Common.Configuration; +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Persistence; +using MediaBrowser.Model.Logging; +using SQLitePCL.pretty; + +namespace Emby.Server.Implementations.Data +{ + public class SqliteUserDataRepository : BaseSqliteRepository, IUserDataRepository + { + private SQLiteDatabaseConnection _connection; + + public SqliteUserDataRepository(ILogger logger, IApplicationPaths appPaths) + : base(logger) + { + DbFilePath = Path.Combine(appPaths.DataPath, "userdata_v2.db"); + } + + protected override bool EnableConnectionPooling + { + get { return false; } + } + + /// + /// Gets the name of the repository + /// + /// The name. + public string Name + { + get + { + return "SQLite"; + } + } + + /// + /// Opens the connection to the database + /// + /// Task. + public void Initialize(SQLiteDatabaseConnection connection, ReaderWriterLockSlim writeLock) + { + WriteLock.Dispose(); + WriteLock = writeLock; + _connection = connection; + + string[] queries = { + + "create table if not exists UserDataDb.userdata (key nvarchar, userId GUID, rating float null, played bit, playCount int, isFavorite bit, playbackPositionTicks bigint, lastPlayedDate datetime null)", + + "drop index if exists UserDataDb.idx_userdata", + "drop index if exists UserDataDb.idx_userdata1", + "drop index if exists UserDataDb.idx_userdata2", + "drop index if exists UserDataDb.userdataindex1", + + "create unique index if not exists UserDataDb.userdataindex on userdata (key, userId)", + "create index if not exists UserDataDb.userdataindex2 on userdata (key, userId, played)", + "create index if not exists UserDataDb.userdataindex3 on userdata (key, userId, playbackPositionTicks)", + "create index if not exists UserDataDb.userdataindex4 on userdata (key, userId, isFavorite)", + + //pragmas + "pragma temp_store = memory", + + "pragma shrink_memory" + }; + + _connection.RunQueries(queries); + + connection.RunInTransaction(db => + { + var existingColumnNames = GetColumnNames(db, "userdata"); + + AddColumn(db, "userdata", "AudioStreamIndex", "int", existingColumnNames); + AddColumn(db, "userdata", "SubtitleStreamIndex", "int", existingColumnNames); + }); + } + + /// + /// Saves the user data. + /// + /// The user id. + /// The key. + /// The user data. + /// The cancellation token. + /// Task. + /// userData + /// or + /// cancellationToken + /// or + /// userId + /// or + /// userDataId + public Task SaveUserData(Guid userId, string key, UserItemData userData, CancellationToken cancellationToken) + { + if (userData == null) + { + throw new ArgumentNullException("userData"); + } + if (userId == Guid.Empty) + { + throw new ArgumentNullException("userId"); + } + if (string.IsNullOrEmpty(key)) + { + throw new ArgumentNullException("key"); + } + + return PersistUserData(userId, key, userData, cancellationToken); + } + + public Task SaveAllUserData(Guid userId, IEnumerable userData, CancellationToken cancellationToken) + { + if (userData == null) + { + throw new ArgumentNullException("userData"); + } + if (userId == Guid.Empty) + { + throw new ArgumentNullException("userId"); + } + + return PersistAllUserData(userId, userData.ToList(), cancellationToken); + } + + /// + /// Persists the user data. + /// + /// The user id. + /// The key. + /// The user data. + /// The cancellation token. + /// Task. + public async Task PersistUserData(Guid userId, string key, UserItemData userData, CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + + using (WriteLock.Write()) + { + _connection.RunInTransaction(db => + { + SaveUserData(db, userId, key, userData); + }); + } + } + + private void SaveUserData(IDatabaseConnection db, Guid userId, string key, UserItemData userData) + { + var paramList = new List(); + var commandText = "replace into userdata (key, userId, rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex) values (?, ?, ?,?,?,?,?,?,?,?)"; + + paramList.Add(key); + paramList.Add(userId.ToGuidParamValue()); + paramList.Add(userData.Rating); + paramList.Add(userData.Played); + paramList.Add(userData.PlayCount); + paramList.Add(userData.IsFavorite); + paramList.Add(userData.PlaybackPositionTicks); + + if (userData.LastPlayedDate.HasValue) + { + paramList.Add(userData.LastPlayedDate.Value.ToDateTimeParamValue()); + } + else + { + paramList.Add(null); + } + paramList.Add(userData.AudioStreamIndex); + paramList.Add(userData.SubtitleStreamIndex); + + db.Execute(commandText, paramList.ToArray()); + } + + /// + /// Persist all user data for the specified user + /// + private async Task PersistAllUserData(Guid userId, List userDataList, CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + + using (WriteLock.Write()) + { + _connection.RunInTransaction(db => + { + foreach (var userItemData in userDataList) + { + SaveUserData(db, userId, userItemData.Key, userItemData); + } + }); + } + } + + /// + /// Gets the user data. + /// + /// The user id. + /// The key. + /// Task{UserItemData}. + /// + /// userId + /// or + /// key + /// + public UserItemData GetUserData(Guid userId, string key) + { + if (userId == Guid.Empty) + { + throw new ArgumentNullException("userId"); + } + if (string.IsNullOrEmpty(key)) + { + throw new ArgumentNullException("key"); + } + + var commandText = "select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where key = ? and userId=?"; + + var paramList = new List(); + paramList.Add(key); + paramList.Add(userId.ToGuidParamValue()); + + foreach (var row in _connection.Query(commandText, paramList.ToArray())) + { + return ReadRow(row); + } + + return null; + } + + public UserItemData GetUserData(Guid userId, List keys) + { + if (userId == Guid.Empty) + { + throw new ArgumentNullException("userId"); + } + if (keys == null) + { + throw new ArgumentNullException("keys"); + } + + if (keys.Count == 0) + { + return null; + } + + return GetUserData(userId, keys[0]); + } + + /// + /// Return all user-data associated with the given user + /// + /// + /// + public IEnumerable GetAllUserData(Guid userId) + { + if (userId == Guid.Empty) + { + throw new ArgumentNullException("userId"); + } + + var list = new List(); + + using (WriteLock.Read()) + { + var commandText = "select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where userId=?"; + + var paramList = new List(); + paramList.Add(userId.ToGuidParamValue()); + + foreach (var row in _connection.Query(commandText, paramList.ToArray())) + { + list.Add(ReadRow(row)); + } + } + + return list; + } + + /// + /// Read a row from the specified reader into the provided userData object + /// + /// + private UserItemData ReadRow(IReadOnlyList reader) + { + var userData = new UserItemData(); + + userData.Key = reader[0].ToString(); + userData.UserId = reader[1].ReadGuid(); + + if (reader[2].SQLiteType != SQLiteType.Null) + { + userData.Rating = reader[2].ToDouble(); + } + + userData.Played = reader[3].ToBool(); + userData.PlayCount = reader[4].ToInt(); + userData.IsFavorite = reader[5].ToBool(); + userData.PlaybackPositionTicks = reader[6].ToInt64(); + + if (reader[7].SQLiteType != SQLiteType.Null) + { + userData.LastPlayedDate = reader[7].ReadDateTime(); + } + + if (reader[8].SQLiteType != SQLiteType.Null) + { + userData.AudioStreamIndex = reader[8].ToInt(); + } + + if (reader[9].SQLiteType != SQLiteType.Null) + { + userData.SubtitleStreamIndex = reader[9].ToInt(); + } + + return userData; + } + + protected override void Dispose(bool dispose) + { + // handled by library database + } + + protected override void CloseConnection() + { + // handled by library database + } + } +} \ No newline at end of file From 2a0280d48dd4271f60e9d59be932d6ba0f38c62c Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 19 Nov 2016 16:07:01 -0500 Subject: [PATCH 4/4] add dll config file --- .../Data/SqliteExtensions.cs | 10 + .../Data/SqliteItemRepository.cs | 216 ++++--- .../Data/SqliteUserDataRepository.cs | 562 +++++++++--------- .../MediaBrowser.Server.Mono.csproj | 4 + .../SQLitePCLRaw.provider.sqlite3.dll.config | 3 + 5 files changed, 416 insertions(+), 379 deletions(-) create mode 100644 MediaBrowser.Server.Mono/SQLitePCLRaw.provider.sqlite3.dll.config diff --git a/Emby.Server.Implementations/Data/SqliteExtensions.cs b/Emby.Server.Implementations/Data/SqliteExtensions.cs index d9536ae9c..3dc3cec8e 100644 --- a/Emby.Server.Implementations/Data/SqliteExtensions.cs +++ b/Emby.Server.Implementations/Data/SqliteExtensions.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Globalization; using MediaBrowser.Model.IO; using MediaBrowser.Model.Serialization; @@ -127,5 +128,14 @@ namespace Emby.Server.Implementations.Data return stream.ToArray(); } } + + public static void Attach(IDatabaseConnection db, string path, string alias) + { + var commandText = string.Format("attach ? as {0};", alias); + var paramList = new List(); + paramList.Add(path); + + db.Execute(commandText, paramList.ToArray()); + } } } diff --git a/Emby.Server.Implementations/Data/SqliteItemRepository.cs b/Emby.Server.Implementations/Data/SqliteItemRepository.cs index c88bffe04..32cfecfce 100644 --- a/Emby.Server.Implementations/Data/SqliteItemRepository.cs +++ b/Emby.Server.Implementations/Data/SqliteItemRepository.cs @@ -139,7 +139,7 @@ // /// Task. // public async Task Initialize(SqliteUserDataRepository userDataRepo) // { -// _connection = await CreateConnection(false).ConfigureAwait(false); +// _connection = CreateConnection(false); // var createMediaStreamsTableCommand // = "create table if not exists mediastreams (ItemId GUID, StreamIndex INT, StreamType TEXT, Codec TEXT, Language TEXT, ChannelLayout TEXT, Profile TEXT, AspectRatio TEXT, Path TEXT, IsInterlaced BIT, BitRate INT NULL, Channels INT NULL, SampleRate INT NULL, IsDefault BIT, IsForced BIT, IsExternal BIT, Height INT NULL, Width INT NULL, AverageFrameRate FLOAT NULL, RealFrameRate FLOAT NULL, Level FLOAT NULL, PixelFormat TEXT, BitDepth INT NULL, IsAnamorphic BIT NULL, RefFrames INT NULL, CodecTag TEXT NULL, Comment TEXT NULL, NalLengthSize TEXT NULL, IsAvc BIT NULL, Title TEXT NULL, TimeBase TEXT NULL, CodecTimeBase TEXT NULL, PRIMARY KEY (ItemId, StreamIndex))"; @@ -168,109 +168,131 @@ // }; -// _connection.RunQueries(queries, Logger); +// _connection.RunQueries(queries); -// _connection.AddColumn(Logger, "AncestorIds", "AncestorIdText", "Text"); +// _connection.RunInTransaction(db => +// { +// var existingColumnNames = GetColumnNames(db, "AncestorIds"); +// AddColumn(db, "AncestorIds", "AncestorIdText", "Text", existingColumnNames); -// _connection.AddColumn(Logger, "TypedBaseItems", "Path", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "StartDate", "DATETIME"); -// _connection.AddColumn(Logger, "TypedBaseItems", "EndDate", "DATETIME"); -// _connection.AddColumn(Logger, "TypedBaseItems", "ChannelId", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "IsMovie", "BIT"); -// _connection.AddColumn(Logger, "TypedBaseItems", "IsSports", "BIT"); -// _connection.AddColumn(Logger, "TypedBaseItems", "IsKids", "BIT"); -// _connection.AddColumn(Logger, "TypedBaseItems", "CommunityRating", "Float"); -// _connection.AddColumn(Logger, "TypedBaseItems", "CustomRating", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "IndexNumber", "INT"); -// _connection.AddColumn(Logger, "TypedBaseItems", "IsLocked", "BIT"); -// _connection.AddColumn(Logger, "TypedBaseItems", "Name", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "OfficialRating", "Text"); +// existingColumnNames = GetColumnNames(db, "TypedBaseItems"); -// _connection.AddColumn(Logger, "TypedBaseItems", "MediaType", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "Overview", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "ParentIndexNumber", "INT"); -// _connection.AddColumn(Logger, "TypedBaseItems", "PremiereDate", "DATETIME"); -// _connection.AddColumn(Logger, "TypedBaseItems", "ProductionYear", "INT"); -// _connection.AddColumn(Logger, "TypedBaseItems", "ParentId", "GUID"); -// _connection.AddColumn(Logger, "TypedBaseItems", "Genres", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "SchemaVersion", "INT"); -// _connection.AddColumn(Logger, "TypedBaseItems", "SortName", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "RunTimeTicks", "BIGINT"); +// AddColumn(db, "TypedBaseItems", "Path", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "StartDate", "DATETIME", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "EndDate", "DATETIME", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "ChannelId", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "IsMovie", "BIT", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "IsSports", "BIT", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "IsKids", "BIT", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "CommunityRating", "Float", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "CustomRating", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "IndexNumber", "INT", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "IsLocked", "BIT", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "Name", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "OfficialRating", "Text", existingColumnNames); -// _connection.AddColumn(Logger, "TypedBaseItems", "OfficialRatingDescription", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "HomePageUrl", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "VoteCount", "INT"); -// _connection.AddColumn(Logger, "TypedBaseItems", "DisplayMediaType", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "DateCreated", "DATETIME"); -// _connection.AddColumn(Logger, "TypedBaseItems", "DateModified", "DATETIME"); +// AddColumn(db, "TypedBaseItems", "MediaType", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "Overview", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "ParentIndexNumber", "INT", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "PremiereDate", "DATETIME", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "ProductionYear", "INT", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "ParentId", "GUID", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "Genres", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "SchemaVersion", "INT", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "SortName", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "RunTimeTicks", "BIGINT", existingColumnNames); -// _connection.AddColumn(Logger, "TypedBaseItems", "ForcedSortName", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "IsOffline", "BIT"); -// _connection.AddColumn(Logger, "TypedBaseItems", "LocationType", "Text"); +// AddColumn(db, "TypedBaseItems", "OfficialRatingDescription", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "HomePageUrl", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "VoteCount", "INT", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "DisplayMediaType", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "DateCreated", "DATETIME", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "DateModified", "DATETIME", existingColumnNames); -// _connection.AddColumn(Logger, "TypedBaseItems", "IsSeries", "BIT"); -// _connection.AddColumn(Logger, "TypedBaseItems", "IsLive", "BIT"); -// _connection.AddColumn(Logger, "TypedBaseItems", "IsNews", "BIT"); -// _connection.AddColumn(Logger, "TypedBaseItems", "IsPremiere", "BIT"); +// AddColumn(db, "TypedBaseItems", "ForcedSortName", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "IsOffline", "BIT", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "LocationType", "Text", existingColumnNames); -// _connection.AddColumn(Logger, "TypedBaseItems", "EpisodeTitle", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "IsRepeat", "BIT"); +// AddColumn(db, "TypedBaseItems", "IsSeries", "BIT", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "IsLive", "BIT", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "IsNews", "BIT", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "IsPremiere", "BIT", existingColumnNames); -// _connection.AddColumn(Logger, "TypedBaseItems", "PreferredMetadataLanguage", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "PreferredMetadataCountryCode", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "IsHD", "BIT"); -// _connection.AddColumn(Logger, "TypedBaseItems", "ExternalEtag", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "DateLastRefreshed", "DATETIME"); +// AddColumn(db, "TypedBaseItems", "EpisodeTitle", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "IsRepeat", "BIT", existingColumnNames); -// _connection.AddColumn(Logger, "TypedBaseItems", "DateLastSaved", "DATETIME"); -// _connection.AddColumn(Logger, "TypedBaseItems", "IsInMixedFolder", "BIT"); -// _connection.AddColumn(Logger, "TypedBaseItems", "LockedFields", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "Studios", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "Audio", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "ExternalServiceId", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "Tags", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "IsFolder", "BIT"); -// _connection.AddColumn(Logger, "TypedBaseItems", "InheritedParentalRatingValue", "INT"); -// _connection.AddColumn(Logger, "TypedBaseItems", "UnratedType", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "TopParentId", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "IsItemByName", "BIT"); -// _connection.AddColumn(Logger, "TypedBaseItems", "SourceType", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "TrailerTypes", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "CriticRating", "Float"); -// _connection.AddColumn(Logger, "TypedBaseItems", "CriticRatingSummary", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "InheritedTags", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "CleanName", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "PresentationUniqueKey", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "SlugName", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "OriginalTitle", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "PrimaryVersionId", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "DateLastMediaAdded", "DATETIME"); -// _connection.AddColumn(Logger, "TypedBaseItems", "Album", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "IsVirtualItem", "BIT"); -// _connection.AddColumn(Logger, "TypedBaseItems", "SeriesName", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "UserDataKey", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "SeasonName", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "SeasonId", "GUID"); -// _connection.AddColumn(Logger, "TypedBaseItems", "SeriesId", "GUID"); -// _connection.AddColumn(Logger, "TypedBaseItems", "SeriesSortName", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "ExternalSeriesId", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "ShortOverview", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "Tagline", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "Keywords", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "ProviderIds", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "Images", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "ProductionLocations", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "ThemeSongIds", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "ThemeVideoIds", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "TotalBitrate", "INT"); -// _connection.AddColumn(Logger, "TypedBaseItems", "ExtraType", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "Artists", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "AlbumArtists", "Text"); -// _connection.AddColumn(Logger, "TypedBaseItems", "ExternalId", "Text"); +// AddColumn(db, "TypedBaseItems", "PreferredMetadataLanguage", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "PreferredMetadataCountryCode", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "IsHD", "BIT", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "ExternalEtag", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "DateLastRefreshed", "DATETIME", existingColumnNames); -// _connection.AddColumn(Logger, "ItemValues", "CleanValue", "Text"); +// AddColumn(db, "TypedBaseItems", "DateLastSaved", "DATETIME", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "IsInMixedFolder", "BIT", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "LockedFields", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "Studios", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "Audio", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "ExternalServiceId", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "Tags", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "IsFolder", "BIT", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "InheritedParentalRatingValue", "INT", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "UnratedType", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "TopParentId", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "IsItemByName", "BIT", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "SourceType", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "TrailerTypes", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "CriticRating", "Float", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "CriticRatingSummary", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "InheritedTags", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "CleanName", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "PresentationUniqueKey", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "SlugName", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "OriginalTitle", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "PrimaryVersionId", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "DateLastMediaAdded", "DATETIME", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "Album", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "IsVirtualItem", "BIT", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "SeriesName", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "UserDataKey", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "SeasonName", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "SeasonId", "GUID", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "SeriesId", "GUID", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "SeriesSortName", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "ExternalSeriesId", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "ShortOverview", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "Tagline", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "Keywords", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "ProviderIds", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "Images", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "ProductionLocations", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "ThemeSongIds", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "ThemeVideoIds", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "TotalBitrate", "INT", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "ExtraType", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "Artists", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "AlbumArtists", "Text", existingColumnNames); +// AddColumn(db, "TypedBaseItems", "ExternalId", "Text", existingColumnNames); -// _connection.AddColumn(Logger, ChaptersTableName, "ImageDateModified", "DATETIME"); +// existingColumnNames = GetColumnNames(db, "ItemValues"); +// AddColumn(db, "ItemValues", "CleanValue", "Text", existingColumnNames); + +// existingColumnNames = GetColumnNames(db, ChaptersTableName); +// AddColumn(db, ChaptersTableName, "ImageDateModified", "DATETIME", existingColumnNames); + +// existingColumnNames = GetColumnNames(db, "MediaStreams"); +// AddColumn(db, "MediaStreams", "IsAvc", "BIT", existingColumnNames); +// AddColumn(db, "MediaStreams", "TimeBase", "TEXT", existingColumnNames); +// AddColumn(db, "MediaStreams", "CodecTimeBase", "TEXT", existingColumnNames); +// AddColumn(db, "MediaStreams", "Title", "TEXT", existingColumnNames); +// AddColumn(db, "MediaStreams", "NalLengthSize", "TEXT", existingColumnNames); +// AddColumn(db, "MediaStreams", "Comment", "TEXT", existingColumnNames); +// AddColumn(db, "MediaStreams", "CodecTag", "TEXT", existingColumnNames); +// AddColumn(db, "MediaStreams", "PixelFormat", "TEXT", existingColumnNames); +// AddColumn(db, "MediaStreams", "BitDepth", "INT", existingColumnNames); +// AddColumn(db, "MediaStreams", "RefFrames", "INT", existingColumnNames); +// AddColumn(db, "MediaStreams", "KeyFrames", "TEXT", existingColumnNames); +// AddColumn(db, "MediaStreams", "IsAnamorphic", "BIT", existingColumnNames); +// }); // string[] postQueries = @@ -334,14 +356,12 @@ // "create index if not exists idx_ItemValues7 on ItemValues(Type,CleanValue,ItemId)" // }; -// _connection.RunQueries(postQueries, Logger); +// _connection.RunQueries(postQueries); // PrepareStatements(); -// new MediaStreamColumns(_connection, Logger).AddColumns(); - -// DataExtensions.Attach(_connection, Path.Combine(_config.ApplicationPaths.DataPath, "userdata_v2.db"), "UserDataDb"); -// await userDataRepo.Initialize(_connection, WriteLock).ConfigureAwait(false); +// SqliteExtensions.Attach(_connection, Path.Combine(_config.ApplicationPaths.DataPath, "userdata_v2.db"), "UserDataDb"); +// userDataRepo.Initialize(_connection, WriteLock); // //await Vacuum(_connection).ConfigureAwait(false); // } diff --git a/Emby.Server.Implementations/Data/SqliteUserDataRepository.cs b/Emby.Server.Implementations/Data/SqliteUserDataRepository.cs index 4c73b6c6a..5556c4502 100644 --- a/Emby.Server.Implementations/Data/SqliteUserDataRepository.cs +++ b/Emby.Server.Implementations/Data/SqliteUserDataRepository.cs @@ -1,331 +1,331 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using MediaBrowser.Common.Configuration; -using MediaBrowser.Controller.Entities; -using MediaBrowser.Controller.Persistence; -using MediaBrowser.Model.Logging; -using SQLitePCL.pretty; +//using System; +//using System.Collections.Generic; +//using System.IO; +//using System.Linq; +//using System.Threading; +//using System.Threading.Tasks; +//using MediaBrowser.Common.Configuration; +//using MediaBrowser.Controller.Entities; +//using MediaBrowser.Controller.Persistence; +//using MediaBrowser.Model.Logging; +//using SQLitePCL.pretty; -namespace Emby.Server.Implementations.Data -{ - public class SqliteUserDataRepository : BaseSqliteRepository, IUserDataRepository - { - private SQLiteDatabaseConnection _connection; +//namespace Emby.Server.Implementations.Data +//{ +// public class SqliteUserDataRepository : BaseSqliteRepository, IUserDataRepository +// { +// private SQLiteDatabaseConnection _connection; - public SqliteUserDataRepository(ILogger logger, IApplicationPaths appPaths) - : base(logger) - { - DbFilePath = Path.Combine(appPaths.DataPath, "userdata_v2.db"); - } +// public SqliteUserDataRepository(ILogger logger, IApplicationPaths appPaths) +// : base(logger) +// { +// DbFilePath = Path.Combine(appPaths.DataPath, "userdata_v2.db"); +// } - protected override bool EnableConnectionPooling - { - get { return false; } - } +// protected override bool EnableConnectionPooling +// { +// get { return false; } +// } - /// - /// Gets the name of the repository - /// - /// The name. - public string Name - { - get - { - return "SQLite"; - } - } +// /// +// /// Gets the name of the repository +// /// +// /// The name. +// public string Name +// { +// get +// { +// return "SQLite"; +// } +// } - /// - /// Opens the connection to the database - /// - /// Task. - public void Initialize(SQLiteDatabaseConnection connection, ReaderWriterLockSlim writeLock) - { - WriteLock.Dispose(); - WriteLock = writeLock; - _connection = connection; +// /// +// /// Opens the connection to the database +// /// +// /// Task. +// public void Initialize(SQLiteDatabaseConnection connection, ReaderWriterLockSlim writeLock) +// { +// WriteLock.Dispose(); +// WriteLock = writeLock; +// _connection = connection; - string[] queries = { +// string[] queries = { - "create table if not exists UserDataDb.userdata (key nvarchar, userId GUID, rating float null, played bit, playCount int, isFavorite bit, playbackPositionTicks bigint, lastPlayedDate datetime null)", +// "create table if not exists UserDataDb.userdata (key nvarchar, userId GUID, rating float null, played bit, playCount int, isFavorite bit, playbackPositionTicks bigint, lastPlayedDate datetime null)", - "drop index if exists UserDataDb.idx_userdata", - "drop index if exists UserDataDb.idx_userdata1", - "drop index if exists UserDataDb.idx_userdata2", - "drop index if exists UserDataDb.userdataindex1", +// "drop index if exists UserDataDb.idx_userdata", +// "drop index if exists UserDataDb.idx_userdata1", +// "drop index if exists UserDataDb.idx_userdata2", +// "drop index if exists UserDataDb.userdataindex1", - "create unique index if not exists UserDataDb.userdataindex on userdata (key, userId)", - "create index if not exists UserDataDb.userdataindex2 on userdata (key, userId, played)", - "create index if not exists UserDataDb.userdataindex3 on userdata (key, userId, playbackPositionTicks)", - "create index if not exists UserDataDb.userdataindex4 on userdata (key, userId, isFavorite)", +// "create unique index if not exists UserDataDb.userdataindex on userdata (key, userId)", +// "create index if not exists UserDataDb.userdataindex2 on userdata (key, userId, played)", +// "create index if not exists UserDataDb.userdataindex3 on userdata (key, userId, playbackPositionTicks)", +// "create index if not exists UserDataDb.userdataindex4 on userdata (key, userId, isFavorite)", - //pragmas - "pragma temp_store = memory", +// //pragmas +// "pragma temp_store = memory", - "pragma shrink_memory" - }; +// "pragma shrink_memory" +// }; - _connection.RunQueries(queries); +// _connection.RunQueries(queries); - connection.RunInTransaction(db => - { - var existingColumnNames = GetColumnNames(db, "userdata"); +// connection.RunInTransaction(db => +// { +// var existingColumnNames = GetColumnNames(db, "userdata"); - AddColumn(db, "userdata", "AudioStreamIndex", "int", existingColumnNames); - AddColumn(db, "userdata", "SubtitleStreamIndex", "int", existingColumnNames); - }); - } +// AddColumn(db, "userdata", "AudioStreamIndex", "int", existingColumnNames); +// AddColumn(db, "userdata", "SubtitleStreamIndex", "int", existingColumnNames); +// }); +// } - /// - /// Saves the user data. - /// - /// The user id. - /// The key. - /// The user data. - /// The cancellation token. - /// Task. - /// userData - /// or - /// cancellationToken - /// or - /// userId - /// or - /// userDataId - public Task SaveUserData(Guid userId, string key, UserItemData userData, CancellationToken cancellationToken) - { - if (userData == null) - { - throw new ArgumentNullException("userData"); - } - if (userId == Guid.Empty) - { - throw new ArgumentNullException("userId"); - } - if (string.IsNullOrEmpty(key)) - { - throw new ArgumentNullException("key"); - } +// /// +// /// Saves the user data. +// /// +// /// The user id. +// /// The key. +// /// The user data. +// /// The cancellation token. +// /// Task. +// /// userData +// /// or +// /// cancellationToken +// /// or +// /// userId +// /// or +// /// userDataId +// public Task SaveUserData(Guid userId, string key, UserItemData userData, CancellationToken cancellationToken) +// { +// if (userData == null) +// { +// throw new ArgumentNullException("userData"); +// } +// if (userId == Guid.Empty) +// { +// throw new ArgumentNullException("userId"); +// } +// if (string.IsNullOrEmpty(key)) +// { +// throw new ArgumentNullException("key"); +// } - return PersistUserData(userId, key, userData, cancellationToken); - } +// return PersistUserData(userId, key, userData, cancellationToken); +// } - public Task SaveAllUserData(Guid userId, IEnumerable userData, CancellationToken cancellationToken) - { - if (userData == null) - { - throw new ArgumentNullException("userData"); - } - if (userId == Guid.Empty) - { - throw new ArgumentNullException("userId"); - } +// public Task SaveAllUserData(Guid userId, IEnumerable userData, CancellationToken cancellationToken) +// { +// if (userData == null) +// { +// throw new ArgumentNullException("userData"); +// } +// if (userId == Guid.Empty) +// { +// throw new ArgumentNullException("userId"); +// } - return PersistAllUserData(userId, userData.ToList(), cancellationToken); - } +// return PersistAllUserData(userId, userData.ToList(), cancellationToken); +// } - /// - /// Persists the user data. - /// - /// The user id. - /// The key. - /// The user data. - /// The cancellation token. - /// Task. - public async Task PersistUserData(Guid userId, string key, UserItemData userData, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); +// /// +// /// Persists the user data. +// /// +// /// The user id. +// /// The key. +// /// The user data. +// /// The cancellation token. +// /// Task. +// public async Task PersistUserData(Guid userId, string key, UserItemData userData, CancellationToken cancellationToken) +// { +// cancellationToken.ThrowIfCancellationRequested(); - using (WriteLock.Write()) - { - _connection.RunInTransaction(db => - { - SaveUserData(db, userId, key, userData); - }); - } - } +// using (WriteLock.Write()) +// { +// _connection.RunInTransaction(db => +// { +// SaveUserData(db, userId, key, userData); +// }); +// } +// } - private void SaveUserData(IDatabaseConnection db, Guid userId, string key, UserItemData userData) - { - var paramList = new List(); - var commandText = "replace into userdata (key, userId, rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex) values (?, ?, ?,?,?,?,?,?,?,?)"; +// private void SaveUserData(IDatabaseConnection db, Guid userId, string key, UserItemData userData) +// { +// var paramList = new List(); +// var commandText = "replace into userdata (key, userId, rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex) values (?, ?, ?,?,?,?,?,?,?,?)"; - paramList.Add(key); - paramList.Add(userId.ToGuidParamValue()); - paramList.Add(userData.Rating); - paramList.Add(userData.Played); - paramList.Add(userData.PlayCount); - paramList.Add(userData.IsFavorite); - paramList.Add(userData.PlaybackPositionTicks); +// paramList.Add(key); +// paramList.Add(userId.ToGuidParamValue()); +// paramList.Add(userData.Rating); +// paramList.Add(userData.Played); +// paramList.Add(userData.PlayCount); +// paramList.Add(userData.IsFavorite); +// paramList.Add(userData.PlaybackPositionTicks); - if (userData.LastPlayedDate.HasValue) - { - paramList.Add(userData.LastPlayedDate.Value.ToDateTimeParamValue()); - } - else - { - paramList.Add(null); - } - paramList.Add(userData.AudioStreamIndex); - paramList.Add(userData.SubtitleStreamIndex); +// if (userData.LastPlayedDate.HasValue) +// { +// paramList.Add(userData.LastPlayedDate.Value.ToDateTimeParamValue()); +// } +// else +// { +// paramList.Add(null); +// } +// paramList.Add(userData.AudioStreamIndex); +// paramList.Add(userData.SubtitleStreamIndex); - db.Execute(commandText, paramList.ToArray()); - } +// db.Execute(commandText, paramList.ToArray()); +// } - /// - /// Persist all user data for the specified user - /// - private async Task PersistAllUserData(Guid userId, List userDataList, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); +// /// +// /// Persist all user data for the specified user +// /// +// private async Task PersistAllUserData(Guid userId, List userDataList, CancellationToken cancellationToken) +// { +// cancellationToken.ThrowIfCancellationRequested(); - using (WriteLock.Write()) - { - _connection.RunInTransaction(db => - { - foreach (var userItemData in userDataList) - { - SaveUserData(db, userId, userItemData.Key, userItemData); - } - }); - } - } +// using (WriteLock.Write()) +// { +// _connection.RunInTransaction(db => +// { +// foreach (var userItemData in userDataList) +// { +// SaveUserData(db, userId, userItemData.Key, userItemData); +// } +// }); +// } +// } - /// - /// Gets the user data. - /// - /// The user id. - /// The key. - /// Task{UserItemData}. - /// - /// userId - /// or - /// key - /// - public UserItemData GetUserData(Guid userId, string key) - { - if (userId == Guid.Empty) - { - throw new ArgumentNullException("userId"); - } - if (string.IsNullOrEmpty(key)) - { - throw new ArgumentNullException("key"); - } +// /// +// /// Gets the user data. +// /// +// /// The user id. +// /// The key. +// /// Task{UserItemData}. +// /// +// /// userId +// /// or +// /// key +// /// +// public UserItemData GetUserData(Guid userId, string key) +// { +// if (userId == Guid.Empty) +// { +// throw new ArgumentNullException("userId"); +// } +// if (string.IsNullOrEmpty(key)) +// { +// throw new ArgumentNullException("key"); +// } - var commandText = "select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where key = ? and userId=?"; +// var commandText = "select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where key = ? and userId=?"; - var paramList = new List(); - paramList.Add(key); - paramList.Add(userId.ToGuidParamValue()); +// var paramList = new List(); +// paramList.Add(key); +// paramList.Add(userId.ToGuidParamValue()); - foreach (var row in _connection.Query(commandText, paramList.ToArray())) - { - return ReadRow(row); - } +// foreach (var row in _connection.Query(commandText, paramList.ToArray())) +// { +// return ReadRow(row); +// } - return null; - } +// return null; +// } - public UserItemData GetUserData(Guid userId, List keys) - { - if (userId == Guid.Empty) - { - throw new ArgumentNullException("userId"); - } - if (keys == null) - { - throw new ArgumentNullException("keys"); - } +// public UserItemData GetUserData(Guid userId, List keys) +// { +// if (userId == Guid.Empty) +// { +// throw new ArgumentNullException("userId"); +// } +// if (keys == null) +// { +// throw new ArgumentNullException("keys"); +// } - if (keys.Count == 0) - { - return null; - } +// if (keys.Count == 0) +// { +// return null; +// } - return GetUserData(userId, keys[0]); - } +// return GetUserData(userId, keys[0]); +// } - /// - /// Return all user-data associated with the given user - /// - /// - /// - public IEnumerable GetAllUserData(Guid userId) - { - if (userId == Guid.Empty) - { - throw new ArgumentNullException("userId"); - } +// /// +// /// Return all user-data associated with the given user +// /// +// /// +// /// +// public IEnumerable GetAllUserData(Guid userId) +// { +// if (userId == Guid.Empty) +// { +// throw new ArgumentNullException("userId"); +// } - var list = new List(); +// var list = new List(); - using (WriteLock.Read()) - { - var commandText = "select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where userId=?"; +// using (WriteLock.Read()) +// { +// var commandText = "select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where userId=?"; - var paramList = new List(); - paramList.Add(userId.ToGuidParamValue()); +// var paramList = new List(); +// paramList.Add(userId.ToGuidParamValue()); - foreach (var row in _connection.Query(commandText, paramList.ToArray())) - { - list.Add(ReadRow(row)); - } - } +// foreach (var row in _connection.Query(commandText, paramList.ToArray())) +// { +// list.Add(ReadRow(row)); +// } +// } - return list; - } +// return list; +// } - /// - /// Read a row from the specified reader into the provided userData object - /// - /// - private UserItemData ReadRow(IReadOnlyList reader) - { - var userData = new UserItemData(); +// /// +// /// Read a row from the specified reader into the provided userData object +// /// +// /// +// private UserItemData ReadRow(IReadOnlyList reader) +// { +// var userData = new UserItemData(); - userData.Key = reader[0].ToString(); - userData.UserId = reader[1].ReadGuid(); +// userData.Key = reader[0].ToString(); +// userData.UserId = reader[1].ReadGuid(); - if (reader[2].SQLiteType != SQLiteType.Null) - { - userData.Rating = reader[2].ToDouble(); - } +// if (reader[2].SQLiteType != SQLiteType.Null) +// { +// userData.Rating = reader[2].ToDouble(); +// } - userData.Played = reader[3].ToBool(); - userData.PlayCount = reader[4].ToInt(); - userData.IsFavorite = reader[5].ToBool(); - userData.PlaybackPositionTicks = reader[6].ToInt64(); +// userData.Played = reader[3].ToBool(); +// userData.PlayCount = reader[4].ToInt(); +// userData.IsFavorite = reader[5].ToBool(); +// userData.PlaybackPositionTicks = reader[6].ToInt64(); - if (reader[7].SQLiteType != SQLiteType.Null) - { - userData.LastPlayedDate = reader[7].ReadDateTime(); - } +// if (reader[7].SQLiteType != SQLiteType.Null) +// { +// userData.LastPlayedDate = reader[7].ReadDateTime(); +// } - if (reader[8].SQLiteType != SQLiteType.Null) - { - userData.AudioStreamIndex = reader[8].ToInt(); - } +// if (reader[8].SQLiteType != SQLiteType.Null) +// { +// userData.AudioStreamIndex = reader[8].ToInt(); +// } - if (reader[9].SQLiteType != SQLiteType.Null) - { - userData.SubtitleStreamIndex = reader[9].ToInt(); - } +// if (reader[9].SQLiteType != SQLiteType.Null) +// { +// userData.SubtitleStreamIndex = reader[9].ToInt(); +// } - return userData; - } +// return userData; +// } - protected override void Dispose(bool dispose) - { - // handled by library database - } +// protected override void Dispose(bool dispose) +// { +// // handled by library database +// } - protected override void CloseConnection() - { - // handled by library database - } - } -} \ No newline at end of file +// protected override void CloseConnection() +// { +// // handled by library database +// } +// } +//} \ No newline at end of file diff --git a/MediaBrowser.Server.Mono/MediaBrowser.Server.Mono.csproj b/MediaBrowser.Server.Mono/MediaBrowser.Server.Mono.csproj index bd21db6cc..a0dc59cef 100644 --- a/MediaBrowser.Server.Mono/MediaBrowser.Server.Mono.csproj +++ b/MediaBrowser.Server.Mono/MediaBrowser.Server.Mono.csproj @@ -230,6 +230,10 @@ PreserveNewest + + Designer + PreserveNewest + PreserveNewest Designer diff --git a/MediaBrowser.Server.Mono/SQLitePCLRaw.provider.sqlite3.dll.config b/MediaBrowser.Server.Mono/SQLitePCLRaw.provider.sqlite3.dll.config new file mode 100644 index 000000000..83a6cd9f3 --- /dev/null +++ b/MediaBrowser.Server.Mono/SQLitePCLRaw.provider.sqlite3.dll.config @@ -0,0 +1,3 @@ + + + \ No newline at end of file