mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
commit
2ea0f7c545
@ -509,7 +509,7 @@ namespace Emby.Dlna.ContentDirectory
|
|||||||
{
|
{
|
||||||
var itemsResult = _libraryManager.GetItemsResult(new InternalItemsQuery(user)
|
var itemsResult = _libraryManager.GetItemsResult(new InternalItemsQuery(user)
|
||||||
{
|
{
|
||||||
Person = person.Name,
|
PersonIds = new[] { person.Id.ToString("N") },
|
||||||
IncludeItemTypes = new[] { typeof(Movie).Name, typeof(Series).Name, typeof(Trailer).Name },
|
IncludeItemTypes = new[] { typeof(Movie).Name, typeof(Series).Name, typeof(Trailer).Name },
|
||||||
SortBy = new[] { ItemSortBy.SortName },
|
SortBy = new[] { ItemSortBy.SortName },
|
||||||
Limit = limit,
|
Limit = limit,
|
||||||
|
@ -238,6 +238,12 @@ namespace Emby.Dlna
|
|||||||
|
|
||||||
private bool IsMatch(IDictionary<string, string> headers, HttpHeaderInfo header)
|
private bool IsMatch(IDictionary<string, string> headers, HttpHeaderInfo header)
|
||||||
{
|
{
|
||||||
|
// Handle invalid user setup
|
||||||
|
if (string.IsNullOrWhiteSpace(header.Name))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
string value;
|
string value;
|
||||||
|
|
||||||
if (headers.TryGetValue(header.Name, out value))
|
if (headers.TryGetValue(header.Name, out value))
|
||||||
|
@ -84,7 +84,6 @@ using Emby.Dlna.Ssdp;
|
|||||||
using Emby.Server.Core;
|
using Emby.Server.Core;
|
||||||
using Emby.Server.Implementations.Activity;
|
using Emby.Server.Implementations.Activity;
|
||||||
using Emby.Server.Core.Configuration;
|
using Emby.Server.Core.Configuration;
|
||||||
using Emby.Server.Core.Data;
|
|
||||||
using Emby.Server.Implementations.Devices;
|
using Emby.Server.Implementations.Devices;
|
||||||
using Emby.Server.Implementations.FFMpeg;
|
using Emby.Server.Implementations.FFMpeg;
|
||||||
using Emby.Server.Core.IO;
|
using Emby.Server.Core.IO;
|
||||||
@ -550,7 +549,7 @@ namespace Emby.Server.Core
|
|||||||
DisplayPreferencesRepository = displayPreferencesRepo;
|
DisplayPreferencesRepository = displayPreferencesRepo;
|
||||||
RegisterSingleInstance(DisplayPreferencesRepository);
|
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;
|
ItemRepository = itemRepo;
|
||||||
RegisterSingleInstance(ItemRepository);
|
RegisterSingleInstance(ItemRepository);
|
||||||
|
|
||||||
@ -693,10 +692,10 @@ namespace Emby.Server.Core
|
|||||||
|
|
||||||
displayPreferencesRepo.Initialize();
|
displayPreferencesRepo.Initialize();
|
||||||
|
|
||||||
var userDataRepo = new SqliteUserDataRepository(LogManager, ApplicationPaths, GetDbConnector());
|
var userDataRepo = new SqliteUserDataRepository(LogManager.GetLogger("SqliteUserDataRepository"), ApplicationPaths);
|
||||||
|
|
||||||
((UserDataManager)UserDataManager).Repository = userDataRepo;
|
((UserDataManager)UserDataManager).Repository = userDataRepo;
|
||||||
await itemRepo.Initialize(userDataRepo).ConfigureAwait(false);
|
itemRepo.Initialize(userDataRepo);
|
||||||
((LibraryManager)LibraryManager).ItemRepository = ItemRepository;
|
((LibraryManager)LibraryManager).ItemRepository = ItemRepository;
|
||||||
ConfigureNotificationsRepository();
|
ConfigureNotificationsRepository();
|
||||||
progress.Report(100);
|
progress.Report(100);
|
||||||
@ -1444,7 +1443,6 @@ namespace Emby.Server.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void AuthorizeServer();
|
protected abstract void AuthorizeServer();
|
||||||
protected abstract IDbConnector GetDbConnector();
|
|
||||||
|
|
||||||
public event EventHandler HasUpdateAvailableChanged;
|
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -57,18 +57,21 @@ namespace Emby.Server.Implementations.Activity
|
|||||||
{
|
{
|
||||||
connection.RunInTransaction(db =>
|
connection.RunInTransaction(db =>
|
||||||
{
|
{
|
||||||
var commandText = "replace into ActivityLogEntries (Id, Name, Overview, ShortOverview, Type, ItemId, UserId, DateCreated, LogSeverity) values (?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
using (var statement = db.PrepareStatement("replace into ActivityLogEntries (Id, Name, Overview, ShortOverview, Type, ItemId, UserId, DateCreated, LogSeverity) values (@Id, @Name, @Overview, @ShortOverview, @Type, @ItemId, @UserId, @DateCreated, @LogSeverity)"))
|
||||||
|
{
|
||||||
|
statement.TryBind("@Id", entry.Id.ToGuidParamValue());
|
||||||
|
statement.TryBind("@Name", entry.Name);
|
||||||
|
|
||||||
db.Execute(commandText,
|
statement.TryBind("@Overview", entry.Overview);
|
||||||
entry.Id.ToGuidParamValue(),
|
statement.TryBind("@ShortOverview", entry.ShortOverview);
|
||||||
entry.Name,
|
statement.TryBind("@Type", entry.Type);
|
||||||
entry.Overview,
|
statement.TryBind("@ItemId", entry.ItemId);
|
||||||
entry.ShortOverview,
|
statement.TryBind("@UserId", entry.UserId);
|
||||||
entry.Type,
|
statement.TryBind("@DateCreated", entry.Date.ToDateTimeParamValue());
|
||||||
entry.ItemId,
|
statement.TryBind("@LogSeverity", entry.Severity.ToString());
|
||||||
entry.UserId,
|
|
||||||
entry.Date.ToDateTimeParamValue(),
|
statement.MoveNext();
|
||||||
entry.Severity.ToString());
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -81,14 +84,11 @@ namespace Emby.Server.Implementations.Activity
|
|||||||
using (var connection = CreateConnection(true))
|
using (var connection = CreateConnection(true))
|
||||||
{
|
{
|
||||||
var commandText = BaseActivitySelectText;
|
var commandText = BaseActivitySelectText;
|
||||||
|
|
||||||
var whereClauses = new List<string>();
|
var whereClauses = new List<string>();
|
||||||
var paramList = new List<object>();
|
|
||||||
|
|
||||||
if (minDate.HasValue)
|
if (minDate.HasValue)
|
||||||
{
|
{
|
||||||
whereClauses.Add("DateCreated>=?");
|
whereClauses.Add("DateCreated>=@DateCreated");
|
||||||
paramList.Add(minDate.Value.ToDateTimeParamValue());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var whereTextWithoutPaging = whereClauses.Count == 0 ?
|
var whereTextWithoutPaging = whereClauses.Count == 0 ?
|
||||||
@ -119,14 +119,32 @@ namespace Emby.Server.Implementations.Activity
|
|||||||
commandText += " LIMIT " + limit.Value.ToString(_usCulture);
|
commandText += " LIMIT " + limit.Value.ToString(_usCulture);
|
||||||
}
|
}
|
||||||
|
|
||||||
var totalRecordCount = connection.Query("select count (Id) from ActivityLogEntries" + whereTextWithoutPaging, paramList.ToArray()).SelectScalarInt().First();
|
|
||||||
|
|
||||||
var list = new List<ActivityLogEntry>();
|
var list = new List<ActivityLogEntry>();
|
||||||
|
|
||||||
foreach (var row in connection.Query(commandText, paramList.ToArray()))
|
using (var statement = connection.PrepareStatement(commandText))
|
||||||
|
{
|
||||||
|
if (minDate.HasValue)
|
||||||
|
{
|
||||||
|
statement.TryBind("@DateCreated", minDate.Value.ToDateTimeParamValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var row in statement.ExecuteQuery())
|
||||||
{
|
{
|
||||||
list.Add(GetEntry(row));
|
list.Add(GetEntry(row));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int totalRecordCount;
|
||||||
|
|
||||||
|
using (var statement = connection.PrepareStatement("select count (Id) from ActivityLogEntries" + whereTextWithoutPaging))
|
||||||
|
{
|
||||||
|
if (minDate.HasValue)
|
||||||
|
{
|
||||||
|
statement.TryBind("@DateCreated", minDate.Value.ToDateTimeParamValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
totalRecordCount = statement.ExecuteQuery().SelectScalarInt().First();
|
||||||
|
}
|
||||||
|
|
||||||
return new QueryResult<ActivityLogEntry>()
|
return new QueryResult<ActivityLogEntry>()
|
||||||
{
|
{
|
||||||
|
@ -135,9 +135,9 @@ namespace Emby.Server.Implementations.Data
|
|||||||
});
|
});
|
||||||
|
|
||||||
var numComplete = 0;
|
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();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
|
@ -100,14 +100,17 @@ namespace Emby.Server.Implementations.Data
|
|||||||
|
|
||||||
private void SaveDisplayPreferences(DisplayPreferences displayPreferences, Guid userId, string client, IDatabaseConnection connection)
|
private void SaveDisplayPreferences(DisplayPreferences displayPreferences, Guid userId, string client, IDatabaseConnection connection)
|
||||||
{
|
{
|
||||||
var commandText = "replace into userdisplaypreferences (id, userid, client, data) values (?, ?, ?, ?)";
|
using (var statement = connection.PrepareStatement("replace into userdisplaypreferences (id, userid, client, data) values (@id, @userid, @client, @data)"))
|
||||||
|
{
|
||||||
var serialized = _jsonSerializer.SerializeToBytes(displayPreferences, _memoryStreamProvider);
|
var serialized = _jsonSerializer.SerializeToBytes(displayPreferences, _memoryStreamProvider);
|
||||||
|
|
||||||
connection.Execute(commandText,
|
statement.TryBind("@id", displayPreferences.Id.ToGuidParamValue());
|
||||||
displayPreferences.Id.ToGuidParamValue(),
|
statement.TryBind("@userId", userId.ToGuidParamValue());
|
||||||
userId.ToGuidParamValue(),
|
statement.TryBind("@client", client);
|
||||||
client,
|
statement.TryBind("@data", serialized);
|
||||||
serialized);
|
|
||||||
|
statement.MoveNext();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -163,17 +166,17 @@ namespace Emby.Server.Implementations.Data
|
|||||||
{
|
{
|
||||||
using (var connection = CreateConnection(true))
|
using (var connection = CreateConnection(true))
|
||||||
{
|
{
|
||||||
var commandText = "select data from userdisplaypreferences where id = ? and userId=? and client=?";
|
using (var statement = connection.PrepareStatement("select data from userdisplaypreferences where id = @id and userId=@userId and client=@client"))
|
||||||
|
{
|
||||||
|
statement.TryBind("@id", guidId.ToGuidParamValue());
|
||||||
|
statement.TryBind("@userId", userId.ToGuidParamValue());
|
||||||
|
statement.TryBind("@client", client);
|
||||||
|
|
||||||
var paramList = new List<object>();
|
foreach (var row in statement.ExecuteQuery())
|
||||||
paramList.Add(guidId.ToGuidParamValue());
|
|
||||||
paramList.Add(userId.ToGuidParamValue());
|
|
||||||
paramList.Add(client);
|
|
||||||
|
|
||||||
foreach (var row in connection.Query(commandText, paramList.ToArray()))
|
|
||||||
{
|
{
|
||||||
return Get(row);
|
return Get(row);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return new DisplayPreferences
|
return new DisplayPreferences
|
||||||
{
|
{
|
||||||
@ -197,17 +200,17 @@ namespace Emby.Server.Implementations.Data
|
|||||||
{
|
{
|
||||||
using (var connection = CreateConnection(true))
|
using (var connection = CreateConnection(true))
|
||||||
{
|
{
|
||||||
var commandText = "select data from userdisplaypreferences where userId=?";
|
using (var statement = connection.PrepareStatement("select data from userdisplaypreferences where userId=@userId"))
|
||||||
|
{
|
||||||
|
statement.TryBind("@userId", userId.ToGuidParamValue());
|
||||||
|
|
||||||
var paramList = new List<object>();
|
foreach (var row in statement.ExecuteQuery())
|
||||||
paramList.Add(userId.ToGuidParamValue());
|
|
||||||
|
|
||||||
foreach (var row in connection.Query(commandText, paramList.ToArray()))
|
|
||||||
{
|
{
|
||||||
list.Add(Get(row));
|
list.Add(Get(row));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
@ -137,5 +137,256 @@ namespace Emby.Server.Implementations.Data
|
|||||||
|
|
||||||
db.Execute(commandText, paramList.ToArray());
|
db.Execute(commandText, paramList.ToArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool IsDBNull(this IReadOnlyList<IResultSetValue> result, int index)
|
||||||
|
{
|
||||||
|
return result[index].SQLiteType == SQLiteType.Null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string GetString(this IReadOnlyList<IResultSetValue> result, int index)
|
||||||
|
{
|
||||||
|
return result[index].ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool GetBoolean(this IReadOnlyList<IResultSetValue> result, int index)
|
||||||
|
{
|
||||||
|
return result[index].ToBool();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int GetInt32(this IReadOnlyList<IResultSetValue> result, int index)
|
||||||
|
{
|
||||||
|
return result[index].ToInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static long GetInt64(this IReadOnlyList<IResultSetValue> result, int index)
|
||||||
|
{
|
||||||
|
return result[index].ToInt64();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float GetFloat(this IReadOnlyList<IResultSetValue> result, int index)
|
||||||
|
{
|
||||||
|
return result[index].ToFloat();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Guid GetGuid(this IReadOnlyList<IResultSetValue> result, int index)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
if (statement.BindParameters.TryGetValue(name, out bindParam))
|
||||||
|
{
|
||||||
|
bindParam.Bind(value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CheckName(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void TryBind(this IStatement statement, string name, string value)
|
||||||
|
{
|
||||||
|
IBindParameter bindParam;
|
||||||
|
if (statement.BindParameters.TryGetValue(name, out bindParam))
|
||||||
|
{
|
||||||
|
if (value == null)
|
||||||
|
{
|
||||||
|
bindParam.BindNull();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bindParam.Bind(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CheckName(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void TryBind(this IStatement statement, string name, bool value)
|
||||||
|
{
|
||||||
|
IBindParameter bindParam;
|
||||||
|
if (statement.BindParameters.TryGetValue(name, out bindParam))
|
||||||
|
{
|
||||||
|
bindParam.Bind(value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CheckName(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void TryBind(this IStatement statement, string name, float value)
|
||||||
|
{
|
||||||
|
IBindParameter bindParam;
|
||||||
|
if (statement.BindParameters.TryGetValue(name, out bindParam))
|
||||||
|
{
|
||||||
|
bindParam.Bind(value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CheckName(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void TryBind(this IStatement statement, string name, int value)
|
||||||
|
{
|
||||||
|
IBindParameter bindParam;
|
||||||
|
if (statement.BindParameters.TryGetValue(name, out bindParam))
|
||||||
|
{
|
||||||
|
bindParam.Bind(value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CheckName(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void TryBind(this IStatement statement, string name, Guid value)
|
||||||
|
{
|
||||||
|
IBindParameter bindParam;
|
||||||
|
if (statement.BindParameters.TryGetValue(name, out bindParam))
|
||||||
|
{
|
||||||
|
bindParam.Bind(value.ToGuidParamValue());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CheckName(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void TryBind(this IStatement statement, string name, DateTime value)
|
||||||
|
{
|
||||||
|
IBindParameter bindParam;
|
||||||
|
if (statement.BindParameters.TryGetValue(name, out bindParam))
|
||||||
|
{
|
||||||
|
bindParam.Bind(value.ToDateTimeParamValue());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CheckName(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void TryBind(this IStatement statement, string name, long value)
|
||||||
|
{
|
||||||
|
IBindParameter bindParam;
|
||||||
|
if (statement.BindParameters.TryGetValue(name, out bindParam))
|
||||||
|
{
|
||||||
|
bindParam.Bind(value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CheckName(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void TryBind(this IStatement statement, string name, byte[] value)
|
||||||
|
{
|
||||||
|
IBindParameter bindParam;
|
||||||
|
if (statement.BindParameters.TryGetValue(name, out bindParam))
|
||||||
|
{
|
||||||
|
bindParam.Bind(value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CheckName(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void TryBindNull(this IStatement statement, string name)
|
||||||
|
{
|
||||||
|
IBindParameter bindParam;
|
||||||
|
if (statement.BindParameters.TryGetValue(name, out bindParam))
|
||||||
|
{
|
||||||
|
bindParam.BindNull();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CheckName(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void TryBind(this IStatement statement, string name, DateTime? value)
|
||||||
|
{
|
||||||
|
if (value.HasValue)
|
||||||
|
{
|
||||||
|
TryBind(statement, name, value.Value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TryBindNull(statement, name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void TryBind(this IStatement statement, string name, Guid? value)
|
||||||
|
{
|
||||||
|
if (value.HasValue)
|
||||||
|
{
|
||||||
|
TryBind(statement, name, value.Value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TryBindNull(statement, name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void TryBind(this IStatement statement, string name, int? value)
|
||||||
|
{
|
||||||
|
if (value.HasValue)
|
||||||
|
{
|
||||||
|
TryBind(statement, name, value.Value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TryBindNull(statement, name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void TryBind(this IStatement statement, string name, float? value)
|
||||||
|
{
|
||||||
|
if (value.HasValue)
|
||||||
|
{
|
||||||
|
TryBind(statement, name, value.Value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TryBindNull(statement, name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void TryBind(this IStatement statement, string name, bool? value)
|
||||||
|
{
|
||||||
|
if (value.HasValue)
|
||||||
|
{
|
||||||
|
TryBind(statement, name, value.Value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TryBindNull(statement, name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IEnumerable<IReadOnlyList<IResultSetValue>> ExecuteQuery(
|
||||||
|
this IStatement This)
|
||||||
|
{
|
||||||
|
while (This.MoveNext())
|
||||||
|
{
|
||||||
|
yield return This.Current;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,331 +1,359 @@
|
|||||||
//using System;
|
using System;
|
||||||
//using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
//using System.IO;
|
using System.IO;
|
||||||
//using System.Linq;
|
using System.Linq;
|
||||||
//using System.Threading;
|
using System.Threading;
|
||||||
//using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
//using MediaBrowser.Common.Configuration;
|
using MediaBrowser.Common.Configuration;
|
||||||
//using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Entities;
|
||||||
//using MediaBrowser.Controller.Persistence;
|
using MediaBrowser.Controller.Persistence;
|
||||||
//using MediaBrowser.Model.Logging;
|
using MediaBrowser.Model.Logging;
|
||||||
//using SQLitePCL.pretty;
|
using SQLitePCL.pretty;
|
||||||
|
|
||||||
//namespace Emby.Server.Implementations.Data
|
namespace Emby.Server.Implementations.Data
|
||||||
//{
|
{
|
||||||
// public class SqliteUserDataRepository : BaseSqliteRepository, IUserDataRepository
|
public class SqliteUserDataRepository : BaseSqliteRepository, IUserDataRepository
|
||||||
// {
|
{
|
||||||
// private SQLiteDatabaseConnection _connection;
|
private SQLiteDatabaseConnection _connection;
|
||||||
|
|
||||||
// public SqliteUserDataRepository(ILogger logger, IApplicationPaths appPaths)
|
public SqliteUserDataRepository(ILogger logger, IApplicationPaths appPaths)
|
||||||
// : base(logger)
|
: base(logger)
|
||||||
// {
|
{
|
||||||
// DbFilePath = Path.Combine(appPaths.DataPath, "userdata_v2.db");
|
DbFilePath = Path.Combine(appPaths.DataPath, "userdata_v2.db");
|
||||||
// }
|
}
|
||||||
|
|
||||||
// protected override bool EnableConnectionPooling
|
protected override bool EnableConnectionPooling
|
||||||
// {
|
{
|
||||||
// get { return false; }
|
get { return false; }
|
||||||
// }
|
}
|
||||||
|
|
||||||
// /// <summary>
|
/// <summary>
|
||||||
// /// Gets the name of the repository
|
/// Gets the name of the repository
|
||||||
// /// </summary>
|
/// </summary>
|
||||||
// /// <value>The name.</value>
|
/// <value>The name.</value>
|
||||||
// public string Name
|
public string Name
|
||||||
// {
|
{
|
||||||
// get
|
get
|
||||||
// {
|
{
|
||||||
// return "SQLite";
|
return "SQLite";
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
// /// <summary>
|
/// <summary>
|
||||||
// /// Opens the connection to the database
|
/// Opens the connection to the database
|
||||||
// /// </summary>
|
/// </summary>
|
||||||
// /// <returns>Task.</returns>
|
/// <returns>Task.</returns>
|
||||||
// public void Initialize(SQLiteDatabaseConnection connection, ReaderWriterLockSlim writeLock)
|
public void Initialize(SQLiteDatabaseConnection connection, ReaderWriterLockSlim writeLock)
|
||||||
// {
|
{
|
||||||
// WriteLock.Dispose();
|
WriteLock.Dispose();
|
||||||
// WriteLock = writeLock;
|
WriteLock = writeLock;
|
||||||
// _connection = connection;
|
_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_userdata",
|
||||||
// "drop index if exists UserDataDb.idx_userdata1",
|
"drop index if exists UserDataDb.idx_userdata1",
|
||||||
// "drop index if exists UserDataDb.idx_userdata2",
|
"drop index if exists UserDataDb.idx_userdata2",
|
||||||
// "drop index if exists UserDataDb.userdataindex1",
|
"drop index if exists UserDataDb.userdataindex1",
|
||||||
|
|
||||||
// "create unique index if not exists UserDataDb.userdataindex on userdata (key, userId)",
|
"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.userdataindex2 on userdata (key, userId, played)",
|
||||||
// "create index if not exists UserDataDb.userdataindex3 on userdata (key, userId, playbackPositionTicks)",
|
"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 index if not exists UserDataDb.userdataindex4 on userdata (key, userId, isFavorite)",
|
||||||
|
|
||||||
// //pragmas
|
//pragmas
|
||||||
// "pragma temp_store = memory",
|
"pragma temp_store = memory",
|
||||||
|
|
||||||
// "pragma shrink_memory"
|
"pragma shrink_memory"
|
||||||
// };
|
};
|
||||||
|
|
||||||
// _connection.RunQueries(queries);
|
_connection.RunQueries(queries);
|
||||||
|
|
||||||
// connection.RunInTransaction(db =>
|
connection.RunInTransaction(db =>
|
||||||
// {
|
{
|
||||||
// var existingColumnNames = GetColumnNames(db, "userdata");
|
var existingColumnNames = GetColumnNames(db, "userdata");
|
||||||
|
|
||||||
// AddColumn(db, "userdata", "AudioStreamIndex", "int", existingColumnNames);
|
AddColumn(db, "userdata", "AudioStreamIndex", "int", existingColumnNames);
|
||||||
// AddColumn(db, "userdata", "SubtitleStreamIndex", "int", existingColumnNames);
|
AddColumn(db, "userdata", "SubtitleStreamIndex", "int", existingColumnNames);
|
||||||
// });
|
});
|
||||||
// }
|
}
|
||||||
|
|
||||||
// /// <summary>
|
/// <summary>
|
||||||
// /// Saves the user data.
|
/// Saves the user data.
|
||||||
// /// </summary>
|
/// </summary>
|
||||||
// /// <param name="userId">The user id.</param>
|
/// <param name="userId">The user id.</param>
|
||||||
// /// <param name="key">The key.</param>
|
/// <param name="key">The key.</param>
|
||||||
// /// <param name="userData">The user data.</param>
|
/// <param name="userData">The user data.</param>
|
||||||
// /// <param name="cancellationToken">The cancellation token.</param>
|
/// <param name="cancellationToken">The cancellation token.</param>
|
||||||
// /// <returns>Task.</returns>
|
/// <returns>Task.</returns>
|
||||||
// /// <exception cref="System.ArgumentNullException">userData
|
/// <exception cref="System.ArgumentNullException">userData
|
||||||
// /// or
|
/// or
|
||||||
// /// cancellationToken
|
/// cancellationToken
|
||||||
// /// or
|
/// or
|
||||||
// /// userId
|
/// userId
|
||||||
// /// or
|
/// or
|
||||||
// /// userDataId</exception>
|
/// userDataId</exception>
|
||||||
// public Task SaveUserData(Guid userId, string key, UserItemData userData, CancellationToken cancellationToken)
|
public Task SaveUserData(Guid userId, string key, UserItemData userData, CancellationToken cancellationToken)
|
||||||
// {
|
{
|
||||||
// if (userData == null)
|
if (userData == null)
|
||||||
// {
|
{
|
||||||
// throw new ArgumentNullException("userData");
|
throw new ArgumentNullException("userData");
|
||||||
// }
|
}
|
||||||
// if (userId == Guid.Empty)
|
if (userId == Guid.Empty)
|
||||||
// {
|
{
|
||||||
// throw new ArgumentNullException("userId");
|
throw new ArgumentNullException("userId");
|
||||||
// }
|
}
|
||||||
// if (string.IsNullOrEmpty(key))
|
if (string.IsNullOrEmpty(key))
|
||||||
// {
|
{
|
||||||
// throw new ArgumentNullException("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)
|
public Task SaveAllUserData(Guid userId, IEnumerable<UserItemData> userData, CancellationToken cancellationToken)
|
||||||
// {
|
{
|
||||||
// if (userData == null)
|
if (userData == null)
|
||||||
// {
|
{
|
||||||
// throw new ArgumentNullException("userData");
|
throw new ArgumentNullException("userData");
|
||||||
// }
|
}
|
||||||
// if (userId == Guid.Empty)
|
if (userId == Guid.Empty)
|
||||||
// {
|
{
|
||||||
// throw new ArgumentNullException("userId");
|
throw new ArgumentNullException("userId");
|
||||||
// }
|
}
|
||||||
|
|
||||||
// return PersistAllUserData(userId, userData.ToList(), cancellationToken);
|
return PersistAllUserData(userId, userData.ToList(), cancellationToken);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// /// <summary>
|
/// <summary>
|
||||||
// /// Persists the user data.
|
/// Persists the user data.
|
||||||
// /// </summary>
|
/// </summary>
|
||||||
// /// <param name="userId">The user id.</param>
|
/// <param name="userId">The user id.</param>
|
||||||
// /// <param name="key">The key.</param>
|
/// <param name="key">The key.</param>
|
||||||
// /// <param name="userData">The user data.</param>
|
/// <param name="userData">The user data.</param>
|
||||||
// /// <param name="cancellationToken">The cancellation token.</param>
|
/// <param name="cancellationToken">The cancellation token.</param>
|
||||||
// /// <returns>Task.</returns>
|
/// <returns>Task.</returns>
|
||||||
// public async Task PersistUserData(Guid userId, string key, UserItemData userData, CancellationToken cancellationToken)
|
public async Task PersistUserData(Guid userId, string key, UserItemData userData, CancellationToken cancellationToken)
|
||||||
// {
|
{
|
||||||
// cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
// using (WriteLock.Write())
|
using (WriteLock.Write())
|
||||||
// {
|
{
|
||||||
// _connection.RunInTransaction(db =>
|
_connection.RunInTransaction(db =>
|
||||||
// {
|
{
|
||||||
// SaveUserData(db, userId, key, userData);
|
SaveUserData(db, userId, key, userData);
|
||||||
// });
|
});
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
// private void SaveUserData(IDatabaseConnection db, Guid userId, string key, UserItemData userData)
|
private void SaveUserData(IDatabaseConnection db, Guid userId, string key, UserItemData userData)
|
||||||
// {
|
{
|
||||||
// var paramList = new List<object>();
|
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)"))
|
||||||
// var commandText = "replace into userdata (key, userId, rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex) values (?, ?, ?,?,?,?,?,?,?,?)";
|
{
|
||||||
|
statement.TryBind("@UserId", userId.ToGuidParamValue());
|
||||||
|
statement.TryBind("@Key", key);
|
||||||
|
|
||||||
// paramList.Add(key);
|
if (userData.Rating.HasValue)
|
||||||
// paramList.Add(userId.ToGuidParamValue());
|
{
|
||||||
// paramList.Add(userData.Rating);
|
statement.TryBind("@rating", userData.Rating.Value);
|
||||||
// paramList.Add(userData.Played);
|
}
|
||||||
// paramList.Add(userData.PlayCount);
|
else
|
||||||
// paramList.Add(userData.IsFavorite);
|
{
|
||||||
// paramList.Add(userData.PlaybackPositionTicks);
|
statement.TryBindNull("@rating");
|
||||||
|
}
|
||||||
|
|
||||||
// if (userData.LastPlayedDate.HasValue)
|
statement.TryBind("@played", userData.Played);
|
||||||
// {
|
statement.TryBind("@playCount", userData.PlayCount);
|
||||||
// paramList.Add(userData.LastPlayedDate.Value.ToDateTimeParamValue());
|
statement.TryBind("@isFavorite", userData.IsFavorite);
|
||||||
// }
|
statement.TryBind("@playbackPositionTicks", userData.PlaybackPositionTicks);
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// paramList.Add(null);
|
|
||||||
// }
|
|
||||||
// paramList.Add(userData.AudioStreamIndex);
|
|
||||||
// paramList.Add(userData.SubtitleStreamIndex);
|
|
||||||
|
|
||||||
// db.Execute(commandText, paramList.ToArray());
|
if (userData.LastPlayedDate.HasValue)
|
||||||
// }
|
{
|
||||||
|
statement.TryBind("@lastPlayedDate", userData.LastPlayedDate.Value.ToDateTimeParamValue());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
statement.TryBindNull("@lastPlayedDate");
|
||||||
|
}
|
||||||
|
|
||||||
// /// <summary>
|
if (userData.AudioStreamIndex.HasValue)
|
||||||
// /// Persist all user data for the specified user
|
{
|
||||||
// /// </summary>
|
statement.TryBind("@AudioStreamIndex", userData.AudioStreamIndex.Value);
|
||||||
// private async Task PersistAllUserData(Guid userId, List<UserItemData> userDataList, CancellationToken cancellationToken)
|
}
|
||||||
// {
|
else
|
||||||
// cancellationToken.ThrowIfCancellationRequested();
|
{
|
||||||
|
statement.TryBindNull("@AudioStreamIndex");
|
||||||
|
}
|
||||||
|
|
||||||
// using (WriteLock.Write())
|
if (userData.SubtitleStreamIndex.HasValue)
|
||||||
// {
|
{
|
||||||
// _connection.RunInTransaction(db =>
|
statement.TryBind("@SubtitleStreamIndex", userData.SubtitleStreamIndex.Value);
|
||||||
// {
|
}
|
||||||
// foreach (var userItemData in userDataList)
|
else
|
||||||
// {
|
{
|
||||||
// SaveUserData(db, userId, userItemData.Key, userItemData);
|
statement.TryBindNull("@SubtitleStreamIndex");
|
||||||
// }
|
}
|
||||||
// });
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// /// <summary>
|
statement.MoveNext();
|
||||||
// /// 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");
|
|
||||||
// }
|
|
||||||
|
|
||||||
// var commandText = "select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where key = ? and userId=?";
|
/// <summary>
|
||||||
|
/// Persist all user data for the specified user
|
||||||
|
/// </summary>
|
||||||
|
private async Task PersistAllUserData(Guid userId, List<UserItemData> userDataList, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
// var paramList = new List<object>();
|
using (WriteLock.Write())
|
||||||
// paramList.Add(key);
|
{
|
||||||
// paramList.Add(userId.ToGuidParamValue());
|
_connection.RunInTransaction(db =>
|
||||||
|
{
|
||||||
|
foreach (var userItemData in userDataList)
|
||||||
|
{
|
||||||
|
SaveUserData(db, userId, userItemData.Key, userItemData);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// foreach (var row in _connection.Query(commandText, paramList.ToArray()))
|
/// <summary>
|
||||||
// {
|
/// Gets the user data.
|
||||||
// return ReadRow(row);
|
/// </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");
|
||||||
|
}
|
||||||
|
|
||||||
// return null;
|
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);
|
||||||
|
|
||||||
// public UserItemData GetUserData(Guid userId, List<string> keys)
|
foreach (var row in statement.ExecuteQuery())
|
||||||
// {
|
{
|
||||||
// if (userId == Guid.Empty)
|
return ReadRow(row);
|
||||||
// {
|
}
|
||||||
// throw new ArgumentNullException("userId");
|
}
|
||||||
// }
|
}
|
||||||
// if (keys == null)
|
|
||||||
// {
|
|
||||||
// throw new ArgumentNullException("keys");
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (keys.Count == 0)
|
return null;
|
||||||
// {
|
}
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return GetUserData(userId, keys[0]);
|
public UserItemData GetUserData(Guid userId, List<string> keys)
|
||||||
// }
|
{
|
||||||
|
if (userId == Guid.Empty)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("userId");
|
||||||
|
}
|
||||||
|
if (keys == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("keys");
|
||||||
|
}
|
||||||
|
|
||||||
// /// <summary>
|
if (keys.Count == 0)
|
||||||
// /// Return all user-data associated with the given user
|
{
|
||||||
// /// </summary>
|
return null;
|
||||||
// /// <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>();
|
return GetUserData(userId, keys[0]);
|
||||||
|
}
|
||||||
|
|
||||||
// using (WriteLock.Read())
|
/// <summary>
|
||||||
// {
|
/// Return all user-data associated with the given user
|
||||||
// var commandText = "select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where userId=?";
|
/// </summary>
|
||||||
|
/// <param name="userId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public IEnumerable<UserItemData> GetAllUserData(Guid userId)
|
||||||
|
{
|
||||||
|
if (userId == Guid.Empty)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("userId");
|
||||||
|
}
|
||||||
|
|
||||||
// var paramList = new List<object>();
|
var list = new List<UserItemData>();
|
||||||
// paramList.Add(userId.ToGuidParamValue());
|
|
||||||
|
|
||||||
// foreach (var row in _connection.Query(commandText, paramList.ToArray()))
|
using (WriteLock.Write())
|
||||||
// {
|
{
|
||||||
// list.Add(ReadRow(row));
|
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());
|
||||||
|
|
||||||
// return list;
|
foreach (var row in statement.ExecuteQuery())
|
||||||
// }
|
{
|
||||||
|
list.Add(ReadRow(row));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// /// <summary>
|
return list;
|
||||||
// /// 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();
|
/// <summary>
|
||||||
// userData.UserId = reader[1].ReadGuid();
|
/// 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();
|
||||||
|
|
||||||
// if (reader[2].SQLiteType != SQLiteType.Null)
|
userData.Key = reader[0].ToString();
|
||||||
// {
|
userData.UserId = reader[1].ReadGuid();
|
||||||
// userData.Rating = reader[2].ToDouble();
|
|
||||||
// }
|
|
||||||
|
|
||||||
// userData.Played = reader[3].ToBool();
|
if (reader[2].SQLiteType != SQLiteType.Null)
|
||||||
// userData.PlayCount = reader[4].ToInt();
|
{
|
||||||
// userData.IsFavorite = reader[5].ToBool();
|
userData.Rating = reader[2].ToDouble();
|
||||||
// userData.PlaybackPositionTicks = reader[6].ToInt64();
|
}
|
||||||
|
|
||||||
// if (reader[7].SQLiteType != SQLiteType.Null)
|
userData.Played = reader[3].ToBool();
|
||||||
// {
|
userData.PlayCount = reader[4].ToInt();
|
||||||
// userData.LastPlayedDate = reader[7].ReadDateTime();
|
userData.IsFavorite = reader[5].ToBool();
|
||||||
// }
|
userData.PlaybackPositionTicks = reader[6].ToInt64();
|
||||||
|
|
||||||
// if (reader[8].SQLiteType != SQLiteType.Null)
|
if (reader[7].SQLiteType != SQLiteType.Null)
|
||||||
// {
|
{
|
||||||
// userData.AudioStreamIndex = reader[8].ToInt();
|
userData.LastPlayedDate = reader[7].ReadDateTime();
|
||||||
// }
|
}
|
||||||
|
|
||||||
// if (reader[9].SQLiteType != SQLiteType.Null)
|
if (reader[8].SQLiteType != SQLiteType.Null)
|
||||||
// {
|
{
|
||||||
// userData.SubtitleStreamIndex = reader[9].ToInt();
|
userData.AudioStreamIndex = reader[8].ToInt();
|
||||||
// }
|
}
|
||||||
|
|
||||||
// return userData;
|
if (reader[9].SQLiteType != SQLiteType.Null)
|
||||||
// }
|
{
|
||||||
|
userData.SubtitleStreamIndex = reader[9].ToInt();
|
||||||
|
}
|
||||||
|
|
||||||
// protected override void Dispose(bool dispose)
|
return userData;
|
||||||
// {
|
}
|
||||||
// // handled by library database
|
|
||||||
// }
|
|
||||||
|
|
||||||
// protected override void CloseConnection()
|
protected override void Dispose(bool dispose)
|
||||||
// {
|
{
|
||||||
// // handled by library database
|
// handled by library database
|
||||||
// }
|
}
|
||||||
// }
|
|
||||||
//}
|
protected override void CloseConnection()
|
||||||
|
{
|
||||||
|
// handled by library database
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -89,11 +89,12 @@ namespace Emby.Server.Implementations.Data
|
|||||||
{
|
{
|
||||||
connection.RunInTransaction(db =>
|
connection.RunInTransaction(db =>
|
||||||
{
|
{
|
||||||
var commandText = "replace into users (guid, data) values (?, ?)";
|
using (var statement = db.PrepareStatement("replace into users (guid, data) values (@guid, @data)"))
|
||||||
|
{
|
||||||
db.Execute(commandText,
|
statement.TryBind("@guid", user.Id.ToGuidParamValue());
|
||||||
user.Id.ToGuidParamValue(),
|
statement.TryBind("@data", serialized);
|
||||||
serialized);
|
statement.MoveNext();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -151,10 +152,11 @@ namespace Emby.Server.Implementations.Data
|
|||||||
{
|
{
|
||||||
connection.RunInTransaction(db =>
|
connection.RunInTransaction(db =>
|
||||||
{
|
{
|
||||||
var commandText = "delete from users where guid=?";
|
using (var statement = db.PrepareStatement("delete from users where guid=@id"))
|
||||||
|
{
|
||||||
db.Execute(commandText,
|
statement.TryBind("@id", user.Id.ToGuidParamValue());
|
||||||
user.Id.ToGuidParamValue());
|
statement.MoveNext();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ namespace Emby.Server.Implementations.FileOrganization
|
|||||||
return new[] {
|
return new[] {
|
||||||
|
|
||||||
// Every so often
|
// Every so often
|
||||||
new TaskTriggerInfo { Type = TaskTriggerInfo.TriggerInterval, IntervalTicks = TimeSpan.FromMinutes(15).Ticks}
|
new TaskTriggerInfo { Type = TaskTriggerInfo.TriggerInterval, IntervalTicks = TimeSpan.FromMinutes(5).Ticks}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,7 +107,12 @@ namespace Emby.Server.Implementations.Notifications
|
|||||||
{
|
{
|
||||||
using (var connection = CreateConnection(true))
|
using (var connection = CreateConnection(true))
|
||||||
{
|
{
|
||||||
foreach (var row in connection.Query("select Level from Notifications where UserId=? and IsRead=?", userId.ToGuidParamValue(), false))
|
using (var statement = connection.PrepareStatement("select Level from Notifications where UserId=@UserId and IsRead=@IsRead"))
|
||||||
|
{
|
||||||
|
statement.TryBind("@IsRead", false);
|
||||||
|
statement.TryBind("@UserId", userId.ToGuidParamValue());
|
||||||
|
|
||||||
|
foreach (var row in statement.ExecuteQuery())
|
||||||
{
|
{
|
||||||
var levels = new List<NotificationLevel>();
|
var levels = new List<NotificationLevel>();
|
||||||
|
|
||||||
@ -120,6 +125,7 @@ namespace Emby.Server.Implementations.Notifications
|
|||||||
result.MaxUnreadNotificationLevel = levels.Max();
|
result.MaxUnreadNotificationLevel = levels.Max();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -220,17 +226,21 @@ namespace Emby.Server.Implementations.Notifications
|
|||||||
{
|
{
|
||||||
connection.RunInTransaction(conn =>
|
connection.RunInTransaction(conn =>
|
||||||
{
|
{
|
||||||
conn.Execute("replace into Notifications (Id, UserId, Date, Name, Description, Url, Level, IsRead, Category, RelatedId) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
using (var statement = conn.PrepareStatement("replace into Notifications (Id, UserId, Date, Name, Description, Url, Level, IsRead, Category, RelatedId) values (@Id, @UserId, @Date, @Name, @Description, @Url, @Level, @IsRead, @Category, @RelatedId)"))
|
||||||
notification.Id.ToGuidParamValue(),
|
{
|
||||||
notification.UserId.ToGuidParamValue(),
|
statement.TryBind("@Id", notification.Id.ToGuidParamValue());
|
||||||
notification.Date.ToDateTimeParamValue(),
|
statement.TryBind("@UserId", notification.UserId.ToGuidParamValue());
|
||||||
notification.Name,
|
statement.TryBind("@Date", notification.Date.ToDateTimeParamValue());
|
||||||
notification.Description,
|
statement.TryBind("@Name", notification.Name);
|
||||||
notification.Url,
|
statement.TryBind("@Description", notification.Description);
|
||||||
notification.Level.ToString(),
|
statement.TryBind("@Url", notification.Url);
|
||||||
notification.IsRead,
|
statement.TryBind("@Level", notification.Level.ToString());
|
||||||
string.Empty,
|
statement.TryBind("@IsRead", notification.IsRead);
|
||||||
string.Empty);
|
statement.TryBind("@Category", string.Empty);
|
||||||
|
statement.TryBind("@RelatedId", string.Empty);
|
||||||
|
|
||||||
|
statement.MoveNext();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -279,7 +289,13 @@ namespace Emby.Server.Implementations.Notifications
|
|||||||
{
|
{
|
||||||
connection.RunInTransaction(conn =>
|
connection.RunInTransaction(conn =>
|
||||||
{
|
{
|
||||||
conn.Execute("update Notifications set IsRead=? where UserId=?", userId.ToGuidParamValue(), isRead);
|
using (var statement = conn.PrepareStatement("update Notifications set IsRead=@IsRead where UserId=@UserId"))
|
||||||
|
{
|
||||||
|
statement.TryBind("@IsRead", isRead);
|
||||||
|
statement.TryBind("@UserId", userId.ToGuidParamValue());
|
||||||
|
|
||||||
|
statement.MoveNext();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -295,12 +311,21 @@ namespace Emby.Server.Implementations.Notifications
|
|||||||
{
|
{
|
||||||
connection.RunInTransaction(conn =>
|
connection.RunInTransaction(conn =>
|
||||||
{
|
{
|
||||||
var userIdParam = userId.ToGuidParamValue();
|
using (var statement = conn.PrepareStatement("update Notifications set IsRead=@IsRead where UserId=@UserId and Id=@Id"))
|
||||||
|
{
|
||||||
|
statement.TryBind("@IsRead", isRead);
|
||||||
|
statement.TryBind("@UserId", userId.ToGuidParamValue());
|
||||||
|
|
||||||
foreach (var id in notificationIdList)
|
foreach (var id in notificationIdList)
|
||||||
{
|
{
|
||||||
conn.Execute("update Notifications set IsRead=? where UserId=? and Id=?", userIdParam, isRead, id);
|
statement.Reset();
|
||||||
|
|
||||||
|
statement.TryBind("@Id", id.ToGuidParamValue());
|
||||||
|
|
||||||
|
statement.MoveNext();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,19 +69,30 @@ namespace Emby.Server.Implementations.Security
|
|||||||
{
|
{
|
||||||
connection.RunInTransaction(db =>
|
connection.RunInTransaction(db =>
|
||||||
{
|
{
|
||||||
var commandText = "replace into AccessTokens (Id, AccessToken, DeviceId, AppName, AppVersion, DeviceName, UserId, IsActive, DateCreated, DateRevoked) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
using (var statement = db.PrepareStatement("replace into AccessTokens (Id, AccessToken, DeviceId, AppName, AppVersion, DeviceName, UserId, IsActive, DateCreated, DateRevoked) values (@Id, @AccessToken, @DeviceId, @AppName, @AppVersion, @DeviceName, @UserId, @IsActive, @DateCreated, @DateRevoked)"))
|
||||||
|
{
|
||||||
|
statement.TryBind("@Id", info.Id.ToGuidParamValue());
|
||||||
|
statement.TryBind("@AccessToken", info.AccessToken);
|
||||||
|
|
||||||
db.Execute(commandText,
|
statement.TryBind("@DeviceId", info.DeviceId);
|
||||||
info.Id.ToGuidParamValue(),
|
statement.TryBind("@AppName", info.AppName);
|
||||||
info.AccessToken,
|
statement.TryBind("@AppVersion", info.AppVersion);
|
||||||
info.DeviceId,
|
statement.TryBind("@DeviceName", info.DeviceName);
|
||||||
info.AppName,
|
statement.TryBind("@UserId", info.UserId);
|
||||||
info.AppVersion,
|
statement.TryBind("@IsActive", info.IsActive);
|
||||||
info.DeviceName,
|
statement.TryBind("@DateCreated", info.DateCreated.ToDateTimeParamValue());
|
||||||
info.UserId,
|
|
||||||
info.IsActive,
|
if (info.DateRevoked.HasValue)
|
||||||
info.DateCreated.ToDateTimeParamValue(),
|
{
|
||||||
info.DateRevoked.HasValue ? info.DateRevoked.Value.ToDateTimeParamValue() : null);
|
statement.TryBind("@DateRevoked", info.DateRevoked.Value.ToDateTimeParamValue());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
statement.TryBindNull("@DateRevoked");
|
||||||
|
}
|
||||||
|
|
||||||
|
statement.MoveNext();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -89,6 +100,29 @@ namespace Emby.Server.Implementations.Security
|
|||||||
|
|
||||||
private const string BaseSelectText = "select Id, AccessToken, DeviceId, AppName, AppVersion, DeviceName, UserId, IsActive, DateCreated, DateRevoked from AccessTokens";
|
private const string BaseSelectText = "select Id, AccessToken, DeviceId, AppName, AppVersion, DeviceName, UserId, IsActive, DateCreated, DateRevoked from AccessTokens";
|
||||||
|
|
||||||
|
private void BindAuthenticationQueryParams(AuthenticationInfoQuery query, IStatement statement)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrWhiteSpace(query.AccessToken))
|
||||||
|
{
|
||||||
|
statement.TryBind("@AccessToken", query.AccessToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(query.UserId))
|
||||||
|
{
|
||||||
|
statement.TryBind("@UserId", query.UserId);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(query.DeviceId))
|
||||||
|
{
|
||||||
|
statement.TryBind("@DeviceId", query.DeviceId);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (query.IsActive.HasValue)
|
||||||
|
{
|
||||||
|
statement.TryBind("@IsActive", query.IsActive.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public QueryResult<AuthenticationInfo> Get(AuthenticationInfoQuery query)
|
public QueryResult<AuthenticationInfo> Get(AuthenticationInfoQuery query)
|
||||||
{
|
{
|
||||||
if (query == null)
|
if (query == null)
|
||||||
@ -99,7 +133,6 @@ namespace Emby.Server.Implementations.Security
|
|||||||
using (var connection = CreateConnection(true))
|
using (var connection = CreateConnection(true))
|
||||||
{
|
{
|
||||||
var commandText = BaseSelectText;
|
var commandText = BaseSelectText;
|
||||||
var paramList = new List<object>();
|
|
||||||
|
|
||||||
var whereClauses = new List<string>();
|
var whereClauses = new List<string>();
|
||||||
|
|
||||||
@ -107,26 +140,22 @@ namespace Emby.Server.Implementations.Security
|
|||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(query.AccessToken))
|
if (!string.IsNullOrWhiteSpace(query.AccessToken))
|
||||||
{
|
{
|
||||||
whereClauses.Add("AccessToken=?");
|
whereClauses.Add("AccessToken=@AccessToken");
|
||||||
paramList.Add(query.AccessToken);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(query.UserId))
|
if (!string.IsNullOrWhiteSpace(query.UserId))
|
||||||
{
|
{
|
||||||
whereClauses.Add("UserId=?");
|
whereClauses.Add("UserId=@UserId");
|
||||||
paramList.Add(query.UserId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(query.DeviceId))
|
if (!string.IsNullOrWhiteSpace(query.DeviceId))
|
||||||
{
|
{
|
||||||
whereClauses.Add("DeviceId=?");
|
whereClauses.Add("DeviceId=@DeviceId");
|
||||||
paramList.Add(query.DeviceId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (query.IsActive.HasValue)
|
if (query.IsActive.HasValue)
|
||||||
{
|
{
|
||||||
whereClauses.Add("IsActive=?");
|
whereClauses.Add("IsActive=@IsActive");
|
||||||
paramList.Add(query.IsActive.Value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (query.HasUser.HasValue)
|
if (query.HasUser.HasValue)
|
||||||
@ -171,12 +200,20 @@ namespace Emby.Server.Implementations.Security
|
|||||||
|
|
||||||
var list = new List<AuthenticationInfo>();
|
var list = new List<AuthenticationInfo>();
|
||||||
|
|
||||||
foreach (var row in connection.Query(commandText, paramList.ToArray()))
|
using (var statement = connection.PrepareStatement(commandText))
|
||||||
|
{
|
||||||
|
BindAuthenticationQueryParams(query, statement);
|
||||||
|
|
||||||
|
foreach (var row in statement.ExecuteQuery())
|
||||||
{
|
{
|
||||||
list.Add(Get(row));
|
list.Add(Get(row));
|
||||||
}
|
}
|
||||||
|
|
||||||
var count = connection.Query("select count (Id) from AccessTokens" + whereTextWithoutPaging, paramList.ToArray())
|
using (var totalCountStatement = connection.PrepareStatement("select count (Id) from AccessTokens" + whereTextWithoutPaging))
|
||||||
|
{
|
||||||
|
BindAuthenticationQueryParams(query, totalCountStatement);
|
||||||
|
|
||||||
|
var count = totalCountStatement.ExecuteQuery()
|
||||||
.SelectScalarInt()
|
.SelectScalarInt()
|
||||||
.First();
|
.First();
|
||||||
|
|
||||||
@ -187,6 +224,8 @@ namespace Emby.Server.Implementations.Security
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public AuthenticationInfo Get(string id)
|
public AuthenticationInfo Get(string id)
|
||||||
{
|
{
|
||||||
@ -199,12 +238,13 @@ namespace Emby.Server.Implementations.Security
|
|||||||
{
|
{
|
||||||
using (var connection = CreateConnection(true))
|
using (var connection = CreateConnection(true))
|
||||||
{
|
{
|
||||||
var commandText = BaseSelectText + " where Id=?";
|
var commandText = BaseSelectText + " where Id=@Id";
|
||||||
var paramList = new List<object>();
|
|
||||||
|
|
||||||
paramList.Add(id.ToGuidParamValue());
|
using (var statement = connection.PrepareStatement(commandText))
|
||||||
|
{
|
||||||
|
statement.BindParameters["@Id"].Bind(id.ToGuidParamValue());
|
||||||
|
|
||||||
foreach (var row in connection.Query(commandText, paramList.ToArray()))
|
foreach (var row in statement.ExecuteQuery())
|
||||||
{
|
{
|
||||||
return Get(row);
|
return Get(row);
|
||||||
}
|
}
|
||||||
@ -212,6 +252,7 @@ namespace Emby.Server.Implementations.Security
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private AuthenticationInfo Get(IReadOnlyList<IResultSetValue> reader)
|
private AuthenticationInfo Get(IReadOnlyList<IResultSetValue> reader)
|
||||||
{
|
{
|
||||||
|
@ -492,14 +492,11 @@ namespace Emby.Server.Implementations.Sync
|
|||||||
using (var connection = CreateConnection(true))
|
using (var connection = CreateConnection(true))
|
||||||
{
|
{
|
||||||
var commandText = "select ItemId,Status,Progress from SyncJobItems";
|
var commandText = "select ItemId,Status,Progress from SyncJobItems";
|
||||||
|
|
||||||
var whereClauses = new List<string>();
|
var whereClauses = new List<string>();
|
||||||
var paramList = new List<object>();
|
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(query.TargetId))
|
if (!string.IsNullOrWhiteSpace(query.TargetId))
|
||||||
{
|
{
|
||||||
whereClauses.Add("TargetId=?");
|
whereClauses.Add("TargetId=@TargetId");
|
||||||
paramList.Add(query.TargetId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (query.Statuses.Length > 0)
|
if (query.Statuses.Length > 0)
|
||||||
@ -514,24 +511,41 @@ namespace Emby.Server.Implementations.Sync
|
|||||||
commandText += " where " + string.Join(" AND ", whereClauses.ToArray());
|
commandText += " where " + string.Join(" AND ", whereClauses.ToArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var row in connection.Query(commandText, paramList.ToArray()))
|
using (var statement = connection.PrepareStatement(commandText))
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrWhiteSpace(query.TargetId))
|
||||||
|
{
|
||||||
|
statement.TryBind("@TargetId", query.TargetId);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var row in statement.ExecuteQuery())
|
||||||
{
|
{
|
||||||
AddStatusResult(row, result, false);
|
AddStatusResult(row, result, false);
|
||||||
}
|
}
|
||||||
LogQueryTime("GetSyncedItemProgresses", commandText, now);
|
LogQueryTime("GetSyncedItemProgresses", commandText, now);
|
||||||
|
}
|
||||||
|
|
||||||
commandText = commandText
|
commandText = commandText
|
||||||
.Replace("select ItemId,Status,Progress from SyncJobItems", "select ItemIds,Status,Progress from SyncJobs")
|
.Replace("select ItemId,Status,Progress from SyncJobItems", "select ItemIds,Status,Progress from SyncJobs")
|
||||||
.Replace("'Synced'", "'Completed','CompletedWithError'");
|
.Replace("'Synced'", "'Completed','CompletedWithError'");
|
||||||
|
|
||||||
now = DateTime.UtcNow;
|
now = DateTime.UtcNow;
|
||||||
foreach (var row in connection.Query(commandText, paramList.ToArray()))
|
|
||||||
|
using (var statement = connection.PrepareStatement(commandText))
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrWhiteSpace(query.TargetId))
|
||||||
|
{
|
||||||
|
statement.TryBind("@TargetId", query.TargetId);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var row in statement.ExecuteQuery())
|
||||||
{
|
{
|
||||||
AddStatusResult(row, result, true);
|
AddStatusResult(row, result, true);
|
||||||
}
|
}
|
||||||
LogQueryTime("GetSyncedItemProgresses", commandText, now);
|
LogQueryTime("GetSyncedItemProgresses", commandText, now);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ namespace MediaBrowser.Controller.Entities
|
|||||||
|
|
||||||
public IEnumerable<BaseItem> GetTaggedItems(InternalItemsQuery query)
|
public IEnumerable<BaseItem> GetTaggedItems(InternalItemsQuery query)
|
||||||
{
|
{
|
||||||
query.Person = Name;
|
query.PersonIds = new[] { Id.ToString("N") };
|
||||||
|
|
||||||
return LibraryManager.GetItemList(query);
|
return LibraryManager.GetItemList(query);
|
||||||
}
|
}
|
||||||
@ -95,7 +95,7 @@ namespace MediaBrowser.Controller.Entities
|
|||||||
{
|
{
|
||||||
var itemsWithPerson = LibraryManager.GetItemIds(new InternalItemsQuery
|
var itemsWithPerson = LibraryManager.GetItemIds(new InternalItemsQuery
|
||||||
{
|
{
|
||||||
Person = Name
|
PersonIds = new[] { Id.ToString("N") }
|
||||||
});
|
});
|
||||||
|
|
||||||
return inputItems.Where(i => itemsWithPerson.Contains(i.Id));
|
return inputItems.Where(i => itemsWithPerson.Contains(i.Id));
|
||||||
|
@ -51,7 +51,7 @@ namespace MediaBrowser.Controller.Persistence
|
|||||||
/// <param name="items">The items.</param>
|
/// <param name="items">The items.</param>
|
||||||
/// <param name="cancellationToken">The cancellation token.</param>
|
/// <param name="cancellationToken">The cancellation token.</param>
|
||||||
/// <returns>Task.</returns>
|
/// <returns>Task.</returns>
|
||||||
Task SaveItems(IEnumerable<BaseItem> items, CancellationToken cancellationToken);
|
Task SaveItems(List<BaseItem> items, CancellationToken cancellationToken);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Retrieves the item.
|
/// Retrieves the item.
|
||||||
@ -147,7 +147,7 @@ namespace MediaBrowser.Controller.Persistence
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="query">The query.</param>
|
/// <param name="query">The query.</param>
|
||||||
/// <returns>QueryResult<Tuple<Guid, System.String>>.</returns>
|
/// <returns>QueryResult<Tuple<Guid, System.String>>.</returns>
|
||||||
QueryResult<Tuple<Guid, string>> GetItemIdsWithPath(InternalItemsQuery query);
|
List<Tuple<Guid, string>> GetItemIdsWithPath(InternalItemsQuery query);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the item list.
|
/// Gets the item list.
|
||||||
|
@ -62,13 +62,10 @@ namespace MediaBrowser.Providers.People
|
|||||||
|
|
||||||
public Task<IEnumerable<RemoteImageInfo>> GetImages(IHasImages item, CancellationToken cancellationToken)
|
public Task<IEnumerable<RemoteImageInfo>> GetImages(IHasImages item, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
// Avoid implicitly captured closure
|
|
||||||
var itemName = item.Name;
|
|
||||||
|
|
||||||
var seriesWithPerson = _libraryManager.GetItemList(new InternalItemsQuery
|
var seriesWithPerson = _libraryManager.GetItemList(new InternalItemsQuery
|
||||||
{
|
{
|
||||||
IncludeItemTypes = new[] { typeof(Series).Name },
|
IncludeItemTypes = new[] { typeof(Series).Name },
|
||||||
Person = itemName
|
PersonIds = new[] { item.Id.ToString("N") }
|
||||||
|
|
||||||
}).Cast<Series>()
|
}).Cast<Series>()
|
||||||
.Where(i => TvdbSeriesProvider.IsValidSeries(i.ProviderIds))
|
.Where(i => TvdbSeriesProvider.IsValidSeries(i.ProviderIds))
|
||||||
|
@ -57,7 +57,7 @@ namespace MediaBrowser.Providers.TV
|
|||||||
|
|
||||||
if (OmdbProvider.IsValidSeries(info.SeriesProviderIds) && info.IndexNumber.HasValue && info.ParentIndexNumber.HasValue)
|
if (OmdbProvider.IsValidSeries(info.SeriesProviderIds) && info.IndexNumber.HasValue && info.ParentIndexNumber.HasValue)
|
||||||
{
|
{
|
||||||
var seriesImdbId = info.SeriesProviderIds[MetadataProviders.Imdb.ToString()];
|
var seriesImdbId = info.GetProviderId(MetadataProviders.Imdb);
|
||||||
|
|
||||||
result.HasMetadata = await new OmdbProvider(_jsonSerializer, _httpClient, _fileSystem, _configurationManager).FetchEpisodeData(result, info.IndexNumber.Value, info.ParentIndexNumber.Value, seriesImdbId, info.MetadataLanguage, info.MetadataCountryCode, cancellationToken).ConfigureAwait(false);
|
result.HasMetadata = await new OmdbProvider(_jsonSerializer, _httpClient, _fileSystem, _configurationManager).FetchEpisodeData(result, info.IndexNumber.Value, info.ParentIndexNumber.Value, seriesImdbId, info.MetadataLanguage, info.MetadataCountryCode, cancellationToken).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
@ -115,9 +115,6 @@
|
|||||||
<HintPath>..\packages\SQLitePCLRaw.provider.sqlite3.net45.1.1.1-pre20161109081005\lib\net45\SQLitePCLRaw.provider.sqlite3.dll</HintPath>
|
<HintPath>..\packages\SQLitePCLRaw.provider.sqlite3.net45.1.1.1-pre20161109081005\lib\net45\SQLitePCLRaw.provider.sqlite3.dll</HintPath>
|
||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System.Data.SQLite">
|
|
||||||
<HintPath>..\ThirdParty\System.Data.SQLite.ManagedOnly\1.0.94.0\System.Data.SQLite.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="System.Data" />
|
<Reference Include="System.Data" />
|
||||||
<Reference Include="Emby.Common.Implementations">
|
<Reference Include="Emby.Common.Implementations">
|
||||||
<HintPath>..\ThirdParty\emby\Emby.Common.Implementations.dll</HintPath>
|
<HintPath>..\ThirdParty\emby\Emby.Common.Implementations.dll</HintPath>
|
||||||
@ -151,9 +148,6 @@
|
|||||||
<Compile Include="Main.cs" />
|
<Compile Include="Main.cs" />
|
||||||
<Compile Include="MenuBarIcon.cs" />
|
<Compile Include="MenuBarIcon.cs" />
|
||||||
<Compile Include="Native\DbConnector.cs" />
|
<Compile Include="Native\DbConnector.cs" />
|
||||||
<Compile Include="..\MediaBrowser.Server.Startup.Common\Persistence\SqliteExtensions.cs">
|
|
||||||
<Link>Native\SqliteExtensions.cs</Link>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="MacAppHost.cs" />
|
<Compile Include="MacAppHost.cs" />
|
||||||
<Compile Include="Native\MonoFileSystem.cs" />
|
<Compile Include="Native\MonoFileSystem.cs" />
|
||||||
<Compile Include="Native\PowerManagement.cs" />
|
<Compile Include="Native\PowerManagement.cs" />
|
||||||
|
@ -88,10 +88,6 @@
|
|||||||
<HintPath>..\packages\SQLitePCLRaw.core.1.1.1-pre20161109081005\lib\net45\SQLitePCLRaw.core.dll</HintPath>
|
<HintPath>..\packages\SQLitePCLRaw.core.1.1.1-pre20161109081005\lib\net45\SQLitePCLRaw.core.dll</HintPath>
|
||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="SQLitePCLRaw.provider.sqlite3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=62684c7b4f184e3f, processorArchitecture=MSIL">
|
|
||||||
<HintPath>..\packages\SQLitePCLRaw.provider.sqlite3.net45.1.1.1-pre20161109081005\lib\net45\SQLitePCLRaw.provider.sqlite3.dll</HintPath>
|
|
||||||
<Private>True</Private>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="MediaBrowser.IsoMounting.Linux">
|
<Reference Include="MediaBrowser.IsoMounting.Linux">
|
||||||
<HintPath>..\ThirdParty\MediaBrowser.IsoMounting.Linux\MediaBrowser.IsoMounting.Linux.dll</HintPath>
|
<HintPath>..\ThirdParty\MediaBrowser.IsoMounting.Linux\MediaBrowser.IsoMounting.Linux.dll</HintPath>
|
||||||
@ -99,7 +95,7 @@
|
|||||||
<Reference Include="System.Configuration" />
|
<Reference Include="System.Configuration" />
|
||||||
<Reference Include="System.Data" />
|
<Reference Include="System.Data" />
|
||||||
<Reference Include="System.Data.SQLite">
|
<Reference Include="System.Data.SQLite">
|
||||||
<HintPath>..\ThirdParty\System.Data.SQLite.ManagedOnly\1.0.94.0\System.Data.SQLite.dll</HintPath>
|
<HintPath>..\ThirdParty\SQLitePCLRaw.provider.sqlite3.net45\System.Data.SQLite.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System.IO.Compression" />
|
<Reference Include="System.IO.Compression" />
|
||||||
<Reference Include="System.Runtime.Serialization" />
|
<Reference Include="System.Runtime.Serialization" />
|
||||||
@ -108,14 +104,10 @@
|
|||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="..\MediaBrowser.Server.Startup.Common\Persistence\SqliteExtensions.cs">
|
|
||||||
<Link>Native\SqliteExtensions.cs</Link>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="..\SharedVersion.cs">
|
<Compile Include="..\SharedVersion.cs">
|
||||||
<Link>Properties\SharedVersion.cs</Link>
|
<Link>Properties\SharedVersion.cs</Link>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="MonoAppHost.cs" />
|
<Compile Include="MonoAppHost.cs" />
|
||||||
<Compile Include="Native\DbConnector.cs" />
|
|
||||||
<Compile Include="Native\MonoFileSystem.cs" />
|
<Compile Include="Native\MonoFileSystem.cs" />
|
||||||
<Compile Include="Native\PowerManagement.cs" />
|
<Compile Include="Native\PowerManagement.cs" />
|
||||||
<Compile Include="Program.cs" />
|
<Compile Include="Program.cs" />
|
||||||
@ -230,10 +222,6 @@
|
|||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
<None Include="packages.config" />
|
<None Include="packages.config" />
|
||||||
<None Include="SQLitePCLRaw.provider.sqlite3.dll.config">
|
|
||||||
<SubType>Designer</SubType>
|
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
|
||||||
</None>
|
|
||||||
<None Include="System.Data.SQLite.dll.config">
|
<None Include="System.Data.SQLite.dll.config">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
|
@ -2,14 +2,12 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Emby.Server.Core;
|
using Emby.Server.Core;
|
||||||
using Emby.Server.Core.Data;
|
|
||||||
using Emby.Server.Implementations;
|
using Emby.Server.Implementations;
|
||||||
using Emby.Server.Implementations.FFMpeg;
|
using Emby.Server.Implementations.FFMpeg;
|
||||||
using MediaBrowser.IsoMounter;
|
using MediaBrowser.IsoMounter;
|
||||||
using MediaBrowser.Model.IO;
|
using MediaBrowser.Model.IO;
|
||||||
using MediaBrowser.Model.Logging;
|
using MediaBrowser.Model.Logging;
|
||||||
using MediaBrowser.Model.System;
|
using MediaBrowser.Model.System;
|
||||||
using MediaBrowser.Server.Mono.Native;
|
|
||||||
|
|
||||||
namespace MediaBrowser.Server.Mono
|
namespace MediaBrowser.Server.Mono
|
||||||
{
|
{
|
||||||
@ -123,11 +121,6 @@ namespace MediaBrowser.Server.Mono
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override IDbConnector GetDbConnector()
|
|
||||||
{
|
|
||||||
return new DbConnector(Logger);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void ConfigureAutoRunInternal(bool autorun)
|
protected override void ConfigureAutoRunInternal(bool autorun)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,3 +0,0 @@
|
|||||||
<configuration>
|
|
||||||
<dllmap dll="sqlite3" target="libsqlite3.so" os="linux"/>
|
|
||||||
</configuration>
|
|
@ -6,5 +6,4 @@
|
|||||||
<package id="SharpCompress" version="0.14.0" targetFramework="net46" />
|
<package id="SharpCompress" version="0.14.0" targetFramework="net46" />
|
||||||
<package id="SimpleInjector" version="3.2.4" targetFramework="net46" />
|
<package id="SimpleInjector" version="3.2.4" targetFramework="net46" />
|
||||||
<package id="SQLitePCLRaw.core" version="1.1.1-pre20161109081005" targetFramework="net46" />
|
<package id="SQLitePCLRaw.core" version="1.1.1-pre20161109081005" targetFramework="net46" />
|
||||||
<package id="SQLitePCLRaw.provider.sqlite3.net45" version="1.1.1-pre20161109081005" targetFramework="net46" />
|
|
||||||
</packages>
|
</packages>
|
@ -102,10 +102,6 @@
|
|||||||
<Reference Include="System.Configuration" />
|
<Reference Include="System.Configuration" />
|
||||||
<Reference Include="System.Configuration.Install" />
|
<Reference Include="System.Configuration.Install" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
<Reference Include="System.Data.SQLite, Version=1.0.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.Drawing" />
|
||||||
<Reference Include="System.IO.Compression" />
|
<Reference Include="System.IO.Compression" />
|
||||||
<Reference Include="System.Management" />
|
<Reference Include="System.Management" />
|
||||||
@ -121,9 +117,6 @@
|
|||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="..\MediaBrowser.Server.Startup.Common\Persistence\SqliteExtensions.cs">
|
|
||||||
<Link>Native\SqliteExtensions.cs</Link>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="..\SharedVersion.cs">
|
<Compile Include="..\SharedVersion.cs">
|
||||||
<Link>Properties\SharedVersion.cs</Link>
|
<Link>Properties\SharedVersion.cs</Link>
|
||||||
</Compile>
|
</Compile>
|
||||||
@ -141,7 +134,6 @@
|
|||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="MainStartup.cs" />
|
<Compile Include="MainStartup.cs" />
|
||||||
<Compile Include="Native\LnkShortcutHandler.cs" />
|
<Compile Include="Native\LnkShortcutHandler.cs" />
|
||||||
<Compile Include="Native\DbConnector.cs" />
|
|
||||||
<Compile Include="Native\LoopbackUtil.cs" />
|
<Compile Include="Native\LoopbackUtil.cs" />
|
||||||
<Compile Include="Native\PowerManagement.cs" />
|
<Compile Include="Native\PowerManagement.cs" />
|
||||||
<Compile Include="Native\Standby.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.IO;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Emby.Server.Core;
|
using Emby.Server.Core;
|
||||||
using Emby.Server.Core.Data;
|
|
||||||
using Emby.Server.Implementations;
|
using Emby.Server.Implementations;
|
||||||
using Emby.Server.Implementations.EntryPoints;
|
using Emby.Server.Implementations.EntryPoints;
|
||||||
using Emby.Server.Implementations.FFMpeg;
|
using Emby.Server.Implementations.FFMpeg;
|
||||||
@ -92,11 +91,6 @@ namespace MediaBrowser.ServerApplication
|
|||||||
ConfigurationManager.CommonApplicationPaths.TempDirectory);
|
ConfigurationManager.CommonApplicationPaths.TempDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override IDbConnector GetDbConnector()
|
|
||||||
{
|
|
||||||
return new DbConnector(Logger);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void ConfigureAutoRunInternal(bool autorun)
|
protected override void ConfigureAutoRunInternal(bool autorun)
|
||||||
{
|
{
|
||||||
var shortcutPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.StartMenu), "Emby", "Emby Server.lnk");
|
var shortcutPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.StartMenu), "Emby", "Emby Server.lnk");
|
||||||
|
@ -52,7 +52,7 @@ namespace MediaBrowser.XbmcMetadata
|
|||||||
|
|
||||||
var items = _libraryManager.GetItemList(new InternalItemsQuery
|
var items = _libraryManager.GetItemList(new InternalItemsQuery
|
||||||
{
|
{
|
||||||
Person = person.Name
|
PersonIds = new [] { person.Id.ToString("N") }
|
||||||
|
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user