add dll config file

pull/702/head
Luke Pulverenti 8 years ago
parent 9d1b4e1074
commit 2a0280d48d

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using MediaBrowser.Model.IO; using MediaBrowser.Model.IO;
using MediaBrowser.Model.Serialization; using MediaBrowser.Model.Serialization;
@ -127,5 +128,14 @@ namespace Emby.Server.Implementations.Data
return stream.ToArray(); return stream.ToArray();
} }
} }
public static void Attach(IDatabaseConnection db, string path, string alias)
{
var commandText = string.Format("attach ? as {0};", alias);
var paramList = new List<object>();
paramList.Add(path);
db.Execute(commandText, paramList.ToArray());
}
} }
} }

@ -139,7 +139,7 @@
// /// <returns>Task.</returns> // /// <returns>Task.</returns>
// public async Task Initialize(SqliteUserDataRepository userDataRepo) // public async Task Initialize(SqliteUserDataRepository userDataRepo)
// { // {
// _connection = await CreateConnection(false).ConfigureAwait(false); // _connection = CreateConnection(false);
// var createMediaStreamsTableCommand // var createMediaStreamsTableCommand
// = "create table if not exists mediastreams (ItemId GUID, StreamIndex INT, StreamType TEXT, Codec TEXT, Language TEXT, ChannelLayout TEXT, Profile TEXT, AspectRatio TEXT, Path TEXT, IsInterlaced BIT, BitRate INT NULL, Channels INT NULL, SampleRate INT NULL, IsDefault BIT, IsForced BIT, IsExternal BIT, Height INT NULL, Width INT NULL, AverageFrameRate FLOAT NULL, RealFrameRate FLOAT NULL, Level FLOAT NULL, PixelFormat TEXT, BitDepth INT NULL, IsAnamorphic BIT NULL, RefFrames INT NULL, CodecTag TEXT NULL, Comment TEXT NULL, NalLengthSize TEXT NULL, IsAvc BIT NULL, Title TEXT NULL, TimeBase TEXT NULL, CodecTimeBase TEXT NULL, PRIMARY KEY (ItemId, StreamIndex))"; // = "create table if not exists mediastreams (ItemId GUID, StreamIndex INT, StreamType TEXT, Codec TEXT, Language TEXT, ChannelLayout TEXT, Profile TEXT, AspectRatio TEXT, Path TEXT, IsInterlaced BIT, BitRate INT NULL, Channels INT NULL, SampleRate INT NULL, IsDefault BIT, IsForced BIT, IsExternal BIT, Height INT NULL, Width INT NULL, AverageFrameRate FLOAT NULL, RealFrameRate FLOAT NULL, Level FLOAT NULL, PixelFormat TEXT, BitDepth INT NULL, IsAnamorphic BIT NULL, RefFrames INT NULL, CodecTag TEXT NULL, Comment TEXT NULL, NalLengthSize TEXT NULL, IsAvc BIT NULL, Title TEXT NULL, TimeBase TEXT NULL, CodecTimeBase TEXT NULL, PRIMARY KEY (ItemId, StreamIndex))";
@ -168,109 +168,131 @@
// }; // };
// _connection.RunQueries(queries, Logger); // _connection.RunQueries(queries);
// _connection.AddColumn(Logger, "AncestorIds", "AncestorIdText", "Text"); // _connection.RunInTransaction(db =>
// {
// _connection.AddColumn(Logger, "TypedBaseItems", "Path", "Text"); // var existingColumnNames = GetColumnNames(db, "AncestorIds");
// _connection.AddColumn(Logger, "TypedBaseItems", "StartDate", "DATETIME"); // AddColumn(db, "AncestorIds", "AncestorIdText", "Text", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "EndDate", "DATETIME");
// _connection.AddColumn(Logger, "TypedBaseItems", "ChannelId", "Text"); // existingColumnNames = GetColumnNames(db, "TypedBaseItems");
// _connection.AddColumn(Logger, "TypedBaseItems", "IsMovie", "BIT");
// _connection.AddColumn(Logger, "TypedBaseItems", "IsSports", "BIT"); // AddColumn(db, "TypedBaseItems", "Path", "Text", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "IsKids", "BIT"); // AddColumn(db, "TypedBaseItems", "StartDate", "DATETIME", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "CommunityRating", "Float"); // AddColumn(db, "TypedBaseItems", "EndDate", "DATETIME", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "CustomRating", "Text"); // AddColumn(db, "TypedBaseItems", "ChannelId", "Text", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "IndexNumber", "INT"); // AddColumn(db, "TypedBaseItems", "IsMovie", "BIT", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "IsLocked", "BIT"); // AddColumn(db, "TypedBaseItems", "IsSports", "BIT", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "Name", "Text"); // AddColumn(db, "TypedBaseItems", "IsKids", "BIT", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "OfficialRating", "Text"); // AddColumn(db, "TypedBaseItems", "CommunityRating", "Float", existingColumnNames);
// AddColumn(db, "TypedBaseItems", "CustomRating", "Text", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "MediaType", "Text"); // AddColumn(db, "TypedBaseItems", "IndexNumber", "INT", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "Overview", "Text"); // AddColumn(db, "TypedBaseItems", "IsLocked", "BIT", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "ParentIndexNumber", "INT"); // AddColumn(db, "TypedBaseItems", "Name", "Text", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "PremiereDate", "DATETIME"); // AddColumn(db, "TypedBaseItems", "OfficialRating", "Text", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "ProductionYear", "INT");
// _connection.AddColumn(Logger, "TypedBaseItems", "ParentId", "GUID"); // AddColumn(db, "TypedBaseItems", "MediaType", "Text", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "Genres", "Text"); // AddColumn(db, "TypedBaseItems", "Overview", "Text", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "SchemaVersion", "INT"); // AddColumn(db, "TypedBaseItems", "ParentIndexNumber", "INT", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "SortName", "Text"); // AddColumn(db, "TypedBaseItems", "PremiereDate", "DATETIME", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "RunTimeTicks", "BIGINT"); // AddColumn(db, "TypedBaseItems", "ProductionYear", "INT", existingColumnNames);
// AddColumn(db, "TypedBaseItems", "ParentId", "GUID", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "OfficialRatingDescription", "Text"); // AddColumn(db, "TypedBaseItems", "Genres", "Text", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "HomePageUrl", "Text"); // AddColumn(db, "TypedBaseItems", "SchemaVersion", "INT", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "VoteCount", "INT"); // AddColumn(db, "TypedBaseItems", "SortName", "Text", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "DisplayMediaType", "Text"); // AddColumn(db, "TypedBaseItems", "RunTimeTicks", "BIGINT", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "DateCreated", "DATETIME");
// _connection.AddColumn(Logger, "TypedBaseItems", "DateModified", "DATETIME"); // AddColumn(db, "TypedBaseItems", "OfficialRatingDescription", "Text", existingColumnNames);
// AddColumn(db, "TypedBaseItems", "HomePageUrl", "Text", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "ForcedSortName", "Text"); // AddColumn(db, "TypedBaseItems", "VoteCount", "INT", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "IsOffline", "BIT"); // AddColumn(db, "TypedBaseItems", "DisplayMediaType", "Text", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "LocationType", "Text"); // AddColumn(db, "TypedBaseItems", "DateCreated", "DATETIME", existingColumnNames);
// AddColumn(db, "TypedBaseItems", "DateModified", "DATETIME", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "IsSeries", "BIT");
// _connection.AddColumn(Logger, "TypedBaseItems", "IsLive", "BIT"); // AddColumn(db, "TypedBaseItems", "ForcedSortName", "Text", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "IsNews", "BIT"); // AddColumn(db, "TypedBaseItems", "IsOffline", "BIT", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "IsPremiere", "BIT"); // AddColumn(db, "TypedBaseItems", "LocationType", "Text", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "EpisodeTitle", "Text"); // AddColumn(db, "TypedBaseItems", "IsSeries", "BIT", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "IsRepeat", "BIT"); // AddColumn(db, "TypedBaseItems", "IsLive", "BIT", existingColumnNames);
// AddColumn(db, "TypedBaseItems", "IsNews", "BIT", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "PreferredMetadataLanguage", "Text"); // AddColumn(db, "TypedBaseItems", "IsPremiere", "BIT", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "PreferredMetadataCountryCode", "Text");
// _connection.AddColumn(Logger, "TypedBaseItems", "IsHD", "BIT"); // AddColumn(db, "TypedBaseItems", "EpisodeTitle", "Text", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "ExternalEtag", "Text"); // AddColumn(db, "TypedBaseItems", "IsRepeat", "BIT", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "DateLastRefreshed", "DATETIME");
// AddColumn(db, "TypedBaseItems", "PreferredMetadataLanguage", "Text", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "DateLastSaved", "DATETIME"); // AddColumn(db, "TypedBaseItems", "PreferredMetadataCountryCode", "Text", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "IsInMixedFolder", "BIT"); // AddColumn(db, "TypedBaseItems", "IsHD", "BIT", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "LockedFields", "Text"); // AddColumn(db, "TypedBaseItems", "ExternalEtag", "Text", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "Studios", "Text"); // AddColumn(db, "TypedBaseItems", "DateLastRefreshed", "DATETIME", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "Audio", "Text");
// _connection.AddColumn(Logger, "TypedBaseItems", "ExternalServiceId", "Text"); // AddColumn(db, "TypedBaseItems", "DateLastSaved", "DATETIME", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "Tags", "Text"); // AddColumn(db, "TypedBaseItems", "IsInMixedFolder", "BIT", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "IsFolder", "BIT"); // AddColumn(db, "TypedBaseItems", "LockedFields", "Text", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "InheritedParentalRatingValue", "INT"); // AddColumn(db, "TypedBaseItems", "Studios", "Text", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "UnratedType", "Text"); // AddColumn(db, "TypedBaseItems", "Audio", "Text", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "TopParentId", "Text"); // AddColumn(db, "TypedBaseItems", "ExternalServiceId", "Text", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "IsItemByName", "BIT"); // AddColumn(db, "TypedBaseItems", "Tags", "Text", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "SourceType", "Text"); // AddColumn(db, "TypedBaseItems", "IsFolder", "BIT", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "TrailerTypes", "Text"); // AddColumn(db, "TypedBaseItems", "InheritedParentalRatingValue", "INT", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "CriticRating", "Float"); // AddColumn(db, "TypedBaseItems", "UnratedType", "Text", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "CriticRatingSummary", "Text"); // AddColumn(db, "TypedBaseItems", "TopParentId", "Text", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "InheritedTags", "Text"); // AddColumn(db, "TypedBaseItems", "IsItemByName", "BIT", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "CleanName", "Text"); // AddColumn(db, "TypedBaseItems", "SourceType", "Text", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "PresentationUniqueKey", "Text"); // AddColumn(db, "TypedBaseItems", "TrailerTypes", "Text", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "SlugName", "Text"); // AddColumn(db, "TypedBaseItems", "CriticRating", "Float", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "OriginalTitle", "Text"); // AddColumn(db, "TypedBaseItems", "CriticRatingSummary", "Text", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "PrimaryVersionId", "Text"); // AddColumn(db, "TypedBaseItems", "InheritedTags", "Text", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "DateLastMediaAdded", "DATETIME"); // AddColumn(db, "TypedBaseItems", "CleanName", "Text", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "Album", "Text"); // AddColumn(db, "TypedBaseItems", "PresentationUniqueKey", "Text", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "IsVirtualItem", "BIT"); // AddColumn(db, "TypedBaseItems", "SlugName", "Text", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "SeriesName", "Text"); // AddColumn(db, "TypedBaseItems", "OriginalTitle", "Text", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "UserDataKey", "Text"); // AddColumn(db, "TypedBaseItems", "PrimaryVersionId", "Text", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "SeasonName", "Text"); // AddColumn(db, "TypedBaseItems", "DateLastMediaAdded", "DATETIME", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "SeasonId", "GUID"); // AddColumn(db, "TypedBaseItems", "Album", "Text", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "SeriesId", "GUID"); // AddColumn(db, "TypedBaseItems", "IsVirtualItem", "BIT", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "SeriesSortName", "Text"); // AddColumn(db, "TypedBaseItems", "SeriesName", "Text", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "ExternalSeriesId", "Text"); // AddColumn(db, "TypedBaseItems", "UserDataKey", "Text", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "ShortOverview", "Text"); // AddColumn(db, "TypedBaseItems", "SeasonName", "Text", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "Tagline", "Text"); // AddColumn(db, "TypedBaseItems", "SeasonId", "GUID", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "Keywords", "Text"); // AddColumn(db, "TypedBaseItems", "SeriesId", "GUID", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "ProviderIds", "Text"); // AddColumn(db, "TypedBaseItems", "SeriesSortName", "Text", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "Images", "Text"); // AddColumn(db, "TypedBaseItems", "ExternalSeriesId", "Text", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "ProductionLocations", "Text"); // AddColumn(db, "TypedBaseItems", "ShortOverview", "Text", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "ThemeSongIds", "Text"); // AddColumn(db, "TypedBaseItems", "Tagline", "Text", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "ThemeVideoIds", "Text"); // AddColumn(db, "TypedBaseItems", "Keywords", "Text", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "TotalBitrate", "INT"); // AddColumn(db, "TypedBaseItems", "ProviderIds", "Text", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "ExtraType", "Text"); // AddColumn(db, "TypedBaseItems", "Images", "Text", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "Artists", "Text"); // AddColumn(db, "TypedBaseItems", "ProductionLocations", "Text", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "AlbumArtists", "Text"); // AddColumn(db, "TypedBaseItems", "ThemeSongIds", "Text", existingColumnNames);
// _connection.AddColumn(Logger, "TypedBaseItems", "ExternalId", "Text"); // AddColumn(db, "TypedBaseItems", "ThemeVideoIds", "Text", existingColumnNames);
// AddColumn(db, "TypedBaseItems", "TotalBitrate", "INT", existingColumnNames);
// _connection.AddColumn(Logger, "ItemValues", "CleanValue", "Text"); // AddColumn(db, "TypedBaseItems", "ExtraType", "Text", existingColumnNames);
// AddColumn(db, "TypedBaseItems", "Artists", "Text", existingColumnNames);
// _connection.AddColumn(Logger, ChaptersTableName, "ImageDateModified", "DATETIME"); // AddColumn(db, "TypedBaseItems", "AlbumArtists", "Text", existingColumnNames);
// AddColumn(db, "TypedBaseItems", "ExternalId", "Text", existingColumnNames);
// existingColumnNames = GetColumnNames(db, "ItemValues");
// AddColumn(db, "ItemValues", "CleanValue", "Text", existingColumnNames);
// existingColumnNames = GetColumnNames(db, ChaptersTableName);
// AddColumn(db, ChaptersTableName, "ImageDateModified", "DATETIME", existingColumnNames);
// existingColumnNames = GetColumnNames(db, "MediaStreams");
// AddColumn(db, "MediaStreams", "IsAvc", "BIT", existingColumnNames);
// AddColumn(db, "MediaStreams", "TimeBase", "TEXT", existingColumnNames);
// AddColumn(db, "MediaStreams", "CodecTimeBase", "TEXT", existingColumnNames);
// AddColumn(db, "MediaStreams", "Title", "TEXT", existingColumnNames);
// AddColumn(db, "MediaStreams", "NalLengthSize", "TEXT", existingColumnNames);
// AddColumn(db, "MediaStreams", "Comment", "TEXT", existingColumnNames);
// AddColumn(db, "MediaStreams", "CodecTag", "TEXT", existingColumnNames);
// AddColumn(db, "MediaStreams", "PixelFormat", "TEXT", existingColumnNames);
// AddColumn(db, "MediaStreams", "BitDepth", "INT", existingColumnNames);
// AddColumn(db, "MediaStreams", "RefFrames", "INT", existingColumnNames);
// AddColumn(db, "MediaStreams", "KeyFrames", "TEXT", existingColumnNames);
// AddColumn(db, "MediaStreams", "IsAnamorphic", "BIT", existingColumnNames);
// });
// string[] postQueries = // string[] postQueries =
@ -334,14 +356,12 @@
// "create index if not exists idx_ItemValues7 on ItemValues(Type,CleanValue,ItemId)" // "create index if not exists idx_ItemValues7 on ItemValues(Type,CleanValue,ItemId)"
// }; // };
// _connection.RunQueries(postQueries, Logger); // _connection.RunQueries(postQueries);
// PrepareStatements(); // PrepareStatements();
// new MediaStreamColumns(_connection, Logger).AddColumns(); // SqliteExtensions.Attach(_connection, Path.Combine(_config.ApplicationPaths.DataPath, "userdata_v2.db"), "UserDataDb");
// userDataRepo.Initialize(_connection, WriteLock);
// DataExtensions.Attach(_connection, Path.Combine(_config.ApplicationPaths.DataPath, "userdata_v2.db"), "UserDataDb");
// await userDataRepo.Initialize(_connection, WriteLock).ConfigureAwait(false);
// //await Vacuum(_connection).ConfigureAwait(false); // //await Vacuum(_connection).ConfigureAwait(false);
// } // }

@ -1,331 +1,331 @@
using System; //using System;
using System.Collections.Generic; //using System.Collections.Generic;
using System.IO; //using System.IO;
using System.Linq; //using System.Linq;
using System.Threading; //using System.Threading;
using System.Threading.Tasks; //using System.Threading.Tasks;
using MediaBrowser.Common.Configuration; //using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller.Entities; //using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Persistence; //using MediaBrowser.Controller.Persistence;
using MediaBrowser.Model.Logging; //using MediaBrowser.Model.Logging;
using SQLitePCL.pretty; //using SQLitePCL.pretty;
namespace Emby.Server.Implementations.Data //namespace Emby.Server.Implementations.Data
{ //{
public class SqliteUserDataRepository : BaseSqliteRepository, IUserDataRepository // public class SqliteUserDataRepository : BaseSqliteRepository, IUserDataRepository
{ // {
private SQLiteDatabaseConnection _connection; // private SQLiteDatabaseConnection _connection;
public SqliteUserDataRepository(ILogger logger, IApplicationPaths appPaths) // public SqliteUserDataRepository(ILogger logger, IApplicationPaths appPaths)
: base(logger) // : base(logger)
{ // {
DbFilePath = Path.Combine(appPaths.DataPath, "userdata_v2.db"); // DbFilePath = Path.Combine(appPaths.DataPath, "userdata_v2.db");
} // }
protected override bool EnableConnectionPooling // protected override bool EnableConnectionPooling
{ // {
get { return false; } // get { return false; }
} // }
/// <summary> // /// <summary>
/// Gets the name of the repository // /// Gets the name of the repository
/// </summary> // /// </summary>
/// <value>The name.</value> // /// <value>The name.</value>
public string Name // public string Name
{ // {
get // get
{ // {
return "SQLite"; // return "SQLite";
} // }
} // }
/// <summary> // /// <summary>
/// Opens the connection to the database // /// Opens the connection to the database
/// </summary> // /// </summary>
/// <returns>Task.</returns> // /// <returns>Task.</returns>
public void Initialize(SQLiteDatabaseConnection connection, ReaderWriterLockSlim writeLock) // public void Initialize(SQLiteDatabaseConnection connection, ReaderWriterLockSlim writeLock)
{ // {
WriteLock.Dispose(); // WriteLock.Dispose();
WriteLock = writeLock; // WriteLock = writeLock;
_connection = connection; // _connection = connection;
string[] queries = { // string[] queries = {
"create table if not exists UserDataDb.userdata (key nvarchar, userId GUID, rating float null, played bit, playCount int, isFavorite bit, playbackPositionTicks bigint, lastPlayedDate datetime null)", // "create table if not exists UserDataDb.userdata (key nvarchar, userId GUID, rating float null, played bit, playCount int, isFavorite bit, playbackPositionTicks bigint, lastPlayedDate datetime null)",
"drop index if exists UserDataDb.idx_userdata", // "drop index if exists UserDataDb.idx_userdata",
"drop index if exists UserDataDb.idx_userdata1", // "drop index if exists UserDataDb.idx_userdata1",
"drop index if exists UserDataDb.idx_userdata2", // "drop index if exists UserDataDb.idx_userdata2",
"drop index if exists UserDataDb.userdataindex1", // "drop index if exists UserDataDb.userdataindex1",
"create unique index if not exists UserDataDb.userdataindex on userdata (key, userId)", // "create unique index if not exists UserDataDb.userdataindex on userdata (key, userId)",
"create index if not exists UserDataDb.userdataindex2 on userdata (key, userId, played)", // "create index if not exists UserDataDb.userdataindex2 on userdata (key, userId, played)",
"create index if not exists UserDataDb.userdataindex3 on userdata (key, userId, playbackPositionTicks)", // "create index if not exists UserDataDb.userdataindex3 on userdata (key, userId, playbackPositionTicks)",
"create index if not exists UserDataDb.userdataindex4 on userdata (key, userId, isFavorite)", // "create index if not exists UserDataDb.userdataindex4 on userdata (key, userId, isFavorite)",
//pragmas // //pragmas
"pragma temp_store = memory", // "pragma temp_store = memory",
"pragma shrink_memory" // "pragma shrink_memory"
}; // };
_connection.RunQueries(queries); // _connection.RunQueries(queries);
connection.RunInTransaction(db => // connection.RunInTransaction(db =>
{ // {
var existingColumnNames = GetColumnNames(db, "userdata"); // var existingColumnNames = GetColumnNames(db, "userdata");
AddColumn(db, "userdata", "AudioStreamIndex", "int", existingColumnNames); // AddColumn(db, "userdata", "AudioStreamIndex", "int", existingColumnNames);
AddColumn(db, "userdata", "SubtitleStreamIndex", "int", existingColumnNames); // AddColumn(db, "userdata", "SubtitleStreamIndex", "int", existingColumnNames);
}); // });
} // }
/// <summary> // /// <summary>
/// Saves the user data. // /// Saves the user data.
/// </summary> // /// </summary>
/// <param name="userId">The user id.</param> // /// <param name="userId">The user id.</param>
/// <param name="key">The key.</param> // /// <param name="key">The key.</param>
/// <param name="userData">The user data.</param> // /// <param name="userData">The user data.</param>
/// <param name="cancellationToken">The cancellation token.</param> // /// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns> // /// <returns>Task.</returns>
/// <exception cref="System.ArgumentNullException">userData // /// <exception cref="System.ArgumentNullException">userData
/// or // /// or
/// cancellationToken // /// cancellationToken
/// or // /// or
/// userId // /// userId
/// or // /// or
/// userDataId</exception> // /// userDataId</exception>
public Task SaveUserData(Guid userId, string key, UserItemData userData, CancellationToken cancellationToken) // public Task SaveUserData(Guid userId, string key, UserItemData userData, CancellationToken cancellationToken)
{ // {
if (userData == null) // if (userData == null)
{ // {
throw new ArgumentNullException("userData"); // throw new ArgumentNullException("userData");
} // }
if (userId == Guid.Empty) // if (userId == Guid.Empty)
{ // {
throw new ArgumentNullException("userId"); // throw new ArgumentNullException("userId");
} // }
if (string.IsNullOrEmpty(key)) // if (string.IsNullOrEmpty(key))
{ // {
throw new ArgumentNullException("key"); // throw new ArgumentNullException("key");
} // }
return PersistUserData(userId, key, userData, cancellationToken); // return PersistUserData(userId, key, userData, cancellationToken);
} // }
public Task SaveAllUserData(Guid userId, IEnumerable<UserItemData> userData, CancellationToken cancellationToken) // public Task SaveAllUserData(Guid userId, IEnumerable<UserItemData> userData, CancellationToken cancellationToken)
{ // {
if (userData == null) // if (userData == null)
{ // {
throw new ArgumentNullException("userData"); // throw new ArgumentNullException("userData");
} // }
if (userId == Guid.Empty) // if (userId == Guid.Empty)
{ // {
throw new ArgumentNullException("userId"); // throw new ArgumentNullException("userId");
} // }
return PersistAllUserData(userId, userData.ToList(), cancellationToken); // return PersistAllUserData(userId, userData.ToList(), cancellationToken);
} // }
/// <summary> // /// <summary>
/// Persists the user data. // /// Persists the user data.
/// </summary> // /// </summary>
/// <param name="userId">The user id.</param> // /// <param name="userId">The user id.</param>
/// <param name="key">The key.</param> // /// <param name="key">The key.</param>
/// <param name="userData">The user data.</param> // /// <param name="userData">The user data.</param>
/// <param name="cancellationToken">The cancellation token.</param> // /// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns> // /// <returns>Task.</returns>
public async Task PersistUserData(Guid userId, string key, UserItemData userData, CancellationToken cancellationToken) // public async Task PersistUserData(Guid userId, string key, UserItemData userData, CancellationToken cancellationToken)
{ // {
cancellationToken.ThrowIfCancellationRequested(); // cancellationToken.ThrowIfCancellationRequested();
using (WriteLock.Write()) // using (WriteLock.Write())
{ // {
_connection.RunInTransaction(db => // _connection.RunInTransaction(db =>
{ // {
SaveUserData(db, userId, key, userData); // SaveUserData(db, userId, key, userData);
}); // });
} // }
} // }
private void SaveUserData(IDatabaseConnection db, Guid userId, string key, UserItemData userData) // private void SaveUserData(IDatabaseConnection db, Guid userId, string key, UserItemData userData)
{ // {
var paramList = new List<object>(); // var paramList = new List<object>();
var commandText = "replace into userdata (key, userId, rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex) values (?, ?, ?,?,?,?,?,?,?,?)"; // var commandText = "replace into userdata (key, userId, rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex) values (?, ?, ?,?,?,?,?,?,?,?)";
paramList.Add(key); // paramList.Add(key);
paramList.Add(userId.ToGuidParamValue()); // paramList.Add(userId.ToGuidParamValue());
paramList.Add(userData.Rating); // paramList.Add(userData.Rating);
paramList.Add(userData.Played); // paramList.Add(userData.Played);
paramList.Add(userData.PlayCount); // paramList.Add(userData.PlayCount);
paramList.Add(userData.IsFavorite); // paramList.Add(userData.IsFavorite);
paramList.Add(userData.PlaybackPositionTicks); // paramList.Add(userData.PlaybackPositionTicks);
if (userData.LastPlayedDate.HasValue) // if (userData.LastPlayedDate.HasValue)
{ // {
paramList.Add(userData.LastPlayedDate.Value.ToDateTimeParamValue()); // paramList.Add(userData.LastPlayedDate.Value.ToDateTimeParamValue());
} // }
else // else
{ // {
paramList.Add(null); // paramList.Add(null);
} // }
paramList.Add(userData.AudioStreamIndex); // paramList.Add(userData.AudioStreamIndex);
paramList.Add(userData.SubtitleStreamIndex); // paramList.Add(userData.SubtitleStreamIndex);
db.Execute(commandText, paramList.ToArray()); // db.Execute(commandText, paramList.ToArray());
} // }
/// <summary> // /// <summary>
/// Persist all user data for the specified user // /// Persist all user data for the specified user
/// </summary> // /// </summary>
private async Task PersistAllUserData(Guid userId, List<UserItemData> userDataList, CancellationToken cancellationToken) // private async Task PersistAllUserData(Guid userId, List<UserItemData> userDataList, CancellationToken cancellationToken)
{ // {
cancellationToken.ThrowIfCancellationRequested(); // cancellationToken.ThrowIfCancellationRequested();
using (WriteLock.Write()) // using (WriteLock.Write())
{ // {
_connection.RunInTransaction(db => // _connection.RunInTransaction(db =>
{ // {
foreach (var userItemData in userDataList) // foreach (var userItemData in userDataList)
{ // {
SaveUserData(db, userId, userItemData.Key, userItemData); // SaveUserData(db, userId, userItemData.Key, userItemData);
} // }
}); // });
} // }
} // }
/// <summary> // /// <summary>
/// Gets the user data. // /// Gets the user data.
/// </summary> // /// </summary>
/// <param name="userId">The user id.</param> // /// <param name="userId">The user id.</param>
/// <param name="key">The key.</param> // /// <param name="key">The key.</param>
/// <returns>Task{UserItemData}.</returns> // /// <returns>Task{UserItemData}.</returns>
/// <exception cref="System.ArgumentNullException"> // /// <exception cref="System.ArgumentNullException">
/// userId // /// userId
/// or // /// or
/// key // /// key
/// </exception> // /// </exception>
public UserItemData GetUserData(Guid userId, string key) // public UserItemData GetUserData(Guid userId, string key)
{ // {
if (userId == Guid.Empty) // if (userId == Guid.Empty)
{ // {
throw new ArgumentNullException("userId"); // throw new ArgumentNullException("userId");
} // }
if (string.IsNullOrEmpty(key)) // if (string.IsNullOrEmpty(key))
{ // {
throw new ArgumentNullException("key"); // throw new ArgumentNullException("key");
} // }
var commandText = "select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where key = ? and userId=?"; // var commandText = "select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where key = ? and userId=?";
var paramList = new List<object>(); // var paramList = new List<object>();
paramList.Add(key); // paramList.Add(key);
paramList.Add(userId.ToGuidParamValue()); // paramList.Add(userId.ToGuidParamValue());
foreach (var row in _connection.Query(commandText, paramList.ToArray())) // foreach (var row in _connection.Query(commandText, paramList.ToArray()))
{ // {
return ReadRow(row); // return ReadRow(row);
} // }
return null; // return null;
} // }
public UserItemData GetUserData(Guid userId, List<string> keys) // public UserItemData GetUserData(Guid userId, List<string> keys)
{ // {
if (userId == Guid.Empty) // if (userId == Guid.Empty)
{ // {
throw new ArgumentNullException("userId"); // throw new ArgumentNullException("userId");
} // }
if (keys == null) // if (keys == null)
{ // {
throw new ArgumentNullException("keys"); // throw new ArgumentNullException("keys");
} // }
if (keys.Count == 0) // if (keys.Count == 0)
{ // {
return null; // return null;
} // }
return GetUserData(userId, keys[0]); // return GetUserData(userId, keys[0]);
} // }
/// <summary> // /// <summary>
/// Return all user-data associated with the given user // /// Return all user-data associated with the given user
/// </summary> // /// </summary>
/// <param name="userId"></param> // /// <param name="userId"></param>
/// <returns></returns> // /// <returns></returns>
public IEnumerable<UserItemData> GetAllUserData(Guid userId) // public IEnumerable<UserItemData> GetAllUserData(Guid userId)
{ // {
if (userId == Guid.Empty) // if (userId == Guid.Empty)
{ // {
throw new ArgumentNullException("userId"); // throw new ArgumentNullException("userId");
} // }
var list = new List<UserItemData>(); // var list = new List<UserItemData>();
using (WriteLock.Read()) // using (WriteLock.Read())
{ // {
var commandText = "select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where userId=?"; // var commandText = "select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where userId=?";
var paramList = new List<object>(); // var paramList = new List<object>();
paramList.Add(userId.ToGuidParamValue()); // paramList.Add(userId.ToGuidParamValue());
foreach (var row in _connection.Query(commandText, paramList.ToArray())) // foreach (var row in _connection.Query(commandText, paramList.ToArray()))
{ // {
list.Add(ReadRow(row)); // list.Add(ReadRow(row));
} // }
} // }
return list; // return list;
} // }
/// <summary> // /// <summary>
/// Read a row from the specified reader into the provided userData object // /// Read a row from the specified reader into the provided userData object
/// </summary> // /// </summary>
/// <param name="reader"></param> // /// <param name="reader"></param>
private UserItemData ReadRow(IReadOnlyList<IResultSetValue> reader) // private UserItemData ReadRow(IReadOnlyList<IResultSetValue> reader)
{ // {
var userData = new UserItemData(); // var userData = new UserItemData();
userData.Key = reader[0].ToString(); // userData.Key = reader[0].ToString();
userData.UserId = reader[1].ReadGuid(); // userData.UserId = reader[1].ReadGuid();
if (reader[2].SQLiteType != SQLiteType.Null) // if (reader[2].SQLiteType != SQLiteType.Null)
{ // {
userData.Rating = reader[2].ToDouble(); // userData.Rating = reader[2].ToDouble();
} // }
userData.Played = reader[3].ToBool(); // userData.Played = reader[3].ToBool();
userData.PlayCount = reader[4].ToInt(); // userData.PlayCount = reader[4].ToInt();
userData.IsFavorite = reader[5].ToBool(); // userData.IsFavorite = reader[5].ToBool();
userData.PlaybackPositionTicks = reader[6].ToInt64(); // userData.PlaybackPositionTicks = reader[6].ToInt64();
if (reader[7].SQLiteType != SQLiteType.Null) // if (reader[7].SQLiteType != SQLiteType.Null)
{ // {
userData.LastPlayedDate = reader[7].ReadDateTime(); // userData.LastPlayedDate = reader[7].ReadDateTime();
} // }
if (reader[8].SQLiteType != SQLiteType.Null) // if (reader[8].SQLiteType != SQLiteType.Null)
{ // {
userData.AudioStreamIndex = reader[8].ToInt(); // userData.AudioStreamIndex = reader[8].ToInt();
} // }
if (reader[9].SQLiteType != SQLiteType.Null) // if (reader[9].SQLiteType != SQLiteType.Null)
{ // {
userData.SubtitleStreamIndex = reader[9].ToInt(); // userData.SubtitleStreamIndex = reader[9].ToInt();
} // }
return userData; // return userData;
} // }
protected override void Dispose(bool dispose) // protected override void Dispose(bool dispose)
{ // {
// handled by library database // // handled by library database
} // }
protected override void CloseConnection() // protected override void CloseConnection()
{ // {
// handled by library database // // handled by library database
} // }
} // }
} //}

@ -230,6 +230,10 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
<None Include="packages.config" /> <None Include="packages.config" />
<None Include="SQLitePCLRaw.provider.sqlite3.dll.config">
<SubType>Designer</SubType>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="System.Data.SQLite.dll.config"> <None Include="System.Data.SQLite.dll.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<SubType>Designer</SubType> <SubType>Designer</SubType>

@ -0,0 +1,3 @@
<configuration>
<dllmap dll="sqlite3" target="libsqlite3.so" os="linux"/>
</configuration>
Loading…
Cancel
Save