update db init
This commit is contained in:
parent
7f62a99ab5
commit
184f3bc50a
|
@ -84,7 +84,6 @@ using Emby.Dlna.Ssdp;
|
|||
using Emby.Server.Core;
|
||||
using Emby.Server.Implementations.Activity;
|
||||
using Emby.Server.Core.Configuration;
|
||||
using Emby.Server.Core.Data;
|
||||
using Emby.Server.Implementations.Devices;
|
||||
using Emby.Server.Implementations.FFMpeg;
|
||||
using Emby.Server.Core.IO;
|
||||
|
@ -550,7 +549,7 @@ namespace Emby.Server.Core
|
|||
DisplayPreferencesRepository = displayPreferencesRepo;
|
||||
RegisterSingleInstance(DisplayPreferencesRepository);
|
||||
|
||||
var itemRepo = new SqliteItemRepository(ServerConfigurationManager, JsonSerializer, LogManager, GetDbConnector(), MemoryStreamFactory, assemblyInfo);
|
||||
var itemRepo = new SqliteItemRepository(ServerConfigurationManager, JsonSerializer, LogManager.GetLogger("SqliteItemRepository"), MemoryStreamFactory, assemblyInfo, FileSystemManager);
|
||||
ItemRepository = itemRepo;
|
||||
RegisterSingleInstance(ItemRepository);
|
||||
|
||||
|
@ -693,10 +692,10 @@ namespace Emby.Server.Core
|
|||
|
||||
displayPreferencesRepo.Initialize();
|
||||
|
||||
var userDataRepo = new SqliteUserDataRepository(LogManager, ApplicationPaths, GetDbConnector());
|
||||
var userDataRepo = new SqliteUserDataRepository(LogManager.GetLogger("SqliteUserDataRepository"), ApplicationPaths);
|
||||
|
||||
((UserDataManager)UserDataManager).Repository = userDataRepo;
|
||||
await itemRepo.Initialize(userDataRepo).ConfigureAwait(false);
|
||||
itemRepo.Initialize(userDataRepo);
|
||||
((LibraryManager)LibraryManager).ItemRepository = ItemRepository;
|
||||
ConfigureNotificationsRepository();
|
||||
progress.Report(100);
|
||||
|
@ -1444,7 +1443,6 @@ namespace Emby.Server.Core
|
|||
}
|
||||
|
||||
protected abstract void AuthorizeServer();
|
||||
protected abstract IDbConnector GetDbConnector();
|
||||
|
||||
public event EventHandler HasUpdateAvailableChanged;
|
||||
|
||||
|
|
|
@ -1,114 +0,0 @@
|
|||
using System;
|
||||
using System.Data;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Model.Logging;
|
||||
|
||||
namespace Emby.Server.Core.Data
|
||||
{
|
||||
public abstract class BaseSqliteRepository : IDisposable
|
||||
{
|
||||
protected SemaphoreSlim WriteLock = new SemaphoreSlim(1, 1);
|
||||
protected readonly IDbConnector DbConnector;
|
||||
protected ILogger Logger;
|
||||
|
||||
protected string DbFilePath { get; set; }
|
||||
|
||||
protected BaseSqliteRepository(ILogManager logManager, IDbConnector dbConnector)
|
||||
{
|
||||
DbConnector = dbConnector;
|
||||
Logger = logManager.GetLogger(GetType().Name);
|
||||
}
|
||||
|
||||
protected virtual bool EnableConnectionPooling
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
protected virtual async Task<IDbConnection> CreateConnection(bool isReadOnly = false)
|
||||
{
|
||||
var connection = await DbConnector.Connect(DbFilePath, false, true).ConfigureAwait(false);
|
||||
|
||||
connection.RunQueries(new[]
|
||||
{
|
||||
"pragma temp_store = memory"
|
||||
|
||||
}, Logger);
|
||||
|
||||
return connection;
|
||||
}
|
||||
|
||||
private bool _disposed;
|
||||
protected void CheckDisposed()
|
||||
{
|
||||
if (_disposed)
|
||||
{
|
||||
throw new ObjectDisposedException(GetType().Name + " has been disposed and cannot be accessed.");
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_disposed = true;
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
protected async Task Vacuum(IDbConnection connection)
|
||||
{
|
||||
CheckDisposed();
|
||||
|
||||
await WriteLock.WaitAsync().ConfigureAwait(false);
|
||||
|
||||
try
|
||||
{
|
||||
using (var cmd = connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "vacuum";
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.ErrorException("Failed to vacuum:", e);
|
||||
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
WriteLock.Release();
|
||||
}
|
||||
}
|
||||
|
||||
private readonly object _disposeLock = new object();
|
||||
|
||||
/// <summary>
|
||||
/// Releases unmanaged and - optionally - managed resources.
|
||||
/// </summary>
|
||||
/// <param name="dispose"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
|
||||
protected virtual void Dispose(bool dispose)
|
||||
{
|
||||
if (dispose)
|
||||
{
|
||||
try
|
||||
{
|
||||
lock (_disposeLock)
|
||||
{
|
||||
WriteLock.Wait();
|
||||
|
||||
CloseConnection();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.ErrorException("Error disposing database", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void CloseConnection()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,186 +0,0 @@
|
|||
using System;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using MediaBrowser.Model.IO;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.Model.Serialization;
|
||||
|
||||
namespace Emby.Server.Core.Data
|
||||
{
|
||||
public static class DataExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Determines whether the specified conn is open.
|
||||
/// </summary>
|
||||
/// <param name="conn">The conn.</param>
|
||||
/// <returns><c>true</c> if the specified conn is open; otherwise, <c>false</c>.</returns>
|
||||
public static bool IsOpen(this IDbConnection conn)
|
||||
{
|
||||
return conn.State == ConnectionState.Open;
|
||||
}
|
||||
|
||||
public static IDataParameter GetParameter(this IDbCommand cmd, int index)
|
||||
{
|
||||
return (IDataParameter)cmd.Parameters[index];
|
||||
}
|
||||
|
||||
public static IDataParameter GetParameter(this IDbCommand cmd, string name)
|
||||
{
|
||||
return (IDataParameter)cmd.Parameters[name];
|
||||
}
|
||||
|
||||
public static IDataParameter Add(this IDataParameterCollection paramCollection, IDbCommand cmd, string name, DbType type)
|
||||
{
|
||||
var param = cmd.CreateParameter();
|
||||
|
||||
param.ParameterName = name;
|
||||
param.DbType = type;
|
||||
|
||||
paramCollection.Add(param);
|
||||
|
||||
return param;
|
||||
}
|
||||
|
||||
public static IDataParameter Add(this IDataParameterCollection paramCollection, IDbCommand cmd, string name)
|
||||
{
|
||||
var param = cmd.CreateParameter();
|
||||
|
||||
param.ParameterName = name;
|
||||
|
||||
paramCollection.Add(param);
|
||||
|
||||
return param;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets a stream from a DataReader at a given ordinal
|
||||
/// </summary>
|
||||
/// <returns>Stream.</returns>
|
||||
/// <exception cref="System.ArgumentNullException">reader</exception>
|
||||
public static Stream GetMemoryStream(this IDataReader reader, int ordinal, IMemoryStreamFactory streamProvider)
|
||||
{
|
||||
if (reader == null)
|
||||
{
|
||||
throw new ArgumentNullException("reader");
|
||||
}
|
||||
|
||||
var memoryStream = streamProvider.CreateNew();
|
||||
var num = 0L;
|
||||
var array = new byte[4096];
|
||||
long bytes;
|
||||
do
|
||||
{
|
||||
bytes = reader.GetBytes(ordinal, num, array, 0, array.Length);
|
||||
memoryStream.Write(array, 0, (int)bytes);
|
||||
num += bytes;
|
||||
}
|
||||
while (bytes > 0L);
|
||||
memoryStream.Position = 0;
|
||||
return memoryStream;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Runs the queries.
|
||||
/// </summary>
|
||||
/// <param name="connection">The connection.</param>
|
||||
/// <param name="queries">The queries.</param>
|
||||
/// <param name="logger">The logger.</param>
|
||||
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
|
||||
/// <exception cref="System.ArgumentNullException">queries</exception>
|
||||
public static void RunQueries(this IDbConnection connection, string[] queries, ILogger logger)
|
||||
{
|
||||
if (queries == null)
|
||||
{
|
||||
throw new ArgumentNullException("queries");
|
||||
}
|
||||
|
||||
using (var tran = connection.BeginTransaction())
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var cmd = connection.CreateCommand())
|
||||
{
|
||||
foreach (var query in queries)
|
||||
{
|
||||
cmd.Transaction = tran;
|
||||
cmd.CommandText = query;
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
|
||||
tran.Commit();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.ErrorException("Error running queries", e);
|
||||
tran.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void Attach(IDbConnection db, string path, string alias)
|
||||
{
|
||||
using (var cmd = db.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = string.Format("attach @dbPath as {0};", alias);
|
||||
cmd.Parameters.Add(cmd, "@dbPath", DbType.String);
|
||||
cmd.GetParameter(0).Value = path;
|
||||
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serializes to bytes.
|
||||
/// </summary>
|
||||
/// <returns>System.Byte[][].</returns>
|
||||
/// <exception cref="System.ArgumentNullException">obj</exception>
|
||||
public static byte[] SerializeToBytes(this IJsonSerializer json, object obj, IMemoryStreamFactory streamProvider)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
throw new ArgumentNullException("obj");
|
||||
}
|
||||
|
||||
using (var stream = streamProvider.CreateNew())
|
||||
{
|
||||
json.SerializeToStream(obj, stream);
|
||||
return stream.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public static void AddColumn(this IDbConnection connection, ILogger logger, string table, string columnName, string type)
|
||||
{
|
||||
using (var cmd = connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "PRAGMA table_info(" + table + ")";
|
||||
|
||||
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult))
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
if (!reader.IsDBNull(1))
|
||||
{
|
||||
var name = reader.GetString(1);
|
||||
|
||||
if (string.Equals(name, columnName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var builder = new StringBuilder();
|
||||
|
||||
builder.AppendLine("alter table " + table);
|
||||
builder.AppendLine("add column " + columnName + " " + type + " NULL");
|
||||
|
||||
connection.RunQueries(new[] { builder.ToString() }, logger);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
using System.Data;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Emby.Server.Core.Data
|
||||
{
|
||||
public interface IDbConnector
|
||||
{
|
||||
Task<IDbConnection> Connect(string dbPath, bool isReadOnly, bool enablePooling = false, int? cacheSize = null);
|
||||
}
|
||||
}
|
|
@ -1,408 +0,0 @@
|
|||
using System;
|
||||
using System.Data;
|
||||
using System.Text;
|
||||
using MediaBrowser.Model.Logging;
|
||||
|
||||
namespace Emby.Server.Core.Data
|
||||
{
|
||||
public class MediaStreamColumns
|
||||
{
|
||||
private readonly IDbConnection _connection;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public MediaStreamColumns(IDbConnection connection, ILogger logger)
|
||||
{
|
||||
_connection = connection;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void AddColumns()
|
||||
{
|
||||
AddPixelFormatColumnCommand();
|
||||
AddBitDepthCommand();
|
||||
AddIsAnamorphicColumn();
|
||||
AddKeyFramesColumn();
|
||||
AddRefFramesCommand();
|
||||
AddCodecTagColumn();
|
||||
AddCommentColumn();
|
||||
AddNalColumn();
|
||||
AddIsAvcColumn();
|
||||
AddTitleColumn();
|
||||
AddTimeBaseColumn();
|
||||
AddCodecTimeBaseColumn();
|
||||
}
|
||||
|
||||
private void AddIsAvcColumn()
|
||||
{
|
||||
using (var cmd = _connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "PRAGMA table_info(mediastreams)";
|
||||
|
||||
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult))
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
if (!reader.IsDBNull(1))
|
||||
{
|
||||
var name = reader.GetString(1);
|
||||
|
||||
if (string.Equals(name, "IsAvc", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var builder = new StringBuilder();
|
||||
|
||||
builder.AppendLine("alter table mediastreams");
|
||||
builder.AppendLine("add column IsAvc BIT NULL");
|
||||
|
||||
_connection.RunQueries(new[] { builder.ToString() }, _logger);
|
||||
}
|
||||
|
||||
private void AddTimeBaseColumn()
|
||||
{
|
||||
using (var cmd = _connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "PRAGMA table_info(mediastreams)";
|
||||
|
||||
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult))
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
if (!reader.IsDBNull(1))
|
||||
{
|
||||
var name = reader.GetString(1);
|
||||
|
||||
if (string.Equals(name, "TimeBase", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var builder = new StringBuilder();
|
||||
|
||||
builder.AppendLine("alter table mediastreams");
|
||||
builder.AppendLine("add column TimeBase TEXT");
|
||||
|
||||
_connection.RunQueries(new[] { builder.ToString() }, _logger);
|
||||
}
|
||||
|
||||
private void AddCodecTimeBaseColumn()
|
||||
{
|
||||
using (var cmd = _connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "PRAGMA table_info(mediastreams)";
|
||||
|
||||
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult))
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
if (!reader.IsDBNull(1))
|
||||
{
|
||||
var name = reader.GetString(1);
|
||||
|
||||
if (string.Equals(name, "CodecTimeBase", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var builder = new StringBuilder();
|
||||
|
||||
builder.AppendLine("alter table mediastreams");
|
||||
builder.AppendLine("add column CodecTimeBase TEXT");
|
||||
|
||||
_connection.RunQueries(new[] { builder.ToString() }, _logger);
|
||||
}
|
||||
|
||||
private void AddTitleColumn()
|
||||
{
|
||||
using (var cmd = _connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "PRAGMA table_info(mediastreams)";
|
||||
|
||||
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult))
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
if (!reader.IsDBNull(1))
|
||||
{
|
||||
var name = reader.GetString(1);
|
||||
|
||||
if (string.Equals(name, "Title", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var builder = new StringBuilder();
|
||||
|
||||
builder.AppendLine("alter table mediastreams");
|
||||
builder.AppendLine("add column Title TEXT");
|
||||
|
||||
_connection.RunQueries(new[] { builder.ToString() }, _logger);
|
||||
}
|
||||
|
||||
private void AddNalColumn()
|
||||
{
|
||||
using (var cmd = _connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "PRAGMA table_info(mediastreams)";
|
||||
|
||||
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult))
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
if (!reader.IsDBNull(1))
|
||||
{
|
||||
var name = reader.GetString(1);
|
||||
|
||||
if (string.Equals(name, "NalLengthSize", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var builder = new StringBuilder();
|
||||
|
||||
builder.AppendLine("alter table mediastreams");
|
||||
builder.AppendLine("add column NalLengthSize TEXT");
|
||||
|
||||
_connection.RunQueries(new[] { builder.ToString() }, _logger);
|
||||
}
|
||||
|
||||
private void AddCommentColumn()
|
||||
{
|
||||
using (var cmd = _connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "PRAGMA table_info(mediastreams)";
|
||||
|
||||
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult))
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
if (!reader.IsDBNull(1))
|
||||
{
|
||||
var name = reader.GetString(1);
|
||||
|
||||
if (string.Equals(name, "Comment", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var builder = new StringBuilder();
|
||||
|
||||
builder.AppendLine("alter table mediastreams");
|
||||
builder.AppendLine("add column Comment TEXT");
|
||||
|
||||
_connection.RunQueries(new[] { builder.ToString() }, _logger);
|
||||
}
|
||||
|
||||
private void AddCodecTagColumn()
|
||||
{
|
||||
using (var cmd = _connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "PRAGMA table_info(mediastreams)";
|
||||
|
||||
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult))
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
if (!reader.IsDBNull(1))
|
||||
{
|
||||
var name = reader.GetString(1);
|
||||
|
||||
if (string.Equals(name, "CodecTag", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var builder = new StringBuilder();
|
||||
|
||||
builder.AppendLine("alter table mediastreams");
|
||||
builder.AppendLine("add column CodecTag TEXT");
|
||||
|
||||
_connection.RunQueries(new[] { builder.ToString() }, _logger);
|
||||
}
|
||||
|
||||
private void AddPixelFormatColumnCommand()
|
||||
{
|
||||
using (var cmd = _connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "PRAGMA table_info(mediastreams)";
|
||||
|
||||
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult))
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
if (!reader.IsDBNull(1))
|
||||
{
|
||||
var name = reader.GetString(1);
|
||||
|
||||
if (string.Equals(name, "PixelFormat", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var builder = new StringBuilder();
|
||||
|
||||
builder.AppendLine("alter table mediastreams");
|
||||
builder.AppendLine("add column PixelFormat TEXT");
|
||||
|
||||
_connection.RunQueries(new[] { builder.ToString() }, _logger);
|
||||
}
|
||||
|
||||
private void AddBitDepthCommand()
|
||||
{
|
||||
using (var cmd = _connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "PRAGMA table_info(mediastreams)";
|
||||
|
||||
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult))
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
if (!reader.IsDBNull(1))
|
||||
{
|
||||
var name = reader.GetString(1);
|
||||
|
||||
if (string.Equals(name, "BitDepth", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var builder = new StringBuilder();
|
||||
|
||||
builder.AppendLine("alter table mediastreams");
|
||||
builder.AppendLine("add column BitDepth INT NULL");
|
||||
|
||||
_connection.RunQueries(new[] { builder.ToString() }, _logger);
|
||||
}
|
||||
|
||||
private void AddRefFramesCommand()
|
||||
{
|
||||
using (var cmd = _connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "PRAGMA table_info(mediastreams)";
|
||||
|
||||
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult))
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
if (!reader.IsDBNull(1))
|
||||
{
|
||||
var name = reader.GetString(1);
|
||||
|
||||
if (string.Equals(name, "RefFrames", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var builder = new StringBuilder();
|
||||
|
||||
builder.AppendLine("alter table mediastreams");
|
||||
builder.AppendLine("add column RefFrames INT NULL");
|
||||
|
||||
_connection.RunQueries(new[] { builder.ToString() }, _logger);
|
||||
}
|
||||
|
||||
private void AddKeyFramesColumn()
|
||||
{
|
||||
using (var cmd = _connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "PRAGMA table_info(mediastreams)";
|
||||
|
||||
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult))
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
if (!reader.IsDBNull(1))
|
||||
{
|
||||
var name = reader.GetString(1);
|
||||
|
||||
if (string.Equals(name, "KeyFrames", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var builder = new StringBuilder();
|
||||
|
||||
builder.AppendLine("alter table mediastreams");
|
||||
builder.AppendLine("add column KeyFrames TEXT NULL");
|
||||
|
||||
_connection.RunQueries(new[] { builder.ToString() }, _logger);
|
||||
}
|
||||
|
||||
private void AddIsAnamorphicColumn()
|
||||
{
|
||||
using (var cmd = _connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "PRAGMA table_info(mediastreams)";
|
||||
|
||||
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult))
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
if (!reader.IsDBNull(1))
|
||||
{
|
||||
var name = reader.GetString(1);
|
||||
|
||||
if (string.Equals(name, "IsAnamorphic", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var builder = new StringBuilder();
|
||||
|
||||
builder.AppendLine("alter table mediastreams");
|
||||
builder.AppendLine("add column IsAnamorphic BIT NULL");
|
||||
|
||||
_connection.RunQueries(new[] { builder.ToString() }, _logger);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -1,453 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
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;
|
||||
|
||||
namespace Emby.Server.Core.Data
|
||||
{
|
||||
public class SqliteUserDataRepository : BaseSqliteRepository, IUserDataRepository
|
||||
{
|
||||
private IDbConnection _connection;
|
||||
|
||||
public SqliteUserDataRepository(ILogManager logManager, IApplicationPaths appPaths, IDbConnector connector) : base(logManager, connector)
|
||||
{
|
||||
DbFilePath = Path.Combine(appPaths.DataPath, "userdata_v2.db");
|
||||
}
|
||||
|
||||
protected override bool EnableConnectionPooling
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the repository
|
||||
/// </summary>
|
||||
/// <value>The name.</value>
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return "SQLite";
|
||||
}
|
||||
}
|
||||
|
||||
protected override async Task<IDbConnection> CreateConnection(bool isReadOnly = false)
|
||||
{
|
||||
var connection = await DbConnector.Connect(DbFilePath, false, false, 10000).ConfigureAwait(false);
|
||||
|
||||
connection.RunQueries(new[]
|
||||
{
|
||||
"pragma temp_store = memory"
|
||||
|
||||
}, Logger);
|
||||
|
||||
return connection;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens the connection to the database
|
||||
/// </summary>
|
||||
/// <returns>Task.</returns>
|
||||
public async Task Initialize(IDbConnection connection, SemaphoreSlim 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, Logger);
|
||||
|
||||
_connection.AddColumn(Logger, "userdata", "AudioStreamIndex", "int");
|
||||
_connection.AddColumn(Logger, "userdata", "SubtitleStreamIndex", "int");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves the user data.
|
||||
/// </summary>
|
||||
/// <param name="userId">The user id.</param>
|
||||
/// <param name="key">The key.</param>
|
||||
/// <param name="userData">The user data.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task.</returns>
|
||||
/// <exception cref="System.ArgumentNullException">userData
|
||||
/// or
|
||||
/// cancellationToken
|
||||
/// or
|
||||
/// userId
|
||||
/// or
|
||||
/// userDataId</exception>
|
||||
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<UserItemData> userData, CancellationToken cancellationToken)
|
||||
{
|
||||
if (userData == null)
|
||||
{
|
||||
throw new ArgumentNullException("userData");
|
||||
}
|
||||
if (userId == Guid.Empty)
|
||||
{
|
||||
throw new ArgumentNullException("userId");
|
||||
}
|
||||
|
||||
return PersistAllUserData(userId, userData, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Persists the user data.
|
||||
/// </summary>
|
||||
/// <param name="userId">The user id.</param>
|
||||
/// <param name="key">The key.</param>
|
||||
/// <param name="userData">The user data.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task.</returns>
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Persist all user data for the specified user
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="userData"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
private async Task PersistAllUserData(Guid userId, IEnumerable<UserItemData> 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();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the user data.
|
||||
/// </summary>
|
||||
/// <param name="userId">The user id.</param>
|
||||
/// <param name="key">The key.</param>
|
||||
/// <returns>Task{UserItemData}.</returns>
|
||||
/// <exception cref="System.ArgumentNullException">
|
||||
/// userId
|
||||
/// or
|
||||
/// key
|
||||
/// </exception>
|
||||
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<string> 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<string>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return all user-data associated with the given user
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<UserItemData> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a row from the specified reader into the provided userData object
|
||||
/// </summary>
|
||||
/// <param name="reader"></param>
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
|
@ -135,9 +135,9 @@ namespace Emby.Server.Implementations.Data
|
|||
});
|
||||
|
||||
var numComplete = 0;
|
||||
var numItems = result.Items.Length;
|
||||
var numItems = result.Count;
|
||||
|
||||
foreach (var item in result.Items)
|
||||
foreach (var item in result)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
|
|
|
@ -173,6 +173,16 @@ namespace Emby.Server.Implementations.Data
|
|||
return result[index].ReadGuid();
|
||||
}
|
||||
|
||||
private static void CheckName(string name)
|
||||
{
|
||||
#if DEBUG
|
||||
//if (!name.IndexOf("@", StringComparison.OrdinalIgnoreCase) != 0)
|
||||
{
|
||||
throw new Exception("Invalid param name: " + name);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void TryBind(this IStatement statement, string name, double value)
|
||||
{
|
||||
IBindParameter bindParam;
|
||||
|
@ -180,6 +190,10 @@ namespace Emby.Server.Implementations.Data
|
|||
{
|
||||
bindParam.Bind(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
CheckName(name);
|
||||
}
|
||||
}
|
||||
|
||||
public static void TryBind(this IStatement statement, string name, string value)
|
||||
|
@ -187,7 +201,18 @@ namespace Emby.Server.Implementations.Data
|
|||
IBindParameter bindParam;
|
||||
if (statement.BindParameters.TryGetValue(name, out bindParam))
|
||||
{
|
||||
bindParam.Bind(value);
|
||||
if (value == null)
|
||||
{
|
||||
bindParam.BindNull();
|
||||
}
|
||||
else
|
||||
{
|
||||
bindParam.Bind(value);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CheckName(name);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -198,6 +223,10 @@ namespace Emby.Server.Implementations.Data
|
|||
{
|
||||
bindParam.Bind(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
CheckName(name);
|
||||
}
|
||||
}
|
||||
|
||||
public static void TryBind(this IStatement statement, string name, float value)
|
||||
|
@ -207,6 +236,10 @@ namespace Emby.Server.Implementations.Data
|
|||
{
|
||||
bindParam.Bind(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
CheckName(name);
|
||||
}
|
||||
}
|
||||
|
||||
public static void TryBind(this IStatement statement, string name, int value)
|
||||
|
@ -216,6 +249,10 @@ namespace Emby.Server.Implementations.Data
|
|||
{
|
||||
bindParam.Bind(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
CheckName(name);
|
||||
}
|
||||
}
|
||||
|
||||
public static void TryBind(this IStatement statement, string name, Guid value)
|
||||
|
@ -225,6 +262,10 @@ namespace Emby.Server.Implementations.Data
|
|||
{
|
||||
bindParam.Bind(value.ToGuidParamValue());
|
||||
}
|
||||
else
|
||||
{
|
||||
CheckName(name);
|
||||
}
|
||||
}
|
||||
|
||||
public static void TryBind(this IStatement statement, string name, DateTime value)
|
||||
|
@ -234,6 +275,10 @@ namespace Emby.Server.Implementations.Data
|
|||
{
|
||||
bindParam.Bind(value.ToDateTimeParamValue());
|
||||
}
|
||||
else
|
||||
{
|
||||
CheckName(name);
|
||||
}
|
||||
}
|
||||
|
||||
public static void TryBind(this IStatement statement, string name, long value)
|
||||
|
@ -243,6 +288,10 @@ namespace Emby.Server.Implementations.Data
|
|||
{
|
||||
bindParam.Bind(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
CheckName(name);
|
||||
}
|
||||
}
|
||||
|
||||
public static void TryBind(this IStatement statement, string name, byte[] value)
|
||||
|
@ -252,6 +301,10 @@ namespace Emby.Server.Implementations.Data
|
|||
{
|
||||
bindParam.Bind(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
CheckName(name);
|
||||
}
|
||||
}
|
||||
|
||||
public static void TryBindNull(this IStatement statement, string name)
|
||||
|
@ -261,6 +314,10 @@ namespace Emby.Server.Implementations.Data
|
|||
{
|
||||
bindParam.BindNull();
|
||||
}
|
||||
else
|
||||
{
|
||||
CheckName(name);
|
||||
}
|
||||
}
|
||||
|
||||
public static void TryBind(this IStatement statement, string name, DateTime? value)
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,356 +1,359 @@
|
|||
//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; }
|
||||
}
|
||||
|
||||
// /// <summary>
|
||||
// /// Gets the name of the repository
|
||||
// /// </summary>
|
||||
// /// <value>The name.</value>
|
||||
// public string Name
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// return "SQLite";
|
||||
// }
|
||||
// }
|
||||
/// <summary>
|
||||
/// Gets the name of the repository
|
||||
/// </summary>
|
||||
/// <value>The name.</value>
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return "SQLite";
|
||||
}
|
||||
}
|
||||
|
||||
// /// <summary>
|
||||
// /// Opens the connection to the database
|
||||
// /// </summary>
|
||||
// /// <returns>Task.</returns>
|
||||
// public void Initialize(SQLiteDatabaseConnection connection, ReaderWriterLockSlim writeLock)
|
||||
// {
|
||||
// WriteLock.Dispose();
|
||||
// WriteLock = writeLock;
|
||||
// _connection = connection;
|
||||
/// <summary>
|
||||
/// Opens the connection to the database
|
||||
/// </summary>
|
||||
/// <returns>Task.</returns>
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
||||
// /// <summary>
|
||||
// /// Saves the user data.
|
||||
// /// </summary>
|
||||
// /// <param name="userId">The user id.</param>
|
||||
// /// <param name="key">The key.</param>
|
||||
// /// <param name="userData">The user data.</param>
|
||||
// /// <param name="cancellationToken">The cancellation token.</param>
|
||||
// /// <returns>Task.</returns>
|
||||
// /// <exception cref="System.ArgumentNullException">userData
|
||||
// /// or
|
||||
// /// cancellationToken
|
||||
// /// or
|
||||
// /// userId
|
||||
// /// or
|
||||
// /// userDataId</exception>
|
||||
// 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");
|
||||
// }
|
||||
/// <summary>
|
||||
/// Saves the user data.
|
||||
/// </summary>
|
||||
/// <param name="userId">The user id.</param>
|
||||
/// <param name="key">The key.</param>
|
||||
/// <param name="userData">The user data.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task.</returns>
|
||||
/// <exception cref="System.ArgumentNullException">userData
|
||||
/// or
|
||||
/// cancellationToken
|
||||
/// or
|
||||
/// userId
|
||||
/// or
|
||||
/// userDataId</exception>
|
||||
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<UserItemData> userData, CancellationToken cancellationToken)
|
||||
// {
|
||||
// if (userData == null)
|
||||
// {
|
||||
// throw new ArgumentNullException("userData");
|
||||
// }
|
||||
// if (userId == Guid.Empty)
|
||||
// {
|
||||
// throw new ArgumentNullException("userId");
|
||||
// }
|
||||
public Task SaveAllUserData(Guid userId, IEnumerable<UserItemData> 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);
|
||||
}
|
||||
|
||||
// /// <summary>
|
||||
// /// Persists the user data.
|
||||
// /// </summary>
|
||||
// /// <param name="userId">The user id.</param>
|
||||
// /// <param name="key">The key.</param>
|
||||
// /// <param name="userData">The user data.</param>
|
||||
// /// <param name="cancellationToken">The cancellation token.</param>
|
||||
// /// <returns>Task.</returns>
|
||||
// public async Task PersistUserData(Guid userId, string key, UserItemData userData, CancellationToken cancellationToken)
|
||||
// {
|
||||
// cancellationToken.ThrowIfCancellationRequested();
|
||||
/// <summary>
|
||||
/// Persists the user data.
|
||||
/// </summary>
|
||||
/// <param name="userId">The user id.</param>
|
||||
/// <param name="key">The key.</param>
|
||||
/// <param name="userData">The user data.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task.</returns>
|
||||
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)
|
||||
// {
|
||||
// using (var statement = _connection.PrepareStatement("replace into userdata (key, userId, rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex) values (@key, @userId, @rating,@played,@playCount,@isFavorite,@playbackPositionTicks,@lastPlayedDate,@AudioStreamIndex,@SubtitleStreamIndex)"))
|
||||
// {
|
||||
// statement.TryBind("@UserId", userId.ToGuidParamValue());
|
||||
// statement.TryBind("@Key", key);
|
||||
private void SaveUserData(IDatabaseConnection db, Guid userId, string key, UserItemData userData)
|
||||
{
|
||||
using (var statement = _connection.PrepareStatement("replace into userdata (key, userId, rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex) values (@key, @userId, @rating,@played,@playCount,@isFavorite,@playbackPositionTicks,@lastPlayedDate,@AudioStreamIndex,@SubtitleStreamIndex)"))
|
||||
{
|
||||
statement.TryBind("@UserId", userId.ToGuidParamValue());
|
||||
statement.TryBind("@Key", key);
|
||||
|
||||
// if (userData.Rating.HasValue)
|
||||
// {
|
||||
// statement.TryBind("@rating", userData.Rating.Value);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// statement.TryBindNull("@rating");
|
||||
// }
|
||||
if (userData.Rating.HasValue)
|
||||
{
|
||||
statement.TryBind("@rating", userData.Rating.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
statement.TryBindNull("@rating");
|
||||
}
|
||||
|
||||
// statement.TryBind("@played", userData.Played);
|
||||
// statement.TryBind("@playCount", userData.PlayCount);
|
||||
// statement.TryBind("@isFavorite", userData.IsFavorite);
|
||||
// statement.TryBind("@playbackPositionTicks", userData.PlaybackPositionTicks);
|
||||
statement.TryBind("@played", userData.Played);
|
||||
statement.TryBind("@playCount", userData.PlayCount);
|
||||
statement.TryBind("@isFavorite", userData.IsFavorite);
|
||||
statement.TryBind("@playbackPositionTicks", userData.PlaybackPositionTicks);
|
||||
|
||||
// if (userData.LastPlayedDate.HasValue)
|
||||
// {
|
||||
// statement.TryBind("@lastPlayedDate", userData.LastPlayedDate.Value.ToDateTimeParamValue());
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// statement.TryBindNull("@lastPlayedDate");
|
||||
// }
|
||||
if (userData.LastPlayedDate.HasValue)
|
||||
{
|
||||
statement.TryBind("@lastPlayedDate", userData.LastPlayedDate.Value.ToDateTimeParamValue());
|
||||
}
|
||||
else
|
||||
{
|
||||
statement.TryBindNull("@lastPlayedDate");
|
||||
}
|
||||
|
||||
// if (userData.AudioStreamIndex.HasValue)
|
||||
// {
|
||||
// statement.TryBind("@AudioStreamIndex", userData.AudioStreamIndex.Value);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// statement.TryBindNull("@AudioStreamIndex");
|
||||
// }
|
||||
if (userData.AudioStreamIndex.HasValue)
|
||||
{
|
||||
statement.TryBind("@AudioStreamIndex", userData.AudioStreamIndex.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
statement.TryBindNull("@AudioStreamIndex");
|
||||
}
|
||||
|
||||
// if (userData.SubtitleStreamIndex.HasValue)
|
||||
// {
|
||||
// statement.TryBind("@SubtitleStreamIndex", userData.SubtitleStreamIndex.Value);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// statement.TryBindNull("@SubtitleStreamIndex");
|
||||
// }
|
||||
if (userData.SubtitleStreamIndex.HasValue)
|
||||
{
|
||||
statement.TryBind("@SubtitleStreamIndex", userData.SubtitleStreamIndex.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
statement.TryBindNull("@SubtitleStreamIndex");
|
||||
}
|
||||
|
||||
// statement.MoveNext();
|
||||
// }
|
||||
// }
|
||||
statement.MoveNext();
|
||||
}
|
||||
}
|
||||
|
||||
// /// <summary>
|
||||
// /// Persist all user data for the specified user
|
||||
// /// </summary>
|
||||
// private async Task PersistAllUserData(Guid userId, List<UserItemData> userDataList, CancellationToken cancellationToken)
|
||||
// {
|
||||
// cancellationToken.ThrowIfCancellationRequested();
|
||||
/// <summary>
|
||||
/// Persist all user data for the specified user
|
||||
/// </summary>
|
||||
private async Task PersistAllUserData(Guid userId, List<UserItemData> 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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// /// <summary>
|
||||
// /// Gets the user data.
|
||||
// /// </summary>
|
||||
// /// <param name="userId">The user id.</param>
|
||||
// /// <param name="key">The key.</param>
|
||||
// /// <returns>Task{UserItemData}.</returns>
|
||||
// /// <exception cref="System.ArgumentNullException">
|
||||
// /// userId
|
||||
// /// or
|
||||
// /// key
|
||||
// /// </exception>
|
||||
// public UserItemData GetUserData(Guid userId, string key)
|
||||
// {
|
||||
// if (userId == Guid.Empty)
|
||||
// {
|
||||
// throw new ArgumentNullException("userId");
|
||||
// }
|
||||
// if (string.IsNullOrEmpty(key))
|
||||
// {
|
||||
// throw new ArgumentNullException("key");
|
||||
// }
|
||||
/// <summary>
|
||||
/// Gets the user data.
|
||||
/// </summary>
|
||||
/// <param name="userId">The user id.</param>
|
||||
/// <param name="key">The key.</param>
|
||||
/// <returns>Task{UserItemData}.</returns>
|
||||
/// <exception cref="System.ArgumentNullException">
|
||||
/// userId
|
||||
/// or
|
||||
/// key
|
||||
/// </exception>
|
||||
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 statement = _connection.PrepareStatement("select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where key =@Key and userId=@UserId"))
|
||||
// {
|
||||
// statement.TryBind("@UserId", userId.ToGuidParamValue());
|
||||
// statement.TryBind("@Key", key);
|
||||
using (WriteLock.Write())
|
||||
{
|
||||
using (var statement = _connection.PrepareStatement("select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where key =@Key and userId=@UserId"))
|
||||
{
|
||||
statement.TryBind("@UserId", userId.ToGuidParamValue());
|
||||
statement.TryBind("@Key", key);
|
||||
|
||||
// foreach (var row in statement.ExecuteQuery())
|
||||
// {
|
||||
// return ReadRow(row);
|
||||
// }
|
||||
// }
|
||||
foreach (var row in statement.ExecuteQuery())
|
||||
{
|
||||
return ReadRow(row);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// return null;
|
||||
// }
|
||||
return null;
|
||||
}
|
||||
|
||||
// public UserItemData GetUserData(Guid userId, List<string> keys)
|
||||
// {
|
||||
// if (userId == Guid.Empty)
|
||||
// {
|
||||
// throw new ArgumentNullException("userId");
|
||||
// }
|
||||
// if (keys == null)
|
||||
// {
|
||||
// throw new ArgumentNullException("keys");
|
||||
// }
|
||||
public UserItemData GetUserData(Guid userId, List<string> 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]);
|
||||
}
|
||||
|
||||
// /// <summary>
|
||||
// /// Return all user-data associated with the given user
|
||||
// /// </summary>
|
||||
// /// <param name="userId"></param>
|
||||
// /// <returns></returns>
|
||||
// public IEnumerable<UserItemData> GetAllUserData(Guid userId)
|
||||
// {
|
||||
// if (userId == Guid.Empty)
|
||||
// {
|
||||
// throw new ArgumentNullException("userId");
|
||||
// }
|
||||
/// <summary>
|
||||
/// Return all user-data associated with the given user
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<UserItemData> GetAllUserData(Guid userId)
|
||||
{
|
||||
if (userId == Guid.Empty)
|
||||
{
|
||||
throw new ArgumentNullException("userId");
|
||||
}
|
||||
|
||||
// var list = new List<UserItemData>();
|
||||
var list = new List<UserItemData>();
|
||||
|
||||
// using (WriteLock.Read())
|
||||
// {
|
||||
// using (var statement = _connection.PrepareStatement("select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where userId=@UserId"))
|
||||
// {
|
||||
// statement.TryBind("@UserId", userId.ToGuidParamValue());
|
||||
using (WriteLock.Write())
|
||||
{
|
||||
using (var statement = _connection.PrepareStatement("select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where userId=@UserId"))
|
||||
{
|
||||
statement.TryBind("@UserId", userId.ToGuidParamValue());
|
||||
|
||||
// foreach (var row in statement.ExecuteQuery())
|
||||
// {
|
||||
// list.Add(ReadRow(row));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
foreach (var row in statement.ExecuteQuery())
|
||||
{
|
||||
list.Add(ReadRow(row));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// return list;
|
||||
// }
|
||||
return list;
|
||||
}
|
||||
|
||||
// /// <summary>
|
||||
// /// Read a row from the specified reader into the provided userData object
|
||||
// /// </summary>
|
||||
// /// <param name="reader"></param>
|
||||
// private UserItemData ReadRow(IReadOnlyList<IResultSetValue> reader)
|
||||
// {
|
||||
// var userData = new UserItemData();
|
||||
/// <summary>
|
||||
/// Read a row from the specified reader into the provided userData object
|
||||
/// </summary>
|
||||
/// <param name="reader"></param>
|
||||
private UserItemData ReadRow(IReadOnlyList<IResultSetValue> 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
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
protected override void CloseConnection()
|
||||
{
|
||||
// handled by library database
|
||||
}
|
||||
}
|
||||
}
|
|
@ -147,7 +147,7 @@ namespace MediaBrowser.Controller.Persistence
|
|||
/// </summary>
|
||||
/// <param name="query">The query.</param>
|
||||
/// <returns>QueryResult<Tuple<Guid, System.String>>.</returns>
|
||||
QueryResult<Tuple<Guid, string>> GetItemIdsWithPath(InternalItemsQuery query);
|
||||
List<Tuple<Guid, string>> GetItemIdsWithPath(InternalItemsQuery query);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the item list.
|
||||
|
|
|
@ -98,9 +98,6 @@
|
|||
</Reference>
|
||||
<Reference Include="System.Configuration" />
|
||||
<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>
|
||||
<Reference Include="System.IO.Compression" />
|
||||
<Reference Include="System.Runtime.Serialization" />
|
||||
<Reference Include="System.ServiceModel" />
|
||||
|
@ -108,14 +105,10 @@
|
|||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\MediaBrowser.Server.Startup.Common\Persistence\SqliteExtensions.cs">
|
||||
<Link>Native\SqliteExtensions.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\SharedVersion.cs">
|
||||
<Link>Properties\SharedVersion.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="MonoAppHost.cs" />
|
||||
<Compile Include="Native\DbConnector.cs" />
|
||||
<Compile Include="Native\MonoFileSystem.cs" />
|
||||
<Compile Include="Native\PowerManagement.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
|
|
|
@ -2,14 +2,12 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using Emby.Server.Core;
|
||||
using Emby.Server.Core.Data;
|
||||
using Emby.Server.Implementations;
|
||||
using Emby.Server.Implementations.FFMpeg;
|
||||
using MediaBrowser.IsoMounter;
|
||||
using MediaBrowser.Model.IO;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.Model.System;
|
||||
using MediaBrowser.Server.Mono.Native;
|
||||
|
||||
namespace MediaBrowser.Server.Mono
|
||||
{
|
||||
|
@ -123,11 +121,6 @@ namespace MediaBrowser.Server.Mono
|
|||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
protected override IDbConnector GetDbConnector()
|
||||
{
|
||||
return new DbConnector(Logger);
|
||||
}
|
||||
|
||||
protected override void ConfigureAutoRunInternal(bool autorun)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
using System.Data;
|
||||
using System.Threading.Tasks;
|
||||
using Emby.Server.Core.Data;
|
||||
using MediaBrowser.Model.Logging;
|
||||
|
||||
namespace MediaBrowser.Server.Mono.Native
|
||||
{
|
||||
public class DbConnector : IDbConnector
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public DbConnector(ILogger logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public Task<IDbConnection> Connect(string dbPath, bool isReadOnly, bool enablePooling = false, int? cacheSize = null)
|
||||
{
|
||||
return SqliteExtensions.ConnectToDb(dbPath, isReadOnly, enablePooling, cacheSize, _logger);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -102,10 +102,6 @@
|
|||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Configuration.Install" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Data.SQLite, Version=1.0.103.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\ThirdParty\System.Data.SQLite.ManagedOnly\1.0.94.0\System.Data.SQLite.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.IO.Compression" />
|
||||
<Reference Include="System.Management" />
|
||||
|
@ -121,9 +117,6 @@
|
|||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\MediaBrowser.Server.Startup.Common\Persistence\SqliteExtensions.cs">
|
||||
<Link>Native\SqliteExtensions.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\SharedVersion.cs">
|
||||
<Link>Properties\SharedVersion.cs</Link>
|
||||
</Compile>
|
||||
|
@ -141,7 +134,6 @@
|
|||
</Compile>
|
||||
<Compile Include="MainStartup.cs" />
|
||||
<Compile Include="Native\LnkShortcutHandler.cs" />
|
||||
<Compile Include="Native\DbConnector.cs" />
|
||||
<Compile Include="Native\LoopbackUtil.cs" />
|
||||
<Compile Include="Native\PowerManagement.cs" />
|
||||
<Compile Include="Native\Standby.cs" />
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
using System.Data;
|
||||
using System.Threading.Tasks;
|
||||
using Emby.Server.Core.Data;
|
||||
using MediaBrowser.Model.Logging;
|
||||
|
||||
namespace MediaBrowser.ServerApplication.Native
|
||||
{
|
||||
public class DbConnector : IDbConnector
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public DbConnector(ILogger logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public Task<IDbConnection> Connect(string dbPath, bool isReadOnly, bool enablePooling = false, int? cacheSize = null)
|
||||
{
|
||||
return SqliteExtensions.ConnectToDb(dbPath, isReadOnly, enablePooling, cacheSize, _logger);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,7 +4,6 @@ using System.Diagnostics;
|
|||
using System.IO;
|
||||
using System.Reflection;
|
||||
using Emby.Server.Core;
|
||||
using Emby.Server.Core.Data;
|
||||
using Emby.Server.Implementations;
|
||||
using Emby.Server.Implementations.EntryPoints;
|
||||
using Emby.Server.Implementations.FFMpeg;
|
||||
|
@ -92,11 +91,6 @@ namespace MediaBrowser.ServerApplication
|
|||
ConfigurationManager.CommonApplicationPaths.TempDirectory);
|
||||
}
|
||||
|
||||
protected override IDbConnector GetDbConnector()
|
||||
{
|
||||
return new DbConnector(Logger);
|
||||
}
|
||||
|
||||
protected override void ConfigureAutoRunInternal(bool autorun)
|
||||
{
|
||||
var shortcutPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.StartMenu), "Emby", "Emby Server.lnk");
|
||||
|
|
Loading…
Reference in New Issue
Block a user