//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;
// public SqliteUserDataRepository(ILogger logger, IApplicationPaths appPaths)
// : base(logger)
// {
// DbFilePath = Path.Combine(appPaths.DataPath, "userdata_v2.db");
// }
// protected override bool EnableConnectionPooling
// {
// get { return false; }
// }
// ///
// /// Gets the name of the repository
// ///
// /// The name.
// public string Name
// {
// get
// {
// return "SQLite";
// }
// }
// ///
// /// Opens the connection to the database
// ///
// /// Task.
// public void Initialize(SQLiteDatabaseConnection connection, ReaderWriterLockSlim 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);
// connection.RunInTransaction(db =>
// {
// var existingColumnNames = GetColumnNames(db, "userdata");
// AddColumn(db, "userdata", "AudioStreamIndex", "int", existingColumnNames);
// AddColumn(db, "userdata", "SubtitleStreamIndex", "int", existingColumnNames);
// });
// }
// ///
// /// Saves the user data.
// ///
// /// The user id.
// /// The key.
// /// The user data.
// /// The cancellation token.
// /// Task.
// /// userData
// /// or
// /// cancellationToken
// /// or
// /// userId
// /// or
// /// userDataId
// 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 userData, CancellationToken cancellationToken)
// {
// if (userData == null)
// {
// throw new ArgumentNullException("userData");
// }
// if (userId == Guid.Empty)
// {
// throw new ArgumentNullException("userId");
// }
// return PersistAllUserData(userId, userData.ToList(), cancellationToken);
// }
// ///
// /// Persists the user data.
// ///
// /// The user id.
// /// The key.
// /// The user data.
// /// The cancellation token.
// /// Task.
// 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);
// });
// }
// }
// private void SaveUserData(IDatabaseConnection db, Guid userId, string key, UserItemData userData)
// {
// var paramList = new List