aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/Data/SqliteUserDataRepository.cs
diff options
context:
space:
mode:
authorLogicalPhallacy <44458166+LogicalPhallacy@users.noreply.github.com>2019-01-23 00:31:35 -0800
committerGitHub <noreply@github.com>2019-01-23 00:31:35 -0800
commit404bd04cbc17dc8c8bf4a5c9aa3ca9c5cd85aa68 (patch)
tree3d267c6ceef9439a034c113095e10e4d619e7c70 /Emby.Server.Implementations/Data/SqliteUserDataRepository.cs
parent8ff89fdc0c30f595a171ffc550f907ef22b6212a (diff)
parente05e002b8bb4d13eb2b80b56a0aad8903ddb701e (diff)
Merge pull request #8 from jellyfin/master
rebase to latest master
Diffstat (limited to 'Emby.Server.Implementations/Data/SqliteUserDataRepository.cs')
-rw-r--r--Emby.Server.Implementations/Data/SqliteUserDataRepository.cs59
1 files changed, 23 insertions, 36 deletions
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>();