commit
2ea0f7c545
|
@ -509,7 +509,7 @@ namespace Emby.Dlna.ContentDirectory
|
|||
{
|
||||
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 },
|
||||
SortBy = new[] { ItemSortBy.SortName },
|
||||
Limit = limit,
|
||||
|
|
|
@ -238,6 +238,12 @@ namespace Emby.Dlna
|
|||
|
||||
private bool IsMatch(IDictionary<string, string> headers, HttpHeaderInfo header)
|
||||
{
|
||||
// Handle invalid user setup
|
||||
if (string.IsNullOrWhiteSpace(header.Name))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
string value;
|
||||
|
||||
if (headers.TryGetValue(header.Name, out value))
|
||||
|
|
|
@ -84,7 +84,6 @@ using Emby.Dlna.Ssdp;
|
|||
using Emby.Server.Core;
|
||||
using Emby.Server.Implementations.Activity;
|
||||
using Emby.Server.Core.Configuration;
|
||||
using Emby.Server.Core.Data;
|
||||
using Emby.Server.Implementations.Devices;
|
||||
using Emby.Server.Implementations.FFMpeg;
|
||||
using Emby.Server.Core.IO;
|
||||
|
@ -550,7 +549,7 @@ namespace Emby.Server.Core
|
|||
DisplayPreferencesRepository = displayPreferencesRepo;
|
||||
RegisterSingleInstance(DisplayPreferencesRepository);
|
||||
|
||||
var itemRepo = new SqliteItemRepository(ServerConfigurationManager, JsonSerializer, LogManager, GetDbConnector(), MemoryStreamFactory, assemblyInfo);
|
||||
var itemRepo = new SqliteItemRepository(ServerConfigurationManager, JsonSerializer, LogManager.GetLogger("SqliteItemRepository"), MemoryStreamFactory, assemblyInfo, FileSystemManager);
|
||||
ItemRepository = itemRepo;
|
||||
RegisterSingleInstance(ItemRepository);
|
||||
|
||||
|
@ -693,10 +692,10 @@ namespace Emby.Server.Core
|
|||
|
||||
displayPreferencesRepo.Initialize();
|
||||
|
||||
var userDataRepo = new SqliteUserDataRepository(LogManager, ApplicationPaths, GetDbConnector());
|
||||
var userDataRepo = new SqliteUserDataRepository(LogManager.GetLogger("SqliteUserDataRepository"), ApplicationPaths);
|
||||
|
||||
((UserDataManager)UserDataManager).Repository = userDataRepo;
|
||||
await itemRepo.Initialize(userDataRepo).ConfigureAwait(false);
|
||||
itemRepo.Initialize(userDataRepo);
|
||||
((LibraryManager)LibraryManager).ItemRepository = ItemRepository;
|
||||
ConfigureNotificationsRepository();
|
||||
progress.Report(100);
|
||||
|
@ -1444,7 +1443,6 @@ namespace Emby.Server.Core
|
|||
}
|
||||
|
||||
protected abstract void AuthorizeServer();
|
||||
protected abstract IDbConnector GetDbConnector();
|
||||
|
||||
public event EventHandler HasUpdateAvailableChanged;
|
||||
|
||||
|
|
|
@ -1,114 +0,0 @@
|
|||
using System;
|
||||
using System.Data;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Model.Logging;
|
||||
|
||||
namespace Emby.Server.Core.Data
|
||||
{
|
||||
public abstract class BaseSqliteRepository : IDisposable
|
||||
{
|
||||
protected SemaphoreSlim WriteLock = new SemaphoreSlim(1, 1);
|
||||
protected readonly IDbConnector DbConnector;
|
||||
protected ILogger Logger;
|
||||
|
||||
protected string DbFilePath { get; set; }
|
||||
|
||||
protected BaseSqliteRepository(ILogManager logManager, IDbConnector dbConnector)
|
||||
{
|
||||
DbConnector = dbConnector;
|
||||
Logger = logManager.GetLogger(GetType().Name);
|
||||
}
|
||||
|
||||
protected virtual bool EnableConnectionPooling
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
protected virtual async Task<IDbConnection> CreateConnection(bool isReadOnly = false)
|
||||
{
|
||||
var connection = await DbConnector.Connect(DbFilePath, false, true).ConfigureAwait(false);
|
||||
|
||||
connection.RunQueries(new[]
|
||||
{
|
||||
"pragma temp_store = memory"
|
||||
|
||||
}, Logger);
|
||||
|
||||
return connection;
|
||||
}
|
||||
|
||||
private bool _disposed;
|
||||
protected void CheckDisposed()
|
||||
{
|
||||
if (_disposed)
|
||||
{
|
||||
throw new ObjectDisposedException(GetType().Name + " has been disposed and cannot be accessed.");
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_disposed = true;
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
protected async Task Vacuum(IDbConnection connection)
|
||||
{
|
||||
CheckDisposed();
|
||||
|
||||
await WriteLock.WaitAsync().ConfigureAwait(false);
|
||||
|
||||
try
|
||||
{
|
||||
using (var cmd = connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "vacuum";
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.ErrorException("Failed to vacuum:", e);
|
||||
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
WriteLock.Release();
|
||||
}
|
||||
}
|
||||
|
||||
private readonly object _disposeLock = new object();
|
||||
|
||||
/// <summary>
|
||||
/// Releases unmanaged and - optionally - managed resources.
|
||||
/// </summary>
|
||||
/// <param name="dispose"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
|
||||
protected virtual void Dispose(bool dispose)
|
||||
{
|
||||
if (dispose)
|
||||
{
|
||||
try
|
||||
{
|
||||
lock (_disposeLock)
|
||||
{
|
||||
WriteLock.Wait();
|
||||
|
||||
CloseConnection();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.ErrorException("Error disposing database", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void CloseConnection()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,186 +0,0 @@
|
|||
using System;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using MediaBrowser.Model.IO;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.Model.Serialization;
|
||||
|
||||
namespace Emby.Server.Core.Data
|
||||
{
|
||||
public static class DataExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Determines whether the specified conn is open.
|
||||
/// </summary>
|
||||
/// <param name="conn">The conn.</param>
|
||||
/// <returns><c>true</c> if the specified conn is open; otherwise, <c>false</c>.</returns>
|
||||
public static bool IsOpen(this IDbConnection conn)
|
||||
{
|
||||
return conn.State == ConnectionState.Open;
|
||||
}
|
||||
|
||||
public static IDataParameter GetParameter(this IDbCommand cmd, int index)
|
||||
{
|
||||
return (IDataParameter)cmd.Parameters[index];
|
||||
}
|
||||
|
||||
public static IDataParameter GetParameter(this IDbCommand cmd, string name)
|
||||
{
|
||||
return (IDataParameter)cmd.Parameters[name];
|
||||
}
|
||||
|
||||
public static IDataParameter Add(this IDataParameterCollection paramCollection, IDbCommand cmd, string name, DbType type)
|
||||
{
|
||||
var param = cmd.CreateParameter();
|
||||
|
||||
param.ParameterName = name;
|
||||
param.DbType = type;
|
||||
|
||||
paramCollection.Add(param);
|
||||
|
||||
return param;
|
||||
}
|
||||
|
||||
public static IDataParameter Add(this IDataParameterCollection paramCollection, IDbCommand cmd, string name)
|
||||
{
|
||||
var param = cmd.CreateParameter();
|
||||
|
||||
param.ParameterName = name;
|
||||
|
||||
paramCollection.Add(param);
|
||||
|
||||
return param;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets a stream from a DataReader at a given ordinal
|
||||
/// </summary>
|
||||
/// <returns>Stream.</returns>
|
||||
/// <exception cref="System.ArgumentNullException">reader</exception>
|
||||
public static Stream GetMemoryStream(this IDataReader reader, int ordinal, IMemoryStreamFactory streamProvider)
|
||||
{
|
||||
if (reader == null)
|
||||
{
|
||||
throw new ArgumentNullException("reader");
|
||||
}
|
||||
|
||||
var memoryStream = streamProvider.CreateNew();
|
||||
var num = 0L;
|
||||
var array = new byte[4096];
|
||||
long bytes;
|
||||
do
|
||||
{
|
||||
bytes = reader.GetBytes(ordinal, num, array, 0, array.Length);
|
||||
memoryStream.Write(array, 0, (int)bytes);
|
||||
num += bytes;
|
||||
}
|
||||
while (bytes > 0L);
|
||||
memoryStream.Position = 0;
|
||||
return memoryStream;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Runs the queries.
|
||||
/// </summary>
|
||||
/// <param name="connection">The connection.</param>
|
||||
/// <param name="queries">The queries.</param>
|
||||
/// <param name="logger">The logger.</param>
|
||||
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
|
||||
/// <exception cref="System.ArgumentNullException">queries</exception>
|
||||
public static void RunQueries(this IDbConnection connection, string[] queries, ILogger logger)
|
||||
{
|
||||
if (queries == null)
|
||||
{
|
||||
throw new ArgumentNullException("queries");
|
||||
}
|
||||
|
||||
using (var tran = connection.BeginTransaction())
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var cmd = connection.CreateCommand())
|
||||
{
|
||||
foreach (var query in queries)
|
||||
{
|
||||
cmd.Transaction = tran;
|
||||
cmd.CommandText = query;
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
|
||||
tran.Commit();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.ErrorException("Error running queries", e);
|
||||
tran.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void Attach(IDbConnection db, string path, string alias)
|
||||
{
|
||||
using (var cmd = db.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = string.Format("attach @dbPath as {0};", alias);
|
||||
cmd.Parameters.Add(cmd, "@dbPath", DbType.String);
|
||||
cmd.GetParameter(0).Value = path;
|
||||
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serializes to bytes.
|
||||
/// </summary>
|
||||
/// <returns>System.Byte[][].</returns>
|
||||
/// <exception cref="System.ArgumentNullException">obj</exception>
|
||||
public static byte[] SerializeToBytes(this IJsonSerializer json, object obj, IMemoryStreamFactory streamProvider)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
throw new ArgumentNullException("obj");
|
||||
}
|
||||
|
||||
using (var stream = streamProvider.CreateNew())
|
||||
{
|
||||
json.SerializeToStream(obj, stream);
|
||||
return stream.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public static void AddColumn(this IDbConnection connection, ILogger logger, string table, string columnName, string type)
|
||||
{
|
||||
using (var cmd = connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "PRAGMA table_info(" + table + ")";
|
||||
|
||||
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult))
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
if (!reader.IsDBNull(1))
|
||||
{
|
||||
var name = reader.GetString(1);
|
||||
|
||||
if (string.Equals(name, columnName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var builder = new StringBuilder();
|
||||
|
||||
builder.AppendLine("alter table " + table);
|
||||
builder.AppendLine("add column " + columnName + " " + type + " NULL");
|
||||
|
||||
connection.RunQueries(new[] { builder.ToString() }, logger);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
using System.Data;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Emby.Server.Core.Data
|
||||
{
|
||||
public interface IDbConnector
|
||||
{
|
||||
Task<IDbConnection> Connect(string dbPath, bool isReadOnly, bool enablePooling = false, int? cacheSize = null);
|
||||
}
|
||||
}
|
|
@ -1,408 +0,0 @@
|
|||
using System;
|
||||
using System.Data;
|
||||
using System.Text;
|
||||
using MediaBrowser.Model.Logging;
|
||||
|
||||
namespace Emby.Server.Core.Data
|
||||
{
|
||||
public class MediaStreamColumns
|
||||
{
|
||||
private readonly IDbConnection _connection;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public MediaStreamColumns(IDbConnection connection, ILogger logger)
|
||||
{
|
||||
_connection = connection;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void AddColumns()
|
||||
{
|
||||
AddPixelFormatColumnCommand();
|
||||
AddBitDepthCommand();
|
||||
AddIsAnamorphicColumn();
|
||||
AddKeyFramesColumn();
|
||||
AddRefFramesCommand();
|
||||
AddCodecTagColumn();
|
||||
AddCommentColumn();
|
||||
AddNalColumn();
|
||||
AddIsAvcColumn();
|
||||
AddTitleColumn();
|
||||
AddTimeBaseColumn();
|
||||
AddCodecTimeBaseColumn();
|
||||
}
|
||||
|
||||
private void AddIsAvcColumn()
|
||||
{
|
||||
using (var cmd = _connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "PRAGMA table_info(mediastreams)";
|
||||
|
||||
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult))
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
if (!reader.IsDBNull(1))
|
||||
{
|
||||
var name = reader.GetString(1);
|
||||
|
||||
if (string.Equals(name, "IsAvc", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var builder = new StringBuilder();
|
||||
|
||||
builder.AppendLine("alter table mediastreams");
|
||||
builder.AppendLine("add column IsAvc BIT NULL");
|
||||
|
||||
_connection.RunQueries(new[] { builder.ToString() }, _logger);
|
||||
}
|
||||
|
||||
private void AddTimeBaseColumn()
|
||||
{
|
||||
using (var cmd = _connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "PRAGMA table_info(mediastreams)";
|
||||
|
||||
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult))
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
if (!reader.IsDBNull(1))
|
||||
{
|
||||
var name = reader.GetString(1);
|
||||
|
||||
if (string.Equals(name, "TimeBase", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var builder = new StringBuilder();
|
||||
|
||||
builder.AppendLine("alter table mediastreams");
|
||||
builder.AppendLine("add column TimeBase TEXT");
|
||||
|
||||
_connection.RunQueries(new[] { builder.ToString() }, _logger);
|
||||
}
|
||||
|
||||
private void AddCodecTimeBaseColumn()
|
||||
{
|
||||
using (var cmd = _connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "PRAGMA table_info(mediastreams)";
|
||||
|
||||
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult))
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
if (!reader.IsDBNull(1))
|
||||
{
|
||||
var name = reader.GetString(1);
|
||||
|
||||
if (string.Equals(name, "CodecTimeBase", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var builder = new StringBuilder();
|
||||
|
||||
builder.AppendLine("alter table mediastreams");
|
||||
builder.AppendLine("add column CodecTimeBase TEXT");
|
||||
|
||||
_connection.RunQueries(new[] { builder.ToString() }, _logger);
|
||||
}
|
||||
|
||||
private void AddTitleColumn()
|
||||
{
|
||||
using (var cmd = _connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "PRAGMA table_info(mediastreams)";
|
||||
|
||||
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult))
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
if (!reader.IsDBNull(1))
|
||||
{
|
||||
var name = reader.GetString(1);
|
||||
|
||||
if (string.Equals(name, "Title", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var builder = new StringBuilder();
|
||||
|
||||
builder.AppendLine("alter table mediastreams");
|
||||
builder.AppendLine("add column Title TEXT");
|
||||
|
||||
_connection.RunQueries(new[] { builder.ToString() }, _logger);
|
||||
}
|
||||
|
||||
private void AddNalColumn()
|
||||
{
|
||||
using (var cmd = _connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "PRAGMA table_info(mediastreams)";
|
||||
|
||||
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult))
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
if (!reader.IsDBNull(1))
|
||||
{
|
||||
var name = reader.GetString(1);
|
||||
|
||||
if (string.Equals(name, "NalLengthSize", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var builder = new StringBuilder();
|
||||
|
||||
builder.AppendLine("alter table mediastreams");
|
||||
builder.AppendLine("add column NalLengthSize TEXT");
|
||||
|
||||
_connection.RunQueries(new[] { builder.ToString() }, _logger);
|
||||
}
|
||||
|
||||
private void AddCommentColumn()
|
||||
{
|
||||
using (var cmd = _connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "PRAGMA table_info(mediastreams)";
|
||||
|
||||
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult))
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
if (!reader.IsDBNull(1))
|
||||
{
|
||||
var name = reader.GetString(1);
|
||||
|
||||
if (string.Equals(name, "Comment", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var builder = new StringBuilder();
|
||||
|
||||
builder.AppendLine("alter table mediastreams");
|
||||
builder.AppendLine("add column Comment TEXT");
|
||||
|
||||
_connection.RunQueries(new[] { builder.ToString() }, _logger);
|
||||
}
|
||||
|
||||
private void AddCodecTagColumn()
|
||||
{
|
||||
using (var cmd = _connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "PRAGMA table_info(mediastreams)";
|
||||
|
||||
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult))
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
if (!reader.IsDBNull(1))
|
||||
{
|
||||
var name = reader.GetString(1);
|
||||
|
||||
if (string.Equals(name, "CodecTag", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var builder = new StringBuilder();
|
||||
|
||||
builder.AppendLine("alter table mediastreams");
|
||||
builder.AppendLine("add column CodecTag TEXT");
|
||||
|
||||
_connection.RunQueries(new[] { builder.ToString() }, _logger);
|
||||
}
|
||||
|
||||
private void AddPixelFormatColumnCommand()
|
||||
{
|
||||
using (var cmd = _connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "PRAGMA table_info(mediastreams)";
|
||||
|
||||
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult))
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
if (!reader.IsDBNull(1))
|
||||
{
|
||||
var name = reader.GetString(1);
|
||||
|
||||
if (string.Equals(name, "PixelFormat", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var builder = new StringBuilder();
|
||||
|
||||
builder.AppendLine("alter table mediastreams");
|
||||
builder.AppendLine("add column PixelFormat TEXT");
|
||||
|
||||
_connection.RunQueries(new[] { builder.ToString() }, _logger);
|
||||
}
|
||||
|
||||
private void AddBitDepthCommand()
|
||||
{
|
||||
using (var cmd = _connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "PRAGMA table_info(mediastreams)";
|
||||
|
||||
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult))
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
if (!reader.IsDBNull(1))
|
||||
{
|
||||
var name = reader.GetString(1);
|
||||
|
||||
if (string.Equals(name, "BitDepth", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var builder = new StringBuilder();
|
||||
|
||||
builder.AppendLine("alter table mediastreams");
|
||||
builder.AppendLine("add column BitDepth INT NULL");
|
||||
|
||||
_connection.RunQueries(new[] { builder.ToString() }, _logger);
|
||||
}
|
||||
|
||||
private void AddRefFramesCommand()
|
||||
{
|
||||
using (var cmd = _connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "PRAGMA table_info(mediastreams)";
|
||||
|
||||
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult))
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
if (!reader.IsDBNull(1))
|
||||
{
|
||||
var name = reader.GetString(1);
|
||||
|
||||
if (string.Equals(name, "RefFrames", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var builder = new StringBuilder();
|
||||
|
||||
builder.AppendLine("alter table mediastreams");
|
||||
builder.AppendLine("add column RefFrames INT NULL");
|
||||
|
||||
_connection.RunQueries(new[] { builder.ToString() }, _logger);
|
||||
}
|
||||
|
||||
private void AddKeyFramesColumn()
|
||||
{
|
||||
using (var cmd = _connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "PRAGMA table_info(mediastreams)";
|
||||
|
||||
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult))
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
if (!reader.IsDBNull(1))
|
||||
{
|
||||
var name = reader.GetString(1);
|
||||
|
||||
if (string.Equals(name, "KeyFrames", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var builder = new StringBuilder();
|
||||
|
||||
builder.AppendLine("alter table mediastreams");
|
||||
builder.AppendLine("add column KeyFrames TEXT NULL");
|
||||
|
||||
_connection.RunQueries(new[] { builder.ToString() }, _logger);
|
||||
}
|
||||
|
||||
private void AddIsAnamorphicColumn()
|
||||
{
|
||||
using (var cmd = _connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "PRAGMA table_info(mediastreams)";
|
||||
|
||||
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult))
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
if (!reader.IsDBNull(1))
|
||||
{
|
||||
var name = reader.GetString(1);
|
||||
|
||||
if (string.Equals(name, "IsAnamorphic", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var builder = new StringBuilder();
|
||||
|
||||
builder.AppendLine("alter table mediastreams");
|
||||
builder.AppendLine("add column IsAnamorphic BIT NULL");
|
||||
|
||||
_connection.RunQueries(new[] { builder.ToString() }, _logger);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -1,453 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Common.Configuration;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Persistence;
|
||||
using MediaBrowser.Model.Logging;
|
||||
|
||||
namespace Emby.Server.Core.Data
|
||||
{
|
||||
public class SqliteUserDataRepository : BaseSqliteRepository, IUserDataRepository
|
||||
{
|
||||
private IDbConnection _connection;
|
||||
|
||||
public SqliteUserDataRepository(ILogManager logManager, IApplicationPaths appPaths, IDbConnector connector) : base(logManager, connector)
|
||||
{
|
||||
DbFilePath = Path.Combine(appPaths.DataPath, "userdata_v2.db");
|
||||
}
|
||||
|
||||
protected override bool EnableConnectionPooling
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the repository
|
||||
/// </summary>
|
||||
/// <value>The name.</value>
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return "SQLite";
|
||||
}
|
||||
}
|
||||
|
||||
protected override async Task<IDbConnection> CreateConnection(bool isReadOnly = false)
|
||||
{
|
||||
var connection = await DbConnector.Connect(DbFilePath, false, false, 10000).ConfigureAwait(false);
|
||||
|
||||
connection.RunQueries(new[]
|
||||
{
|
||||
"pragma temp_store = memory"
|
||||
|
||||
}, Logger);
|
||||
|
||||
return connection;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens the connection to the database
|
||||
/// </summary>
|
||||
/// <returns>Task.</returns>
|
||||
public async Task Initialize(IDbConnection connection, SemaphoreSlim writeLock)
|
||||
{
|
||||
WriteLock.Dispose();
|
||||
WriteLock = writeLock;
|
||||
_connection = connection;
|
||||
|
||||
string[] queries = {
|
||||
|
||||
"create table if not exists UserDataDb.userdata (key nvarchar, userId GUID, rating float null, played bit, playCount int, isFavorite bit, playbackPositionTicks bigint, lastPlayedDate datetime null)",
|
||||
|
||||
"drop index if exists UserDataDb.idx_userdata",
|
||||
"drop index if exists UserDataDb.idx_userdata1",
|
||||
"drop index if exists UserDataDb.idx_userdata2",
|
||||
"drop index if exists UserDataDb.userdataindex1",
|
||||
|
||||
"create unique index if not exists UserDataDb.userdataindex on userdata (key, userId)",
|
||||
"create index if not exists UserDataDb.userdataindex2 on userdata (key, userId, played)",
|
||||
"create index if not exists UserDataDb.userdataindex3 on userdata (key, userId, playbackPositionTicks)",
|
||||
"create index if not exists UserDataDb.userdataindex4 on userdata (key, userId, isFavorite)",
|
||||
|
||||
//pragmas
|
||||
"pragma temp_store = memory",
|
||||
|
||||
"pragma shrink_memory"
|
||||
};
|
||||
|
||||
_connection.RunQueries(queries, Logger);
|
||||
|
||||
_connection.AddColumn(Logger, "userdata", "AudioStreamIndex", "int");
|
||||
_connection.AddColumn(Logger, "userdata", "SubtitleStreamIndex", "int");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves the user data.
|
||||
/// </summary>
|
||||
/// <param name="userId">The user id.</param>
|
||||
/// <param name="key">The key.</param>
|
||||
/// <param name="userData">The user data.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task.</returns>
|
||||
/// <exception cref="System.ArgumentNullException">userData
|
||||
/// or
|
||||
/// cancellationToken
|
||||
/// or
|
||||
/// userId
|
||||
/// or
|
||||
/// userDataId</exception>
|
||||
public Task SaveUserData(Guid userId, string key, UserItemData userData, CancellationToken cancellationToken)
|
||||
{
|
||||
if (userData == null)
|
||||
{
|
||||
throw new ArgumentNullException("userData");
|
||||
}
|
||||
if (userId == Guid.Empty)
|
||||
{
|
||||
throw new ArgumentNullException("userId");
|
||||
}
|
||||
if (string.IsNullOrEmpty(key))
|
||||
{
|
||||
throw new ArgumentNullException("key");
|
||||
}
|
||||
|
||||
return PersistUserData(userId, key, userData, cancellationToken);
|
||||
}
|
||||
|
||||
public Task SaveAllUserData(Guid userId, IEnumerable<UserItemData> userData, CancellationToken cancellationToken)
|
||||
{
|
||||
if (userData == null)
|
||||
{
|
||||
throw new ArgumentNullException("userData");
|
||||
}
|
||||
if (userId == Guid.Empty)
|
||||
{
|
||||
throw new ArgumentNullException("userId");
|
||||
}
|
||||
|
||||
return PersistAllUserData(userId, userData, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Persists the user data.
|
||||
/// </summary>
|
||||
/// <param name="userId">The user id.</param>
|
||||
/// <param name="key">The key.</param>
|
||||
/// <param name="userData">The user data.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task.</returns>
|
||||
public async Task PersistUserData(Guid userId, string key, UserItemData userData, CancellationToken cancellationToken)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
await WriteLock.WaitAsync(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
IDbTransaction transaction = null;
|
||||
|
||||
try
|
||||
{
|
||||
transaction = _connection.BeginTransaction();
|
||||
|
||||
using (var cmd = _connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "replace into userdata (key, userId, rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex) values (@key, @userId, @rating,@played,@playCount,@isFavorite,@playbackPositionTicks,@lastPlayedDate,@AudioStreamIndex,@SubtitleStreamIndex)";
|
||||
|
||||
cmd.Parameters.Add(cmd, "@key", DbType.String).Value = key;
|
||||
cmd.Parameters.Add(cmd, "@userId", DbType.Guid).Value = userId;
|
||||
cmd.Parameters.Add(cmd, "@rating", DbType.Double).Value = userData.Rating;
|
||||
cmd.Parameters.Add(cmd, "@played", DbType.Boolean).Value = userData.Played;
|
||||
cmd.Parameters.Add(cmd, "@playCount", DbType.Int32).Value = userData.PlayCount;
|
||||
cmd.Parameters.Add(cmd, "@isFavorite", DbType.Boolean).Value = userData.IsFavorite;
|
||||
cmd.Parameters.Add(cmd, "@playbackPositionTicks", DbType.Int64).Value = userData.PlaybackPositionTicks;
|
||||
cmd.Parameters.Add(cmd, "@lastPlayedDate", DbType.DateTime).Value = userData.LastPlayedDate;
|
||||
cmd.Parameters.Add(cmd, "@AudioStreamIndex", DbType.Int32).Value = userData.AudioStreamIndex;
|
||||
cmd.Parameters.Add(cmd, "@SubtitleStreamIndex", DbType.Int32).Value = userData.SubtitleStreamIndex;
|
||||
|
||||
cmd.Transaction = transaction;
|
||||
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
if (transaction != null)
|
||||
{
|
||||
transaction.Rollback();
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.ErrorException("Failed to save user data:", e);
|
||||
|
||||
if (transaction != null)
|
||||
{
|
||||
transaction.Rollback();
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (transaction != null)
|
||||
{
|
||||
transaction.Dispose();
|
||||
}
|
||||
|
||||
WriteLock.Release();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Persist all user data for the specified user
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="userData"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
private async Task PersistAllUserData(Guid userId, IEnumerable<UserItemData> userData, CancellationToken cancellationToken)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
await WriteLock.WaitAsync(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
IDbTransaction transaction = null;
|
||||
|
||||
try
|
||||
{
|
||||
transaction = _connection.BeginTransaction();
|
||||
|
||||
foreach (var userItemData in userData)
|
||||
{
|
||||
using (var cmd = _connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "replace into userdata (key, userId, rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex) values (@key, @userId, @rating,@played,@playCount,@isFavorite,@playbackPositionTicks,@lastPlayedDate,@AudioStreamIndex,@SubtitleStreamIndex)";
|
||||
|
||||
cmd.Parameters.Add(cmd, "@key", DbType.String).Value = userItemData.Key;
|
||||
cmd.Parameters.Add(cmd, "@userId", DbType.Guid).Value = userId;
|
||||
cmd.Parameters.Add(cmd, "@rating", DbType.Double).Value = userItemData.Rating;
|
||||
cmd.Parameters.Add(cmd, "@played", DbType.Boolean).Value = userItemData.Played;
|
||||
cmd.Parameters.Add(cmd, "@playCount", DbType.Int32).Value = userItemData.PlayCount;
|
||||
cmd.Parameters.Add(cmd, "@isFavorite", DbType.Boolean).Value = userItemData.IsFavorite;
|
||||
cmd.Parameters.Add(cmd, "@playbackPositionTicks", DbType.Int64).Value = userItemData.PlaybackPositionTicks;
|
||||
cmd.Parameters.Add(cmd, "@lastPlayedDate", DbType.DateTime).Value = userItemData.LastPlayedDate;
|
||||
cmd.Parameters.Add(cmd, "@AudioStreamIndex", DbType.Int32).Value = userItemData.AudioStreamIndex;
|
||||
cmd.Parameters.Add(cmd, "@SubtitleStreamIndex", DbType.Int32).Value = userItemData.SubtitleStreamIndex;
|
||||
|
||||
cmd.Transaction = transaction;
|
||||
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
}
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
if (transaction != null)
|
||||
{
|
||||
transaction.Rollback();
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.ErrorException("Failed to save user data:", e);
|
||||
|
||||
if (transaction != null)
|
||||
{
|
||||
transaction.Rollback();
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (transaction != null)
|
||||
{
|
||||
transaction.Dispose();
|
||||
}
|
||||
|
||||
WriteLock.Release();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the user data.
|
||||
/// </summary>
|
||||
/// <param name="userId">The user id.</param>
|
||||
/// <param name="key">The key.</param>
|
||||
/// <returns>Task{UserItemData}.</returns>
|
||||
/// <exception cref="System.ArgumentNullException">
|
||||
/// userId
|
||||
/// or
|
||||
/// key
|
||||
/// </exception>
|
||||
public UserItemData GetUserData(Guid userId, string key)
|
||||
{
|
||||
if (userId == Guid.Empty)
|
||||
{
|
||||
throw new ArgumentNullException("userId");
|
||||
}
|
||||
if (string.IsNullOrEmpty(key))
|
||||
{
|
||||
throw new ArgumentNullException("key");
|
||||
}
|
||||
|
||||
using (var cmd = _connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where key = @key and userId=@userId";
|
||||
|
||||
cmd.Parameters.Add(cmd, "@key", DbType.String).Value = key;
|
||||
cmd.Parameters.Add(cmd, "@userId", DbType.Guid).Value = userId;
|
||||
|
||||
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult | CommandBehavior.SingleRow))
|
||||
{
|
||||
if (reader.Read())
|
||||
{
|
||||
return ReadRow(reader);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public UserItemData GetUserData(Guid userId, List<string> keys)
|
||||
{
|
||||
if (userId == Guid.Empty)
|
||||
{
|
||||
throw new ArgumentNullException("userId");
|
||||
}
|
||||
if (keys == null)
|
||||
{
|
||||
throw new ArgumentNullException("keys");
|
||||
}
|
||||
|
||||
using (var cmd = _connection.CreateCommand())
|
||||
{
|
||||
var index = 0;
|
||||
var userdataKeys = new List<string>();
|
||||
var builder = new StringBuilder();
|
||||
foreach (var key in keys)
|
||||
{
|
||||
var paramName = "@Key" + index;
|
||||
userdataKeys.Add("Key =" + paramName);
|
||||
cmd.Parameters.Add(cmd, paramName, DbType.String).Value = key;
|
||||
builder.Append(" WHEN Key=" + paramName + " THEN " + index);
|
||||
index++;
|
||||
break;
|
||||
}
|
||||
|
||||
var keyText = string.Join(" OR ", userdataKeys.ToArray());
|
||||
|
||||
cmd.CommandText = "select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where userId=@userId AND (" + keyText + ") ";
|
||||
|
||||
cmd.CommandText += " ORDER BY (Case " + builder + " Else " + keys.Count.ToString(CultureInfo.InvariantCulture) + " End )";
|
||||
cmd.CommandText += " LIMIT 1";
|
||||
|
||||
cmd.Parameters.Add(cmd, "@userId", DbType.Guid).Value = userId;
|
||||
|
||||
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult | CommandBehavior.SingleRow))
|
||||
{
|
||||
if (reader.Read())
|
||||
{
|
||||
return ReadRow(reader);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return all user-data associated with the given user
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<UserItemData> GetAllUserData(Guid userId)
|
||||
{
|
||||
if (userId == Guid.Empty)
|
||||
{
|
||||
throw new ArgumentNullException("userId");
|
||||
}
|
||||
|
||||
using (var cmd = _connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where userId=@userId";
|
||||
|
||||
cmd.Parameters.Add(cmd, "@userId", DbType.Guid).Value = userId;
|
||||
|
||||
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult))
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
yield return ReadRow(reader);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a row from the specified reader into the provided userData object
|
||||
/// </summary>
|
||||
/// <param name="reader"></param>
|
||||
private UserItemData ReadRow(IDataReader reader)
|
||||
{
|
||||
var userData = new UserItemData();
|
||||
|
||||
userData.Key = reader.GetString(0);
|
||||
userData.UserId = reader.GetGuid(1);
|
||||
|
||||
if (!reader.IsDBNull(2))
|
||||
{
|
||||
userData.Rating = reader.GetDouble(2);
|
||||
}
|
||||
|
||||
userData.Played = reader.GetBoolean(3);
|
||||
userData.PlayCount = reader.GetInt32(4);
|
||||
userData.IsFavorite = reader.GetBoolean(5);
|
||||
userData.PlaybackPositionTicks = reader.GetInt64(6);
|
||||
|
||||
if (!reader.IsDBNull(7))
|
||||
{
|
||||
userData.LastPlayedDate = reader.GetDateTime(7).ToUniversalTime();
|
||||
}
|
||||
|
||||
if (!reader.IsDBNull(8))
|
||||
{
|
||||
userData.AudioStreamIndex = reader.GetInt32(8);
|
||||
}
|
||||
|
||||
if (!reader.IsDBNull(9))
|
||||
{
|
||||
userData.SubtitleStreamIndex = reader.GetInt32(9);
|
||||
}
|
||||
|
||||
return userData;
|
||||
}
|
||||
|
||||
protected override void Dispose(bool dispose)
|
||||
{
|
||||
// handled by library database
|
||||
}
|
||||
|
||||
protected override void CloseConnection()
|
||||
{
|
||||
// handled by library database
|
||||
}
|
||||
}
|
||||
}
|
|
@ -57,18 +57,21 @@ namespace Emby.Server.Implementations.Activity
|
|||
{
|
||||
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,
|
||||
entry.Id.ToGuidParamValue(),
|
||||
entry.Name,
|
||||
entry.Overview,
|
||||
entry.ShortOverview,
|
||||
entry.Type,
|
||||
entry.ItemId,
|
||||
entry.UserId,
|
||||
entry.Date.ToDateTimeParamValue(),
|
||||
entry.Severity.ToString());
|
||||
statement.TryBind("@Overview", entry.Overview);
|
||||
statement.TryBind("@ShortOverview", entry.ShortOverview);
|
||||
statement.TryBind("@Type", entry.Type);
|
||||
statement.TryBind("@ItemId", entry.ItemId);
|
||||
statement.TryBind("@UserId", entry.UserId);
|
||||
statement.TryBind("@DateCreated", entry.Date.ToDateTimeParamValue());
|
||||
statement.TryBind("@LogSeverity", entry.Severity.ToString());
|
||||
|
||||
statement.MoveNext();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -81,19 +84,16 @@ namespace Emby.Server.Implementations.Activity
|
|||
using (var connection = CreateConnection(true))
|
||||
{
|
||||
var commandText = BaseActivitySelectText;
|
||||
|
||||
var whereClauses = new List<string>();
|
||||
var paramList = new List<object>();
|
||||
|
||||
if (minDate.HasValue)
|
||||
{
|
||||
whereClauses.Add("DateCreated>=?");
|
||||
paramList.Add(minDate.Value.ToDateTimeParamValue());
|
||||
whereClauses.Add("DateCreated>=@DateCreated");
|
||||
}
|
||||
|
||||
var whereTextWithoutPaging = whereClauses.Count == 0 ?
|
||||
string.Empty :
|
||||
" where " + string.Join(" AND ", whereClauses.ToArray());
|
||||
string.Empty :
|
||||
" where " + string.Join(" AND ", whereClauses.ToArray());
|
||||
|
||||
if (startIndex.HasValue && startIndex.Value > 0)
|
||||
{
|
||||
|
@ -119,13 +119,31 @@ namespace Emby.Server.Implementations.Activity
|
|||
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>();
|
||||
|
||||
foreach (var row in connection.Query(commandText, paramList.ToArray()))
|
||||
using (var statement = connection.PrepareStatement(commandText))
|
||||
{
|
||||
list.Add(GetEntry(row));
|
||||
if (minDate.HasValue)
|
||||
{
|
||||
statement.TryBind("@DateCreated", minDate.Value.ToDateTimeParamValue());
|
||||
}
|
||||
|
||||
foreach (var row in statement.ExecuteQuery())
|
||||
{
|
||||
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>()
|
||||
|
|
|
@ -135,9 +135,9 @@ namespace Emby.Server.Implementations.Data
|
|||
});
|
||||
|
||||
var numComplete = 0;
|
||||
var numItems = result.Items.Length;
|
||||
var numItems = result.Count;
|
||||
|
||||
foreach (var item in result.Items)
|
||||
foreach (var item in result)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
|
|
|
@ -100,14 +100,17 @@ namespace Emby.Server.Implementations.Data
|
|||
|
||||
private void SaveDisplayPreferences(DisplayPreferences displayPreferences, Guid userId, string client, IDatabaseConnection connection)
|
||||
{
|
||||
var commandText = "replace into userdisplaypreferences (id, userid, client, data) values (?, ?, ?, ?)";
|
||||
var serialized = _jsonSerializer.SerializeToBytes(displayPreferences, _memoryStreamProvider);
|
||||
using (var statement = connection.PrepareStatement("replace into userdisplaypreferences (id, userid, client, data) values (@id, @userid, @client, @data)"))
|
||||
{
|
||||
var serialized = _jsonSerializer.SerializeToBytes(displayPreferences, _memoryStreamProvider);
|
||||
|
||||
connection.Execute(commandText,
|
||||
displayPreferences.Id.ToGuidParamValue(),
|
||||
userId.ToGuidParamValue(),
|
||||
client,
|
||||
serialized);
|
||||
statement.TryBind("@id", displayPreferences.Id.ToGuidParamValue());
|
||||
statement.TryBind("@userId", userId.ToGuidParamValue());
|
||||
statement.TryBind("@client", client);
|
||||
statement.TryBind("@data", serialized);
|
||||
|
||||
statement.MoveNext();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -163,16 +166,16 @@ namespace Emby.Server.Implementations.Data
|
|||
{
|
||||
using (var connection = CreateConnection(true))
|
||||
{
|
||||
var commandText = "select data from userdisplaypreferences where id = ? and userId=? and client=?";
|
||||
|
||||
var paramList = new List<object>();
|
||||
paramList.Add(guidId.ToGuidParamValue());
|
||||
paramList.Add(userId.ToGuidParamValue());
|
||||
paramList.Add(client);
|
||||
|
||||
foreach (var row in connection.Query(commandText, paramList.ToArray()))
|
||||
using (var statement = connection.PrepareStatement("select data from userdisplaypreferences where id = @id and userId=@userId and client=@client"))
|
||||
{
|
||||
return Get(row);
|
||||
statement.TryBind("@id", guidId.ToGuidParamValue());
|
||||
statement.TryBind("@userId", userId.ToGuidParamValue());
|
||||
statement.TryBind("@client", client);
|
||||
|
||||
foreach (var row in statement.ExecuteQuery())
|
||||
{
|
||||
return Get(row);
|
||||
}
|
||||
}
|
||||
|
||||
return new DisplayPreferences
|
||||
|
@ -197,14 +200,14 @@ namespace Emby.Server.Implementations.Data
|
|||
{
|
||||
using (var connection = CreateConnection(true))
|
||||
{
|
||||
var commandText = "select data from userdisplaypreferences where userId=?";
|
||||
|
||||
var paramList = new List<object>();
|
||||
paramList.Add(userId.ToGuidParamValue());
|
||||
|
||||
foreach (var row in connection.Query(commandText, paramList.ToArray()))
|
||||
using (var statement = connection.PrepareStatement("select data from userdisplaypreferences where userId=@userId"))
|
||||
{
|
||||
list.Add(Get(row));
|
||||
statement.TryBind("@userId", userId.ToGuidParamValue());
|
||||
|
||||
foreach (var row in statement.ExecuteQuery())
|
||||
{
|
||||
list.Add(Get(row));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -137,5 +137,256 @@ namespace Emby.Server.Implementations.Data
|
|||
|
||||
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.Collections.Generic;
|
||||
//using System.IO;
|
||||
//using System.Linq;
|
||||
//using System.Threading;
|
||||
//using System.Threading.Tasks;
|
||||
//using MediaBrowser.Common.Configuration;
|
||||
//using MediaBrowser.Controller.Entities;
|
||||
//using MediaBrowser.Controller.Persistence;
|
||||
//using MediaBrowser.Model.Logging;
|
||||
//using SQLitePCL.pretty;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Common.Configuration;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Persistence;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using SQLitePCL.pretty;
|
||||
|
||||
//namespace Emby.Server.Implementations.Data
|
||||
//{
|
||||
// public class SqliteUserDataRepository : BaseSqliteRepository, IUserDataRepository
|
||||
// {
|
||||
// private SQLiteDatabaseConnection _connection;
|
||||
namespace Emby.Server.Implementations.Data
|
||||
{
|
||||
public class SqliteUserDataRepository : BaseSqliteRepository, IUserDataRepository
|
||||
{
|
||||
private SQLiteDatabaseConnection _connection;
|
||||
|
||||
// public SqliteUserDataRepository(ILogger logger, IApplicationPaths appPaths)
|
||||
// : base(logger)
|
||||
// {
|
||||
// DbFilePath = Path.Combine(appPaths.DataPath, "userdata_v2.db");
|
||||
// }
|
||||
public SqliteUserDataRepository(ILogger logger, IApplicationPaths appPaths)
|
||||
: base(logger)
|
||||
{
|
||||
DbFilePath = Path.Combine(appPaths.DataPath, "userdata_v2.db");
|
||||
}
|
||||
|
||||
// protected override bool EnableConnectionPooling
|
||||
// {
|
||||
// get { return false; }
|
||||
// }
|
||||
protected override bool EnableConnectionPooling
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
// /// <summary>
|
||||
// /// Gets the name of the repository
|
||||
// /// </summary>
|
||||
// /// <value>The name.</value>
|
||||
// public string Name
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// return "SQLite";
|
||||
// }
|
||||
// }
|
||||
/// <summary>
|
||||
/// Gets the name of the repository
|
||||
/// </summary>
|
||||
/// <value>The name.</value>
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return "SQLite";
|
||||
}
|
||||
}
|
||||
|
||||
// /// <summary>
|
||||
// /// Opens the connection to the database
|
||||
// /// </summary>
|
||||
// /// <returns>Task.</returns>
|
||||
// public void Initialize(SQLiteDatabaseConnection connection, ReaderWriterLockSlim writeLock)
|
||||
// {
|
||||
// WriteLock.Dispose();
|
||||
// WriteLock = writeLock;
|
||||
// _connection = connection;
|
||||
/// <summary>
|
||||
/// Opens the connection to the database
|
||||
/// </summary>
|
||||
/// <returns>Task.</returns>
|
||||
public void Initialize(SQLiteDatabaseConnection connection, ReaderWriterLockSlim writeLock)
|
||||
{
|
||||
WriteLock.Dispose();
|
||||
WriteLock = writeLock;
|
||||
_connection = connection;
|
||||
|
||||
// string[] queries = {
|
||||
string[] queries = {
|
||||
|
||||
// "create table if not exists UserDataDb.userdata (key nvarchar, userId GUID, rating float null, played bit, playCount int, isFavorite bit, playbackPositionTicks bigint, lastPlayedDate datetime null)",
|
||||
"create table if not exists UserDataDb.userdata (key nvarchar, userId GUID, rating float null, played bit, playCount int, isFavorite bit, playbackPositionTicks bigint, lastPlayedDate datetime null)",
|
||||
|
||||
// "drop index if exists UserDataDb.idx_userdata",
|
||||
// "drop index if exists UserDataDb.idx_userdata1",
|
||||
// "drop index if exists UserDataDb.idx_userdata2",
|
||||
// "drop index if exists UserDataDb.userdataindex1",
|
||||
"drop index if exists UserDataDb.idx_userdata",
|
||||
"drop index if exists UserDataDb.idx_userdata1",
|
||||
"drop index if exists UserDataDb.idx_userdata2",
|
||||
"drop index if exists UserDataDb.userdataindex1",
|
||||
|
||||
// "create unique index if not exists UserDataDb.userdataindex on userdata (key, userId)",
|
||||
// "create index if not exists UserDataDb.userdataindex2 on userdata (key, userId, played)",
|
||||
// "create index if not exists UserDataDb.userdataindex3 on userdata (key, userId, playbackPositionTicks)",
|
||||
// "create index if not exists UserDataDb.userdataindex4 on userdata (key, userId, isFavorite)",
|
||||
"create unique index if not exists UserDataDb.userdataindex on userdata (key, userId)",
|
||||
"create index if not exists UserDataDb.userdataindex2 on userdata (key, userId, played)",
|
||||
"create index if not exists UserDataDb.userdataindex3 on userdata (key, userId, playbackPositionTicks)",
|
||||
"create index if not exists UserDataDb.userdataindex4 on userdata (key, userId, isFavorite)",
|
||||
|
||||
// //pragmas
|
||||
// "pragma temp_store = memory",
|
||||
//pragmas
|
||||
"pragma temp_store = memory",
|
||||
|
||||
// "pragma shrink_memory"
|
||||
// };
|
||||
"pragma shrink_memory"
|
||||
};
|
||||
|
||||
// _connection.RunQueries(queries);
|
||||
_connection.RunQueries(queries);
|
||||
|
||||
// connection.RunInTransaction(db =>
|
||||
// {
|
||||
// var existingColumnNames = GetColumnNames(db, "userdata");
|
||||
connection.RunInTransaction(db =>
|
||||
{
|
||||
var existingColumnNames = GetColumnNames(db, "userdata");
|
||||
|
||||
// AddColumn(db, "userdata", "AudioStreamIndex", "int", existingColumnNames);
|
||||
// AddColumn(db, "userdata", "SubtitleStreamIndex", "int", existingColumnNames);
|
||||
// });
|
||||
// }
|
||||
AddColumn(db, "userdata", "AudioStreamIndex", "int", existingColumnNames);
|
||||
AddColumn(db, "userdata", "SubtitleStreamIndex", "int", existingColumnNames);
|
||||
});
|
||||
}
|
||||
|
||||
// /// <summary>
|
||||
// /// Saves the user data.
|
||||
// /// </summary>
|
||||
// /// <param name="userId">The user id.</param>
|
||||
// /// <param name="key">The key.</param>
|
||||
// /// <param name="userData">The user data.</param>
|
||||
// /// <param name="cancellationToken">The cancellation token.</param>
|
||||
// /// <returns>Task.</returns>
|
||||
// /// <exception cref="System.ArgumentNullException">userData
|
||||
// /// or
|
||||
// /// cancellationToken
|
||||
// /// or
|
||||
// /// userId
|
||||
// /// or
|
||||
// /// userDataId</exception>
|
||||
// public Task SaveUserData(Guid userId, string key, UserItemData userData, CancellationToken cancellationToken)
|
||||
// {
|
||||
// if (userData == null)
|
||||
// {
|
||||
// throw new ArgumentNullException("userData");
|
||||
// }
|
||||
// if (userId == Guid.Empty)
|
||||
// {
|
||||
// throw new ArgumentNullException("userId");
|
||||
// }
|
||||
// if (string.IsNullOrEmpty(key))
|
||||
// {
|
||||
// throw new ArgumentNullException("key");
|
||||
// }
|
||||
/// <summary>
|
||||
/// Saves the user data.
|
||||
/// </summary>
|
||||
/// <param name="userId">The user id.</param>
|
||||
/// <param name="key">The key.</param>
|
||||
/// <param name="userData">The user data.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task.</returns>
|
||||
/// <exception cref="System.ArgumentNullException">userData
|
||||
/// or
|
||||
/// cancellationToken
|
||||
/// or
|
||||
/// userId
|
||||
/// or
|
||||
/// userDataId</exception>
|
||||
public Task SaveUserData(Guid userId, string key, UserItemData userData, CancellationToken cancellationToken)
|
||||
{
|
||||
if (userData == null)
|
||||
{
|
||||
throw new ArgumentNullException("userData");
|
||||
}
|
||||
if (userId == Guid.Empty)
|
||||
{
|
||||
throw new ArgumentNullException("userId");
|
||||
}
|
||||
if (string.IsNullOrEmpty(key))
|
||||
{
|
||||
throw new ArgumentNullException("key");
|
||||
}
|
||||
|
||||
// return PersistUserData(userId, key, userData, cancellationToken);
|
||||
// }
|
||||
return PersistUserData(userId, key, userData, cancellationToken);
|
||||
}
|
||||
|
||||
// public Task SaveAllUserData(Guid userId, IEnumerable<UserItemData> userData, CancellationToken cancellationToken)
|
||||
// {
|
||||
// if (userData == null)
|
||||
// {
|
||||
// throw new ArgumentNullException("userData");
|
||||
// }
|
||||
// if (userId == Guid.Empty)
|
||||
// {
|
||||
// throw new ArgumentNullException("userId");
|
||||
// }
|
||||
public Task SaveAllUserData(Guid userId, IEnumerable<UserItemData> userData, CancellationToken cancellationToken)
|
||||
{
|
||||
if (userData == null)
|
||||
{
|
||||
throw new ArgumentNullException("userData");
|
||||
}
|
||||
if (userId == Guid.Empty)
|
||||
{
|
||||
throw new ArgumentNullException("userId");
|
||||
}
|
||||
|
||||
// return PersistAllUserData(userId, userData.ToList(), cancellationToken);
|
||||
// }
|
||||
return PersistAllUserData(userId, userData.ToList(), cancellationToken);
|
||||
}
|
||||
|
||||
// /// <summary>
|
||||
// /// Persists the user data.
|
||||
// /// </summary>
|
||||
// /// <param name="userId">The user id.</param>
|
||||
// /// <param name="key">The key.</param>
|
||||
// /// <param name="userData">The user data.</param>
|
||||
// /// <param name="cancellationToken">The cancellation token.</param>
|
||||
// /// <returns>Task.</returns>
|
||||
// public async Task PersistUserData(Guid userId, string key, UserItemData userData, CancellationToken cancellationToken)
|
||||
// {
|
||||
// cancellationToken.ThrowIfCancellationRequested();
|
||||
/// <summary>
|
||||
/// Persists the user data.
|
||||
/// </summary>
|
||||
/// <param name="userId">The user id.</param>
|
||||
/// <param name="key">The key.</param>
|
||||
/// <param name="userData">The user data.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task.</returns>
|
||||
public async Task PersistUserData(Guid userId, string key, UserItemData userData, CancellationToken cancellationToken)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
// using (WriteLock.Write())
|
||||
// {
|
||||
// _connection.RunInTransaction(db =>
|
||||
// {
|
||||
// SaveUserData(db, userId, key, userData);
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
using (WriteLock.Write())
|
||||
{
|
||||
_connection.RunInTransaction(db =>
|
||||
{
|
||||
SaveUserData(db, userId, key, userData);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// private void SaveUserData(IDatabaseConnection db, Guid userId, string key, UserItemData userData)
|
||||
// {
|
||||
// var paramList = new List<object>();
|
||||
// var commandText = "replace into userdata (key, userId, rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex) values (?, ?, ?,?,?,?,?,?,?,?)";
|
||||
private void SaveUserData(IDatabaseConnection db, Guid userId, string key, UserItemData userData)
|
||||
{
|
||||
using (var statement = _connection.PrepareStatement("replace into userdata (key, userId, rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex) values (@key, @userId, @rating,@played,@playCount,@isFavorite,@playbackPositionTicks,@lastPlayedDate,@AudioStreamIndex,@SubtitleStreamIndex)"))
|
||||
{
|
||||
statement.TryBind("@UserId", userId.ToGuidParamValue());
|
||||
statement.TryBind("@Key", key);
|
||||
|
||||
// paramList.Add(key);
|
||||
// paramList.Add(userId.ToGuidParamValue());
|
||||
// paramList.Add(userData.Rating);
|
||||
// paramList.Add(userData.Played);
|
||||
// paramList.Add(userData.PlayCount);
|
||||
// paramList.Add(userData.IsFavorite);
|
||||
// paramList.Add(userData.PlaybackPositionTicks);
|
||||
if (userData.Rating.HasValue)
|
||||
{
|
||||
statement.TryBind("@rating", userData.Rating.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
statement.TryBindNull("@rating");
|
||||
}
|
||||
|
||||
// if (userData.LastPlayedDate.HasValue)
|
||||
// {
|
||||
// paramList.Add(userData.LastPlayedDate.Value.ToDateTimeParamValue());
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// paramList.Add(null);
|
||||
// }
|
||||
// paramList.Add(userData.AudioStreamIndex);
|
||||
// paramList.Add(userData.SubtitleStreamIndex);
|
||||
statement.TryBind("@played", userData.Played);
|
||||
statement.TryBind("@playCount", userData.PlayCount);
|
||||
statement.TryBind("@isFavorite", userData.IsFavorite);
|
||||
statement.TryBind("@playbackPositionTicks", userData.PlaybackPositionTicks);
|
||||
|
||||
// db.Execute(commandText, paramList.ToArray());
|
||||
// }
|
||||
if (userData.LastPlayedDate.HasValue)
|
||||
{
|
||||
statement.TryBind("@lastPlayedDate", userData.LastPlayedDate.Value.ToDateTimeParamValue());
|
||||
}
|
||||
else
|
||||
{
|
||||
statement.TryBindNull("@lastPlayedDate");
|
||||
}
|
||||
|
||||
// /// <summary>
|
||||
// /// Persist all user data for the specified user
|
||||
// /// </summary>
|
||||
// private async Task PersistAllUserData(Guid userId, List<UserItemData> userDataList, CancellationToken cancellationToken)
|
||||
// {
|
||||
// cancellationToken.ThrowIfCancellationRequested();
|
||||
if (userData.AudioStreamIndex.HasValue)
|
||||
{
|
||||
statement.TryBind("@AudioStreamIndex", userData.AudioStreamIndex.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
statement.TryBindNull("@AudioStreamIndex");
|
||||
}
|
||||
|
||||
// using (WriteLock.Write())
|
||||
// {
|
||||
// _connection.RunInTransaction(db =>
|
||||
// {
|
||||
// foreach (var userItemData in userDataList)
|
||||
// {
|
||||
// SaveUserData(db, userId, userItemData.Key, userItemData);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
if (userData.SubtitleStreamIndex.HasValue)
|
||||
{
|
||||
statement.TryBind("@SubtitleStreamIndex", userData.SubtitleStreamIndex.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
statement.TryBindNull("@SubtitleStreamIndex");
|
||||
}
|
||||
|
||||
// /// <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");
|
||||
// }
|
||||
statement.MoveNext();
|
||||
}
|
||||
}
|
||||
|
||||
// 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>();
|
||||
// paramList.Add(key);
|
||||
// paramList.Add(userId.ToGuidParamValue());
|
||||
using (WriteLock.Write())
|
||||
{
|
||||
_connection.RunInTransaction(db =>
|
||||
{
|
||||
foreach (var userItemData in userDataList)
|
||||
{
|
||||
SaveUserData(db, userId, userItemData.Key, userItemData);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// foreach (var row in _connection.Query(commandText, paramList.ToArray()))
|
||||
// {
|
||||
// return ReadRow(row);
|
||||
// }
|
||||
/// <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");
|
||||
}
|
||||
|
||||
// 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)
|
||||
// {
|
||||
// if (userId == Guid.Empty)
|
||||
// {
|
||||
// throw new ArgumentNullException("userId");
|
||||
// }
|
||||
// if (keys == null)
|
||||
// {
|
||||
// throw new ArgumentNullException("keys");
|
||||
// }
|
||||
foreach (var row in statement.ExecuteQuery())
|
||||
{
|
||||
return ReadRow(row);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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>
|
||||
// /// 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");
|
||||
// }
|
||||
if (keys.Count == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// var list = new List<UserItemData>();
|
||||
return GetUserData(userId, keys[0]);
|
||||
}
|
||||
|
||||
// using (WriteLock.Read())
|
||||
// {
|
||||
// var commandText = "select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where userId=?";
|
||||
/// <summary>
|
||||
/// Return all user-data associated with the given user
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<UserItemData> GetAllUserData(Guid userId)
|
||||
{
|
||||
if (userId == Guid.Empty)
|
||||
{
|
||||
throw new ArgumentNullException("userId");
|
||||
}
|
||||
|
||||
// var paramList = new List<object>();
|
||||
// paramList.Add(userId.ToGuidParamValue());
|
||||
var list = new List<UserItemData>();
|
||||
|
||||
// foreach (var row in _connection.Query(commandText, paramList.ToArray()))
|
||||
// {
|
||||
// list.Add(ReadRow(row));
|
||||
// }
|
||||
// }
|
||||
using (WriteLock.Write())
|
||||
{
|
||||
using (var statement = _connection.PrepareStatement("select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where userId=@UserId"))
|
||||
{
|
||||
statement.TryBind("@UserId", userId.ToGuidParamValue());
|
||||
|
||||
// return list;
|
||||
// }
|
||||
foreach (var row in statement.ExecuteQuery())
|
||||
{
|
||||
list.Add(ReadRow(row));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// /// <summary>
|
||||
// /// Read a row from the specified reader into the provided userData object
|
||||
// /// </summary>
|
||||
// /// <param name="reader"></param>
|
||||
// private UserItemData ReadRow(IReadOnlyList<IResultSetValue> reader)
|
||||
// {
|
||||
// var userData = new UserItemData();
|
||||
return list;
|
||||
}
|
||||
|
||||
// userData.Key = reader[0].ToString();
|
||||
// userData.UserId = reader[1].ReadGuid();
|
||||
/// <summary>
|
||||
/// Read a row from the specified reader into the provided userData object
|
||||
/// </summary>
|
||||
/// <param name="reader"></param>
|
||||
private UserItemData ReadRow(IReadOnlyList<IResultSetValue> reader)
|
||||
{
|
||||
var userData = new UserItemData();
|
||||
|
||||
// if (reader[2].SQLiteType != SQLiteType.Null)
|
||||
// {
|
||||
// userData.Rating = reader[2].ToDouble();
|
||||
// }
|
||||
userData.Key = reader[0].ToString();
|
||||
userData.UserId = reader[1].ReadGuid();
|
||||
|
||||
// userData.Played = reader[3].ToBool();
|
||||
// userData.PlayCount = reader[4].ToInt();
|
||||
// userData.IsFavorite = reader[5].ToBool();
|
||||
// userData.PlaybackPositionTicks = reader[6].ToInt64();
|
||||
if (reader[2].SQLiteType != SQLiteType.Null)
|
||||
{
|
||||
userData.Rating = reader[2].ToDouble();
|
||||
}
|
||||
|
||||
// if (reader[7].SQLiteType != SQLiteType.Null)
|
||||
// {
|
||||
// userData.LastPlayedDate = reader[7].ReadDateTime();
|
||||
// }
|
||||
userData.Played = reader[3].ToBool();
|
||||
userData.PlayCount = reader[4].ToInt();
|
||||
userData.IsFavorite = reader[5].ToBool();
|
||||
userData.PlaybackPositionTicks = reader[6].ToInt64();
|
||||
|
||||
// if (reader[8].SQLiteType != SQLiteType.Null)
|
||||
// {
|
||||
// userData.AudioStreamIndex = reader[8].ToInt();
|
||||
// }
|
||||
if (reader[7].SQLiteType != SQLiteType.Null)
|
||||
{
|
||||
userData.LastPlayedDate = reader[7].ReadDateTime();
|
||||
}
|
||||
|
||||
// if (reader[9].SQLiteType != SQLiteType.Null)
|
||||
// {
|
||||
// userData.SubtitleStreamIndex = reader[9].ToInt();
|
||||
// }
|
||||
if (reader[8].SQLiteType != SQLiteType.Null)
|
||||
{
|
||||
userData.AudioStreamIndex = reader[8].ToInt();
|
||||
}
|
||||
|
||||
// return userData;
|
||||
// }
|
||||
if (reader[9].SQLiteType != SQLiteType.Null)
|
||||
{
|
||||
userData.SubtitleStreamIndex = reader[9].ToInt();
|
||||
}
|
||||
|
||||
// protected override void Dispose(bool dispose)
|
||||
// {
|
||||
// // handled by library database
|
||||
// }
|
||||
return userData;
|
||||
}
|
||||
|
||||
// protected override void CloseConnection()
|
||||
// {
|
||||
// // handled by library database
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
protected override void Dispose(bool dispose)
|
||||
{
|
||||
// handled by library database
|
||||
}
|
||||
|
||||
protected override void CloseConnection()
|
||||
{
|
||||
// handled by library database
|
||||
}
|
||||
}
|
||||
}
|
|
@ -89,11 +89,12 @@ namespace Emby.Server.Implementations.Data
|
|||
{
|
||||
connection.RunInTransaction(db =>
|
||||
{
|
||||
var commandText = "replace into users (guid, data) values (?, ?)";
|
||||
|
||||
db.Execute(commandText,
|
||||
user.Id.ToGuidParamValue(),
|
||||
serialized);
|
||||
using (var statement = db.PrepareStatement("replace into users (guid, data) values (@guid, @data)"))
|
||||
{
|
||||
statement.TryBind("@guid", user.Id.ToGuidParamValue());
|
||||
statement.TryBind("@data", serialized);
|
||||
statement.MoveNext();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -151,10 +152,11 @@ namespace Emby.Server.Implementations.Data
|
|||
{
|
||||
connection.RunInTransaction(db =>
|
||||
{
|
||||
var commandText = "delete from users where guid=?";
|
||||
|
||||
db.Execute(commandText,
|
||||
user.Id.ToGuidParamValue());
|
||||
using (var statement = db.PrepareStatement("delete from users where guid=@id"))
|
||||
{
|
||||
statement.TryBind("@id", user.Id.ToGuidParamValue());
|
||||
statement.MoveNext();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ namespace Emby.Server.Implementations.FileOrganization
|
|||
return new[] {
|
||||
|
||||
// Every so often
|
||||
new TaskTriggerInfo { Type = TaskTriggerInfo.TriggerInterval, IntervalTicks = TimeSpan.FromMinutes(15).Ticks}
|
||||
new TaskTriggerInfo { Type = TaskTriggerInfo.TriggerInterval, IntervalTicks = TimeSpan.FromMinutes(5).Ticks}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -107,17 +107,23 @@ namespace Emby.Server.Implementations.Notifications
|
|||
{
|
||||
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"))
|
||||
{
|
||||
var levels = new List<NotificationLevel>();
|
||||
statement.TryBind("@IsRead", false);
|
||||
statement.TryBind("@UserId", userId.ToGuidParamValue());
|
||||
|
||||
levels.Add(GetLevel(row, 0));
|
||||
|
||||
result.UnreadCount = levels.Count;
|
||||
|
||||
if (levels.Count > 0)
|
||||
foreach (var row in statement.ExecuteQuery())
|
||||
{
|
||||
result.MaxUnreadNotificationLevel = levels.Max();
|
||||
var levels = new List<NotificationLevel>();
|
||||
|
||||
levels.Add(GetLevel(row, 0));
|
||||
|
||||
result.UnreadCount = levels.Count;
|
||||
|
||||
if (levels.Count > 0)
|
||||
{
|
||||
result.MaxUnreadNotificationLevel = levels.Max();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -220,17 +226,21 @@ namespace Emby.Server.Implementations.Notifications
|
|||
{
|
||||
connection.RunInTransaction(conn =>
|
||||
{
|
||||
conn.Execute("replace into Notifications (Id, UserId, Date, Name, Description, Url, Level, IsRead, Category, RelatedId) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
notification.Id.ToGuidParamValue(),
|
||||
notification.UserId.ToGuidParamValue(),
|
||||
notification.Date.ToDateTimeParamValue(),
|
||||
notification.Name,
|
||||
notification.Description,
|
||||
notification.Url,
|
||||
notification.Level.ToString(),
|
||||
notification.IsRead,
|
||||
string.Empty,
|
||||
string.Empty);
|
||||
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)"))
|
||||
{
|
||||
statement.TryBind("@Id", notification.Id.ToGuidParamValue());
|
||||
statement.TryBind("@UserId", notification.UserId.ToGuidParamValue());
|
||||
statement.TryBind("@Date", notification.Date.ToDateTimeParamValue());
|
||||
statement.TryBind("@Name", notification.Name);
|
||||
statement.TryBind("@Description", notification.Description);
|
||||
statement.TryBind("@Url", notification.Url);
|
||||
statement.TryBind("@Level", notification.Level.ToString());
|
||||
statement.TryBind("@IsRead", notification.IsRead);
|
||||
statement.TryBind("@Category", string.Empty);
|
||||
statement.TryBind("@RelatedId", string.Empty);
|
||||
|
||||
statement.MoveNext();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -279,7 +289,13 @@ namespace Emby.Server.Implementations.Notifications
|
|||
{
|
||||
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 =>
|
||||
{
|
||||
var userIdParam = userId.ToGuidParamValue();
|
||||
|
||||
foreach (var id in notificationIdList)
|
||||
using (var statement = conn.PrepareStatement("update Notifications set IsRead=@IsRead where UserId=@UserId and Id=@Id"))
|
||||
{
|
||||
conn.Execute("update Notifications set IsRead=? where UserId=? and Id=?", userIdParam, isRead, id);
|
||||
statement.TryBind("@IsRead", isRead);
|
||||
statement.TryBind("@UserId", userId.ToGuidParamValue());
|
||||
|
||||
foreach (var id in notificationIdList)
|
||||
{
|
||||
statement.Reset();
|
||||
|
||||
statement.TryBind("@Id", id.ToGuidParamValue());
|
||||
|
||||
statement.MoveNext();
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,19 +69,30 @@ namespace Emby.Server.Implementations.Security
|
|||
{
|
||||
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,
|
||||
info.Id.ToGuidParamValue(),
|
||||
info.AccessToken,
|
||||
info.DeviceId,
|
||||
info.AppName,
|
||||
info.AppVersion,
|
||||
info.DeviceName,
|
||||
info.UserId,
|
||||
info.IsActive,
|
||||
info.DateCreated.ToDateTimeParamValue(),
|
||||
info.DateRevoked.HasValue ? info.DateRevoked.Value.ToDateTimeParamValue() : null);
|
||||
statement.TryBind("@DeviceId", info.DeviceId);
|
||||
statement.TryBind("@AppName", info.AppName);
|
||||
statement.TryBind("@AppVersion", info.AppVersion);
|
||||
statement.TryBind("@DeviceName", info.DeviceName);
|
||||
statement.TryBind("@UserId", info.UserId);
|
||||
statement.TryBind("@IsActive", info.IsActive);
|
||||
statement.TryBind("@DateCreated", info.DateCreated.ToDateTimeParamValue());
|
||||
|
||||
if (info.DateRevoked.HasValue)
|
||||
{
|
||||
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 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)
|
||||
{
|
||||
if (query == null)
|
||||
|
@ -99,7 +133,6 @@ namespace Emby.Server.Implementations.Security
|
|||
using (var connection = CreateConnection(true))
|
||||
{
|
||||
var commandText = BaseSelectText;
|
||||
var paramList = new List<object>();
|
||||
|
||||
var whereClauses = new List<string>();
|
||||
|
||||
|
@ -107,26 +140,22 @@ namespace Emby.Server.Implementations.Security
|
|||
|
||||
if (!string.IsNullOrWhiteSpace(query.AccessToken))
|
||||
{
|
||||
whereClauses.Add("AccessToken=?");
|
||||
paramList.Add(query.AccessToken);
|
||||
whereClauses.Add("AccessToken=@AccessToken");
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(query.UserId))
|
||||
{
|
||||
whereClauses.Add("UserId=?");
|
||||
paramList.Add(query.UserId);
|
||||
whereClauses.Add("UserId=@UserId");
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(query.DeviceId))
|
||||
{
|
||||
whereClauses.Add("DeviceId=?");
|
||||
paramList.Add(query.DeviceId);
|
||||
whereClauses.Add("DeviceId=@DeviceId");
|
||||
}
|
||||
|
||||
if (query.IsActive.HasValue)
|
||||
{
|
||||
whereClauses.Add("IsActive=?");
|
||||
paramList.Add(query.IsActive.Value);
|
||||
whereClauses.Add("IsActive=@IsActive");
|
||||
}
|
||||
|
||||
if (query.HasUser.HasValue)
|
||||
|
@ -171,20 +200,30 @@ namespace Emby.Server.Implementations.Security
|
|||
|
||||
var list = new List<AuthenticationInfo>();
|
||||
|
||||
foreach (var row in connection.Query(commandText, paramList.ToArray()))
|
||||
using (var statement = connection.PrepareStatement(commandText))
|
||||
{
|
||||
list.Add(Get(row));
|
||||
BindAuthenticationQueryParams(query, statement);
|
||||
|
||||
foreach (var row in statement.ExecuteQuery())
|
||||
{
|
||||
list.Add(Get(row));
|
||||
}
|
||||
|
||||
using (var totalCountStatement = connection.PrepareStatement("select count (Id) from AccessTokens" + whereTextWithoutPaging))
|
||||
{
|
||||
BindAuthenticationQueryParams(query, totalCountStatement);
|
||||
|
||||
var count = totalCountStatement.ExecuteQuery()
|
||||
.SelectScalarInt()
|
||||
.First();
|
||||
|
||||
return new QueryResult<AuthenticationInfo>()
|
||||
{
|
||||
Items = list.ToArray(),
|
||||
TotalRecordCount = count
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
var count = connection.Query("select count (Id) from AccessTokens" + whereTextWithoutPaging, paramList.ToArray())
|
||||
.SelectScalarInt()
|
||||
.First();
|
||||
|
||||
return new QueryResult<AuthenticationInfo>()
|
||||
{
|
||||
Items = list.ToArray(),
|
||||
TotalRecordCount = count
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -199,16 +238,18 @@ namespace Emby.Server.Implementations.Security
|
|||
{
|
||||
using (var connection = CreateConnection(true))
|
||||
{
|
||||
var commandText = BaseSelectText + " where Id=?";
|
||||
var paramList = new List<object>();
|
||||
var commandText = BaseSelectText + " where Id=@Id";
|
||||
|
||||
paramList.Add(id.ToGuidParamValue());
|
||||
|
||||
foreach (var row in connection.Query(commandText, paramList.ToArray()))
|
||||
using (var statement = connection.PrepareStatement(commandText))
|
||||
{
|
||||
return Get(row);
|
||||
statement.BindParameters["@Id"].Bind(id.ToGuidParamValue());
|
||||
|
||||
foreach (var row in statement.ExecuteQuery())
|
||||
{
|
||||
return Get(row);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -492,14 +492,11 @@ namespace Emby.Server.Implementations.Sync
|
|||
using (var connection = CreateConnection(true))
|
||||
{
|
||||
var commandText = "select ItemId,Status,Progress from SyncJobItems";
|
||||
|
||||
var whereClauses = new List<string>();
|
||||
var paramList = new List<object>();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(query.TargetId))
|
||||
{
|
||||
whereClauses.Add("TargetId=?");
|
||||
paramList.Add(query.TargetId);
|
||||
whereClauses.Add("TargetId=@TargetId");
|
||||
}
|
||||
|
||||
if (query.Statuses.Length > 0)
|
||||
|
@ -514,22 +511,39 @@ namespace Emby.Server.Implementations.Sync
|
|||
commandText += " where " + string.Join(" AND ", whereClauses.ToArray());
|
||||
}
|
||||
|
||||
foreach (var row in connection.Query(commandText, paramList.ToArray()))
|
||||
using (var statement = connection.PrepareStatement(commandText))
|
||||
{
|
||||
AddStatusResult(row, result, false);
|
||||
if (!string.IsNullOrWhiteSpace(query.TargetId))
|
||||
{
|
||||
statement.TryBind("@TargetId", query.TargetId);
|
||||
}
|
||||
|
||||
foreach (var row in statement.ExecuteQuery())
|
||||
{
|
||||
AddStatusResult(row, result, false);
|
||||
}
|
||||
LogQueryTime("GetSyncedItemProgresses", commandText, now);
|
||||
}
|
||||
LogQueryTime("GetSyncedItemProgresses", commandText, now);
|
||||
|
||||
commandText = commandText
|
||||
.Replace("select ItemId,Status,Progress from SyncJobItems", "select ItemIds,Status,Progress from SyncJobs")
|
||||
.Replace("'Synced'", "'Completed','CompletedWithError'");
|
||||
|
||||
now = DateTime.UtcNow;
|
||||
foreach (var row in connection.Query(commandText, paramList.ToArray()))
|
||||
|
||||
using (var statement = connection.PrepareStatement(commandText))
|
||||
{
|
||||
AddStatusResult(row, result, true);
|
||||
if (!string.IsNullOrWhiteSpace(query.TargetId))
|
||||
{
|
||||
statement.TryBind("@TargetId", query.TargetId);
|
||||
}
|
||||
|
||||
foreach (var row in statement.ExecuteQuery())
|
||||
{
|
||||
AddStatusResult(row, result, true);
|
||||
}
|
||||
LogQueryTime("GetSyncedItemProgresses", commandText, now);
|
||||
}
|
||||
LogQueryTime("GetSyncedItemProgresses", commandText, now);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ namespace MediaBrowser.Controller.Entities
|
|||
|
||||
public IEnumerable<BaseItem> GetTaggedItems(InternalItemsQuery query)
|
||||
{
|
||||
query.Person = Name;
|
||||
query.PersonIds = new[] { Id.ToString("N") };
|
||||
|
||||
return LibraryManager.GetItemList(query);
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ namespace MediaBrowser.Controller.Entities
|
|||
{
|
||||
var itemsWithPerson = LibraryManager.GetItemIds(new InternalItemsQuery
|
||||
{
|
||||
Person = Name
|
||||
PersonIds = new[] { Id.ToString("N") }
|
||||
});
|
||||
|
||||
return inputItems.Where(i => itemsWithPerson.Contains(i.Id));
|
||||
|
|
|
@ -51,7 +51,7 @@ namespace MediaBrowser.Controller.Persistence
|
|||
/// <param name="items">The items.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task.</returns>
|
||||
Task SaveItems(IEnumerable<BaseItem> items, CancellationToken cancellationToken);
|
||||
Task SaveItems(List<BaseItem> items, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the item.
|
||||
|
@ -147,7 +147,7 @@ namespace MediaBrowser.Controller.Persistence
|
|||
/// </summary>
|
||||
/// <param name="query">The query.</param>
|
||||
/// <returns>QueryResult<Tuple<Guid, System.String>>.</returns>
|
||||
QueryResult<Tuple<Guid, string>> GetItemIdsWithPath(InternalItemsQuery query);
|
||||
List<Tuple<Guid, string>> GetItemIdsWithPath(InternalItemsQuery query);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the item list.
|
||||
|
|
|
@ -62,13 +62,10 @@ namespace MediaBrowser.Providers.People
|
|||
|
||||
public Task<IEnumerable<RemoteImageInfo>> GetImages(IHasImages item, CancellationToken cancellationToken)
|
||||
{
|
||||
// Avoid implicitly captured closure
|
||||
var itemName = item.Name;
|
||||
|
||||
var seriesWithPerson = _libraryManager.GetItemList(new InternalItemsQuery
|
||||
{
|
||||
IncludeItemTypes = new[] { typeof(Series).Name },
|
||||
Person = itemName
|
||||
PersonIds = new[] { item.Id.ToString("N") }
|
||||
|
||||
}).Cast<Series>()
|
||||
.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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -115,9 +115,6 @@
|
|||
<HintPath>..\packages\SQLitePCLRaw.provider.sqlite3.net45.1.1.1-pre20161109081005\lib\net45\SQLitePCLRaw.provider.sqlite3.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</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="Emby.Common.Implementations">
|
||||
<HintPath>..\ThirdParty\emby\Emby.Common.Implementations.dll</HintPath>
|
||||
|
@ -151,9 +148,6 @@
|
|||
<Compile Include="Main.cs" />
|
||||
<Compile Include="MenuBarIcon.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="Native\MonoFileSystem.cs" />
|
||||
<Compile Include="Native\PowerManagement.cs" />
|
||||
|
|
|
@ -88,10 +88,6 @@
|
|||
<HintPath>..\packages\SQLitePCLRaw.core.1.1.1-pre20161109081005\lib\net45\SQLitePCLRaw.core.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</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="MediaBrowser.IsoMounting.Linux">
|
||||
<HintPath>..\ThirdParty\MediaBrowser.IsoMounting.Linux\MediaBrowser.IsoMounting.Linux.dll</HintPath>
|
||||
|
@ -99,7 +95,7 @@
|
|||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Data.SQLite">
|
||||
<HintPath>..\ThirdParty\System.Data.SQLite.ManagedOnly\1.0.94.0\System.Data.SQLite.dll</HintPath>
|
||||
<HintPath>..\ThirdParty\SQLitePCLRaw.provider.sqlite3.net45\System.Data.SQLite.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.IO.Compression" />
|
||||
<Reference Include="System.Runtime.Serialization" />
|
||||
|
@ -108,14 +104,10 @@
|
|||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\MediaBrowser.Server.Startup.Common\Persistence\SqliteExtensions.cs">
|
||||
<Link>Native\SqliteExtensions.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\SharedVersion.cs">
|
||||
<Link>Properties\SharedVersion.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="MonoAppHost.cs" />
|
||||
<Compile Include="Native\DbConnector.cs" />
|
||||
<Compile Include="Native\MonoFileSystem.cs" />
|
||||
<Compile Include="Native\PowerManagement.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
|
@ -230,10 +222,6 @@
|
|||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<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">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<SubType>Designer</SubType>
|
||||
|
|
|
@ -2,14 +2,12 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using Emby.Server.Core;
|
||||
using Emby.Server.Core.Data;
|
||||
using Emby.Server.Implementations;
|
||||
using Emby.Server.Implementations.FFMpeg;
|
||||
using MediaBrowser.IsoMounter;
|
||||
using MediaBrowser.Model.IO;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.Model.System;
|
||||
using MediaBrowser.Server.Mono.Native;
|
||||
|
||||
namespace MediaBrowser.Server.Mono
|
||||
{
|
||||
|
@ -123,11 +121,6 @@ namespace MediaBrowser.Server.Mono
|
|||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
protected override IDbConnector GetDbConnector()
|
||||
{
|
||||
return new DbConnector(Logger);
|
||||
}
|
||||
|
||||
protected override void ConfigureAutoRunInternal(bool autorun)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
using System.Data;
|
||||
using System.Threading.Tasks;
|
||||
using Emby.Server.Core.Data;
|
||||
using MediaBrowser.Model.Logging;
|
||||
|
||||
namespace MediaBrowser.Server.Mono.Native
|
||||
{
|
||||
public class DbConnector : IDbConnector
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public DbConnector(ILogger logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public Task<IDbConnection> Connect(string dbPath, bool isReadOnly, bool enablePooling = false, int? cacheSize = null)
|
||||
{
|
||||
return SqliteExtensions.ConnectToDb(dbPath, isReadOnly, enablePooling, cacheSize, _logger);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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="SimpleInjector" version="3.2.4" 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>
|
|
@ -102,10 +102,6 @@
|
|||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Configuration.Install" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Data.SQLite, Version=1.0.103.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\ThirdParty\System.Data.SQLite.ManagedOnly\1.0.94.0\System.Data.SQLite.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.IO.Compression" />
|
||||
<Reference Include="System.Management" />
|
||||
|
@ -121,9 +117,6 @@
|
|||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\MediaBrowser.Server.Startup.Common\Persistence\SqliteExtensions.cs">
|
||||
<Link>Native\SqliteExtensions.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\SharedVersion.cs">
|
||||
<Link>Properties\SharedVersion.cs</Link>
|
||||
</Compile>
|
||||
|
@ -141,7 +134,6 @@
|
|||
</Compile>
|
||||
<Compile Include="MainStartup.cs" />
|
||||
<Compile Include="Native\LnkShortcutHandler.cs" />
|
||||
<Compile Include="Native\DbConnector.cs" />
|
||||
<Compile Include="Native\LoopbackUtil.cs" />
|
||||
<Compile Include="Native\PowerManagement.cs" />
|
||||
<Compile Include="Native\Standby.cs" />
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
using System.Data;
|
||||
using System.Threading.Tasks;
|
||||
using Emby.Server.Core.Data;
|
||||
using MediaBrowser.Model.Logging;
|
||||
|
||||
namespace MediaBrowser.ServerApplication.Native
|
||||
{
|
||||
public class DbConnector : IDbConnector
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public DbConnector(ILogger logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public Task<IDbConnection> Connect(string dbPath, bool isReadOnly, bool enablePooling = false, int? cacheSize = null)
|
||||
{
|
||||
return SqliteExtensions.ConnectToDb(dbPath, isReadOnly, enablePooling, cacheSize, _logger);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,7 +4,6 @@ using System.Diagnostics;
|
|||
using System.IO;
|
||||
using System.Reflection;
|
||||
using Emby.Server.Core;
|
||||
using Emby.Server.Core.Data;
|
||||
using Emby.Server.Implementations;
|
||||
using Emby.Server.Implementations.EntryPoints;
|
||||
using Emby.Server.Implementations.FFMpeg;
|
||||
|
@ -92,11 +91,6 @@ namespace MediaBrowser.ServerApplication
|
|||
ConfigurationManager.CommonApplicationPaths.TempDirectory);
|
||||
}
|
||||
|
||||
protected override IDbConnector GetDbConnector()
|
||||
{
|
||||
return new DbConnector(Logger);
|
||||
}
|
||||
|
||||
protected override void ConfigureAutoRunInternal(bool autorun)
|
||||
{
|
||||
var shortcutPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.StartMenu), "Emby", "Emby Server.lnk");
|
||||
|
|
|
@ -52,7 +52,7 @@ namespace MediaBrowser.XbmcMetadata
|
|||
|
||||
var items = _libraryManager.GetItemList(new InternalItemsQuery
|
||||
{
|
||||
Person = person.Name
|
||||
PersonIds = new [] { person.Id.ToString("N") }
|
||||
|
||||
}).ToList();
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user