aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/Data
diff options
context:
space:
mode:
Diffstat (limited to 'Emby.Server.Implementations/Data')
-rw-r--r--Emby.Server.Implementations/Data/BaseSqliteRepository.cs40
-rw-r--r--Emby.Server.Implementations/Data/CleanDatabaseScheduledTask.cs12
-rw-r--r--Emby.Server.Implementations/Data/ManagedConnection.cs9
-rw-r--r--Emby.Server.Implementations/Data/SqliteDisplayPreferencesRepository.cs32
-rw-r--r--Emby.Server.Implementations/Data/SqliteExtensions.cs45
-rw-r--r--Emby.Server.Implementations/Data/SqliteItemRepository.cs167
-rw-r--r--Emby.Server.Implementations/Data/SqliteUserDataRepository.cs59
-rw-r--r--Emby.Server.Implementations/Data/SqliteUserRepository.cs30
-rw-r--r--Emby.Server.Implementations/Data/TypeMapper.cs8
9 files changed, 155 insertions, 247 deletions
diff --git a/Emby.Server.Implementations/Data/BaseSqliteRepository.cs b/Emby.Server.Implementations/Data/BaseSqliteRepository.cs
index 59776c373..0f432c36c 100644
--- a/Emby.Server.Implementations/Data/BaseSqliteRepository.cs
+++ b/Emby.Server.Implementations/Data/BaseSqliteRepository.cs
@@ -1,12 +1,11 @@
-using System;
+using System;
using System.Collections.Generic;
using System.Globalization;
+using System.Linq;
using System.Threading;
-using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
-using SQLitePCL.pretty;
-using System.Linq;
using SQLitePCL;
+using SQLitePCL.pretty;
namespace Emby.Server.Implementations.Data
{
@@ -24,15 +23,9 @@ namespace Emby.Server.Implementations.Data
WriteLock = new ReaderWriterLockSlim(LockRecursionPolicy.NoRecursion);
}
- protected TransactionMode TransactionMode
- {
- get { return TransactionMode.Deferred; }
- }
+ protected TransactionMode TransactionMode => TransactionMode.Deferred;
- protected TransactionMode ReadTransactionMode
- {
- get { return TransactionMode.Deferred; }
- }
+ protected TransactionMode ReadTransactionMode => TransactionMode.Deferred;
internal static int ThreadSafeMode { get; set; }
@@ -58,10 +51,7 @@ namespace Emby.Server.Implementations.Data
private string _defaultWal;
protected ManagedConnection _connection;
- protected virtual bool EnableSingleConnection
- {
- get { return true; }
- }
+ protected virtual bool EnableSingleConnection => true;
protected ManagedConnection CreateConnection(bool isReadOnly = false)
{
@@ -238,21 +228,9 @@ namespace Emby.Server.Implementations.Data
Logger.LogInformation("PRAGMA synchronous=" + db.Query("PRAGMA synchronous").SelectScalarString().First());
}
- protected virtual bool EnableTempStoreMemory
- {
- get
- {
- return false;
- }
- }
+ protected virtual bool EnableTempStoreMemory => false;
- protected virtual int? CacheSize
- {
- get
- {
- return null;
- }
- }
+ protected virtual int? CacheSize => null;
internal static void CheckOk(int rc)
{
@@ -276,7 +254,7 @@ namespace Emby.Server.Implementations.Data
{
if (_disposed)
{
- throw new ObjectDisposedException(GetType().Name + " has been disposed and cannot be accessed.");
+ throw new ObjectDisposedException(GetType().Name, "Object has been disposed and cannot be accessed.");
}
}
diff --git a/Emby.Server.Implementations/Data/CleanDatabaseScheduledTask.cs b/Emby.Server.Implementations/Data/CleanDatabaseScheduledTask.cs
index 536cf21f6..dcfe14943 100644
--- a/Emby.Server.Implementations/Data/CleanDatabaseScheduledTask.cs
+++ b/Emby.Server.Implementations/Data/CleanDatabaseScheduledTask.cs
@@ -1,16 +1,12 @@
-using MediaBrowser.Common.Progress;
-using MediaBrowser.Controller.Entities;
-using MediaBrowser.Controller.Library;
-using MediaBrowser.Controller.Persistence;
-using MediaBrowser.Model.Entities;
-using Microsoft.Extensions.Logging;
using System;
-using System.Collections.Generic;
-using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.Configuration;
+using MediaBrowser.Controller.Entities;
+using MediaBrowser.Controller.Library;
+using MediaBrowser.Controller.Persistence;
using MediaBrowser.Model.IO;
+using Microsoft.Extensions.Logging;
namespace Emby.Server.Implementations.Data
{
diff --git a/Emby.Server.Implementations/Data/ManagedConnection.cs b/Emby.Server.Implementations/Data/ManagedConnection.cs
index 91a2dfdf6..b8f1e581a 100644
--- a/Emby.Server.Implementations/Data/ManagedConnection.cs
+++ b/Emby.Server.Implementations/Data/ManagedConnection.cs
@@ -1,13 +1,10 @@
-using System;
+using System;
using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
using SQLitePCL.pretty;
namespace Emby.Server.Implementations.Data
{
- public class ManagedConnection : IDisposable
+ public class ManagedConnection : IDisposable
{
private SQLiteDatabaseConnection db;
private readonly bool _closeOnDispose;
@@ -50,7 +47,7 @@ namespace Emby.Server.Implementations.Data
public T RunInTransaction<T>(Func<IDatabaseConnection, T> action, TransactionMode mode)
{
- return db.RunInTransaction<T>(action, mode);
+ return db.RunInTransaction(action, mode);
}
public IEnumerable<IReadOnlyList<IResultSetValue>> Query(string sql)
diff --git a/Emby.Server.Implementations/Data/SqliteDisplayPreferencesRepository.cs b/Emby.Server.Implementations/Data/SqliteDisplayPreferencesRepository.cs
index 00e1956cf..3d60925da 100644
--- a/Emby.Server.Implementations/Data/SqliteDisplayPreferencesRepository.cs
+++ b/Emby.Server.Implementations/Data/SqliteDisplayPreferencesRepository.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
@@ -7,8 +7,8 @@ using MediaBrowser.Common.Extensions;
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.IO;
-using Microsoft.Extensions.Logging;
using MediaBrowser.Model.Serialization;
+using Microsoft.Extensions.Logging;
using SQLitePCL.pretty;
namespace Emby.Server.Implementations.Data
@@ -20,8 +20,8 @@ namespace Emby.Server.Implementations.Data
{
protected IFileSystem FileSystem { get; private set; }
- public SqliteDisplayPreferencesRepository(ILogger logger, IJsonSerializer jsonSerializer, IApplicationPaths appPaths, IFileSystem fileSystem)
- : base(logger)
+ public SqliteDisplayPreferencesRepository(ILoggerFactory loggerFactory, IJsonSerializer jsonSerializer, IApplicationPaths appPaths, IFileSystem fileSystem)
+ : base(loggerFactory.CreateLogger(nameof(SqliteDisplayPreferencesRepository)))
{
_jsonSerializer = jsonSerializer;
FileSystem = fileSystem;
@@ -32,13 +32,7 @@ namespace Emby.Server.Implementations.Data
/// Gets the name of the repository
/// </summary>
/// <value>The name.</value>
- public string Name
- {
- get
- {
- return "SQLite";
- }
- }
+ public string Name => "SQLite";
/// <summary>
/// The _json serializer
@@ -89,16 +83,16 @@ namespace Emby.Server.Implementations.Data
/// <param name="client">The client.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns>
- /// <exception cref="System.ArgumentNullException">item</exception>
+ /// <exception cref="ArgumentNullException">item</exception>
public void SaveDisplayPreferences(DisplayPreferences displayPreferences, Guid userId, string client, CancellationToken cancellationToken)
{
if (displayPreferences == null)
{
- throw new ArgumentNullException("displayPreferences");
+ throw new ArgumentNullException(nameof(displayPreferences));
}
if (string.IsNullOrEmpty(displayPreferences.Id))
{
- throw new ArgumentNullException("displayPreferences.Id");
+ throw new ArgumentNullException(nameof(displayPreferences.Id));
}
cancellationToken.ThrowIfCancellationRequested();
@@ -137,12 +131,12 @@ namespace Emby.Server.Implementations.Data
/// <param name="userId">The user id.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns>
- /// <exception cref="System.ArgumentNullException">item</exception>
+ /// <exception cref="ArgumentNullException">item</exception>
public void SaveAllDisplayPreferences(IEnumerable<DisplayPreferences> displayPreferences, Guid userId, CancellationToken cancellationToken)
{
if (displayPreferences == null)
{
- throw new ArgumentNullException("displayPreferences");
+ throw new ArgumentNullException(nameof(displayPreferences));
}
cancellationToken.ThrowIfCancellationRequested();
@@ -169,12 +163,12 @@ namespace Emby.Server.Implementations.Data
/// <param name="userId">The user id.</param>
/// <param name="client">The client.</param>
/// <returns>Task{DisplayPreferences}.</returns>
- /// <exception cref="System.ArgumentNullException">item</exception>
+ /// <exception cref="ArgumentNullException">item</exception>
public DisplayPreferences GetDisplayPreferences(string displayPreferencesId, Guid userId, string client)
{
if (string.IsNullOrEmpty(displayPreferencesId))
{
- throw new ArgumentNullException("displayPreferencesId");
+ throw new ArgumentNullException(nameof(displayPreferencesId));
}
var guidId = displayPreferencesId.GetMD5();
@@ -208,7 +202,7 @@ namespace Emby.Server.Implementations.Data
/// </summary>
/// <param name="userId">The user id.</param>
/// <returns>Task{DisplayPreferences}.</returns>
- /// <exception cref="System.ArgumentNullException">item</exception>
+ /// <exception cref="ArgumentNullException">item</exception>
public IEnumerable<DisplayPreferences> GetAllDisplayPreferences(Guid userId)
{
var list = new List<DisplayPreferences>();
diff --git a/Emby.Server.Implementations/Data/SqliteExtensions.cs b/Emby.Server.Implementations/Data/SqliteExtensions.cs
index a755c65f4..a486cb1a0 100644
--- a/Emby.Server.Implementations/Data/SqliteExtensions.cs
+++ b/Emby.Server.Implementations/Data/SqliteExtensions.cs
@@ -1,10 +1,9 @@
-using System;
+using System;
using System.Collections.Generic;
using System.Globalization;
-using MediaBrowser.Model.IO;
+using System.IO;
using MediaBrowser.Model.Serialization;
using SQLitePCL.pretty;
-using System.IO;
namespace Emby.Server.Implementations.Data
{
@@ -14,7 +13,7 @@ namespace Emby.Server.Implementations.Data
{
if (queries == null)
{
- throw new ArgumentNullException("queries");
+ throw new ArgumentNullException(nameof(queries));
}
connection.RunInTransaction(conn =>
@@ -115,9 +114,7 @@ namespace Emby.Server.Implementations.Data
{
var dateText = result.ToString();
- DateTime dateTimeResult;
-
- if (DateTime.TryParseExact(dateText, _datetimeFormats, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None, out dateTimeResult))
+ if (DateTime.TryParseExact(dateText, _datetimeFormats, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None, out var dateTimeResult))
{
return dateTimeResult.ToUniversalTime();
}
@@ -129,12 +126,12 @@ namespace Emby.Server.Implementations.Data
/// Serializes to bytes.
/// </summary>
/// <returns>System.Byte[][].</returns>
- /// <exception cref="System.ArgumentNullException">obj</exception>
+ /// <exception cref="ArgumentNullException">obj</exception>
public static byte[] SerializeToBytes(this IJsonSerializer json, object obj)
{
if (obj == null)
{
- throw new ArgumentNullException("obj");
+ throw new ArgumentNullException(nameof(obj));
}
using (var stream = new MemoryStream())
@@ -202,8 +199,7 @@ namespace Emby.Server.Implementations.Data
public static void TryBind(this IStatement statement, string name, double value)
{
- IBindParameter bindParam;
- if (statement.BindParameters.TryGetValue(name, out bindParam))
+ if (statement.BindParameters.TryGetValue(name, out IBindParameter bindParam))
{
bindParam.Bind(value);
}
@@ -215,8 +211,7 @@ namespace Emby.Server.Implementations.Data
public static void TryBind(this IStatement statement, string name, string value)
{
- IBindParameter bindParam;
- if (statement.BindParameters.TryGetValue(name, out bindParam))
+ if (statement.BindParameters.TryGetValue(name, out IBindParameter bindParam))
{
if (value == null)
{
@@ -235,8 +230,7 @@ namespace Emby.Server.Implementations.Data
public static void TryBind(this IStatement statement, string name, bool value)
{
- IBindParameter bindParam;
- if (statement.BindParameters.TryGetValue(name, out bindParam))
+ if (statement.BindParameters.TryGetValue(name, out IBindParameter bindParam))
{
bindParam.Bind(value);
}
@@ -248,8 +242,7 @@ namespace Emby.Server.Implementations.Data
public static void TryBind(this IStatement statement, string name, float value)
{
- IBindParameter bindParam;
- if (statement.BindParameters.TryGetValue(name, out bindParam))
+ if (statement.BindParameters.TryGetValue(name, out IBindParameter bindParam))
{
bindParam.Bind(value);
}
@@ -261,8 +254,7 @@ namespace Emby.Server.Implementations.Data
public static void TryBind(this IStatement statement, string name, int value)
{
- IBindParameter bindParam;
- if (statement.BindParameters.TryGetValue(name, out bindParam))
+ if (statement.BindParameters.TryGetValue(name, out IBindParameter bindParam))
{
bindParam.Bind(value);
}
@@ -274,8 +266,7 @@ namespace Emby.Server.Implementations.Data
public static void TryBind(this IStatement statement, string name, Guid value)
{
- IBindParameter bindParam;
- if (statement.BindParameters.TryGetValue(name, out bindParam))
+ if (statement.BindParameters.TryGetValue(name, out IBindParameter bindParam))
{
bindParam.Bind(value.ToGuidBlob());
}
@@ -287,8 +278,7 @@ namespace Emby.Server.Implementations.Data
public static void TryBind(this IStatement statement, string name, DateTime value)
{
- IBindParameter bindParam;
- if (statement.BindParameters.TryGetValue(name, out bindParam))
+ if (statement.BindParameters.TryGetValue(name, out IBindParameter bindParam))
{
bindParam.Bind(value.ToDateTimeParamValue());
}
@@ -300,8 +290,7 @@ namespace Emby.Server.Implementations.Data
public static void TryBind(this IStatement statement, string name, long value)
{
- IBindParameter bindParam;
- if (statement.BindParameters.TryGetValue(name, out bindParam))
+ if (statement.BindParameters.TryGetValue(name, out IBindParameter bindParam))
{
bindParam.Bind(value);
}
@@ -313,8 +302,7 @@ namespace Emby.Server.Implementations.Data
public static void TryBind(this IStatement statement, string name, byte[] value)
{
- IBindParameter bindParam;
- if (statement.BindParameters.TryGetValue(name, out bindParam))
+ if (statement.BindParameters.TryGetValue(name, out IBindParameter bindParam))
{
bindParam.Bind(value);
}
@@ -326,8 +314,7 @@ namespace Emby.Server.Implementations.Data
public static void TryBindNull(this IStatement statement, string name)
{
- IBindParameter bindParam;
- if (statement.BindParameters.TryGetValue(name, out bindParam))
+ if (statement.BindParameters.TryGetValue(name, out IBindParameter bindParam))
{
bindParam.BindNull();
}
diff --git a/Emby.Server.Implementations/Data/SqliteItemRepository.cs b/Emby.Server.Implementations/Data/SqliteItemRepository.cs
index 0f9770e8f..492adef6a 100644
--- a/Emby.Server.Implementations/Data/SqliteItemRepository.cs
+++ b/Emby.Server.Implementations/Data/SqliteItemRepository.cs
@@ -6,17 +6,17 @@ using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading;
-using System.Threading.Tasks;
-using Emby.Server.Implementations.Devices;
using Emby.Server.Implementations.Playlists;
+using MediaBrowser.Controller;
using MediaBrowser.Controller.Channels;
-using MediaBrowser.Controller.Collections;
using MediaBrowser.Controller.Configuration;
+using MediaBrowser.Controller.Drawing;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Extensions;
+using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.LiveTv;
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Controller.Playlists;
@@ -24,17 +24,13 @@ using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.LiveTv;
-using Microsoft.Extensions.Logging;
using MediaBrowser.Model.Querying;
-using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.Reflection;
-using SQLitePCL.pretty;
+using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.System;
using MediaBrowser.Model.Threading;
-using MediaBrowser.Model.Extensions;
-using MediaBrowser.Controller;
-using MediaBrowser.Controller.Drawing;
-using MediaBrowser.Controller.Library;
+using Microsoft.Extensions.Logging;
+using SQLitePCL.pretty;
namespace Emby.Server.Implementations.Data
{
@@ -49,13 +45,7 @@ namespace Emby.Server.Implementations.Data
/// Gets the name of the repository
/// </summary>
/// <value>The name.</value>
- public string Name
- {
- get
- {
- return "SQLite";
- }
- }
+ public string Name => "SQLite";
/// <summary>
/// Gets the json serializer.
@@ -77,16 +67,24 @@ namespace Emby.Server.Implementations.Data
/// <summary>
/// Initializes a new instance of the <see cref="SqliteItemRepository"/> class.
/// </summary>
- public SqliteItemRepository(IServerConfigurationManager config, IServerApplicationHost appHost, IJsonSerializer jsonSerializer, ILogger logger, IAssemblyInfo assemblyInfo, IFileSystem fileSystem, IEnvironmentInfo environmentInfo, ITimerFactory timerFactory)
- : base(logger)
+ public SqliteItemRepository(
+ IServerConfigurationManager config,
+ IServerApplicationHost appHost,
+ IJsonSerializer jsonSerializer,
+ ILoggerFactory loggerFactory,
+ IAssemblyInfo assemblyInfo,
+ IFileSystem fileSystem,
+ IEnvironmentInfo environmentInfo,
+ ITimerFactory timerFactory)
+ : base(loggerFactory.CreateLogger(nameof(SqliteItemRepository)))
{
if (config == null)
{
- throw new ArgumentNullException("config");
+ throw new ArgumentNullException(nameof(config));
}
if (jsonSerializer == null)
{
- throw new ArgumentNullException("jsonSerializer");
+ throw new ArgumentNullException(nameof(jsonSerializer));
}
_appHost = appHost;
@@ -101,21 +99,9 @@ namespace Emby.Server.Implementations.Data
private const string ChaptersTableName = "Chapters2";
- protected override int? CacheSize
- {
- get
- {
- return 20000;
- }
- }
+ protected override int? CacheSize => 20000;
- protected override bool EnableTempStoreMemory
- {
- get
- {
- return true;
- }
- }
+ protected override bool EnableTempStoreMemory => true;
/// <summary>
/// Opens the connection to the database
@@ -455,7 +441,7 @@ namespace Emby.Server.Implementations.Data
"ColorTransfer"
};
- private string GetSaveItemCommandText()
+ private static string GetSaveItemCommandText()
{
var saveColumns = new List<string>
{
@@ -553,12 +539,12 @@ namespace Emby.Server.Implementations.Data
/// </summary>
/// <param name="item">The item.</param>
/// <param name="cancellationToken">The cancellation token.</param>
- /// <exception cref="System.ArgumentNullException">item</exception>
+ /// <exception cref="ArgumentNullException">item</exception>
public void SaveItem(BaseItem item, CancellationToken cancellationToken)
{
if (item == null)
{
- throw new ArgumentNullException("item");
+ throw new ArgumentNullException(nameof(item));
}
SaveItems(new List<BaseItem> { item }, cancellationToken);
@@ -568,7 +554,7 @@ namespace Emby.Server.Implementations.Data
{
if (item == null)
{
- throw new ArgumentNullException("item");
+ throw new ArgumentNullException(nameof(item));
}
CheckDisposed();
@@ -596,7 +582,7 @@ namespace Emby.Server.Implementations.Data
/// </summary>
/// <param name="items">The items.</param>
/// <param name="cancellationToken">The cancellation token.</param>
- /// <exception cref="System.ArgumentNullException">
+ /// <exception cref="ArgumentNullException">
/// items
/// or
/// cancellationToken
@@ -605,7 +591,7 @@ namespace Emby.Server.Implementations.Data
{
if (items == null)
{
- throw new ArgumentNullException("items");
+ throw new ArgumentNullException(nameof(items));
}
cancellationToken.ThrowIfCancellationRequested();
@@ -1070,7 +1056,7 @@ namespace Emby.Server.Implementations.Data
saveItemStatement.MoveNext();
}
- private string SerializeProviderIds(BaseItem item)
+ private static string SerializeProviderIds(BaseItem item)
{
// Ideally we shouldn't need this IsNullOrWhiteSpace check but we're seeing some cases of bad data slip through
var ids = item.ProviderIds
@@ -1085,7 +1071,7 @@ namespace Emby.Server.Implementations.Data
return string.Join("|", ids.Select(i => i.Key + "=" + i.Value).ToArray());
}
- private void DeserializeProviderIds(string value, BaseItem item)
+ private static void DeserializeProviderIds(string value, BaseItem item)
{
if (string.IsNullOrWhiteSpace(value))
{
@@ -1186,25 +1172,21 @@ namespace Emby.Server.Implementations.Data
image.Path = RestorePath(parts[0]);
- long ticks;
- if (long.TryParse(parts[1], NumberStyles.Any, CultureInfo.InvariantCulture, out ticks))
+ if (long.TryParse(parts[1], NumberStyles.Any, CultureInfo.InvariantCulture, out var ticks))
{
image.DateModified = new DateTime(ticks, DateTimeKind.Utc);
}
- ImageType type;
- if (Enum.TryParse(parts[2], true, out type))
+ if (Enum.TryParse(parts[2], true, out ImageType type))
{
image.Type = type;
}
if (parts.Length >= 5)
{
- int width;
- int height;
- if (int.TryParse(parts[3], NumberStyles.Integer, CultureInfo.InvariantCulture, out width))
+ if (int.TryParse(parts[3], NumberStyles.Integer, CultureInfo.InvariantCulture, out var width))
{
- if (int.TryParse(parts[4], NumberStyles.Integer, CultureInfo.InvariantCulture, out height))
+ if (int.TryParse(parts[4], NumberStyles.Integer, CultureInfo.InvariantCulture, out var height))
{
image.Width = width;
image.Height = height;
@@ -1220,13 +1202,13 @@ namespace Emby.Server.Implementations.Data
/// </summary>
/// <param name="id">The id.</param>
/// <returns>BaseItem.</returns>
- /// <exception cref="System.ArgumentNullException">id</exception>
- /// <exception cref="System.ArgumentException"></exception>
+ /// <exception cref="ArgumentNullException">id</exception>
+ /// <exception cref="ArgumentException"></exception>
public BaseItem RetrieveItem(Guid id)
{
if (id.Equals(Guid.Empty))
{
- throw new ArgumentNullException("id");
+ throw new ArgumentNullException(nameof(id));
}
CheckDisposed();
@@ -1611,8 +1593,7 @@ namespace Emby.Server.Implementations.Data
if (!reader.IsDBNull(index))
{
- ProgramAudio audio;
- if (Enum.TryParse(reader.GetString(index), true, out audio))
+ if (Enum.TryParse(reader.GetString(index), true, out ProgramAudio audio))
{
item.Audio = audio;
}
@@ -1656,9 +1637,7 @@ namespace Emby.Server.Implementations.Data
item.LockedFields = reader.GetString(index).Split('|').Where(i => !string.IsNullOrWhiteSpace(i)).Select(
i =>
{
- MetadataFields parsedValue;
-
- if (Enum.TryParse(i, true, out parsedValue))
+ if (Enum.TryParse(i, true, out MetadataFields parsedValue))
{
return parsedValue;
}
@@ -1696,9 +1675,7 @@ namespace Emby.Server.Implementations.Data
trailer.TrailerTypes = reader.GetString(index).Split('|').Where(i => !string.IsNullOrWhiteSpace(i)).Select(
i =>
{
- TrailerType parsedValue;
-
- if (Enum.TryParse(i, true, out parsedValue))
+ if (Enum.TryParse(i, true, out TrailerType parsedValue))
{
return parsedValue;
}
@@ -1879,8 +1856,7 @@ namespace Emby.Server.Implementations.Data
if (!reader.IsDBNull(index))
{
- ExtraType extraType;
- if (Enum.TryParse(reader.GetString(index), true, out extraType))
+ if (Enum.TryParse(reader.GetString(index), true, out ExtraType extraType))
{
item.ExtraType = extraType;
}
@@ -1948,7 +1924,7 @@ namespace Emby.Server.Implementations.Data
return item;
}
- private Guid[] SplitToGuids(string value)
+ private static Guid[] SplitToGuids(string value)
{
var ids = value.Split('|');
@@ -1965,9 +1941,9 @@ namespace Emby.Server.Implementations.Data
/// <summary>
/// Gets chapters for an item
/// </summary>
- /// <param name="id">The id.</param>
+ /// <param name="item">The item.</param>
/// <returns>IEnumerable{ChapterInfo}.</returns>
- /// <exception cref="System.ArgumentNullException">id</exception>
+ /// <exception cref="ArgumentNullException">id</exception>
public List<ChapterInfo> GetChapters(BaseItem item)
{
CheckDisposed();
@@ -1996,10 +1972,10 @@ namespace Emby.Server.Implementations.Data
/// <summary>
/// Gets a single chapter for an item
/// </summary>
- /// <param name="id">The id.</param>
+ /// <param name="item">The item.</param>
/// <param name="index">The index.</param>
/// <returns>ChapterInfo.</returns>
- /// <exception cref="System.ArgumentNullException">id</exception>
+ /// <exception cref="ArgumentNullException">id</exception>
public ChapterInfo GetChapter(BaseItem item, int index)
{
CheckDisposed();
@@ -2067,12 +2043,12 @@ namespace Emby.Server.Implementations.Data
if (id.Equals(Guid.Empty))
{
- throw new ArgumentNullException("id");
+ throw new ArgumentNullException(nameof(id));
}
if (chapters == null)
{
- throw new ArgumentNullException("chapters");
+ throw new ArgumentNullException(nameof(chapters));
}
using (WriteLock.Write())
@@ -2144,7 +2120,7 @@ namespace Emby.Server.Implementations.Data
}
}
- private bool EnableJoinUserData(InternalItemsQuery query)
+ private static bool EnableJoinUserData(InternalItemsQuery query)
{
if (query.User == null)
{
@@ -2681,7 +2657,7 @@ namespace Emby.Server.Implementations.Data
{
if (query == null)
{
- throw new ArgumentNullException("query");
+ throw new ArgumentNullException(nameof(query));
}
CheckDisposed();
@@ -2739,7 +2715,7 @@ namespace Emby.Server.Implementations.Data
{
if (query == null)
{
- throw new ArgumentNullException("query");
+ throw new ArgumentNullException(nameof(query));
}
CheckDisposed();
@@ -2928,7 +2904,7 @@ namespace Emby.Server.Implementations.Data
{
if (query == null)
{
- throw new ArgumentNullException("query");
+ throw new ArgumentNullException(nameof(query));
}
CheckDisposed();
@@ -3212,7 +3188,7 @@ namespace Emby.Server.Implementations.Data
{
if (query == null)
{
- throw new ArgumentNullException("query");
+ throw new ArgumentNullException(nameof(query));
}
CheckDisposed();
@@ -3286,7 +3262,7 @@ namespace Emby.Server.Implementations.Data
{
if (query == null)
{
- throw new ArgumentNullException("query");
+ throw new ArgumentNullException(nameof(query));
}
CheckDisposed();
@@ -3362,7 +3338,7 @@ namespace Emby.Server.Implementations.Data
{
if (query == null)
{
- throw new ArgumentNullException("query");
+ throw new ArgumentNullException(nameof(query));
}
CheckDisposed();
@@ -4038,7 +4014,7 @@ namespace Emby.Server.Implementations.Data
if (query.PersonIds.Length > 0)
{
- // TODO: Should this query with CleanName ?
+ // TODO: Should this query with CleanName ?
var clauses = new List<string>();
var index = 0;
@@ -5171,8 +5147,7 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
private IEnumerable<string> MapIncludeItemTypes(string value)
{
- string[] result;
- if (_types.TryGetValue(value, out result))
+ if (_types.TryGetValue(value, out string[] result))
{
return result;
}
@@ -5184,7 +5159,7 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
{
if (id.Equals(Guid.Empty))
{
- throw new ArgumentNullException("id");
+ throw new ArgumentNullException(nameof(id));
}
CheckDisposed();
@@ -5233,7 +5208,7 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
{
if (query == null)
{
- throw new ArgumentNullException("query");
+ throw new ArgumentNullException(nameof(query));
}
CheckDisposed();
@@ -5273,7 +5248,7 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
{
if (query == null)
{
- throw new ArgumentNullException("query");
+ throw new ArgumentNullException(nameof(query));
}
CheckDisposed();
@@ -5387,19 +5362,19 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
{
if (itemId.Equals(Guid.Empty))
{
- throw new ArgumentNullException("itemId");
+ throw new ArgumentNullException(nameof(itemId));
}
if (ancestorIds == null)
{
- throw new ArgumentNullException("ancestorIds");
+ throw new ArgumentNullException(nameof(ancestorIds));
}
CheckDisposed();
var itemIdBlob = itemId.ToGuidBlob();
- // First delete
+ // First delete
deleteAncestorsStatement.Reset();
deleteAncestorsStatement.TryBind("@ItemId", itemIdBlob);
deleteAncestorsStatement.MoveNext();
@@ -5556,7 +5531,7 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
{
if (query == null)
{
- throw new ArgumentNullException("query");
+ throw new ArgumentNullException(nameof(query));
}
if (!query.Limit.HasValue)
@@ -5915,19 +5890,19 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
{
if (itemId.Equals(Guid.Empty))
{
- throw new ArgumentNullException("itemId");
+ throw new ArgumentNullException(nameof(itemId));
}
if (values == null)
{
- throw new ArgumentNullException("keys");
+ throw new ArgumentNullException(nameof(values));
}
CheckDisposed();
var guidBlob = itemId.ToGuidBlob();
- // First delete
+ // First delete
db.Execute("delete from ItemValues where ItemId=@Id", guidBlob);
InsertItemValues(guidBlob, values, db);
@@ -5991,12 +5966,12 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
{
if (itemId.Equals(Guid.Empty))
{
- throw new ArgumentNullException("itemId");
+ throw new ArgumentNullException(nameof(itemId));
}
if (people == null)
{
- throw new ArgumentNullException("people");
+ throw new ArgumentNullException(nameof(people));
}
CheckDisposed();
@@ -6102,7 +6077,7 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
if (query == null)
{
- throw new ArgumentNullException("query");
+ throw new ArgumentNullException(nameof(query));
}
var cmdText = "select " + string.Join(",", _mediaStreamSaveColumns) + " from mediastreams where";
@@ -6158,12 +6133,12 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
if (id.Equals(Guid.Empty))
{
- throw new ArgumentNullException("id");
+ throw new ArgumentNullException(nameof(id));
}
if (streams == null)
{
- throw new ArgumentNullException("streams");
+ throw new ArgumentNullException(nameof(streams));
}
cancellationToken.ThrowIfCancellationRequested();
diff --git a/Emby.Server.Implementations/Data/SqliteUserDataRepository.cs b/Emby.Server.Implementations/Data/SqliteUserDataRepository.cs
index 6d4ddcedd..7a9b72244 100644
--- a/Emby.Server.Implementations/Data/SqliteUserDataRepository.cs
+++ b/Emby.Server.Implementations/Data/SqliteUserDataRepository.cs
@@ -1,26 +1,25 @@
-using System;
+using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller.Entities;
+using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Model.IO;
using Microsoft.Extensions.Logging;
using SQLitePCL.pretty;
-using MediaBrowser.Controller.Library;
namespace Emby.Server.Implementations.Data
{
public class SqliteUserDataRepository : BaseSqliteRepository, IUserDataRepository
{
- private readonly IFileSystem _fileSystem;
-
- public SqliteUserDataRepository(ILogger logger, IApplicationPaths appPaths, IFileSystem fileSystem)
- : base(logger)
+ public SqliteUserDataRepository(
+ ILoggerFactory loggerFactory,
+ IApplicationPaths appPaths)
+ : base(loggerFactory.CreateLogger(nameof(SqliteUserDataRepository)))
{
- _fileSystem = fileSystem;
DbFilePath = Path.Combine(appPaths.DataPath, "library.db");
}
@@ -28,13 +27,7 @@ namespace Emby.Server.Implementations.Data
/// Gets the name of the repository
/// </summary>
/// <value>The name.</value>
- public string Name
- {
- get
- {
- return "SQLite";
- }
- }
+ public string Name => "SQLite";
/// <summary>
/// Opens the connection to the database
@@ -116,7 +109,7 @@ namespace Emby.Server.Implementations.Data
private List<Guid> GetAllUserIdsWithUserData(IDatabaseConnection db)
{
- List<Guid> list = new List<Guid>();
+ var list = new List<Guid>();
using (var statement = PrepareStatement(db, "select DISTINCT UserId from UserData where UserId not null"))
{
@@ -136,13 +129,7 @@ namespace Emby.Server.Implementations.Data
return list;
}
- protected override bool EnableTempStoreMemory
- {
- get
- {
- return true;
- }
- }
+ protected override bool EnableTempStoreMemory => true;
/// <summary>
/// Saves the user data.
@@ -151,15 +138,15 @@ namespace Emby.Server.Implementations.Data
{
if (userData == null)
{
- throw new ArgumentNullException("userData");
+ throw new ArgumentNullException(nameof(userData));
}
if (internalUserId <= 0)
{
- throw new ArgumentNullException("internalUserId");
+ throw new ArgumentNullException(nameof(internalUserId));
}
if (string.IsNullOrEmpty(key))
{
- throw new ArgumentNullException("key");
+ throw new ArgumentNullException(nameof(key));
}
PersistUserData(internalUserId, key, userData, cancellationToken);
@@ -169,11 +156,11 @@ namespace Emby.Server.Implementations.Data
{
if (userData == null)
{
- throw new ArgumentNullException("userData");
+ throw new ArgumentNullException(nameof(userData));
}
if (internalUserId <= 0)
{
- throw new ArgumentNullException("internalUserId");
+ throw new ArgumentNullException(nameof(internalUserId));
}
PersistAllUserData(internalUserId, userData, cancellationToken);
@@ -182,7 +169,7 @@ namespace Emby.Server.Implementations.Data
/// <summary>
/// Persists the user data.
/// </summary>
- /// <param name="userId">The user id.</param>
+ /// <param name="internalUserId">The user id.</param>
/// <param name="key">The key.</param>
/// <param name="userData">The user data.</param>
/// <param name="cancellationToken">The cancellation token.</param>
@@ -203,7 +190,7 @@ namespace Emby.Server.Implementations.Data
}
}
- private void SaveUserData(IDatabaseConnection db, long internalUserId, string key, UserItemData userData)
+ private static void SaveUserData(IDatabaseConnection db, long internalUserId, string key, UserItemData userData)
{
using (var statement = db.PrepareStatement("replace into UserDatas (key, userId, rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex) values (@key, @userId, @rating,@played,@playCount,@isFavorite,@playbackPositionTicks,@lastPlayedDate,@AudioStreamIndex,@SubtitleStreamIndex)"))
{
@@ -280,10 +267,10 @@ namespace Emby.Server.Implementations.Data
/// <summary>
/// Gets the user data.
/// </summary>
- /// <param name="userId">The user id.</param>
+ /// <param name="internalUserId">The user id.</param>
/// <param name="key">The key.</param>
/// <returns>Task{UserItemData}.</returns>
- /// <exception cref="System.ArgumentNullException">
+ /// <exception cref="ArgumentNullException">
/// userId
/// or
/// key
@@ -292,11 +279,11 @@ namespace Emby.Server.Implementations.Data
{
if (internalUserId <= 0)
{
- throw new ArgumentNullException("internalUserId");
+ throw new ArgumentNullException(nameof(internalUserId));
}
if (string.IsNullOrEmpty(key))
{
- throw new ArgumentNullException("key");
+ throw new ArgumentNullException(nameof(key));
}
using (WriteLock.Read())
@@ -323,7 +310,7 @@ namespace Emby.Server.Implementations.Data
{
if (keys == null)
{
- throw new ArgumentNullException("keys");
+ throw new ArgumentNullException(nameof(keys));
}
if (keys.Count == 0)
@@ -337,13 +324,13 @@ namespace Emby.Server.Implementations.Data
/// <summary>
/// Return all user-data associated with the given user
/// </summary>
- /// <param name="userId"></param>
+ /// <param name="internalUserId"></param>
/// <returns></returns>
public List<UserItemData> GetAllUserData(long internalUserId)
{
if (internalUserId <= 0)
{
- throw new ArgumentNullException("internalUserId");
+ throw new ArgumentNullException(nameof(internalUserId));
}
var list = new List<UserItemData>();
diff --git a/Emby.Server.Implementations/Data/SqliteUserRepository.cs b/Emby.Server.Implementations/Data/SqliteUserRepository.cs
index d490a481e..db359d7dd 100644
--- a/Emby.Server.Implementations/Data/SqliteUserRepository.cs
+++ b/Emby.Server.Implementations/Data/SqliteUserRepository.cs
@@ -1,13 +1,11 @@
-using System;
+using System;
using System.Collections.Generic;
using System.IO;
-using System.Threading;
using MediaBrowser.Controller;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Persistence;
-using MediaBrowser.Model.IO;
-using Microsoft.Extensions.Logging;
using MediaBrowser.Model.Serialization;
+using Microsoft.Extensions.Logging;
using SQLitePCL.pretty;
namespace Emby.Server.Implementations.Data
@@ -19,8 +17,11 @@ namespace Emby.Server.Implementations.Data
{
private readonly IJsonSerializer _jsonSerializer;
- public SqliteUserRepository(ILogger logger, IServerApplicationPaths appPaths, IJsonSerializer jsonSerializer)
- : base(logger)
+ public SqliteUserRepository(
+ ILoggerFactory loggerFactory,
+ IServerApplicationPaths appPaths,
+ IJsonSerializer jsonSerializer)
+ : base(loggerFactory.CreateLogger(nameof(SqliteUserRepository)))
{
_jsonSerializer = jsonSerializer;
@@ -31,13 +32,7 @@ namespace Emby.Server.Implementations.Data
/// Gets the name of the repository
/// </summary>
/// <value>The name.</value>
- public string Name
- {
- get
- {
- return "SQLite";
- }
- }
+ public string Name => "SQLite";
/// <summary>
/// Opens the connection to the database
@@ -85,7 +80,7 @@ namespace Emby.Server.Implementations.Data
{
if (user == null)
{
- throw new ArgumentNullException("user");
+ throw new ArgumentNullException(nameof(user));
}
var serialized = _jsonSerializer.SerializeToBytes(user);
@@ -122,7 +117,7 @@ namespace Emby.Server.Implementations.Data
{
if (user == null)
{
- throw new ArgumentNullException("user");
+ throw new ArgumentNullException(nameof(user));
}
var serialized = _jsonSerializer.SerializeToBytes(user);
@@ -207,14 +202,13 @@ namespace Emby.Server.Implementations.Data
/// Deletes the user.
/// </summary>
/// <param name="user">The user.</param>
- /// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns>
- /// <exception cref="System.ArgumentNullException">user</exception>
+ /// <exception cref="ArgumentNullException">user</exception>
public void DeleteUser(User user)
{
if (user == null)
{
- throw new ArgumentNullException("user");
+ throw new ArgumentNullException(nameof(user));
}
using (WriteLock.Write())
diff --git a/Emby.Server.Implementations/Data/TypeMapper.cs b/Emby.Server.Implementations/Data/TypeMapper.cs
index f4b37749e..37c952e88 100644
--- a/Emby.Server.Implementations/Data/TypeMapper.cs
+++ b/Emby.Server.Implementations/Data/TypeMapper.cs
@@ -1,7 +1,7 @@
-using System;
+using System;
using System.Collections.Concurrent;
-using MediaBrowser.Model.Reflection;
using System.Linq;
+using MediaBrowser.Model.Reflection;
namespace Emby.Server.Implementations.Data
{
@@ -27,12 +27,12 @@ namespace Emby.Server.Implementations.Data
/// </summary>
/// <param name="typeName">Name of the type.</param>
/// <returns>Type.</returns>
- /// <exception cref="System.ArgumentNullException"></exception>
+ /// <exception cref="ArgumentNullException"></exception>
public Type GetType(string typeName)
{
if (string.IsNullOrEmpty(typeName))
{
- throw new ArgumentNullException("typeName");
+ throw new ArgumentNullException(nameof(typeName));
}
return _typeMap.GetOrAdd(typeName, LookupType);