mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-11-16 18:42:52 -07:00
commit
2877da4883
@ -4,7 +4,6 @@ using Emby.Common.Implementations.Devices;
|
||||
using Emby.Common.Implementations.IO;
|
||||
using Emby.Common.Implementations.ScheduledTasks;
|
||||
using Emby.Common.Implementations.Serialization;
|
||||
using Emby.Common.Implementations.Updates;
|
||||
using MediaBrowser.Common.Net;
|
||||
using MediaBrowser.Common.Plugins;
|
||||
using MediaBrowser.Common.Progress;
|
||||
|
@ -22,5 +22,10 @@ namespace Emby.Common.Implementations.Reflection
|
||||
#endif
|
||||
return type.GetTypeInfo().Assembly.GetManifestResourceNames();
|
||||
}
|
||||
|
||||
public Assembly[] GetCurrentAssemblies()
|
||||
{
|
||||
return AppDomain.CurrentDomain.GetAssemblies();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -55,25 +55,6 @@ namespace Emby.Common.Implementations.ScheduledTasks
|
||||
private ILogger Logger { get; set; }
|
||||
private readonly IFileSystem _fileSystem;
|
||||
|
||||
private bool _suspendTriggers;
|
||||
|
||||
public bool SuspendTriggers
|
||||
{
|
||||
get { return _suspendTriggers; }
|
||||
set
|
||||
{
|
||||
Logger.Info("Setting SuspendTriggers to {0}", value);
|
||||
var executeQueued = _suspendTriggers && !value;
|
||||
|
||||
_suspendTriggers = value;
|
||||
|
||||
if (executeQueued)
|
||||
{
|
||||
ExecuteQueuedTasks();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="TaskManager" /> class.
|
||||
/// </summary>
|
||||
@ -230,7 +211,7 @@ namespace Emby.Common.Implementations.ScheduledTasks
|
||||
|
||||
lock (_taskQueue)
|
||||
{
|
||||
if (task.State == TaskState.Idle && !SuspendTriggers)
|
||||
if (task.State == TaskState.Idle)
|
||||
{
|
||||
Execute(task, options);
|
||||
return;
|
||||
@ -322,11 +303,6 @@ namespace Emby.Common.Implementations.ScheduledTasks
|
||||
/// </summary>
|
||||
private void ExecuteQueuedTasks()
|
||||
{
|
||||
if (SuspendTriggers)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Logger.Info("ExecuteQueuedTasks");
|
||||
|
||||
// Execute queued tasks
|
||||
|
@ -14,6 +14,7 @@
|
||||
"System.Net.Http": "4.0.0.0",
|
||||
"System.Net.Primitives": "4.0.0.0",
|
||||
"System.Net.Http.WebRequest": "4.0.0.0",
|
||||
"System.Reflection": "4.0.0.0",
|
||||
"System.Runtime": "4.0.0.0",
|
||||
"System.Runtime.Extensions": "4.0.0.0",
|
||||
"System.Text.Encoding": "4.0.0.0",
|
||||
@ -57,6 +58,7 @@
|
||||
"ServiceStack.Text.Core": "1.0.27",
|
||||
"NLog": "4.4.0-betaV15",
|
||||
"sharpcompress": "0.14.0",
|
||||
"System.AppDomain": "2.0.11",
|
||||
"MediaBrowser.Model": {
|
||||
"target": "project"
|
||||
},
|
||||
|
@ -65,7 +65,6 @@ using Emby.Common.Implementations.Networking;
|
||||
using Emby.Common.Implementations.Reflection;
|
||||
using Emby.Common.Implementations.Serialization;
|
||||
using Emby.Common.Implementations.TextEncoding;
|
||||
using Emby.Common.Implementations.Updates;
|
||||
using Emby.Common.Implementations.Xml;
|
||||
using Emby.Photos;
|
||||
using MediaBrowser.Model.IO;
|
||||
@ -87,13 +86,13 @@ using Emby.Server.Implementations.Activity;
|
||||
using Emby.Server.Core.Configuration;
|
||||
using Emby.Server.Core.Data;
|
||||
using Emby.Server.Implementations.Devices;
|
||||
using Emby.Server.Core.FFMpeg;
|
||||
using Emby.Server.Implementations.FFMpeg;
|
||||
using Emby.Server.Core.IO;
|
||||
using Emby.Server.Core.Localization;
|
||||
using Emby.Server.Core.Migrations;
|
||||
using Emby.Server.Implementations.Migrations;
|
||||
using Emby.Server.Implementations.Security;
|
||||
using Emby.Server.Implementations.Social;
|
||||
using Emby.Server.Core.Sync;
|
||||
using Emby.Server.Implementations.Sync;
|
||||
using Emby.Server.Implementations.Channels;
|
||||
using Emby.Server.Implementations.Collections;
|
||||
using Emby.Server.Implementations.Connect;
|
||||
@ -109,7 +108,7 @@ using Emby.Server.Implementations.MediaEncoder;
|
||||
using Emby.Server.Implementations.Notifications;
|
||||
using Emby.Server.Implementations.Data;
|
||||
using Emby.Server.Implementations.Playlists;
|
||||
using Emby.Server.Implementations.Security;
|
||||
using Emby.Server.Implementations;
|
||||
using Emby.Server.Implementations.ServerManager;
|
||||
using Emby.Server.Implementations.Session;
|
||||
using Emby.Server.Implementations.Social;
|
||||
@ -357,12 +356,6 @@ namespace Emby.Server.Core
|
||||
{
|
||||
await PerformPreInitMigrations().ConfigureAwait(false);
|
||||
|
||||
if (ServerConfigurationManager.Configuration.MigrationVersion < CleanDatabaseScheduledTask.MigrationVersion &&
|
||||
ServerConfigurationManager.Configuration.IsStartupWizardCompleted)
|
||||
{
|
||||
TaskManager.SuspendTriggers = true;
|
||||
}
|
||||
|
||||
await base.RunStartupTasks().ConfigureAwait(false);
|
||||
|
||||
await MediaEncoder.Init().ConfigureAwait(false);
|
||||
@ -494,7 +487,6 @@ namespace Emby.Server.Core
|
||||
{
|
||||
var migrations = new List<IVersionMigration>
|
||||
{
|
||||
new DbMigration(ServerConfigurationManager, TaskManager)
|
||||
};
|
||||
|
||||
foreach (var task in migrations)
|
||||
@ -552,23 +544,23 @@ namespace Emby.Server.Core
|
||||
UserDataManager = new UserDataManager(LogManager, ServerConfigurationManager);
|
||||
RegisterSingleInstance(UserDataManager);
|
||||
|
||||
UserRepository = await GetUserRepository().ConfigureAwait(false);
|
||||
UserRepository = GetUserRepository();
|
||||
|
||||
var displayPreferencesRepo = new SqliteDisplayPreferencesRepository(LogManager.GetLogger("SqliteDisplayPreferencesRepository"), JsonSerializer, ApplicationPaths, MemoryStreamFactory);
|
||||
DisplayPreferencesRepository = displayPreferencesRepo;
|
||||
RegisterSingleInstance(DisplayPreferencesRepository);
|
||||
|
||||
var itemRepo = new SqliteItemRepository(ServerConfigurationManager, JsonSerializer, LogManager, GetDbConnector(), MemoryStreamFactory);
|
||||
var itemRepo = new SqliteItemRepository(ServerConfigurationManager, JsonSerializer, LogManager, GetDbConnector(), MemoryStreamFactory, assemblyInfo);
|
||||
ItemRepository = itemRepo;
|
||||
RegisterSingleInstance(ItemRepository);
|
||||
|
||||
FileOrganizationRepository = await GetFileOrganizationRepository().ConfigureAwait(false);
|
||||
FileOrganizationRepository = GetFileOrganizationRepository();
|
||||
RegisterSingleInstance(FileOrganizationRepository);
|
||||
|
||||
AuthenticationRepository = await GetAuthenticationRepository().ConfigureAwait(false);
|
||||
RegisterSingleInstance(AuthenticationRepository);
|
||||
|
||||
SyncRepository = await GetSyncRepository().ConfigureAwait(false);
|
||||
SyncRepository = GetSyncRepository();
|
||||
RegisterSingleInstance(SyncRepository);
|
||||
|
||||
UserManager = new UserManager(LogManager.GetLogger("UserManager"), ServerConfigurationManager, UserRepository, XmlSerializer, NetworkManager, () => ImageProcessor, () => DtoService, () => ConnectManager, this, JsonSerializer, FileSystemManager, CryptographyProvider, _defaultUserNameFactory());
|
||||
@ -591,7 +583,7 @@ namespace Emby.Server.Core
|
||||
CertificatePath = GetCertificatePath(true);
|
||||
Certificate = GetCertificate(CertificatePath);
|
||||
|
||||
HttpServer = HttpServerFactory.CreateServer(this, LogManager, ServerConfigurationManager, NetworkManager, MemoryStreamFactory, "Emby", "web/index.html", textEncoding, SocketFactory, CryptographyProvider, JsonSerializer, XmlSerializer, EnvironmentInfo, Certificate);
|
||||
HttpServer = HttpServerFactory.CreateServer(this, LogManager, ServerConfigurationManager, NetworkManager, MemoryStreamFactory, "Emby", "web/index.html", textEncoding, SocketFactory, CryptographyProvider, JsonSerializer, XmlSerializer, EnvironmentInfo, Certificate, SupportsDualModeSockets);
|
||||
HttpServer.GlobalResponse = LocalizationManager.GetLocalizedString("StartupEmbyServerIsLoading");
|
||||
RegisterSingleInstance(HttpServer, false);
|
||||
progress.Report(10);
|
||||
@ -714,6 +706,8 @@ namespace Emby.Server.Core
|
||||
await ((UserManager)UserManager).Initialize().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
protected abstract bool SupportsDualModeSockets { get; }
|
||||
|
||||
private ICertificate GetCertificate(string certificateLocation)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(certificateLocation))
|
||||
@ -804,11 +798,11 @@ namespace Emby.Server.Core
|
||||
/// Gets the user repository.
|
||||
/// </summary>
|
||||
/// <returns>Task{IUserRepository}.</returns>
|
||||
private async Task<IUserRepository> GetUserRepository()
|
||||
private IUserRepository GetUserRepository()
|
||||
{
|
||||
var repo = new SqliteUserRepository(LogManager, ApplicationPaths, JsonSerializer, GetDbConnector(), MemoryStreamFactory);
|
||||
var repo = new SqliteUserRepository(LogManager.GetLogger("SqliteUserRepository"), ApplicationPaths, JsonSerializer, MemoryStreamFactory);
|
||||
|
||||
await repo.Initialize().ConfigureAwait(false);
|
||||
repo.Initialize();
|
||||
|
||||
return repo;
|
||||
}
|
||||
@ -817,11 +811,11 @@ namespace Emby.Server.Core
|
||||
/// Gets the file organization repository.
|
||||
/// </summary>
|
||||
/// <returns>Task{IUserRepository}.</returns>
|
||||
private async Task<IFileOrganizationRepository> GetFileOrganizationRepository()
|
||||
private IFileOrganizationRepository GetFileOrganizationRepository()
|
||||
{
|
||||
var repo = new SqliteFileOrganizationRepository(LogManager, ServerConfigurationManager.ApplicationPaths, GetDbConnector());
|
||||
var repo = new SqliteFileOrganizationRepository(LogManager.GetLogger("SqliteFileOrganizationRepository"), ServerConfigurationManager.ApplicationPaths);
|
||||
|
||||
await repo.Initialize().ConfigureAwait(false);
|
||||
repo.Initialize();
|
||||
|
||||
return repo;
|
||||
}
|
||||
@ -844,11 +838,11 @@ namespace Emby.Server.Core
|
||||
return repo;
|
||||
}
|
||||
|
||||
private async Task<ISyncRepository> GetSyncRepository()
|
||||
private ISyncRepository GetSyncRepository()
|
||||
{
|
||||
var repo = new SyncRepository(LogManager, JsonSerializer, ServerConfigurationManager.ApplicationPaths, GetDbConnector());
|
||||
var repo = new SyncRepository(LogManager.GetLogger("SyncRepository"), JsonSerializer, ServerConfigurationManager.ApplicationPaths);
|
||||
|
||||
await repo.Initialize().ConfigureAwait(false);
|
||||
repo.Initialize();
|
||||
|
||||
return repo;
|
||||
}
|
||||
|
@ -1,408 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Controller;
|
||||
using MediaBrowser.Controller.Persistence;
|
||||
using MediaBrowser.Model.FileOrganization;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.Model.Querying;
|
||||
|
||||
namespace Emby.Server.Core.Data
|
||||
{
|
||||
public class SqliteFileOrganizationRepository : BaseSqliteRepository, IFileOrganizationRepository, IDisposable
|
||||
{
|
||||
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
|
||||
|
||||
public SqliteFileOrganizationRepository(ILogManager logManager, IServerApplicationPaths appPaths, IDbConnector connector) : base(logManager, connector)
|
||||
{
|
||||
DbFilePath = Path.Combine(appPaths.DataPath, "fileorganization.db");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens the connection to the database
|
||||
/// </summary>
|
||||
/// <returns>Task.</returns>
|
||||
public async Task Initialize()
|
||||
{
|
||||
using (var connection = await CreateConnection().ConfigureAwait(false))
|
||||
{
|
||||
string[] queries = {
|
||||
|
||||
"create table if not exists FileOrganizerResults (ResultId GUID PRIMARY KEY, OriginalPath TEXT, TargetPath TEXT, FileLength INT, OrganizationDate datetime, Status TEXT, OrganizationType TEXT, StatusMessage TEXT, ExtractedName TEXT, ExtractedYear int null, ExtractedSeasonNumber int null, ExtractedEpisodeNumber int null, ExtractedEndingEpisodeNumber, DuplicatePaths TEXT int null)",
|
||||
"create index if not exists idx_FileOrganizerResults on FileOrganizerResults(ResultId)"
|
||||
};
|
||||
|
||||
connection.RunQueries(queries, Logger);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task SaveResult(FileOrganizationResult result, CancellationToken cancellationToken)
|
||||
{
|
||||
if (result == null)
|
||||
{
|
||||
throw new ArgumentNullException("result");
|
||||
}
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
using (var connection = await CreateConnection().ConfigureAwait(false))
|
||||
{
|
||||
using (var saveResultCommand = connection.CreateCommand())
|
||||
{
|
||||
saveResultCommand.CommandText = "replace into FileOrganizerResults (ResultId, OriginalPath, TargetPath, FileLength, OrganizationDate, Status, OrganizationType, StatusMessage, ExtractedName, ExtractedYear, ExtractedSeasonNumber, ExtractedEpisodeNumber, ExtractedEndingEpisodeNumber, DuplicatePaths) values (@ResultId, @OriginalPath, @TargetPath, @FileLength, @OrganizationDate, @Status, @OrganizationType, @StatusMessage, @ExtractedName, @ExtractedYear, @ExtractedSeasonNumber, @ExtractedEpisodeNumber, @ExtractedEndingEpisodeNumber, @DuplicatePaths)";
|
||||
|
||||
saveResultCommand.Parameters.Add(saveResultCommand, "@ResultId");
|
||||
saveResultCommand.Parameters.Add(saveResultCommand, "@OriginalPath");
|
||||
saveResultCommand.Parameters.Add(saveResultCommand, "@TargetPath");
|
||||
saveResultCommand.Parameters.Add(saveResultCommand, "@FileLength");
|
||||
saveResultCommand.Parameters.Add(saveResultCommand, "@OrganizationDate");
|
||||
saveResultCommand.Parameters.Add(saveResultCommand, "@Status");
|
||||
saveResultCommand.Parameters.Add(saveResultCommand, "@OrganizationType");
|
||||
saveResultCommand.Parameters.Add(saveResultCommand, "@StatusMessage");
|
||||
saveResultCommand.Parameters.Add(saveResultCommand, "@ExtractedName");
|
||||
saveResultCommand.Parameters.Add(saveResultCommand, "@ExtractedYear");
|
||||
saveResultCommand.Parameters.Add(saveResultCommand, "@ExtractedSeasonNumber");
|
||||
saveResultCommand.Parameters.Add(saveResultCommand, "@ExtractedEpisodeNumber");
|
||||
saveResultCommand.Parameters.Add(saveResultCommand, "@ExtractedEndingEpisodeNumber");
|
||||
saveResultCommand.Parameters.Add(saveResultCommand, "@DuplicatePaths");
|
||||
|
||||
IDbTransaction transaction = null;
|
||||
|
||||
try
|
||||
{
|
||||
transaction = connection.BeginTransaction();
|
||||
|
||||
var index = 0;
|
||||
|
||||
saveResultCommand.GetParameter(index++).Value = new Guid(result.Id);
|
||||
saveResultCommand.GetParameter(index++).Value = result.OriginalPath;
|
||||
saveResultCommand.GetParameter(index++).Value = result.TargetPath;
|
||||
saveResultCommand.GetParameter(index++).Value = result.FileSize;
|
||||
saveResultCommand.GetParameter(index++).Value = result.Date;
|
||||
saveResultCommand.GetParameter(index++).Value = result.Status.ToString();
|
||||
saveResultCommand.GetParameter(index++).Value = result.Type.ToString();
|
||||
saveResultCommand.GetParameter(index++).Value = result.StatusMessage;
|
||||
saveResultCommand.GetParameter(index++).Value = result.ExtractedName;
|
||||
saveResultCommand.GetParameter(index++).Value = result.ExtractedYear;
|
||||
saveResultCommand.GetParameter(index++).Value = result.ExtractedSeasonNumber;
|
||||
saveResultCommand.GetParameter(index++).Value = result.ExtractedEpisodeNumber;
|
||||
saveResultCommand.GetParameter(index++).Value = result.ExtractedEndingEpisodeNumber;
|
||||
saveResultCommand.GetParameter(index).Value = string.Join("|", result.DuplicatePaths.ToArray());
|
||||
|
||||
saveResultCommand.Transaction = transaction;
|
||||
|
||||
saveResultCommand.ExecuteNonQuery();
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
if (transaction != null)
|
||||
{
|
||||
transaction.Rollback();
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.ErrorException("Failed to save FileOrganizationResult:", e);
|
||||
|
||||
if (transaction != null)
|
||||
{
|
||||
transaction.Rollback();
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (transaction != null)
|
||||
{
|
||||
transaction.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async Task Delete(string id)
|
||||
{
|
||||
if (string.IsNullOrEmpty(id))
|
||||
{
|
||||
throw new ArgumentNullException("id");
|
||||
}
|
||||
|
||||
using (var connection = await CreateConnection().ConfigureAwait(false))
|
||||
{
|
||||
using (var deleteResultCommand = connection.CreateCommand())
|
||||
{
|
||||
deleteResultCommand.CommandText = "delete from FileOrganizerResults where ResultId = @ResultId";
|
||||
|
||||
deleteResultCommand.Parameters.Add(deleteResultCommand, "@ResultId");
|
||||
|
||||
IDbTransaction transaction = null;
|
||||
|
||||
try
|
||||
{
|
||||
transaction = connection.BeginTransaction();
|
||||
|
||||
deleteResultCommand.GetParameter(0).Value = new Guid(id);
|
||||
|
||||
deleteResultCommand.Transaction = transaction;
|
||||
|
||||
deleteResultCommand.ExecuteNonQuery();
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
if (transaction != null)
|
||||
{
|
||||
transaction.Rollback();
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.ErrorException("Failed to delete FileOrganizationResult:", e);
|
||||
|
||||
if (transaction != null)
|
||||
{
|
||||
transaction.Rollback();
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (transaction != null)
|
||||
{
|
||||
transaction.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DeleteAll()
|
||||
{
|
||||
using (var connection = await CreateConnection().ConfigureAwait(false))
|
||||
{
|
||||
using (var cmd = connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "delete from FileOrganizerResults";
|
||||
|
||||
IDbTransaction transaction = null;
|
||||
|
||||
try
|
||||
{
|
||||
transaction = connection.BeginTransaction();
|
||||
|
||||
cmd.Transaction = transaction;
|
||||
|
||||
cmd.ExecuteNonQuery();
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
if (transaction != null)
|
||||
{
|
||||
transaction.Rollback();
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.ErrorException("Failed to delete results", e);
|
||||
|
||||
if (transaction != null)
|
||||
{
|
||||
transaction.Rollback();
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (transaction != null)
|
||||
{
|
||||
transaction.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public QueryResult<FileOrganizationResult> GetResults(FileOrganizationResultQuery query)
|
||||
{
|
||||
if (query == null)
|
||||
{
|
||||
throw new ArgumentNullException("query");
|
||||
}
|
||||
|
||||
using (var connection = CreateConnection(true).Result)
|
||||
{
|
||||
using (var cmd = connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "SELECT ResultId, OriginalPath, TargetPath, FileLength, OrganizationDate, Status, OrganizationType, StatusMessage, ExtractedName, ExtractedYear, ExtractedSeasonNumber, ExtractedEpisodeNumber, ExtractedEndingEpisodeNumber, DuplicatePaths from FileOrganizerResults";
|
||||
|
||||
if (query.StartIndex.HasValue && query.StartIndex.Value > 0)
|
||||
{
|
||||
cmd.CommandText += string.Format(" WHERE ResultId NOT IN (SELECT ResultId FROM FileOrganizerResults ORDER BY OrganizationDate desc LIMIT {0})",
|
||||
query.StartIndex.Value.ToString(_usCulture));
|
||||
}
|
||||
|
||||
cmd.CommandText += " ORDER BY OrganizationDate desc";
|
||||
|
||||
if (query.Limit.HasValue)
|
||||
{
|
||||
cmd.CommandText += " LIMIT " + query.Limit.Value.ToString(_usCulture);
|
||||
}
|
||||
|
||||
cmd.CommandText += "; select count (ResultId) from FileOrganizerResults";
|
||||
|
||||
var list = new List<FileOrganizationResult>();
|
||||
var count = 0;
|
||||
|
||||
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess))
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
list.Add(GetResult(reader));
|
||||
}
|
||||
|
||||
if (reader.NextResult() && reader.Read())
|
||||
{
|
||||
count = reader.GetInt32(0);
|
||||
}
|
||||
}
|
||||
|
||||
return new QueryResult<FileOrganizationResult>()
|
||||
{
|
||||
Items = list.ToArray(),
|
||||
TotalRecordCount = count
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public FileOrganizationResult GetResult(string id)
|
||||
{
|
||||
if (string.IsNullOrEmpty(id))
|
||||
{
|
||||
throw new ArgumentNullException("id");
|
||||
}
|
||||
|
||||
using (var connection = CreateConnection(true).Result)
|
||||
{
|
||||
var guid = new Guid(id);
|
||||
|
||||
using (var cmd = connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "select ResultId, OriginalPath, TargetPath, FileLength, OrganizationDate, Status, OrganizationType, StatusMessage, ExtractedName, ExtractedYear, ExtractedSeasonNumber, ExtractedEpisodeNumber, ExtractedEndingEpisodeNumber, DuplicatePaths from FileOrganizerResults where ResultId=@Id";
|
||||
|
||||
cmd.Parameters.Add(cmd, "@Id", DbType.Guid).Value = guid;
|
||||
|
||||
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult | CommandBehavior.SingleRow))
|
||||
{
|
||||
if (reader.Read())
|
||||
{
|
||||
return GetResult(reader);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public FileOrganizationResult GetResult(IDataReader reader)
|
||||
{
|
||||
var index = 0;
|
||||
|
||||
var result = new FileOrganizationResult
|
||||
{
|
||||
Id = reader.GetGuid(0).ToString("N")
|
||||
};
|
||||
|
||||
index++;
|
||||
if (!reader.IsDBNull(index))
|
||||
{
|
||||
result.OriginalPath = reader.GetString(index);
|
||||
}
|
||||
|
||||
index++;
|
||||
if (!reader.IsDBNull(index))
|
||||
{
|
||||
result.TargetPath = reader.GetString(index);
|
||||
}
|
||||
|
||||
index++;
|
||||
result.FileSize = reader.GetInt64(index);
|
||||
|
||||
index++;
|
||||
result.Date = reader.GetDateTime(index).ToUniversalTime();
|
||||
|
||||
index++;
|
||||
result.Status = (FileSortingStatus)Enum.Parse(typeof(FileSortingStatus), reader.GetString(index), true);
|
||||
|
||||
index++;
|
||||
result.Type = (FileOrganizerType)Enum.Parse(typeof(FileOrganizerType), reader.GetString(index), true);
|
||||
|
||||
index++;
|
||||
if (!reader.IsDBNull(index))
|
||||
{
|
||||
result.StatusMessage = reader.GetString(index);
|
||||
}
|
||||
|
||||
result.OriginalFileName = Path.GetFileName(result.OriginalPath);
|
||||
|
||||
index++;
|
||||
if (!reader.IsDBNull(index))
|
||||
{
|
||||
result.ExtractedName = reader.GetString(index);
|
||||
}
|
||||
|
||||
index++;
|
||||
if (!reader.IsDBNull(index))
|
||||
{
|
||||
result.ExtractedYear = reader.GetInt32(index);
|
||||
}
|
||||
|
||||
index++;
|
||||
if (!reader.IsDBNull(index))
|
||||
{
|
||||
result.ExtractedSeasonNumber = reader.GetInt32(index);
|
||||
}
|
||||
|
||||
index++;
|
||||
if (!reader.IsDBNull(index))
|
||||
{
|
||||
result.ExtractedEpisodeNumber = reader.GetInt32(index);
|
||||
}
|
||||
|
||||
index++;
|
||||
if (!reader.IsDBNull(index))
|
||||
{
|
||||
result.ExtractedEndingEpisodeNumber = reader.GetInt32(index);
|
||||
}
|
||||
|
||||
index++;
|
||||
if (!reader.IsDBNull(index))
|
||||
{
|
||||
result.DuplicatePaths = reader.GetString(index).Split('|').Where(i => !string.IsNullOrEmpty(i)).ToList();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
@ -28,6 +28,8 @@ using MediaBrowser.Model.Querying;
|
||||
using MediaBrowser.Model.Serialization;
|
||||
using MediaBrowser.Server.Implementations.Devices;
|
||||
using MediaBrowser.Server.Implementations.Playlists;
|
||||
using Emby.Server.Implementations.Data;
|
||||
using MediaBrowser.Model.Reflection;
|
||||
|
||||
namespace Emby.Server.Core.Data
|
||||
{
|
||||
@ -38,7 +40,7 @@ namespace Emby.Server.Core.Data
|
||||
{
|
||||
private IDbConnection _connection;
|
||||
|
||||
private readonly TypeMapper _typeMapper = new TypeMapper();
|
||||
private readonly TypeMapper _typeMapper;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the repository
|
||||
@ -95,7 +97,7 @@ namespace Emby.Server.Core.Data
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SqliteItemRepository"/> class.
|
||||
/// </summary>
|
||||
public SqliteItemRepository(IServerConfigurationManager config, IJsonSerializer jsonSerializer, ILogManager logManager, IDbConnector connector, IMemoryStreamFactory memoryStreamProvider)
|
||||
public SqliteItemRepository(IServerConfigurationManager config, IJsonSerializer jsonSerializer, ILogManager logManager, IDbConnector connector, IMemoryStreamFactory memoryStreamProvider, IAssemblyInfo assemblyInfo)
|
||||
: base(logManager, connector)
|
||||
{
|
||||
if (config == null)
|
||||
@ -110,6 +112,7 @@ namespace Emby.Server.Core.Data
|
||||
_config = config;
|
||||
_jsonSerializer = jsonSerializer;
|
||||
_memoryStreamProvider = memoryStreamProvider;
|
||||
_typeMapper = new TypeMapper(assemblyInfo);
|
||||
|
||||
_criticReviewsPath = Path.Combine(_config.ApplicationPaths.DataPath, "critic-reviews");
|
||||
DbFilePath = Path.Combine(_config.ApplicationPaths.DataPath, "library.db");
|
||||
@ -3060,18 +3063,6 @@ namespace Emby.Server.Core.Data
|
||||
{
|
||||
//whereClauses.Add("(UserId is null or UserId=@UserId)");
|
||||
}
|
||||
if (query.IsCurrentSchema.HasValue)
|
||||
{
|
||||
if (query.IsCurrentSchema.Value)
|
||||
{
|
||||
whereClauses.Add("(SchemaVersion not null AND SchemaVersion=@SchemaVersion)");
|
||||
}
|
||||
else
|
||||
{
|
||||
whereClauses.Add("(SchemaVersion is null or SchemaVersion<>@SchemaVersion)");
|
||||
}
|
||||
cmd.Parameters.Add(cmd, "@SchemaVersion", DbType.Int32).Value = LatestSchemaVersion;
|
||||
}
|
||||
if (query.IsHD.HasValue)
|
||||
{
|
||||
whereClauses.Add("IsHD=@IsHD");
|
||||
@ -3454,7 +3445,7 @@ namespace Emby.Server.Core.Data
|
||||
cmd.Parameters.Add(cmd, "@NameLessThan", DbType.String).Value = query.NameLessThan.ToLower();
|
||||
}
|
||||
|
||||
if (query.ImageTypes.Length > 0 && _config.Configuration.SchemaVersion >= 87)
|
||||
if (query.ImageTypes.Length > 0)
|
||||
{
|
||||
foreach (var requiredImage in query.ImageTypes)
|
||||
{
|
||||
@ -3738,15 +3729,8 @@ namespace Emby.Server.Core.Data
|
||||
}
|
||||
if (query.IsVirtualItem.HasValue)
|
||||
{
|
||||
if (_config.Configuration.SchemaVersion >= 90)
|
||||
{
|
||||
whereClauses.Add("IsVirtualItem=@IsVirtualItem");
|
||||
cmd.Parameters.Add(cmd, "@IsVirtualItem", DbType.Boolean).Value = query.IsVirtualItem.Value;
|
||||
}
|
||||
else if (!query.IsVirtualItem.Value)
|
||||
{
|
||||
whereClauses.Add("LocationType<>'Virtual'");
|
||||
}
|
||||
whereClauses.Add("IsVirtualItem=@IsVirtualItem");
|
||||
cmd.Parameters.Add(cmd, "@IsVirtualItem", DbType.Boolean).Value = query.IsVirtualItem.Value;
|
||||
}
|
||||
if (query.IsSpecialSeason.HasValue)
|
||||
{
|
||||
@ -3770,7 +3754,7 @@ namespace Emby.Server.Core.Data
|
||||
whereClauses.Add("PremiereDate < DATETIME('now')");
|
||||
}
|
||||
}
|
||||
if (query.IsMissing.HasValue && _config.Configuration.SchemaVersion >= 90)
|
||||
if (query.IsMissing.HasValue)
|
||||
{
|
||||
if (query.IsMissing.Value)
|
||||
{
|
||||
@ -3781,7 +3765,7 @@ namespace Emby.Server.Core.Data
|
||||
whereClauses.Add("(IsVirtualItem=0 OR PremiereDate >= DATETIME('now'))");
|
||||
}
|
||||
}
|
||||
if (query.IsVirtualUnaired.HasValue && _config.Configuration.SchemaVersion >= 90)
|
||||
if (query.IsVirtualUnaired.HasValue)
|
||||
{
|
||||
if (query.IsVirtualUnaired.Value)
|
||||
{
|
||||
|
@ -1,237 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Controller;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Persistence;
|
||||
using MediaBrowser.Model.IO;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.Model.Serialization;
|
||||
|
||||
namespace Emby.Server.Core.Data
|
||||
{
|
||||
/// <summary>
|
||||
/// Class SQLiteUserRepository
|
||||
/// </summary>
|
||||
public class SqliteUserRepository : BaseSqliteRepository, IUserRepository
|
||||
{
|
||||
private readonly IJsonSerializer _jsonSerializer;
|
||||
private readonly IMemoryStreamFactory _memoryStreamProvider;
|
||||
|
||||
public SqliteUserRepository(ILogManager logManager, IServerApplicationPaths appPaths, IJsonSerializer jsonSerializer, IDbConnector dbConnector, IMemoryStreamFactory memoryStreamProvider) : base(logManager, dbConnector)
|
||||
{
|
||||
_jsonSerializer = jsonSerializer;
|
||||
_memoryStreamProvider = memoryStreamProvider;
|
||||
|
||||
DbFilePath = Path.Combine(appPaths.DataPath, "users.db");
|
||||
}
|
||||
|
||||
/// <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 async Task Initialize()
|
||||
{
|
||||
using (var connection = await CreateConnection().ConfigureAwait(false))
|
||||
{
|
||||
string[] queries = {
|
||||
|
||||
"create table if not exists users (guid GUID primary key, data BLOB)",
|
||||
"create index if not exists idx_users on users(guid)",
|
||||
"create table if not exists schema_version (table_name primary key, version)",
|
||||
|
||||
"pragma shrink_memory"
|
||||
};
|
||||
|
||||
connection.RunQueries(queries, Logger);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Save a user in the repo
|
||||
/// </summary>
|
||||
/// <param name="user">The user.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task.</returns>
|
||||
/// <exception cref="System.ArgumentNullException">user</exception>
|
||||
public async Task SaveUser(User user, CancellationToken cancellationToken)
|
||||
{
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException("user");
|
||||
}
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var serialized = _jsonSerializer.SerializeToBytes(user, _memoryStreamProvider);
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
using (var connection = await CreateConnection().ConfigureAwait(false))
|
||||
{
|
||||
IDbTransaction transaction = null;
|
||||
|
||||
try
|
||||
{
|
||||
transaction = connection.BeginTransaction();
|
||||
|
||||
using (var cmd = connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "replace into users (guid, data) values (@1, @2)";
|
||||
cmd.Parameters.Add(cmd, "@1", DbType.Guid).Value = user.Id;
|
||||
cmd.Parameters.Add(cmd, "@2", DbType.Binary).Value = serialized;
|
||||
|
||||
cmd.Transaction = transaction;
|
||||
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
if (transaction != null)
|
||||
{
|
||||
transaction.Rollback();
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.ErrorException("Failed to save user:", e);
|
||||
|
||||
if (transaction != null)
|
||||
{
|
||||
transaction.Rollback();
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (transaction != null)
|
||||
{
|
||||
transaction.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve all users from the database
|
||||
/// </summary>
|
||||
/// <returns>IEnumerable{User}.</returns>
|
||||
public IEnumerable<User> RetrieveAllUsers()
|
||||
{
|
||||
var list = new List<User>();
|
||||
|
||||
using (var connection = CreateConnection(true).Result)
|
||||
{
|
||||
using (var cmd = connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "select guid,data from users";
|
||||
|
||||
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult))
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
var id = reader.GetGuid(0);
|
||||
|
||||
using (var stream = reader.GetMemoryStream(1, _memoryStreamProvider))
|
||||
{
|
||||
var user = _jsonSerializer.DeserializeFromStream<User>(stream);
|
||||
user.Id = id;
|
||||
list.Add(user);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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>
|
||||
public async Task DeleteUser(User user, CancellationToken cancellationToken)
|
||||
{
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException("user");
|
||||
}
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
using (var connection = await CreateConnection().ConfigureAwait(false))
|
||||
{
|
||||
IDbTransaction transaction = null;
|
||||
|
||||
try
|
||||
{
|
||||
transaction = connection.BeginTransaction();
|
||||
|
||||
using (var cmd = connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "delete from users where guid=@guid";
|
||||
|
||||
cmd.Parameters.Add(cmd, "@guid", DbType.Guid).Value = user.Id;
|
||||
|
||||
cmd.Transaction = transaction;
|
||||
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
if (transaction != null)
|
||||
{
|
||||
transaction.Rollback();
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.ErrorException("Failed to delete user:", e);
|
||||
|
||||
if (transaction != null)
|
||||
{
|
||||
transaction.Rollback();
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (transaction != null)
|
||||
{
|
||||
transaction.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -95,7 +95,7 @@ namespace Emby.Server.Core.EntryPoints
|
||||
|
||||
NatUtility.StartDiscovery();
|
||||
|
||||
_timer = _timerFactory.Create(ClearCreatedRules, null, TimeSpan.FromMinutes(5), TimeSpan.FromMinutes(5));
|
||||
_timer = _timerFactory.Create(ClearCreatedRules, null, TimeSpan.FromMinutes(10), TimeSpan.FromMinutes(10));
|
||||
|
||||
_deviceDiscovery.DeviceDiscovered += _deviceDiscovery_DeviceDiscovered;
|
||||
|
||||
@ -233,6 +233,7 @@ namespace Emby.Server.Core.EntryPoints
|
||||
await device.CreatePortMap(new Mapping(Protocol.Tcp, privatePort, publicPort)
|
||||
{
|
||||
Description = _appHost.Name
|
||||
|
||||
}).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -44,7 +44,8 @@ namespace Emby.Server.Core
|
||||
IJsonSerializer json,
|
||||
IXmlSerializer xml,
|
||||
IEnvironmentInfo environment,
|
||||
ICertificate certificate)
|
||||
ICertificate certificate,
|
||||
bool enableDualModeSockets)
|
||||
{
|
||||
var logger = logManager.GetLogger("HttpServer");
|
||||
|
||||
@ -63,7 +64,8 @@ namespace Emby.Server.Core
|
||||
environment,
|
||||
certificate,
|
||||
new StreamFactory(),
|
||||
GetParseFn);
|
||||
GetParseFn,
|
||||
enableDualModeSockets);
|
||||
}
|
||||
|
||||
private static Func<string, object> GetParseFn(Type propertyType)
|
||||
|
@ -1,64 +0,0 @@
|
||||
using System.Threading.Tasks;
|
||||
using Emby.Server.Implementations.Data;
|
||||
using MediaBrowser.Controller.Configuration;
|
||||
using MediaBrowser.Model.Tasks;
|
||||
using Emby.Server.Core.Data;
|
||||
using Emby.Server.Implementations.Migrations;
|
||||
|
||||
namespace Emby.Server.Core.Migrations
|
||||
{
|
||||
public class DbMigration : IVersionMigration
|
||||
{
|
||||
private readonly IServerConfigurationManager _config;
|
||||
private readonly ITaskManager _taskManager;
|
||||
|
||||
public DbMigration(IServerConfigurationManager config, ITaskManager taskManager)
|
||||
{
|
||||
_config = config;
|
||||
_taskManager = taskManager;
|
||||
}
|
||||
|
||||
public async Task Run()
|
||||
{
|
||||
// If a forced migration is required, do that now
|
||||
if (_config.Configuration.MigrationVersion < CleanDatabaseScheduledTask.MigrationVersion)
|
||||
{
|
||||
if (!_config.Configuration.IsStartupWizardCompleted)
|
||||
{
|
||||
_config.Configuration.MigrationVersion = CleanDatabaseScheduledTask.MigrationVersion;
|
||||
_config.SaveConfiguration();
|
||||
return;
|
||||
}
|
||||
|
||||
_taskManager.SuspendTriggers = true;
|
||||
CleanDatabaseScheduledTask.EnableUnavailableMessage = true;
|
||||
|
||||
Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(1000).ConfigureAwait(false);
|
||||
|
||||
_taskManager.Execute<CleanDatabaseScheduledTask>();
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (_config.Configuration.SchemaVersion < SqliteItemRepository.LatestSchemaVersion)
|
||||
{
|
||||
if (!_config.Configuration.IsStartupWizardCompleted)
|
||||
{
|
||||
_config.Configuration.SchemaVersion = SqliteItemRepository.LatestSchemaVersion;
|
||||
_config.SaveConfiguration();
|
||||
return;
|
||||
}
|
||||
|
||||
Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(1000).ConfigureAwait(false);
|
||||
|
||||
_taskManager.Execute<CleanDatabaseScheduledTask>();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,976 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Emby.Server.Core.Data;
|
||||
using MediaBrowser.Controller;
|
||||
using MediaBrowser.Controller.Sync;
|
||||
using MediaBrowser.Model.Dto;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.Model.Querying;
|
||||
using MediaBrowser.Model.Serialization;
|
||||
using MediaBrowser.Model.Sync;
|
||||
|
||||
namespace Emby.Server.Core.Sync
|
||||
{
|
||||
public class SyncRepository : BaseSqliteRepository, ISyncRepository
|
||||
{
|
||||
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
|
||||
|
||||
private readonly IJsonSerializer _json;
|
||||
|
||||
public SyncRepository(ILogManager logManager, IJsonSerializer json, IServerApplicationPaths appPaths, IDbConnector connector)
|
||||
: base(logManager, connector)
|
||||
{
|
||||
_json = json;
|
||||
DbFilePath = Path.Combine(appPaths.DataPath, "sync14.db");
|
||||
}
|
||||
|
||||
private class SyncSummary
|
||||
{
|
||||
public Dictionary<string, int> Items { get; set; }
|
||||
|
||||
public SyncSummary()
|
||||
{
|
||||
Items = new Dictionary<string, int>();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async Task Initialize()
|
||||
{
|
||||
using (var connection = await CreateConnection().ConfigureAwait(false))
|
||||
{
|
||||
string[] queries = {
|
||||
|
||||
"create table if not exists SyncJobs (Id GUID PRIMARY KEY, TargetId TEXT NOT NULL, Name TEXT NOT NULL, Profile TEXT, Quality TEXT, Bitrate INT, Status TEXT NOT NULL, Progress FLOAT, UserId TEXT NOT NULL, ItemIds TEXT NOT NULL, Category TEXT, ParentId TEXT, UnwatchedOnly BIT, ItemLimit INT, SyncNewContent BIT, DateCreated DateTime, DateLastModified DateTime, ItemCount int)",
|
||||
|
||||
"create table if not exists SyncJobItems (Id GUID PRIMARY KEY, ItemId TEXT, ItemName TEXT, MediaSourceId TEXT, JobId TEXT, TemporaryPath TEXT, OutputPath TEXT, Status TEXT, TargetId TEXT, DateCreated DateTime, Progress FLOAT, AdditionalFiles TEXT, MediaSource TEXT, IsMarkedForRemoval BIT, JobItemIndex INT, ItemDateModifiedTicks BIGINT)",
|
||||
|
||||
"drop index if exists idx_SyncJobItems2",
|
||||
"drop index if exists idx_SyncJobItems3",
|
||||
"drop index if exists idx_SyncJobs1",
|
||||
"drop index if exists idx_SyncJobs",
|
||||
"drop index if exists idx_SyncJobItems1",
|
||||
"create index if not exists idx_SyncJobItems4 on SyncJobItems(TargetId,ItemId,Status,Progress,DateCreated)",
|
||||
"create index if not exists idx_SyncJobItems5 on SyncJobItems(TargetId,Status,ItemId,Progress)",
|
||||
|
||||
"create index if not exists idx_SyncJobs2 on SyncJobs(TargetId,Status,ItemIds,Progress)",
|
||||
|
||||
"pragma shrink_memory"
|
||||
};
|
||||
|
||||
connection.RunQueries(queries, Logger);
|
||||
|
||||
connection.AddColumn(Logger, "SyncJobs", "Profile", "TEXT");
|
||||
connection.AddColumn(Logger, "SyncJobs", "Bitrate", "INT");
|
||||
connection.AddColumn(Logger, "SyncJobItems", "ItemDateModifiedTicks", "BIGINT");
|
||||
}
|
||||
}
|
||||
|
||||
private const string BaseJobSelectText = "select Id, TargetId, Name, Profile, Quality, Bitrate, Status, Progress, UserId, ItemIds, Category, ParentId, UnwatchedOnly, ItemLimit, SyncNewContent, DateCreated, DateLastModified, ItemCount from SyncJobs";
|
||||
private const string BaseJobItemSelectText = "select Id, ItemId, ItemName, MediaSourceId, JobId, TemporaryPath, OutputPath, Status, TargetId, DateCreated, Progress, AdditionalFiles, MediaSource, IsMarkedForRemoval, JobItemIndex, ItemDateModifiedTicks from SyncJobItems";
|
||||
|
||||
public SyncJob GetJob(string id)
|
||||
{
|
||||
if (string.IsNullOrEmpty(id))
|
||||
{
|
||||
throw new ArgumentNullException("id");
|
||||
}
|
||||
|
||||
CheckDisposed();
|
||||
|
||||
var guid = new Guid(id);
|
||||
|
||||
if (guid == Guid.Empty)
|
||||
{
|
||||
throw new ArgumentNullException("id");
|
||||
}
|
||||
|
||||
using (var connection = CreateConnection(true).Result)
|
||||
{
|
||||
using (var cmd = connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = BaseJobSelectText + " where Id=@Id";
|
||||
|
||||
cmd.Parameters.Add(cmd, "@Id", DbType.Guid).Value = guid;
|
||||
|
||||
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult | CommandBehavior.SingleRow))
|
||||
{
|
||||
if (reader.Read())
|
||||
{
|
||||
return GetJob(reader);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private SyncJob GetJob(IDataReader reader)
|
||||
{
|
||||
var info = new SyncJob
|
||||
{
|
||||
Id = reader.GetGuid(0).ToString("N"),
|
||||
TargetId = reader.GetString(1),
|
||||
Name = reader.GetString(2)
|
||||
};
|
||||
|
||||
if (!reader.IsDBNull(3))
|
||||
{
|
||||
info.Profile = reader.GetString(3);
|
||||
}
|
||||
|
||||
if (!reader.IsDBNull(4))
|
||||
{
|
||||
info.Quality = reader.GetString(4);
|
||||
}
|
||||
|
||||
if (!reader.IsDBNull(5))
|
||||
{
|
||||
info.Bitrate = reader.GetInt32(5);
|
||||
}
|
||||
|
||||
if (!reader.IsDBNull(6))
|
||||
{
|
||||
info.Status = (SyncJobStatus)Enum.Parse(typeof(SyncJobStatus), reader.GetString(6), true);
|
||||
}
|
||||
|
||||
if (!reader.IsDBNull(7))
|
||||
{
|
||||
info.Progress = reader.GetDouble(7);
|
||||
}
|
||||
|
||||
if (!reader.IsDBNull(8))
|
||||
{
|
||||
info.UserId = reader.GetString(8);
|
||||
}
|
||||
|
||||
if (!reader.IsDBNull(9))
|
||||
{
|
||||
info.RequestedItemIds = reader.GetString(9).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
||||
}
|
||||
|
||||
if (!reader.IsDBNull(10))
|
||||
{
|
||||
info.Category = (SyncCategory)Enum.Parse(typeof(SyncCategory), reader.GetString(10), true);
|
||||
}
|
||||
|
||||
if (!reader.IsDBNull(11))
|
||||
{
|
||||
info.ParentId = reader.GetString(11);
|
||||
}
|
||||
|
||||
if (!reader.IsDBNull(12))
|
||||
{
|
||||
info.UnwatchedOnly = reader.GetBoolean(12);
|
||||
}
|
||||
|
||||
if (!reader.IsDBNull(13))
|
||||
{
|
||||
info.ItemLimit = reader.GetInt32(13);
|
||||
}
|
||||
|
||||
info.SyncNewContent = reader.GetBoolean(14);
|
||||
|
||||
info.DateCreated = reader.GetDateTime(15).ToUniversalTime();
|
||||
info.DateLastModified = reader.GetDateTime(16).ToUniversalTime();
|
||||
info.ItemCount = reader.GetInt32(17);
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
public Task Create(SyncJob job)
|
||||
{
|
||||
return InsertOrUpdate(job, true);
|
||||
}
|
||||
|
||||
public Task Update(SyncJob job)
|
||||
{
|
||||
return InsertOrUpdate(job, false);
|
||||
}
|
||||
|
||||
private async Task InsertOrUpdate(SyncJob job, bool insert)
|
||||
{
|
||||
if (job == null)
|
||||
{
|
||||
throw new ArgumentNullException("job");
|
||||
}
|
||||
|
||||
CheckDisposed();
|
||||
|
||||
using (var connection = await CreateConnection().ConfigureAwait(false))
|
||||
{
|
||||
using (var cmd = connection.CreateCommand())
|
||||
{
|
||||
if (insert)
|
||||
{
|
||||
cmd.CommandText = "insert into SyncJobs (Id, TargetId, Name, Profile, Quality, Bitrate, Status, Progress, UserId, ItemIds, Category, ParentId, UnwatchedOnly, ItemLimit, SyncNewContent, DateCreated, DateLastModified, ItemCount) values (@Id, @TargetId, @Name, @Profile, @Quality, @Bitrate, @Status, @Progress, @UserId, @ItemIds, @Category, @ParentId, @UnwatchedOnly, @ItemLimit, @SyncNewContent, @DateCreated, @DateLastModified, @ItemCount)";
|
||||
|
||||
cmd.Parameters.Add(cmd, "@Id");
|
||||
cmd.Parameters.Add(cmd, "@TargetId");
|
||||
cmd.Parameters.Add(cmd, "@Name");
|
||||
cmd.Parameters.Add(cmd, "@Profile");
|
||||
cmd.Parameters.Add(cmd, "@Quality");
|
||||
cmd.Parameters.Add(cmd, "@Bitrate");
|
||||
cmd.Parameters.Add(cmd, "@Status");
|
||||
cmd.Parameters.Add(cmd, "@Progress");
|
||||
cmd.Parameters.Add(cmd, "@UserId");
|
||||
cmd.Parameters.Add(cmd, "@ItemIds");
|
||||
cmd.Parameters.Add(cmd, "@Category");
|
||||
cmd.Parameters.Add(cmd, "@ParentId");
|
||||
cmd.Parameters.Add(cmd, "@UnwatchedOnly");
|
||||
cmd.Parameters.Add(cmd, "@ItemLimit");
|
||||
cmd.Parameters.Add(cmd, "@SyncNewContent");
|
||||
cmd.Parameters.Add(cmd, "@DateCreated");
|
||||
cmd.Parameters.Add(cmd, "@DateLastModified");
|
||||
cmd.Parameters.Add(cmd, "@ItemCount");
|
||||
}
|
||||
else
|
||||
{
|
||||
cmd.CommandText = "update SyncJobs set TargetId=@TargetId,Name=@Name,Profile=@Profile,Quality=@Quality,Bitrate=@Bitrate,Status=@Status,Progress=@Progress,UserId=@UserId,ItemIds=@ItemIds,Category=@Category,ParentId=@ParentId,UnwatchedOnly=@UnwatchedOnly,ItemLimit=@ItemLimit,SyncNewContent=@SyncNewContent,DateCreated=@DateCreated,DateLastModified=@DateLastModified,ItemCount=@ItemCount where Id=@Id";
|
||||
|
||||
cmd.Parameters.Add(cmd, "@Id");
|
||||
cmd.Parameters.Add(cmd, "@TargetId");
|
||||
cmd.Parameters.Add(cmd, "@Name");
|
||||
cmd.Parameters.Add(cmd, "@Profile");
|
||||
cmd.Parameters.Add(cmd, "@Quality");
|
||||
cmd.Parameters.Add(cmd, "@Bitrate");
|
||||
cmd.Parameters.Add(cmd, "@Status");
|
||||
cmd.Parameters.Add(cmd, "@Progress");
|
||||
cmd.Parameters.Add(cmd, "@UserId");
|
||||
cmd.Parameters.Add(cmd, "@ItemIds");
|
||||
cmd.Parameters.Add(cmd, "@Category");
|
||||
cmd.Parameters.Add(cmd, "@ParentId");
|
||||
cmd.Parameters.Add(cmd, "@UnwatchedOnly");
|
||||
cmd.Parameters.Add(cmd, "@ItemLimit");
|
||||
cmd.Parameters.Add(cmd, "@SyncNewContent");
|
||||
cmd.Parameters.Add(cmd, "@DateCreated");
|
||||
cmd.Parameters.Add(cmd, "@DateLastModified");
|
||||
cmd.Parameters.Add(cmd, "@ItemCount");
|
||||
}
|
||||
|
||||
IDbTransaction transaction = null;
|
||||
|
||||
try
|
||||
{
|
||||
transaction = connection.BeginTransaction();
|
||||
|
||||
var index = 0;
|
||||
|
||||
cmd.GetParameter(index++).Value = new Guid(job.Id);
|
||||
cmd.GetParameter(index++).Value = job.TargetId;
|
||||
cmd.GetParameter(index++).Value = job.Name;
|
||||
cmd.GetParameter(index++).Value = job.Profile;
|
||||
cmd.GetParameter(index++).Value = job.Quality;
|
||||
cmd.GetParameter(index++).Value = job.Bitrate;
|
||||
cmd.GetParameter(index++).Value = job.Status.ToString();
|
||||
cmd.GetParameter(index++).Value = job.Progress;
|
||||
cmd.GetParameter(index++).Value = job.UserId;
|
||||
cmd.GetParameter(index++).Value = string.Join(",", job.RequestedItemIds.ToArray());
|
||||
cmd.GetParameter(index++).Value = job.Category;
|
||||
cmd.GetParameter(index++).Value = job.ParentId;
|
||||
cmd.GetParameter(index++).Value = job.UnwatchedOnly;
|
||||
cmd.GetParameter(index++).Value = job.ItemLimit;
|
||||
cmd.GetParameter(index++).Value = job.SyncNewContent;
|
||||
cmd.GetParameter(index++).Value = job.DateCreated;
|
||||
cmd.GetParameter(index++).Value = job.DateLastModified;
|
||||
cmd.GetParameter(index++).Value = job.ItemCount;
|
||||
|
||||
cmd.Transaction = transaction;
|
||||
|
||||
cmd.ExecuteNonQuery();
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
if (transaction != null)
|
||||
{
|
||||
transaction.Rollback();
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.ErrorException("Failed to save record:", e);
|
||||
|
||||
if (transaction != null)
|
||||
{
|
||||
transaction.Rollback();
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (transaction != null)
|
||||
{
|
||||
transaction.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DeleteJob(string id)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(id))
|
||||
{
|
||||
throw new ArgumentNullException("id");
|
||||
}
|
||||
|
||||
CheckDisposed();
|
||||
|
||||
using (var connection = await CreateConnection().ConfigureAwait(false))
|
||||
{
|
||||
using (var deleteJobCommand = connection.CreateCommand())
|
||||
{
|
||||
using (var deleteJobItemsCommand = connection.CreateCommand())
|
||||
{
|
||||
IDbTransaction transaction = null;
|
||||
|
||||
try
|
||||
{
|
||||
// _deleteJobCommand
|
||||
deleteJobCommand.CommandText = "delete from SyncJobs where Id=@Id";
|
||||
deleteJobCommand.Parameters.Add(deleteJobCommand, "@Id");
|
||||
|
||||
transaction = connection.BeginTransaction();
|
||||
|
||||
deleteJobCommand.GetParameter(0).Value = new Guid(id);
|
||||
deleteJobCommand.Transaction = transaction;
|
||||
deleteJobCommand.ExecuteNonQuery();
|
||||
|
||||
// _deleteJobItemsCommand
|
||||
deleteJobItemsCommand.CommandText = "delete from SyncJobItems where JobId=@JobId";
|
||||
deleteJobItemsCommand.Parameters.Add(deleteJobItemsCommand, "@JobId");
|
||||
|
||||
deleteJobItemsCommand.GetParameter(0).Value = id;
|
||||
deleteJobItemsCommand.Transaction = transaction;
|
||||
deleteJobItemsCommand.ExecuteNonQuery();
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
if (transaction != null)
|
||||
{
|
||||
transaction.Rollback();
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.ErrorException("Failed to save record:", e);
|
||||
|
||||
if (transaction != null)
|
||||
{
|
||||
transaction.Rollback();
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (transaction != null)
|
||||
{
|
||||
transaction.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public QueryResult<SyncJob> GetJobs(SyncJobQuery query)
|
||||
{
|
||||
if (query == null)
|
||||
{
|
||||
throw new ArgumentNullException("query");
|
||||
}
|
||||
|
||||
CheckDisposed();
|
||||
|
||||
using (var connection = CreateConnection(true).Result)
|
||||
{
|
||||
using (var cmd = connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = BaseJobSelectText;
|
||||
|
||||
var whereClauses = new List<string>();
|
||||
|
||||
if (query.Statuses.Length > 0)
|
||||
{
|
||||
var statuses = string.Join(",", query.Statuses.Select(i => "'" + i.ToString() + "'").ToArray());
|
||||
|
||||
whereClauses.Add(string.Format("Status in ({0})", statuses));
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(query.TargetId))
|
||||
{
|
||||
whereClauses.Add("TargetId=@TargetId");
|
||||
cmd.Parameters.Add(cmd, "@TargetId", DbType.String).Value = query.TargetId;
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(query.ExcludeTargetIds))
|
||||
{
|
||||
var excludeIds = (query.ExcludeTargetIds ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (excludeIds.Length == 1)
|
||||
{
|
||||
whereClauses.Add("TargetId<>@ExcludeTargetId");
|
||||
cmd.Parameters.Add(cmd, "@ExcludeTargetId", DbType.String).Value = excludeIds[0];
|
||||
}
|
||||
else if (excludeIds.Length > 1)
|
||||
{
|
||||
whereClauses.Add("TargetId<>@ExcludeTargetId");
|
||||
cmd.Parameters.Add(cmd, "@ExcludeTargetId", DbType.String).Value = excludeIds[0];
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(query.UserId))
|
||||
{
|
||||
whereClauses.Add("UserId=@UserId");
|
||||
cmd.Parameters.Add(cmd, "@UserId", DbType.String).Value = query.UserId;
|
||||
}
|
||||
if (query.SyncNewContent.HasValue)
|
||||
{
|
||||
whereClauses.Add("SyncNewContent=@SyncNewContent");
|
||||
cmd.Parameters.Add(cmd, "@SyncNewContent", DbType.Boolean).Value = query.SyncNewContent.Value;
|
||||
}
|
||||
|
||||
cmd.CommandText += " mainTable";
|
||||
|
||||
var whereTextWithoutPaging = whereClauses.Count == 0 ?
|
||||
string.Empty :
|
||||
" where " + string.Join(" AND ", whereClauses.ToArray());
|
||||
|
||||
var startIndex = query.StartIndex ?? 0;
|
||||
if (startIndex > 0)
|
||||
{
|
||||
whereClauses.Add(string.Format("Id NOT IN (SELECT Id FROM SyncJobs ORDER BY (Select Max(DateLastModified) from SyncJobs where TargetId=mainTable.TargetId) DESC, DateLastModified DESC LIMIT {0})",
|
||||
startIndex.ToString(_usCulture)));
|
||||
}
|
||||
|
||||
if (whereClauses.Count > 0)
|
||||
{
|
||||
cmd.CommandText += " where " + string.Join(" AND ", whereClauses.ToArray());
|
||||
}
|
||||
|
||||
cmd.CommandText += " ORDER BY (Select Max(DateLastModified) from SyncJobs where TargetId=mainTable.TargetId) DESC, DateLastModified DESC";
|
||||
|
||||
if (query.Limit.HasValue)
|
||||
{
|
||||
cmd.CommandText += " LIMIT " + query.Limit.Value.ToString(_usCulture);
|
||||
}
|
||||
|
||||
cmd.CommandText += "; select count (Id) from SyncJobs" + whereTextWithoutPaging;
|
||||
|
||||
var list = new List<SyncJob>();
|
||||
var count = 0;
|
||||
|
||||
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess))
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
list.Add(GetJob(reader));
|
||||
}
|
||||
|
||||
if (reader.NextResult() && reader.Read())
|
||||
{
|
||||
count = reader.GetInt32(0);
|
||||
}
|
||||
}
|
||||
|
||||
return new QueryResult<SyncJob>()
|
||||
{
|
||||
Items = list.ToArray(),
|
||||
TotalRecordCount = count
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public SyncJobItem GetJobItem(string id)
|
||||
{
|
||||
if (string.IsNullOrEmpty(id))
|
||||
{
|
||||
throw new ArgumentNullException("id");
|
||||
}
|
||||
|
||||
CheckDisposed();
|
||||
|
||||
var guid = new Guid(id);
|
||||
|
||||
using (var connection = CreateConnection(true).Result)
|
||||
{
|
||||
using (var cmd = connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = BaseJobItemSelectText + " where Id=@Id";
|
||||
|
||||
cmd.Parameters.Add(cmd, "@Id", DbType.Guid).Value = guid;
|
||||
|
||||
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult | CommandBehavior.SingleRow))
|
||||
{
|
||||
if (reader.Read())
|
||||
{
|
||||
return GetJobItem(reader);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private QueryResult<T> GetJobItemReader<T>(SyncJobItemQuery query, string baseSelectText, Func<IDataReader, T> itemFactory)
|
||||
{
|
||||
if (query == null)
|
||||
{
|
||||
throw new ArgumentNullException("query");
|
||||
}
|
||||
|
||||
using (var connection = CreateConnection(true).Result)
|
||||
{
|
||||
using (var cmd = connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = baseSelectText;
|
||||
|
||||
var whereClauses = new List<string>();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(query.JobId))
|
||||
{
|
||||
whereClauses.Add("JobId=@JobId");
|
||||
cmd.Parameters.Add(cmd, "@JobId", DbType.String).Value = query.JobId;
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(query.ItemId))
|
||||
{
|
||||
whereClauses.Add("ItemId=@ItemId");
|
||||
cmd.Parameters.Add(cmd, "@ItemId", DbType.String).Value = query.ItemId;
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(query.TargetId))
|
||||
{
|
||||
whereClauses.Add("TargetId=@TargetId");
|
||||
cmd.Parameters.Add(cmd, "@TargetId", DbType.String).Value = query.TargetId;
|
||||
}
|
||||
|
||||
if (query.Statuses.Length > 0)
|
||||
{
|
||||
var statuses = string.Join(",", query.Statuses.Select(i => "'" + i.ToString() + "'").ToArray());
|
||||
|
||||
whereClauses.Add(string.Format("Status in ({0})", statuses));
|
||||
}
|
||||
|
||||
var whereTextWithoutPaging = whereClauses.Count == 0 ?
|
||||
string.Empty :
|
||||
" where " + string.Join(" AND ", whereClauses.ToArray());
|
||||
|
||||
var startIndex = query.StartIndex ?? 0;
|
||||
if (startIndex > 0)
|
||||
{
|
||||
whereClauses.Add(string.Format("Id NOT IN (SELECT Id FROM SyncJobItems ORDER BY JobItemIndex, DateCreated LIMIT {0})",
|
||||
startIndex.ToString(_usCulture)));
|
||||
}
|
||||
|
||||
if (whereClauses.Count > 0)
|
||||
{
|
||||
cmd.CommandText += " where " + string.Join(" AND ", whereClauses.ToArray());
|
||||
}
|
||||
|
||||
cmd.CommandText += " ORDER BY JobItemIndex, DateCreated";
|
||||
|
||||
if (query.Limit.HasValue)
|
||||
{
|
||||
cmd.CommandText += " LIMIT " + query.Limit.Value.ToString(_usCulture);
|
||||
}
|
||||
|
||||
cmd.CommandText += "; select count (Id) from SyncJobItems" + whereTextWithoutPaging;
|
||||
|
||||
var list = new List<T>();
|
||||
var count = 0;
|
||||
|
||||
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess))
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
list.Add(itemFactory(reader));
|
||||
}
|
||||
|
||||
if (reader.NextResult() && reader.Read())
|
||||
{
|
||||
count = reader.GetInt32(0);
|
||||
}
|
||||
}
|
||||
|
||||
return new QueryResult<T>()
|
||||
{
|
||||
Items = list.ToArray(),
|
||||
TotalRecordCount = count
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Dictionary<string, SyncedItemProgress> GetSyncedItemProgresses(SyncJobItemQuery query)
|
||||
{
|
||||
var result = new Dictionary<string, SyncedItemProgress>();
|
||||
|
||||
var now = DateTime.UtcNow;
|
||||
|
||||
using (var connection = CreateConnection(true).Result)
|
||||
{
|
||||
using (var cmd = connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "select ItemId,Status,Progress from SyncJobItems";
|
||||
|
||||
var whereClauses = new List<string>();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(query.TargetId))
|
||||
{
|
||||
whereClauses.Add("TargetId=@TargetId");
|
||||
cmd.Parameters.Add(cmd, "@TargetId", DbType.String).Value = query.TargetId;
|
||||
}
|
||||
|
||||
if (query.Statuses.Length > 0)
|
||||
{
|
||||
var statuses = string.Join(",", query.Statuses.Select(i => "'" + i.ToString() + "'").ToArray());
|
||||
|
||||
whereClauses.Add(string.Format("Status in ({0})", statuses));
|
||||
}
|
||||
|
||||
if (whereClauses.Count > 0)
|
||||
{
|
||||
cmd.CommandText += " where " + string.Join(" AND ", whereClauses.ToArray());
|
||||
}
|
||||
|
||||
cmd.CommandText += ";" + cmd.CommandText
|
||||
.Replace("select ItemId,Status,Progress from SyncJobItems", "select ItemIds,Status,Progress from SyncJobs")
|
||||
.Replace("'Synced'", "'Completed','CompletedWithError'");
|
||||
|
||||
//Logger.Debug(cmd.CommandText);
|
||||
|
||||
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess))
|
||||
{
|
||||
LogQueryTime("GetSyncedItemProgresses", cmd, now);
|
||||
|
||||
while (reader.Read())
|
||||
{
|
||||
AddStatusResult(reader, result, false);
|
||||
}
|
||||
|
||||
if (reader.NextResult())
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
AddStatusResult(reader, result, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private void LogQueryTime(string methodName, IDbCommand cmd, DateTime startDate)
|
||||
{
|
||||
var elapsed = (DateTime.UtcNow - startDate).TotalMilliseconds;
|
||||
|
||||
var slowThreshold = 1000;
|
||||
|
||||
#if DEBUG
|
||||
slowThreshold = 50;
|
||||
#endif
|
||||
|
||||
if (elapsed >= slowThreshold)
|
||||
{
|
||||
Logger.Debug("{2} query time (slow): {0}ms. Query: {1}",
|
||||
Convert.ToInt32(elapsed),
|
||||
cmd.CommandText,
|
||||
methodName);
|
||||
}
|
||||
else
|
||||
{
|
||||
//Logger.Debug("{2} query time: {0}ms. Query: {1}",
|
||||
// Convert.ToInt32(elapsed),
|
||||
// cmd.CommandText,
|
||||
// methodName);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddStatusResult(IDataReader reader, Dictionary<string, SyncedItemProgress> result, bool multipleIds)
|
||||
{
|
||||
if (reader.IsDBNull(0))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var itemIds = new List<string>();
|
||||
|
||||
var ids = reader.GetString(0);
|
||||
|
||||
if (multipleIds)
|
||||
{
|
||||
itemIds = ids.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
itemIds.Add(ids);
|
||||
}
|
||||
|
||||
if (!reader.IsDBNull(1))
|
||||
{
|
||||
SyncJobItemStatus status;
|
||||
var statusString = reader.GetString(1);
|
||||
if (string.Equals(statusString, "Completed", StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(statusString, "CompletedWithError", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
status = SyncJobItemStatus.Synced;
|
||||
}
|
||||
else
|
||||
{
|
||||
status = (SyncJobItemStatus)Enum.Parse(typeof(SyncJobItemStatus), statusString, true);
|
||||
}
|
||||
|
||||
if (status == SyncJobItemStatus.Synced)
|
||||
{
|
||||
foreach (var itemId in itemIds)
|
||||
{
|
||||
result[itemId] = new SyncedItemProgress
|
||||
{
|
||||
Status = SyncJobItemStatus.Synced
|
||||
};
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
double progress = reader.IsDBNull(2) ? 0.0 : reader.GetDouble(2);
|
||||
|
||||
foreach (var itemId in itemIds)
|
||||
{
|
||||
SyncedItemProgress currentStatus;
|
||||
if (!result.TryGetValue(itemId, out currentStatus) || (currentStatus.Status != SyncJobItemStatus.Synced && progress >= currentStatus.Progress))
|
||||
{
|
||||
result[itemId] = new SyncedItemProgress
|
||||
{
|
||||
Status = status,
|
||||
Progress = progress
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public QueryResult<SyncJobItem> GetJobItems(SyncJobItemQuery query)
|
||||
{
|
||||
return GetJobItemReader(query, BaseJobItemSelectText, GetJobItem);
|
||||
}
|
||||
|
||||
public Task Create(SyncJobItem jobItem)
|
||||
{
|
||||
return InsertOrUpdate(jobItem, true);
|
||||
}
|
||||
|
||||
public Task Update(SyncJobItem jobItem)
|
||||
{
|
||||
return InsertOrUpdate(jobItem, false);
|
||||
}
|
||||
|
||||
private async Task InsertOrUpdate(SyncJobItem jobItem, bool insert)
|
||||
{
|
||||
if (jobItem == null)
|
||||
{
|
||||
throw new ArgumentNullException("jobItem");
|
||||
}
|
||||
|
||||
CheckDisposed();
|
||||
|
||||
using (var connection = await CreateConnection().ConfigureAwait(false))
|
||||
{
|
||||
using (var cmd = connection.CreateCommand())
|
||||
{
|
||||
if (insert)
|
||||
{
|
||||
cmd.CommandText = "insert into SyncJobItems (Id, ItemId, ItemName, MediaSourceId, JobId, TemporaryPath, OutputPath, Status, TargetId, DateCreated, Progress, AdditionalFiles, MediaSource, IsMarkedForRemoval, JobItemIndex, ItemDateModifiedTicks) values (@Id, @ItemId, @ItemName, @MediaSourceId, @JobId, @TemporaryPath, @OutputPath, @Status, @TargetId, @DateCreated, @Progress, @AdditionalFiles, @MediaSource, @IsMarkedForRemoval, @JobItemIndex, @ItemDateModifiedTicks)";
|
||||
|
||||
cmd.Parameters.Add(cmd, "@Id");
|
||||
cmd.Parameters.Add(cmd, "@ItemId");
|
||||
cmd.Parameters.Add(cmd, "@ItemName");
|
||||
cmd.Parameters.Add(cmd, "@MediaSourceId");
|
||||
cmd.Parameters.Add(cmd, "@JobId");
|
||||
cmd.Parameters.Add(cmd, "@TemporaryPath");
|
||||
cmd.Parameters.Add(cmd, "@OutputPath");
|
||||
cmd.Parameters.Add(cmd, "@Status");
|
||||
cmd.Parameters.Add(cmd, "@TargetId");
|
||||
cmd.Parameters.Add(cmd, "@DateCreated");
|
||||
cmd.Parameters.Add(cmd, "@Progress");
|
||||
cmd.Parameters.Add(cmd, "@AdditionalFiles");
|
||||
cmd.Parameters.Add(cmd, "@MediaSource");
|
||||
cmd.Parameters.Add(cmd, "@IsMarkedForRemoval");
|
||||
cmd.Parameters.Add(cmd, "@JobItemIndex");
|
||||
cmd.Parameters.Add(cmd, "@ItemDateModifiedTicks");
|
||||
}
|
||||
else
|
||||
{
|
||||
// cmd
|
||||
cmd.CommandText = "update SyncJobItems set ItemId=@ItemId,ItemName=@ItemName,MediaSourceId=@MediaSourceId,JobId=@JobId,TemporaryPath=@TemporaryPath,OutputPath=@OutputPath,Status=@Status,TargetId=@TargetId,DateCreated=@DateCreated,Progress=@Progress,AdditionalFiles=@AdditionalFiles,MediaSource=@MediaSource,IsMarkedForRemoval=@IsMarkedForRemoval,JobItemIndex=@JobItemIndex,ItemDateModifiedTicks=@ItemDateModifiedTicks where Id=@Id";
|
||||
|
||||
cmd.Parameters.Add(cmd, "@Id");
|
||||
cmd.Parameters.Add(cmd, "@ItemId");
|
||||
cmd.Parameters.Add(cmd, "@ItemName");
|
||||
cmd.Parameters.Add(cmd, "@MediaSourceId");
|
||||
cmd.Parameters.Add(cmd, "@JobId");
|
||||
cmd.Parameters.Add(cmd, "@TemporaryPath");
|
||||
cmd.Parameters.Add(cmd, "@OutputPath");
|
||||
cmd.Parameters.Add(cmd, "@Status");
|
||||
cmd.Parameters.Add(cmd, "@TargetId");
|
||||
cmd.Parameters.Add(cmd, "@DateCreated");
|
||||
cmd.Parameters.Add(cmd, "@Progress");
|
||||
cmd.Parameters.Add(cmd, "@AdditionalFiles");
|
||||
cmd.Parameters.Add(cmd, "@MediaSource");
|
||||
cmd.Parameters.Add(cmd, "@IsMarkedForRemoval");
|
||||
cmd.Parameters.Add(cmd, "@JobItemIndex");
|
||||
cmd.Parameters.Add(cmd, "@ItemDateModifiedTicks");
|
||||
}
|
||||
|
||||
IDbTransaction transaction = null;
|
||||
|
||||
try
|
||||
{
|
||||
transaction = connection.BeginTransaction();
|
||||
|
||||
var index = 0;
|
||||
|
||||
cmd.GetParameter(index++).Value = new Guid(jobItem.Id);
|
||||
cmd.GetParameter(index++).Value = jobItem.ItemId;
|
||||
cmd.GetParameter(index++).Value = jobItem.ItemName;
|
||||
cmd.GetParameter(index++).Value = jobItem.MediaSourceId;
|
||||
cmd.GetParameter(index++).Value = jobItem.JobId;
|
||||
cmd.GetParameter(index++).Value = jobItem.TemporaryPath;
|
||||
cmd.GetParameter(index++).Value = jobItem.OutputPath;
|
||||
cmd.GetParameter(index++).Value = jobItem.Status.ToString();
|
||||
cmd.GetParameter(index++).Value = jobItem.TargetId;
|
||||
cmd.GetParameter(index++).Value = jobItem.DateCreated;
|
||||
cmd.GetParameter(index++).Value = jobItem.Progress;
|
||||
cmd.GetParameter(index++).Value = _json.SerializeToString(jobItem.AdditionalFiles);
|
||||
cmd.GetParameter(index++).Value = jobItem.MediaSource == null ? null : _json.SerializeToString(jobItem.MediaSource);
|
||||
cmd.GetParameter(index++).Value = jobItem.IsMarkedForRemoval;
|
||||
cmd.GetParameter(index++).Value = jobItem.JobItemIndex;
|
||||
cmd.GetParameter(index++).Value = jobItem.ItemDateModifiedTicks;
|
||||
|
||||
cmd.Transaction = transaction;
|
||||
|
||||
cmd.ExecuteNonQuery();
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
if (transaction != null)
|
||||
{
|
||||
transaction.Rollback();
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.ErrorException("Failed to save record:", e);
|
||||
|
||||
if (transaction != null)
|
||||
{
|
||||
transaction.Rollback();
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (transaction != null)
|
||||
{
|
||||
transaction.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private SyncJobItem GetJobItem(IDataReader reader)
|
||||
{
|
||||
var info = new SyncJobItem
|
||||
{
|
||||
Id = reader.GetGuid(0).ToString("N"),
|
||||
ItemId = reader.GetString(1)
|
||||
};
|
||||
|
||||
if (!reader.IsDBNull(2))
|
||||
{
|
||||
info.ItemName = reader.GetString(2);
|
||||
}
|
||||
|
||||
if (!reader.IsDBNull(3))
|
||||
{
|
||||
info.MediaSourceId = reader.GetString(3);
|
||||
}
|
||||
|
||||
info.JobId = reader.GetString(4);
|
||||
|
||||
if (!reader.IsDBNull(5))
|
||||
{
|
||||
info.TemporaryPath = reader.GetString(5);
|
||||
}
|
||||
if (!reader.IsDBNull(6))
|
||||
{
|
||||
info.OutputPath = reader.GetString(6);
|
||||
}
|
||||
|
||||
if (!reader.IsDBNull(7))
|
||||
{
|
||||
info.Status = (SyncJobItemStatus)Enum.Parse(typeof(SyncJobItemStatus), reader.GetString(7), true);
|
||||
}
|
||||
|
||||
info.TargetId = reader.GetString(8);
|
||||
|
||||
info.DateCreated = reader.GetDateTime(9).ToUniversalTime();
|
||||
|
||||
if (!reader.IsDBNull(10))
|
||||
{
|
||||
info.Progress = reader.GetDouble(10);
|
||||
}
|
||||
|
||||
if (!reader.IsDBNull(11))
|
||||
{
|
||||
var json = reader.GetString(11);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(json))
|
||||
{
|
||||
info.AdditionalFiles = _json.DeserializeFromString<List<ItemFileInfo>>(json);
|
||||
}
|
||||
}
|
||||
|
||||
if (!reader.IsDBNull(12))
|
||||
{
|
||||
var json = reader.GetString(12);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(json))
|
||||
{
|
||||
info.MediaSource = _json.DeserializeFromString<MediaSourceInfo>(json);
|
||||
}
|
||||
}
|
||||
|
||||
info.IsMarkedForRemoval = reader.GetBoolean(13);
|
||||
info.JobItemIndex = reader.GetInt32(14);
|
||||
|
||||
if (!reader.IsDBNull(15))
|
||||
{
|
||||
info.ItemDateModifiedTicks = reader.GetInt64(15);
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
}
|
||||
}
|
@ -51,7 +51,7 @@ namespace Emby.Server.Implementations.Activity
|
||||
throw new ArgumentNullException("entry");
|
||||
}
|
||||
|
||||
lock (WriteLock)
|
||||
using (WriteLock.Write())
|
||||
{
|
||||
using (var connection = CreateConnection())
|
||||
{
|
||||
@ -76,7 +76,7 @@ namespace Emby.Server.Implementations.Activity
|
||||
|
||||
public QueryResult<ActivityLogEntry> GetActivityLogEntries(DateTime? minDate, int? startIndex, int? limit)
|
||||
{
|
||||
lock (WriteLock)
|
||||
using (WriteLock.Read())
|
||||
{
|
||||
using (var connection = CreateConnection(true))
|
||||
{
|
||||
@ -87,7 +87,7 @@ namespace Emby.Server.Implementations.Activity
|
||||
|
||||
if (minDate.HasValue)
|
||||
{
|
||||
whereClauses.Add("DateCreated>=@DateCreated");
|
||||
whereClauses.Add("DateCreated>=?");
|
||||
paramList.Add(minDate.Value.ToDateTimeParamValue());
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
using MediaBrowser.Controller;
|
||||
using System;
|
||||
|
||||
namespace Emby.Server.Core.Browser
|
||||
namespace Emby.Server.Implementations.Browser
|
||||
{
|
||||
/// <summary>
|
||||
/// Class BrowserLauncher
|
||||
@ -65,10 +65,8 @@ namespace Emby.Server.Core.Browser
|
||||
{
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch (Exception)
|
||||
{
|
||||
Console.WriteLine("Error launching url: " + url);
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
@ -4,13 +4,15 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using SQLitePCL.pretty;
|
||||
using System.Linq;
|
||||
using SQLitePCL;
|
||||
|
||||
namespace Emby.Server.Implementations.Data
|
||||
{
|
||||
public abstract class BaseSqliteRepository : IDisposable
|
||||
{
|
||||
protected string DbFilePath { get; set; }
|
||||
protected SemaphoreSlim WriteLock = new SemaphoreSlim(1, 1);
|
||||
protected ReaderWriterLockSlim WriteLock = new ReaderWriterLockSlim(LockRecursionPolicy.NoRecursion);
|
||||
protected ILogger Logger { get; private set; }
|
||||
|
||||
protected BaseSqliteRepository(ILogger logger)
|
||||
@ -23,12 +25,20 @@ namespace Emby.Server.Implementations.Data
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
protected virtual SQLiteDatabaseConnection CreateConnection(bool isReadOnly = false)
|
||||
static BaseSqliteRepository()
|
||||
{
|
||||
SQLite3.EnableSharedCache = false;
|
||||
|
||||
int rc = raw.sqlite3_config(raw.SQLITE_CONFIG_MEMSTATUS, 0);
|
||||
//CheckOk(rc);
|
||||
}
|
||||
|
||||
protected virtual SQLiteDatabaseConnection CreateConnection(bool isReadOnly = false)
|
||||
{
|
||||
ConnectionFlags connectionFlags;
|
||||
|
||||
//isReadOnly = false;
|
||||
|
||||
if (isReadOnly)
|
||||
{
|
||||
connectionFlags = ConnectionFlags.ReadOnly;
|
||||
@ -54,25 +64,67 @@ namespace Emby.Server.Implementations.Data
|
||||
|
||||
var db = SQLite3.Open(DbFilePath, connectionFlags, null);
|
||||
|
||||
var queries = new[]
|
||||
var queries = new List<string>
|
||||
{
|
||||
"pragma default_temp_store = memory",
|
||||
"PRAGMA page_size=4096",
|
||||
"PRAGMA journal_mode=WAL",
|
||||
"PRAGMA temp_store=memory",
|
||||
"PRAGMA synchronous=Normal",
|
||||
//"PRAGMA cache size=-10000"
|
||||
};
|
||||
};
|
||||
|
||||
var cacheSize = CacheSize;
|
||||
if (cacheSize.HasValue)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
if (EnableExclusiveMode)
|
||||
{
|
||||
queries.Add("PRAGMA locking_mode=EXCLUSIVE");
|
||||
}
|
||||
|
||||
//foreach (var query in queries)
|
||||
//{
|
||||
// db.Execute(query);
|
||||
//}
|
||||
|
||||
db.ExecuteAll(string.Join(";", queries));
|
||||
|
||||
db.ExecuteAll(string.Join(";", queries.ToArray()));
|
||||
|
||||
return db;
|
||||
}
|
||||
|
||||
protected virtual int? CacheSize
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual bool EnableExclusiveMode
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
internal static void CheckOk(int rc)
|
||||
{
|
||||
string msg = "";
|
||||
|
||||
if (raw.SQLITE_OK != rc)
|
||||
{
|
||||
throw CreateException((ErrorCode)rc, msg);
|
||||
}
|
||||
}
|
||||
|
||||
internal static Exception CreateException(ErrorCode rc, string msg)
|
||||
{
|
||||
var exp = new Exception(msg);
|
||||
|
||||
return exp;
|
||||
}
|
||||
|
||||
private bool _disposed;
|
||||
protected void CheckDisposed()
|
||||
{
|
||||
@ -103,9 +155,10 @@ namespace Emby.Server.Implementations.Data
|
||||
{
|
||||
lock (_disposeLock)
|
||||
{
|
||||
WriteLock.Wait();
|
||||
|
||||
CloseConnection();
|
||||
using (WriteLock.Write())
|
||||
{
|
||||
CloseConnection();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -120,21 +173,30 @@ namespace Emby.Server.Implementations.Data
|
||||
|
||||
}
|
||||
|
||||
protected void AddColumn(IDatabaseConnection connection, string table, string columnName, string type)
|
||||
protected List<string> GetColumnNames(IDatabaseConnection connection, string table)
|
||||
{
|
||||
var list = new List<string>();
|
||||
|
||||
foreach (var row in connection.Query("PRAGMA table_info(" + table + ")"))
|
||||
{
|
||||
if (row[1].SQLiteType != SQLiteType.Null)
|
||||
{
|
||||
var name = row[1].ToString();
|
||||
|
||||
if (string.Equals(name, columnName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return;
|
||||
}
|
||||
list.Add(name);
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
protected void AddColumn(IDatabaseConnection connection, string table, string columnName, string type, List<string> existingColumnNames)
|
||||
{
|
||||
if (existingColumnNames.Contains(columnName, StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
connection.ExecuteAll(string.Join(";", new string[]
|
||||
{
|
||||
"alter table " + table,
|
||||
@ -142,4 +204,51 @@ namespace Emby.Server.Implementations.Data
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
public static class ReaderWriterLockSlimExtensions
|
||||
{
|
||||
private sealed class ReadLockToken : IDisposable
|
||||
{
|
||||
private ReaderWriterLockSlim _sync;
|
||||
public ReadLockToken(ReaderWriterLockSlim sync)
|
||||
{
|
||||
_sync = sync;
|
||||
sync.EnterReadLock();
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
if (_sync != null)
|
||||
{
|
||||
_sync.ExitReadLock();
|
||||
_sync = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
private sealed class WriteLockToken : IDisposable
|
||||
{
|
||||
private ReaderWriterLockSlim _sync;
|
||||
public WriteLockToken(ReaderWriterLockSlim sync)
|
||||
{
|
||||
_sync = sync;
|
||||
sync.EnterWriteLock();
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
if (_sync != null)
|
||||
{
|
||||
_sync.ExitWriteLock();
|
||||
_sync = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static IDisposable Read(this ReaderWriterLockSlim obj)
|
||||
{
|
||||
return new ReadLockToken(obj);
|
||||
}
|
||||
public static IDisposable Write(this ReaderWriterLockSlim obj)
|
||||
{
|
||||
return new WriteLockToken(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
using MediaBrowser.Common.Progress;
|
||||
using MediaBrowser.Controller.Configuration;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.Persistence;
|
||||
@ -7,20 +6,13 @@ using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Common.IO;
|
||||
using MediaBrowser.Model.IO;
|
||||
using MediaBrowser.Controller.Channels;
|
||||
using MediaBrowser.Controller.Entities.Audio;
|
||||
using MediaBrowser.Controller.IO;
|
||||
using MediaBrowser.Controller.LiveTv;
|
||||
using MediaBrowser.Controller.Net;
|
||||
using MediaBrowser.Model.Globalization;
|
||||
using MediaBrowser.Model.Tasks;
|
||||
using Emby.Server.Implementations.ScheduledTasks;
|
||||
|
||||
namespace Emby.Server.Implementations.Data
|
||||
{
|
||||
@ -29,26 +21,14 @@ namespace Emby.Server.Implementations.Data
|
||||
private readonly ILibraryManager _libraryManager;
|
||||
private readonly IItemRepository _itemRepo;
|
||||
private readonly ILogger _logger;
|
||||
private readonly IServerConfigurationManager _config;
|
||||
private readonly IFileSystem _fileSystem;
|
||||
private readonly IHttpServer _httpServer;
|
||||
private readonly ILocalizationManager _localization;
|
||||
private readonly ITaskManager _taskManager;
|
||||
|
||||
public const int MigrationVersion = 23;
|
||||
public static bool EnableUnavailableMessage = false;
|
||||
const int LatestSchemaVersion = 109;
|
||||
|
||||
public CleanDatabaseScheduledTask(ILibraryManager libraryManager, IItemRepository itemRepo, ILogger logger, IServerConfigurationManager config, IFileSystem fileSystem, IHttpServer httpServer, ILocalizationManager localization, ITaskManager taskManager)
|
||||
public CleanDatabaseScheduledTask(ILibraryManager libraryManager, IItemRepository itemRepo, ILogger logger, IFileSystem fileSystem)
|
||||
{
|
||||
_libraryManager = libraryManager;
|
||||
_itemRepo = itemRepo;
|
||||
_logger = logger;
|
||||
_config = config;
|
||||
_fileSystem = fileSystem;
|
||||
_httpServer = httpServer;
|
||||
_localization = localization;
|
||||
_taskManager = taskManager;
|
||||
}
|
||||
|
||||
public string Name
|
||||
@ -68,8 +48,6 @@ namespace Emby.Server.Implementations.Data
|
||||
|
||||
public async Task Execute(CancellationToken cancellationToken, IProgress<double> progress)
|
||||
{
|
||||
OnProgress(0);
|
||||
|
||||
// Ensure these objects are lazy loaded.
|
||||
// Without this there is a deadlock that will need to be investigated
|
||||
var rootChildren = _libraryManager.RootFolder.Children.ToList();
|
||||
@ -78,19 +56,7 @@ namespace Emby.Server.Implementations.Data
|
||||
var innerProgress = new ActionableProgress<double>();
|
||||
innerProgress.RegisterAction(p =>
|
||||
{
|
||||
double newPercentCommplete = .4 * p;
|
||||
OnProgress(newPercentCommplete);
|
||||
|
||||
progress.Report(newPercentCommplete);
|
||||
});
|
||||
|
||||
await UpdateToLatestSchema(cancellationToken, innerProgress).ConfigureAwait(false);
|
||||
|
||||
innerProgress = new ActionableProgress<double>();
|
||||
innerProgress.RegisterAction(p =>
|
||||
{
|
||||
double newPercentCommplete = 40 + .05 * p;
|
||||
OnProgress(newPercentCommplete);
|
||||
double newPercentCommplete = .45 * p;
|
||||
progress.Report(newPercentCommplete);
|
||||
});
|
||||
await CleanDeadItems(cancellationToken, innerProgress).ConfigureAwait(false);
|
||||
@ -100,122 +66,12 @@ namespace Emby.Server.Implementations.Data
|
||||
innerProgress.RegisterAction(p =>
|
||||
{
|
||||
double newPercentCommplete = 45 + .55 * p;
|
||||
OnProgress(newPercentCommplete);
|
||||
progress.Report(newPercentCommplete);
|
||||
});
|
||||
await CleanDeletedItems(cancellationToken, innerProgress).ConfigureAwait(false);
|
||||
progress.Report(100);
|
||||
|
||||
await _itemRepo.UpdateInheritedValues(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (_config.Configuration.MigrationVersion < MigrationVersion)
|
||||
{
|
||||
_config.Configuration.MigrationVersion = MigrationVersion;
|
||||
_config.SaveConfiguration();
|
||||
}
|
||||
|
||||
if (_config.Configuration.SchemaVersion < LatestSchemaVersion)
|
||||
{
|
||||
_config.Configuration.SchemaVersion = LatestSchemaVersion;
|
||||
_config.SaveConfiguration();
|
||||
}
|
||||
|
||||
if (EnableUnavailableMessage)
|
||||
{
|
||||
EnableUnavailableMessage = false;
|
||||
_httpServer.GlobalResponse = null;
|
||||
_taskManager.QueueScheduledTask<RefreshMediaLibraryTask>();
|
||||
}
|
||||
|
||||
_taskManager.SuspendTriggers = false;
|
||||
}
|
||||
|
||||
private void OnProgress(double newPercentCommplete)
|
||||
{
|
||||
if (EnableUnavailableMessage)
|
||||
{
|
||||
var html = "<!doctype html><html><head><title>Emby</title></head><body>";
|
||||
var text = _localization.GetLocalizedString("DbUpgradeMessage");
|
||||
html += string.Format(text, newPercentCommplete.ToString("N2", CultureInfo.InvariantCulture));
|
||||
|
||||
html += "<script>setTimeout(function(){window.location.reload(true);}, 5000);</script>";
|
||||
html += "</body></html>";
|
||||
|
||||
_httpServer.GlobalResponse = html;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task UpdateToLatestSchema(CancellationToken cancellationToken, IProgress<double> progress)
|
||||
{
|
||||
var itemIds = _libraryManager.GetItemIds(new InternalItemsQuery
|
||||
{
|
||||
IsCurrentSchema = false,
|
||||
ExcludeItemTypes = new[] { typeof(LiveTvProgram).Name }
|
||||
});
|
||||
|
||||
var numComplete = 0;
|
||||
var numItems = itemIds.Count;
|
||||
|
||||
_logger.Debug("Upgrading schema for {0} items", numItems);
|
||||
|
||||
var list = new List<BaseItem>();
|
||||
|
||||
foreach (var itemId in itemIds)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
if (itemId != Guid.Empty)
|
||||
{
|
||||
// Somehow some invalid data got into the db. It probably predates the boundary checking
|
||||
var item = _libraryManager.GetItemById(itemId);
|
||||
|
||||
if (item != null)
|
||||
{
|
||||
list.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
if (list.Count >= 1000)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _itemRepo.SaveItems(list, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.ErrorException("Error saving item", ex);
|
||||
}
|
||||
|
||||
list.Clear();
|
||||
}
|
||||
|
||||
numComplete++;
|
||||
double percent = numComplete;
|
||||
percent /= numItems;
|
||||
progress.Report(percent * 100);
|
||||
}
|
||||
|
||||
if (list.Count > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _itemRepo.SaveItems(list, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.ErrorException("Error saving item", ex);
|
||||
}
|
||||
}
|
||||
|
||||
progress.Report(100);
|
||||
}
|
||||
|
||||
private async Task CleanDeadItems(CancellationToken cancellationToken, IProgress<double> progress)
|
||||
|
@ -86,7 +86,7 @@ namespace Emby.Server.Implementations.Data
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
lock (WriteLock)
|
||||
using (WriteLock.Write())
|
||||
{
|
||||
using (var connection = CreateConnection())
|
||||
{
|
||||
@ -127,7 +127,7 @@ namespace Emby.Server.Implementations.Data
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
lock (WriteLock)
|
||||
using (WriteLock.Write())
|
||||
{
|
||||
using (var connection = CreateConnection())
|
||||
{
|
||||
@ -159,24 +159,27 @@ namespace Emby.Server.Implementations.Data
|
||||
|
||||
var guidId = displayPreferencesId.GetMD5();
|
||||
|
||||
using (var connection = CreateConnection(true))
|
||||
using (WriteLock.Read())
|
||||
{
|
||||
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 connection = CreateConnection(true))
|
||||
{
|
||||
return Get(row);
|
||||
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()))
|
||||
{
|
||||
return Get(row);
|
||||
}
|
||||
|
||||
return new DisplayPreferences
|
||||
{
|
||||
Id = guidId.ToString("N")
|
||||
};
|
||||
}
|
||||
|
||||
return new DisplayPreferences
|
||||
{
|
||||
Id = guidId.ToString("N")
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -190,16 +193,19 @@ namespace Emby.Server.Implementations.Data
|
||||
{
|
||||
var list = new List<DisplayPreferences>();
|
||||
|
||||
using (var connection = CreateConnection(true))
|
||||
using (WriteLock.Read())
|
||||
{
|
||||
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 connection = CreateConnection(true))
|
||||
{
|
||||
list.Add(Get(row));
|
||||
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()))
|
||||
{
|
||||
list.Add(Get(row));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,256 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Controller;
|
||||
using MediaBrowser.Controller.Persistence;
|
||||
using MediaBrowser.Model.FileOrganization;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.Model.Querying;
|
||||
using SQLitePCL.pretty;
|
||||
|
||||
namespace Emby.Server.Implementations.Data
|
||||
{
|
||||
public class SqliteFileOrganizationRepository : BaseSqliteRepository, IFileOrganizationRepository, IDisposable
|
||||
{
|
||||
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
|
||||
|
||||
public SqliteFileOrganizationRepository(ILogger logger, IServerApplicationPaths appPaths) : base(logger)
|
||||
{
|
||||
DbFilePath = Path.Combine(appPaths.DataPath, "fileorganization.db");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens the connection to the database
|
||||
/// </summary>
|
||||
/// <returns>Task.</returns>
|
||||
public void Initialize()
|
||||
{
|
||||
using (var connection = CreateConnection())
|
||||
{
|
||||
string[] queries = {
|
||||
|
||||
"create table if not exists FileOrganizerResults (ResultId GUID PRIMARY KEY, OriginalPath TEXT, TargetPath TEXT, FileLength INT, OrganizationDate datetime, Status TEXT, OrganizationType TEXT, StatusMessage TEXT, ExtractedName TEXT, ExtractedYear int null, ExtractedSeasonNumber int null, ExtractedEpisodeNumber int null, ExtractedEndingEpisodeNumber, DuplicatePaths TEXT int null)",
|
||||
"create index if not exists idx_FileOrganizerResults on FileOrganizerResults(ResultId)"
|
||||
};
|
||||
|
||||
connection.RunQueries(queries);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task SaveResult(FileOrganizationResult result, CancellationToken cancellationToken)
|
||||
{
|
||||
if (result == null)
|
||||
{
|
||||
throw new ArgumentNullException("result");
|
||||
}
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
using (var connection = CreateConnection())
|
||||
{
|
||||
connection.RunInTransaction(db =>
|
||||
{
|
||||
var paramList = new List<object>();
|
||||
var commandText = "replace into FileOrganizerResults (ResultId, OriginalPath, TargetPath, FileLength, OrganizationDate, Status, OrganizationType, StatusMessage, ExtractedName, ExtractedYear, ExtractedSeasonNumber, ExtractedEpisodeNumber, ExtractedEndingEpisodeNumber, DuplicatePaths) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
|
||||
paramList.Add(result.Id.ToGuidParamValue());
|
||||
paramList.Add(result.OriginalPath);
|
||||
paramList.Add(result.TargetPath);
|
||||
paramList.Add(result.FileSize);
|
||||
paramList.Add(result.Date.ToDateTimeParamValue());
|
||||
paramList.Add(result.Status.ToString());
|
||||
paramList.Add(result.Type.ToString());
|
||||
paramList.Add(result.StatusMessage);
|
||||
paramList.Add(result.ExtractedName);
|
||||
paramList.Add(result.ExtractedSeasonNumber);
|
||||
paramList.Add(result.ExtractedEpisodeNumber);
|
||||
paramList.Add(result.ExtractedEndingEpisodeNumber);
|
||||
paramList.Add(string.Join("|", result.DuplicatePaths.ToArray()));
|
||||
|
||||
|
||||
db.Execute(commandText, paramList.ToArray());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public async Task Delete(string id)
|
||||
{
|
||||
if (string.IsNullOrEmpty(id))
|
||||
{
|
||||
throw new ArgumentNullException("id");
|
||||
}
|
||||
|
||||
using (var connection = CreateConnection())
|
||||
{
|
||||
connection.RunInTransaction(db =>
|
||||
{
|
||||
var paramList = new List<object>();
|
||||
var commandText = "delete from FileOrganizerResults where ResultId = ?";
|
||||
|
||||
paramList.Add(id.ToGuidParamValue());
|
||||
|
||||
db.Execute(commandText, paramList.ToArray());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DeleteAll()
|
||||
{
|
||||
using (var connection = CreateConnection())
|
||||
{
|
||||
connection.RunInTransaction(db =>
|
||||
{
|
||||
var commandText = "delete from FileOrganizerResults";
|
||||
|
||||
db.Execute(commandText);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public QueryResult<FileOrganizationResult> GetResults(FileOrganizationResultQuery query)
|
||||
{
|
||||
if (query == null)
|
||||
{
|
||||
throw new ArgumentNullException("query");
|
||||
}
|
||||
|
||||
using (var connection = CreateConnection(true))
|
||||
{
|
||||
var commandText = "SELECT ResultId, OriginalPath, TargetPath, FileLength, OrganizationDate, Status, OrganizationType, StatusMessage, ExtractedName, ExtractedYear, ExtractedSeasonNumber, ExtractedEpisodeNumber, ExtractedEndingEpisodeNumber, DuplicatePaths from FileOrganizerResults";
|
||||
|
||||
if (query.StartIndex.HasValue && query.StartIndex.Value > 0)
|
||||
{
|
||||
commandText += string.Format(" WHERE ResultId NOT IN (SELECT ResultId FROM FileOrganizerResults ORDER BY OrganizationDate desc LIMIT {0})",
|
||||
query.StartIndex.Value.ToString(_usCulture));
|
||||
}
|
||||
|
||||
commandText += " ORDER BY OrganizationDate desc";
|
||||
|
||||
if (query.Limit.HasValue)
|
||||
{
|
||||
commandText += " LIMIT " + query.Limit.Value.ToString(_usCulture);
|
||||
}
|
||||
|
||||
var list = new List<FileOrganizationResult>();
|
||||
var count = connection.Query("select count (ResultId) from FileOrganizerResults").SelectScalarInt().First();
|
||||
|
||||
foreach (var row in connection.Query(commandText))
|
||||
{
|
||||
list.Add(GetResult(row));
|
||||
}
|
||||
|
||||
return new QueryResult<FileOrganizationResult>()
|
||||
{
|
||||
Items = list.ToArray(),
|
||||
TotalRecordCount = count
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public FileOrganizationResult GetResult(string id)
|
||||
{
|
||||
if (string.IsNullOrEmpty(id))
|
||||
{
|
||||
throw new ArgumentNullException("id");
|
||||
}
|
||||
|
||||
using (var connection = CreateConnection(true))
|
||||
{
|
||||
var paramList = new List<object>();
|
||||
|
||||
paramList.Add(id.ToGuidParamValue());
|
||||
|
||||
foreach (var row in connection.Query("select ResultId, OriginalPath, TargetPath, FileLength, OrganizationDate, Status, OrganizationType, StatusMessage, ExtractedName, ExtractedYear, ExtractedSeasonNumber, ExtractedEpisodeNumber, ExtractedEndingEpisodeNumber, DuplicatePaths from FileOrganizerResults where ResultId=?", paramList.ToArray()))
|
||||
{
|
||||
return GetResult(row);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public FileOrganizationResult GetResult(IReadOnlyList<IResultSetValue> reader)
|
||||
{
|
||||
var index = 0;
|
||||
|
||||
var result = new FileOrganizationResult
|
||||
{
|
||||
Id = reader[0].ReadGuid().ToString("N")
|
||||
};
|
||||
|
||||
index++;
|
||||
if (reader[index].SQLiteType != SQLiteType.Null)
|
||||
{
|
||||
result.OriginalPath = reader[index].ToString();
|
||||
}
|
||||
|
||||
index++;
|
||||
if (reader[index].SQLiteType != SQLiteType.Null)
|
||||
{
|
||||
result.TargetPath = reader[index].ToString();
|
||||
}
|
||||
|
||||
index++;
|
||||
result.FileSize = reader[index].ToInt64();
|
||||
|
||||
index++;
|
||||
result.Date = reader[index].ReadDateTime();
|
||||
|
||||
index++;
|
||||
result.Status = (FileSortingStatus)Enum.Parse(typeof(FileSortingStatus), reader[index].ToString(), true);
|
||||
|
||||
index++;
|
||||
result.Type = (FileOrganizerType)Enum.Parse(typeof(FileOrganizerType), reader[index].ToString(), true);
|
||||
|
||||
index++;
|
||||
if (reader[index].SQLiteType != SQLiteType.Null)
|
||||
{
|
||||
result.StatusMessage = reader[index].ToString();
|
||||
}
|
||||
|
||||
result.OriginalFileName = Path.GetFileName(result.OriginalPath);
|
||||
|
||||
index++;
|
||||
if (reader[index].SQLiteType != SQLiteType.Null)
|
||||
{
|
||||
result.ExtractedName = reader[index].ToString();
|
||||
}
|
||||
|
||||
index++;
|
||||
if (reader[index].SQLiteType != SQLiteType.Null)
|
||||
{
|
||||
result.ExtractedYear = reader[index].ToInt();
|
||||
}
|
||||
|
||||
index++;
|
||||
if (reader[index].SQLiteType != SQLiteType.Null)
|
||||
{
|
||||
result.ExtractedSeasonNumber = reader[index].ToInt();
|
||||
}
|
||||
|
||||
index++;
|
||||
if (reader[index].SQLiteType != SQLiteType.Null)
|
||||
{
|
||||
result.ExtractedEpisodeNumber = reader[index].ToInt();
|
||||
}
|
||||
|
||||
index++;
|
||||
if (reader[index].SQLiteType != SQLiteType.Null)
|
||||
{
|
||||
result.ExtractedEndingEpisodeNumber = reader[index].ToInt();
|
||||
}
|
||||
|
||||
index++;
|
||||
if (reader[index].SQLiteType != SQLiteType.Null)
|
||||
{
|
||||
result.DuplicatePaths = reader[index].ToString().Split('|').Where(i => !string.IsNullOrEmpty(i)).ToList();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
5279
Emby.Server.Implementations/Data/SqliteItemRepository.cs
Normal file
5279
Emby.Server.Implementations/Data/SqliteItemRepository.cs
Normal file
File diff suppressed because it is too large
Load Diff
446
Emby.Server.Implementations/Data/SqliteUserDataRepository.cs
Normal file
446
Emby.Server.Implementations/Data/SqliteUserDataRepository.cs
Normal file
@ -0,0 +1,446 @@
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//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;
|
||||
//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; }
|
||||
// }
|
||||
|
||||
// /// <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;
|
||||
|
||||
// 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);
|
||||
// });
|
||||
// }
|
||||
|
||||
// /// <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
|
||||
// }
|
||||
// }
|
||||
//}
|
163
Emby.Server.Implementations/Data/SqliteUserRepository.cs
Normal file
163
Emby.Server.Implementations/Data/SqliteUserRepository.cs
Normal file
@ -0,0 +1,163 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Controller;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Persistence;
|
||||
using MediaBrowser.Model.IO;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.Model.Serialization;
|
||||
using SQLitePCL.pretty;
|
||||
|
||||
namespace Emby.Server.Implementations.Data
|
||||
{
|
||||
/// <summary>
|
||||
/// Class SQLiteUserRepository
|
||||
/// </summary>
|
||||
public class SqliteUserRepository : BaseSqliteRepository, IUserRepository
|
||||
{
|
||||
private readonly IJsonSerializer _jsonSerializer;
|
||||
private readonly IMemoryStreamFactory _memoryStreamProvider;
|
||||
|
||||
public SqliteUserRepository(ILogger logger, IServerApplicationPaths appPaths, IJsonSerializer jsonSerializer, IMemoryStreamFactory memoryStreamProvider)
|
||||
: base(logger)
|
||||
{
|
||||
_jsonSerializer = jsonSerializer;
|
||||
_memoryStreamProvider = memoryStreamProvider;
|
||||
|
||||
DbFilePath = Path.Combine(appPaths.DataPath, "users.db");
|
||||
}
|
||||
|
||||
/// <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()
|
||||
{
|
||||
using (var connection = CreateConnection())
|
||||
{
|
||||
string[] queries = {
|
||||
|
||||
"create table if not exists users (guid GUID primary key, data BLOB)",
|
||||
"create index if not exists idx_users on users(guid)",
|
||||
"create table if not exists schema_version (table_name primary key, version)",
|
||||
|
||||
"pragma shrink_memory"
|
||||
};
|
||||
|
||||
connection.RunQueries(queries);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Save a user in the repo
|
||||
/// </summary>
|
||||
/// <param name="user">The user.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task.</returns>
|
||||
/// <exception cref="System.ArgumentNullException">user</exception>
|
||||
public async Task SaveUser(User user, CancellationToken cancellationToken)
|
||||
{
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException("user");
|
||||
}
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var serialized = _jsonSerializer.SerializeToBytes(user, _memoryStreamProvider);
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
using (WriteLock.Write())
|
||||
{
|
||||
using (var connection = CreateConnection())
|
||||
{
|
||||
connection.RunInTransaction(db =>
|
||||
{
|
||||
var commandText = "replace into users (guid, data) values (?, ?)";
|
||||
|
||||
db.Execute(commandText,
|
||||
user.Id.ToGuidParamValue(),
|
||||
serialized);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve all users from the database
|
||||
/// </summary>
|
||||
/// <returns>IEnumerable{User}.</returns>
|
||||
public IEnumerable<User> RetrieveAllUsers()
|
||||
{
|
||||
var list = new List<User>();
|
||||
|
||||
using (WriteLock.Read())
|
||||
{
|
||||
using (var connection = CreateConnection(true))
|
||||
{
|
||||
foreach (var row in connection.Query("select guid,data from users"))
|
||||
{
|
||||
var id = row[0].ReadGuid();
|
||||
|
||||
using (var stream = _memoryStreamProvider.CreateNew(row[1].ToBlob()))
|
||||
{
|
||||
stream.Position = 0;
|
||||
var user = _jsonSerializer.DeserializeFromStream<User>(stream);
|
||||
user.Id = id;
|
||||
list.Add(user);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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>
|
||||
public async Task DeleteUser(User user, CancellationToken cancellationToken)
|
||||
{
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException("user");
|
||||
}
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
using (WriteLock.Write())
|
||||
{
|
||||
using (var connection = CreateConnection())
|
||||
{
|
||||
connection.RunInTransaction(db =>
|
||||
{
|
||||
var commandText = "delete from users where guid=?";
|
||||
|
||||
db.Execute(commandText,
|
||||
user.Id.ToGuidParamValue());
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,19 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using MediaBrowser.Model.Reflection;
|
||||
using System.Linq;
|
||||
|
||||
namespace Emby.Server.Core.Data
|
||||
namespace Emby.Server.Implementations.Data
|
||||
{
|
||||
/// <summary>
|
||||
/// Class TypeMapper
|
||||
/// </summary>
|
||||
public class TypeMapper
|
||||
{
|
||||
private readonly IAssemblyInfo _assemblyInfo;
|
||||
|
||||
/// <summary>
|
||||
/// This holds all the types in the running assemblies so that we can de-serialize properly when we don't have strong types
|
||||
/// </summary>
|
||||
private readonly ConcurrentDictionary<string, Type> _typeMap = new ConcurrentDictionary<string, Type>();
|
||||
|
||||
public TypeMapper(IAssemblyInfo assemblyInfo)
|
||||
{
|
||||
_assemblyInfo = assemblyInfo;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type.
|
||||
/// </summary>
|
||||
@ -24,7 +32,7 @@ namespace Emby.Server.Core.Data
|
||||
{
|
||||
if (string.IsNullOrEmpty(typeName))
|
||||
{
|
||||
throw new ArgumentNullException();
|
||||
throw new ArgumentNullException("typeName");
|
||||
}
|
||||
|
||||
return _typeMap.GetOrAdd(typeName, LookupType);
|
||||
@ -37,11 +45,10 @@ namespace Emby.Server.Core.Data
|
||||
/// <returns>Type.</returns>
|
||||
private Type LookupType(string typeName)
|
||||
{
|
||||
return AppDomain
|
||||
.CurrentDomain
|
||||
.GetAssemblies()
|
||||
.Select(a => a.GetType(typeName, false))
|
||||
.FirstOrDefault(t => t != null);
|
||||
return _assemblyInfo
|
||||
.GetCurrentAssemblies()
|
||||
.Select(a => a.GetType(typeName))
|
||||
.FirstOrDefault(t => t != null);
|
||||
}
|
||||
}
|
||||
}
|
@ -36,6 +36,7 @@
|
||||
<Compile Include="Activity\ActivityManager.cs" />
|
||||
<Compile Include="Activity\ActivityRepository.cs" />
|
||||
<Compile Include="Branding\BrandingConfigurationFactory.cs" />
|
||||
<Compile Include="Browser\BrowserLauncher.cs" />
|
||||
<Compile Include="Channels\ChannelConfigurations.cs" />
|
||||
<Compile Include="Channels\ChannelDynamicMediaSourceProvider.cs" />
|
||||
<Compile Include="Channels\ChannelImageProvider.cs" />
|
||||
@ -51,6 +52,11 @@
|
||||
<Compile Include="Connect\Responses.cs" />
|
||||
<Compile Include="Connect\Validator.cs" />
|
||||
<Compile Include="Data\SqliteDisplayPreferencesRepository.cs" />
|
||||
<Compile Include="Data\SqliteFileOrganizationRepository.cs" />
|
||||
<Compile Include="Data\SqliteItemRepository.cs" />
|
||||
<Compile Include="Data\SqliteUserDataRepository.cs" />
|
||||
<Compile Include="Data\SqliteUserRepository.cs" />
|
||||
<Compile Include="Data\TypeMapper.cs" />
|
||||
<Compile Include="Devices\CameraUploadsDynamicFolder.cs" />
|
||||
<Compile Include="Devices\DeviceManager.cs" />
|
||||
<Compile Include="Devices\DeviceRepository.cs" />
|
||||
@ -62,11 +68,15 @@
|
||||
<Compile Include="EntryPoints\RecordingNotifier.cs" />
|
||||
<Compile Include="EntryPoints\RefreshUsersMetadata.cs" />
|
||||
<Compile Include="EntryPoints\ServerEventNotifier.cs" />
|
||||
<Compile Include="EntryPoints\StartupWizard.cs" />
|
||||
<Compile Include="EntryPoints\SystemEvents.cs" />
|
||||
<Compile Include="EntryPoints\UdpServerEntryPoint.cs" />
|
||||
<Compile Include="EntryPoints\UsageEntryPoint.cs" />
|
||||
<Compile Include="EntryPoints\UsageReporter.cs" />
|
||||
<Compile Include="EntryPoints\UserDataChangeNotifier.cs" />
|
||||
<Compile Include="FFMpeg\FFMpegInfo.cs" />
|
||||
<Compile Include="FFMpeg\FFMpegInstallInfo.cs" />
|
||||
<Compile Include="FFMpeg\FFMpegLoader.cs" />
|
||||
<Compile Include="FileOrganization\EpisodeFileOrganizer.cs" />
|
||||
<Compile Include="FileOrganization\Extensions.cs" />
|
||||
<Compile Include="FileOrganization\FileOrganizationNotifier.cs" />
|
||||
@ -169,6 +179,7 @@
|
||||
<Compile Include="Localization\LocalizationManager.cs" />
|
||||
<Compile Include="MediaEncoder\EncodingManager.cs" />
|
||||
<Compile Include="Migrations\IVersionMigration.cs" />
|
||||
<Compile Include="Migrations\UpdateLevelMigration.cs" />
|
||||
<Compile Include="News\NewsEntryPoint.cs" />
|
||||
<Compile Include="News\NewsService.cs" />
|
||||
<Compile Include="Notifications\CoreNotificationTypes.cs" />
|
||||
@ -237,6 +248,7 @@
|
||||
<Compile Include="Sorting\SortNameComparer.cs" />
|
||||
<Compile Include="Sorting\StartDateComparer.cs" />
|
||||
<Compile Include="Sorting\StudioComparer.cs" />
|
||||
<Compile Include="StartupOptions.cs" />
|
||||
<Compile Include="Sync\AppSyncProvider.cs" />
|
||||
<Compile Include="Sync\CloudSyncProfile.cs" />
|
||||
<Compile Include="Sync\IHasSyncQuality.cs" />
|
||||
@ -252,6 +264,7 @@
|
||||
<Compile Include="Sync\SyncManager.cs" />
|
||||
<Compile Include="Sync\SyncNotificationEntryPoint.cs" />
|
||||
<Compile Include="Sync\SyncRegistrationInfo.cs" />
|
||||
<Compile Include="Sync\SyncRepository.cs" />
|
||||
<Compile Include="Sync\TargetDataProvider.cs" />
|
||||
<Compile Include="TV\SeriesPostScanTask.cs" />
|
||||
<Compile Include="TV\TVSeriesManager.cs" />
|
||||
@ -305,7 +318,7 @@
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="SQLitePCLRaw.core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1488e028ca7ab535, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\SQLitePCLRaw.core.1.1.0\lib\portable-net45+netcore45+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\SQLitePCLRaw.core.dll</HintPath>
|
||||
<HintPath>..\packages\SQLitePCLRaw.core.1.1.1-pre20161109081005\lib\portable-net45+netcore45+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\SQLitePCLRaw.core.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="UniversalDetector, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
|
@ -1,9 +1,9 @@
|
||||
using MediaBrowser.Controller;
|
||||
using Emby.Server.Implementations.Browser;
|
||||
using MediaBrowser.Controller;
|
||||
using MediaBrowser.Controller.Plugins;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using Emby.Server.Core.Browser;
|
||||
|
||||
namespace Emby.Server.Core.EntryPoints
|
||||
namespace Emby.Server.Implementations.EntryPoints
|
||||
{
|
||||
/// <summary>
|
||||
/// Class StartupWizard
|
@ -1,4 +1,4 @@
|
||||
namespace Emby.Server.Core.FFMpeg
|
||||
namespace Emby.Server.Implementations.FFMpeg
|
||||
{
|
||||
/// <summary>
|
||||
/// Class FFMpegInfo
|
@ -1,5 +1,5 @@
|
||||
|
||||
namespace Emby.Server.Core.FFMpeg
|
||||
namespace Emby.Server.Implementations.FFMpeg
|
||||
{
|
||||
public class FFMpegInstallInfo
|
||||
{
|
@ -8,10 +8,10 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Emby.Server.Core;
|
||||
using Emby.Server.Core.FFMpeg;
|
||||
using Emby.Server.Implementations;
|
||||
using Emby.Server.Implementations.FFMpeg;
|
||||
|
||||
namespace Emby.Server.Core.FFMpeg
|
||||
namespace Emby.Server.Implementations.FFMpeg
|
||||
{
|
||||
public class FFMpegLoader
|
||||
{
|
||||
@ -119,11 +119,11 @@ namespace Emby.Server.Core.FFMpeg
|
||||
{
|
||||
var encoderFilename = Path.GetFileName(info.EncoderPath);
|
||||
var probeFilename = Path.GetFileName(info.ProbePath);
|
||||
|
||||
foreach (var directory in Directory.EnumerateDirectories(rootEncoderPath, "*", SearchOption.TopDirectoryOnly)
|
||||
|
||||
foreach (var directory in _fileSystem.GetDirectoryPaths(rootEncoderPath)
|
||||
.ToList())
|
||||
{
|
||||
var allFiles = Directory.EnumerateFiles(directory, "*", SearchOption.AllDirectories).ToList();
|
||||
var allFiles = _fileSystem.GetFilePaths(directory, true).ToList();
|
||||
|
||||
var encoder = allFiles.FirstOrDefault(i => string.Equals(Path.GetFileName(i), encoderFilename, StringComparison.OrdinalIgnoreCase));
|
||||
var probe = allFiles.FirstOrDefault(i => string.Equals(Path.GetFileName(i), probeFilename, StringComparison.OrdinalIgnoreCase));
|
||||
@ -182,7 +182,7 @@ namespace Emby.Server.Core.FFMpeg
|
||||
{
|
||||
ExtractArchive(downloadinfo, tempFile, tempFolder);
|
||||
|
||||
var files = Directory.EnumerateFiles(tempFolder, "*", SearchOption.AllDirectories)
|
||||
var files = _fileSystem.GetFilePaths(tempFolder, true)
|
||||
.ToList();
|
||||
|
||||
foreach (var file in files.Where(i =>
|
@ -74,7 +74,7 @@ namespace Emby.Server.Implementations.FileOrganization
|
||||
return new[] {
|
||||
|
||||
// Every so often
|
||||
new TaskTriggerInfo { Type = TaskTriggerInfo.TriggerInterval, IntervalTicks = TimeSpan.FromMinutes(5).Ticks}
|
||||
new TaskTriggerInfo { Type = TaskTriggerInfo.TriggerInterval, IntervalTicks = TimeSpan.FromMinutes(15).Ticks}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -59,12 +59,13 @@ namespace Emby.Server.Implementations.HttpServer
|
||||
private readonly IEnvironmentInfo _environment;
|
||||
private readonly IStreamFactory _streamFactory;
|
||||
private readonly Func<Type, Func<string, object>> _funcParseFn;
|
||||
private readonly bool _enableDualModeSockets;
|
||||
|
||||
public HttpListenerHost(IServerApplicationHost applicationHost,
|
||||
ILogger logger,
|
||||
IServerConfigurationManager config,
|
||||
string serviceName,
|
||||
string defaultRedirectPath, INetworkManager networkManager, IMemoryStreamFactory memoryStreamProvider, ITextEncoding textEncoding, ISocketFactory socketFactory, ICryptoProvider cryptoProvider, IJsonSerializer jsonSerializer, IXmlSerializer xmlSerializer, IEnvironmentInfo environment, ICertificate certificate, IStreamFactory streamFactory, Func<Type, Func<string, object>> funcParseFn)
|
||||
string defaultRedirectPath, INetworkManager networkManager, IMemoryStreamFactory memoryStreamProvider, ITextEncoding textEncoding, ISocketFactory socketFactory, ICryptoProvider cryptoProvider, IJsonSerializer jsonSerializer, IXmlSerializer xmlSerializer, IEnvironmentInfo environment, ICertificate certificate, IStreamFactory streamFactory, Func<Type, Func<string, object>> funcParseFn, bool enableDualModeSockets)
|
||||
: base(serviceName)
|
||||
{
|
||||
_appHost = applicationHost;
|
||||
@ -80,6 +81,7 @@ namespace Emby.Server.Implementations.HttpServer
|
||||
_certificate = certificate;
|
||||
_streamFactory = streamFactory;
|
||||
_funcParseFn = funcParseFn;
|
||||
_enableDualModeSockets = enableDualModeSockets;
|
||||
_config = config;
|
||||
|
||||
_logger = logger;
|
||||
@ -179,8 +181,6 @@ namespace Emby.Server.Implementations.HttpServer
|
||||
|
||||
private IHttpListener GetListener()
|
||||
{
|
||||
var enableDualMode = _environment.OperatingSystem == OperatingSystem.Windows;
|
||||
|
||||
return new WebSocketSharpListener(_logger,
|
||||
_certificate,
|
||||
_memoryStreamProvider,
|
||||
@ -189,7 +189,7 @@ namespace Emby.Server.Implementations.HttpServer
|
||||
_socketFactory,
|
||||
_cryptoProvider,
|
||||
_streamFactory,
|
||||
enableDualMode,
|
||||
_enableDualModeSockets,
|
||||
GetRequest);
|
||||
}
|
||||
|
||||
|
@ -2,16 +2,15 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Emby.Common.Implementations.Updates;
|
||||
using MediaBrowser.Common.Net;
|
||||
using MediaBrowser.Common.Updates;
|
||||
using MediaBrowser.Controller;
|
||||
using MediaBrowser.Controller.Configuration;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.Model.Serialization;
|
||||
using MediaBrowser.Model.Updates;
|
||||
using Emby.Server.Implementations.Migrations;
|
||||
|
||||
namespace Emby.Server.Core.Migrations
|
||||
namespace Emby.Server.Implementations.Migrations
|
||||
{
|
||||
public class UpdateLevelMigration : IVersionMigration
|
||||
{
|
@ -48,7 +48,7 @@ namespace Emby.Server.Implementations.Notifications
|
||||
{
|
||||
var result = new NotificationResult();
|
||||
|
||||
lock (WriteLock)
|
||||
using (WriteLock.Read())
|
||||
{
|
||||
using (var connection = CreateConnection(true))
|
||||
{
|
||||
@ -103,7 +103,7 @@ namespace Emby.Server.Implementations.Notifications
|
||||
{
|
||||
var result = new NotificationsSummary();
|
||||
|
||||
lock (WriteLock)
|
||||
using (WriteLock.Read())
|
||||
{
|
||||
using (var connection = CreateConnection(true))
|
||||
{
|
||||
@ -214,7 +214,7 @@ namespace Emby.Server.Implementations.Notifications
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
lock (WriteLock)
|
||||
using (WriteLock.Write())
|
||||
{
|
||||
using (var connection = CreateConnection())
|
||||
{
|
||||
@ -273,7 +273,7 @@ namespace Emby.Server.Implementations.Notifications
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
lock (WriteLock)
|
||||
using (WriteLock.Write())
|
||||
{
|
||||
using (var connection = CreateConnection())
|
||||
{
|
||||
@ -289,7 +289,7 @@ namespace Emby.Server.Implementations.Notifications
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
lock (WriteLock)
|
||||
using (WriteLock.Write())
|
||||
{
|
||||
using (var connection = CreateConnection())
|
||||
{
|
||||
|
@ -40,7 +40,9 @@ namespace Emby.Server.Implementations.Security
|
||||
|
||||
connection.RunInTransaction(db =>
|
||||
{
|
||||
AddColumn(db, "AccessTokens", "AppVersion", "TEXT");
|
||||
var existingColumnNames = GetColumnNames(db, "AccessTokens");
|
||||
|
||||
AddColumn(db, "AccessTokens", "AppVersion", "TEXT", existingColumnNames);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -61,7 +63,7 @@ namespace Emby.Server.Implementations.Security
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
lock (WriteLock)
|
||||
using (WriteLock.Write())
|
||||
{
|
||||
using (var connection = CreateConnection())
|
||||
{
|
||||
@ -193,7 +195,7 @@ namespace Emby.Server.Implementations.Security
|
||||
throw new ArgumentNullException("id");
|
||||
}
|
||||
|
||||
lock (WriteLock)
|
||||
using (WriteLock.Read())
|
||||
{
|
||||
using (var connection = CreateConnection(true))
|
||||
{
|
||||
|
@ -50,7 +50,7 @@ namespace Emby.Server.Implementations.Social
|
||||
throw new ArgumentNullException("info.Id");
|
||||
}
|
||||
|
||||
lock (WriteLock)
|
||||
using (WriteLock.Write())
|
||||
{
|
||||
using (var connection = CreateConnection())
|
||||
{
|
||||
@ -75,7 +75,7 @@ namespace Emby.Server.Implementations.Social
|
||||
throw new ArgumentNullException("id");
|
||||
}
|
||||
|
||||
lock (WriteLock)
|
||||
using (WriteLock.Read())
|
||||
{
|
||||
using (var connection = CreateConnection(true))
|
||||
{
|
||||
|
@ -2,11 +2,16 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Emby.Server.Core
|
||||
namespace Emby.Server.Implementations
|
||||
{
|
||||
public class StartupOptions
|
||||
{
|
||||
private readonly List<string> _options = Environment.GetCommandLineArgs().ToList();
|
||||
private readonly List<string> _options;
|
||||
|
||||
public StartupOptions(string[] commandLineArgs)
|
||||
{
|
||||
_options = commandLineArgs.ToList();
|
||||
}
|
||||
|
||||
public bool ContainsOption(string option)
|
||||
{
|
770
Emby.Server.Implementations/Sync/SyncRepository.cs
Normal file
770
Emby.Server.Implementations/Sync/SyncRepository.cs
Normal file
@ -0,0 +1,770 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Emby.Server.Implementations.Data;
|
||||
using MediaBrowser.Controller;
|
||||
using MediaBrowser.Controller.Sync;
|
||||
using MediaBrowser.Model.Dto;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.Model.Querying;
|
||||
using MediaBrowser.Model.Serialization;
|
||||
using MediaBrowser.Model.Sync;
|
||||
using SQLitePCL.pretty;
|
||||
|
||||
namespace Emby.Server.Implementations.Sync
|
||||
{
|
||||
public class SyncRepository : BaseSqliteRepository, ISyncRepository
|
||||
{
|
||||
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
|
||||
|
||||
private readonly IJsonSerializer _json;
|
||||
|
||||
public SyncRepository(ILogger logger, IJsonSerializer json, IServerApplicationPaths appPaths)
|
||||
: base(logger)
|
||||
{
|
||||
_json = json;
|
||||
DbFilePath = Path.Combine(appPaths.DataPath, "sync14.db");
|
||||
}
|
||||
|
||||
private class SyncSummary
|
||||
{
|
||||
public Dictionary<string, int> Items { get; set; }
|
||||
|
||||
public SyncSummary()
|
||||
{
|
||||
Items = new Dictionary<string, int>();
|
||||
}
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
using (var connection = CreateConnection())
|
||||
{
|
||||
string[] queries = {
|
||||
|
||||
"create table if not exists SyncJobs (Id GUID PRIMARY KEY, TargetId TEXT NOT NULL, Name TEXT NOT NULL, Profile TEXT, Quality TEXT, Bitrate INT, Status TEXT NOT NULL, Progress FLOAT, UserId TEXT NOT NULL, ItemIds TEXT NOT NULL, Category TEXT, ParentId TEXT, UnwatchedOnly BIT, ItemLimit INT, SyncNewContent BIT, DateCreated DateTime, DateLastModified DateTime, ItemCount int)",
|
||||
|
||||
"create table if not exists SyncJobItems (Id GUID PRIMARY KEY, ItemId TEXT, ItemName TEXT, MediaSourceId TEXT, JobId TEXT, TemporaryPath TEXT, OutputPath TEXT, Status TEXT, TargetId TEXT, DateCreated DateTime, Progress FLOAT, AdditionalFiles TEXT, MediaSource TEXT, IsMarkedForRemoval BIT, JobItemIndex INT, ItemDateModifiedTicks BIGINT)",
|
||||
|
||||
"drop index if exists idx_SyncJobItems2",
|
||||
"drop index if exists idx_SyncJobItems3",
|
||||
"drop index if exists idx_SyncJobs1",
|
||||
"drop index if exists idx_SyncJobs",
|
||||
"drop index if exists idx_SyncJobItems1",
|
||||
"create index if not exists idx_SyncJobItems4 on SyncJobItems(TargetId,ItemId,Status,Progress,DateCreated)",
|
||||
"create index if not exists idx_SyncJobItems5 on SyncJobItems(TargetId,Status,ItemId,Progress)",
|
||||
|
||||
"create index if not exists idx_SyncJobs2 on SyncJobs(TargetId,Status,ItemIds,Progress)",
|
||||
|
||||
"pragma shrink_memory"
|
||||
};
|
||||
|
||||
connection.RunQueries(queries);
|
||||
|
||||
connection.RunInTransaction(db =>
|
||||
{
|
||||
var existingColumnNames = GetColumnNames(db, "SyncJobs");
|
||||
AddColumn(db, "SyncJobs", "Profile", "TEXT", existingColumnNames);
|
||||
AddColumn(db, "SyncJobs", "Bitrate", "INT", existingColumnNames);
|
||||
|
||||
existingColumnNames = GetColumnNames(db, "SyncJobItems");
|
||||
AddColumn(db, "SyncJobItems", "ItemDateModifiedTicks", "BIGINT", existingColumnNames);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private const string BaseJobSelectText = "select Id, TargetId, Name, Profile, Quality, Bitrate, Status, Progress, UserId, ItemIds, Category, ParentId, UnwatchedOnly, ItemLimit, SyncNewContent, DateCreated, DateLastModified, ItemCount from SyncJobs";
|
||||
private const string BaseJobItemSelectText = "select Id, ItemId, ItemName, MediaSourceId, JobId, TemporaryPath, OutputPath, Status, TargetId, DateCreated, Progress, AdditionalFiles, MediaSource, IsMarkedForRemoval, JobItemIndex, ItemDateModifiedTicks from SyncJobItems";
|
||||
|
||||
public SyncJob GetJob(string id)
|
||||
{
|
||||
if (string.IsNullOrEmpty(id))
|
||||
{
|
||||
throw new ArgumentNullException("id");
|
||||
}
|
||||
|
||||
CheckDisposed();
|
||||
|
||||
var guid = new Guid(id);
|
||||
|
||||
if (guid == Guid.Empty)
|
||||
{
|
||||
throw new ArgumentNullException("id");
|
||||
}
|
||||
|
||||
using (WriteLock.Read())
|
||||
{
|
||||
using (var connection = CreateConnection(true))
|
||||
{
|
||||
var commandText = BaseJobSelectText + " where Id=?";
|
||||
var paramList = new List<object>();
|
||||
|
||||
paramList.Add(guid.ToGuidParamValue());
|
||||
|
||||
foreach (var row in connection.Query(commandText, paramList.ToArray()))
|
||||
{
|
||||
return GetJob(row);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private SyncJob GetJob(IReadOnlyList<IResultSetValue> reader)
|
||||
{
|
||||
var info = new SyncJob
|
||||
{
|
||||
Id = reader[0].ReadGuid().ToString("N"),
|
||||
TargetId = reader[1].ToString(),
|
||||
Name = reader[2].ToString()
|
||||
};
|
||||
|
||||
if (reader[3].SQLiteType != SQLiteType.Null)
|
||||
{
|
||||
info.Profile = reader[3].ToString();
|
||||
}
|
||||
|
||||
if (reader[4].SQLiteType != SQLiteType.Null)
|
||||
{
|
||||
info.Quality = reader[4].ToString();
|
||||
}
|
||||
|
||||
if (reader[5].SQLiteType != SQLiteType.Null)
|
||||
{
|
||||
info.Bitrate = reader[5].ToInt();
|
||||
}
|
||||
|
||||
if (reader[6].SQLiteType != SQLiteType.Null)
|
||||
{
|
||||
info.Status = (SyncJobStatus)Enum.Parse(typeof(SyncJobStatus), reader[6].ToString(), true);
|
||||
}
|
||||
|
||||
if (reader[7].SQLiteType != SQLiteType.Null)
|
||||
{
|
||||
info.Progress = reader[7].ToDouble();
|
||||
}
|
||||
|
||||
if (reader[8].SQLiteType != SQLiteType.Null)
|
||||
{
|
||||
info.UserId = reader[8].ToString();
|
||||
}
|
||||
|
||||
if (reader[9].SQLiteType != SQLiteType.Null)
|
||||
{
|
||||
info.RequestedItemIds = reader[9].ToString().Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
||||
}
|
||||
|
||||
if (reader[10].SQLiteType != SQLiteType.Null)
|
||||
{
|
||||
info.Category = (SyncCategory)Enum.Parse(typeof(SyncCategory), reader[10].ToString(), true);
|
||||
}
|
||||
|
||||
if (reader[11].SQLiteType != SQLiteType.Null)
|
||||
{
|
||||
info.ParentId = reader[11].ToString();
|
||||
}
|
||||
|
||||
if (reader[12].SQLiteType != SQLiteType.Null)
|
||||
{
|
||||
info.UnwatchedOnly = reader[12].ToBool();
|
||||
}
|
||||
|
||||
if (reader[13].SQLiteType != SQLiteType.Null)
|
||||
{
|
||||
info.ItemLimit = reader[13].ToInt();
|
||||
}
|
||||
|
||||
info.SyncNewContent = reader[14].ToBool();
|
||||
|
||||
info.DateCreated = reader[15].ReadDateTime();
|
||||
info.DateLastModified = reader[16].ReadDateTime();
|
||||
info.ItemCount = reader[17].ToInt();
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
public Task Create(SyncJob job)
|
||||
{
|
||||
return InsertOrUpdate(job, true);
|
||||
}
|
||||
|
||||
public Task Update(SyncJob job)
|
||||
{
|
||||
return InsertOrUpdate(job, false);
|
||||
}
|
||||
|
||||
private async Task InsertOrUpdate(SyncJob job, bool insert)
|
||||
{
|
||||
if (job == null)
|
||||
{
|
||||
throw new ArgumentNullException("job");
|
||||
}
|
||||
|
||||
CheckDisposed();
|
||||
|
||||
using (WriteLock.Write())
|
||||
{
|
||||
using (var connection = CreateConnection())
|
||||
{
|
||||
string commandText;
|
||||
var paramList = new List<object>();
|
||||
|
||||
if (insert)
|
||||
{
|
||||
commandText = "insert into SyncJobs (Id, TargetId, Name, Profile, Quality, Bitrate, Status, Progress, UserId, ItemIds, Category, ParentId, UnwatchedOnly, ItemLimit, SyncNewContent, DateCreated, DateLastModified, ItemCount) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
}
|
||||
else
|
||||
{
|
||||
commandText = "update SyncJobs set TargetId=?,Name=?,Profile=?,Quality=?,Bitrate=?,Status=?,Progress=?,UserId=?,ItemIds=?,Category=?,ParentId=?,UnwatchedOnly=?,ItemLimit=?,SyncNewContent=?,DateCreated=?,DateLastModified=?,ItemCount=? where Id=?";
|
||||
}
|
||||
|
||||
paramList.Add(job.Id.ToGuidParamValue());
|
||||
paramList.Add(job.TargetId);
|
||||
paramList.Add(job.Name);
|
||||
paramList.Add(job.Profile);
|
||||
paramList.Add(job.Quality);
|
||||
paramList.Add(job.Bitrate);
|
||||
paramList.Add(job.Status.ToString());
|
||||
paramList.Add(job.Progress);
|
||||
paramList.Add(job.UserId);
|
||||
|
||||
paramList.Add(string.Join(",", job.RequestedItemIds.ToArray()));
|
||||
paramList.Add(job.Category);
|
||||
paramList.Add(job.ParentId);
|
||||
paramList.Add(job.UnwatchedOnly);
|
||||
paramList.Add(job.ItemLimit);
|
||||
paramList.Add(job.SyncNewContent);
|
||||
paramList.Add(job.DateCreated.ToDateTimeParamValue());
|
||||
paramList.Add(job.DateLastModified.ToDateTimeParamValue());
|
||||
paramList.Add(job.ItemCount);
|
||||
|
||||
connection.RunInTransaction(conn =>
|
||||
{
|
||||
conn.Execute(commandText, paramList.ToArray());
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DeleteJob(string id)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(id))
|
||||
{
|
||||
throw new ArgumentNullException("id");
|
||||
}
|
||||
|
||||
CheckDisposed();
|
||||
|
||||
using (WriteLock.Write())
|
||||
{
|
||||
using (var connection = CreateConnection())
|
||||
{
|
||||
connection.RunInTransaction(conn =>
|
||||
{
|
||||
conn.Execute("delete from SyncJobs where Id=?", id.ToGuidParamValue());
|
||||
conn.Execute("delete from SyncJobItems where JobId=?", id);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public QueryResult<SyncJob> GetJobs(SyncJobQuery query)
|
||||
{
|
||||
if (query == null)
|
||||
{
|
||||
throw new ArgumentNullException("query");
|
||||
}
|
||||
|
||||
CheckDisposed();
|
||||
|
||||
using (WriteLock.Read())
|
||||
{
|
||||
using (var connection = CreateConnection(true))
|
||||
{
|
||||
var commandText = BaseJobSelectText;
|
||||
var paramList = new List<object>();
|
||||
|
||||
var whereClauses = new List<string>();
|
||||
|
||||
if (query.Statuses.Length > 0)
|
||||
{
|
||||
var statuses = string.Join(",", query.Statuses.Select(i => "'" + i.ToString() + "'").ToArray());
|
||||
|
||||
whereClauses.Add(string.Format("Status in ({0})", statuses));
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(query.TargetId))
|
||||
{
|
||||
whereClauses.Add("TargetId=?");
|
||||
paramList.Add(query.TargetId);
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(query.ExcludeTargetIds))
|
||||
{
|
||||
var excludeIds = (query.ExcludeTargetIds ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (excludeIds.Length == 1)
|
||||
{
|
||||
whereClauses.Add("TargetId<>?");
|
||||
paramList.Add(excludeIds[0]);
|
||||
}
|
||||
else if (excludeIds.Length > 1)
|
||||
{
|
||||
whereClauses.Add("TargetId<>?");
|
||||
paramList.Add(excludeIds[0]);
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(query.UserId))
|
||||
{
|
||||
whereClauses.Add("UserId=?");
|
||||
paramList.Add(query.UserId);
|
||||
}
|
||||
if (query.SyncNewContent.HasValue)
|
||||
{
|
||||
whereClauses.Add("SyncNewContent=?");
|
||||
paramList.Add(query.SyncNewContent.Value);
|
||||
}
|
||||
|
||||
commandText += " mainTable";
|
||||
|
||||
var whereTextWithoutPaging = whereClauses.Count == 0 ?
|
||||
string.Empty :
|
||||
" where " + string.Join(" AND ", whereClauses.ToArray());
|
||||
|
||||
var startIndex = query.StartIndex ?? 0;
|
||||
if (startIndex > 0)
|
||||
{
|
||||
whereClauses.Add(string.Format("Id NOT IN (SELECT Id FROM SyncJobs ORDER BY (Select Max(DateLastModified) from SyncJobs where TargetId=mainTable.TargetId) DESC, DateLastModified DESC LIMIT {0})",
|
||||
startIndex.ToString(_usCulture)));
|
||||
}
|
||||
|
||||
if (whereClauses.Count > 0)
|
||||
{
|
||||
commandText += " where " + string.Join(" AND ", whereClauses.ToArray());
|
||||
}
|
||||
|
||||
commandText += " ORDER BY (Select Max(DateLastModified) from SyncJobs where TargetId=mainTable.TargetId) DESC, DateLastModified DESC";
|
||||
|
||||
if (query.Limit.HasValue)
|
||||
{
|
||||
commandText += " LIMIT " + query.Limit.Value.ToString(_usCulture);
|
||||
}
|
||||
|
||||
var list = new List<SyncJob>();
|
||||
var count = connection.Query("select count (Id) from SyncJobs" + whereTextWithoutPaging, paramList.ToArray())
|
||||
.SelectScalarInt()
|
||||
.First();
|
||||
|
||||
foreach (var row in connection.Query(commandText, paramList.ToArray()))
|
||||
{
|
||||
list.Add(GetJob(row));
|
||||
}
|
||||
|
||||
return new QueryResult<SyncJob>()
|
||||
{
|
||||
Items = list.ToArray(),
|
||||
TotalRecordCount = count
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public SyncJobItem GetJobItem(string id)
|
||||
{
|
||||
if (string.IsNullOrEmpty(id))
|
||||
{
|
||||
throw new ArgumentNullException("id");
|
||||
}
|
||||
|
||||
CheckDisposed();
|
||||
|
||||
using (WriteLock.Read())
|
||||
{
|
||||
var guid = new Guid(id);
|
||||
|
||||
using (var connection = CreateConnection(true))
|
||||
{
|
||||
var commandText = BaseJobItemSelectText + " where Id=?";
|
||||
var paramList = new List<object>();
|
||||
|
||||
paramList.Add(guid.ToGuidParamValue());
|
||||
|
||||
foreach (var row in connection.Query(commandText, paramList.ToArray()))
|
||||
{
|
||||
return GetJobItem(row);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private QueryResult<T> GetJobItemReader<T>(SyncJobItemQuery query, string baseSelectText, Func<IReadOnlyList<IResultSetValue>, T> itemFactory)
|
||||
{
|
||||
if (query == null)
|
||||
{
|
||||
throw new ArgumentNullException("query");
|
||||
}
|
||||
|
||||
using (WriteLock.Read())
|
||||
{
|
||||
using (var connection = CreateConnection(true))
|
||||
{
|
||||
var commandText = baseSelectText;
|
||||
var paramList = new List<object>();
|
||||
|
||||
var whereClauses = new List<string>();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(query.JobId))
|
||||
{
|
||||
whereClauses.Add("JobId=?");
|
||||
paramList.Add(query.JobId);
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(query.ItemId))
|
||||
{
|
||||
whereClauses.Add("ItemId=?");
|
||||
paramList.Add(query.ItemId);
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(query.TargetId))
|
||||
{
|
||||
whereClauses.Add("TargetId=?");
|
||||
paramList.Add(query.TargetId);
|
||||
}
|
||||
|
||||
if (query.Statuses.Length > 0)
|
||||
{
|
||||
var statuses = string.Join(",", query.Statuses.Select(i => "'" + i.ToString() + "'").ToArray());
|
||||
|
||||
whereClauses.Add(string.Format("Status in ({0})", statuses));
|
||||
}
|
||||
|
||||
var whereTextWithoutPaging = whereClauses.Count == 0 ?
|
||||
string.Empty :
|
||||
" where " + string.Join(" AND ", whereClauses.ToArray());
|
||||
|
||||
var startIndex = query.StartIndex ?? 0;
|
||||
if (startIndex > 0)
|
||||
{
|
||||
whereClauses.Add(string.Format("Id NOT IN (SELECT Id FROM SyncJobItems ORDER BY JobItemIndex, DateCreated LIMIT {0})",
|
||||
startIndex.ToString(_usCulture)));
|
||||
}
|
||||
|
||||
if (whereClauses.Count > 0)
|
||||
{
|
||||
commandText += " where " + string.Join(" AND ", whereClauses.ToArray());
|
||||
}
|
||||
|
||||
commandText += " ORDER BY JobItemIndex, DateCreated";
|
||||
|
||||
if (query.Limit.HasValue)
|
||||
{
|
||||
commandText += " LIMIT " + query.Limit.Value.ToString(_usCulture);
|
||||
}
|
||||
|
||||
var list = new List<T>();
|
||||
var count = connection.Query("select count (Id) from SyncJobItems" + whereTextWithoutPaging, paramList.ToArray())
|
||||
.SelectScalarInt()
|
||||
.First();
|
||||
|
||||
foreach (var row in connection.Query(commandText, paramList.ToArray()))
|
||||
{
|
||||
list.Add(itemFactory(row));
|
||||
}
|
||||
|
||||
return new QueryResult<T>()
|
||||
{
|
||||
Items = list.ToArray(),
|
||||
TotalRecordCount = count
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Dictionary<string, SyncedItemProgress> GetSyncedItemProgresses(SyncJobItemQuery query)
|
||||
{
|
||||
var result = new Dictionary<string, SyncedItemProgress>();
|
||||
|
||||
var now = DateTime.UtcNow;
|
||||
|
||||
using (WriteLock.Read())
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
if (query.Statuses.Length > 0)
|
||||
{
|
||||
var statuses = string.Join(",", query.Statuses.Select(i => "'" + i.ToString() + "'").ToArray());
|
||||
|
||||
whereClauses.Add(string.Format("Status in ({0})", statuses));
|
||||
}
|
||||
|
||||
if (whereClauses.Count > 0)
|
||||
{
|
||||
commandText += " where " + string.Join(" AND ", whereClauses.ToArray());
|
||||
}
|
||||
|
||||
foreach (var row in connection.Query(commandText, paramList.ToArray()))
|
||||
{
|
||||
AddStatusResult(row, result, false);
|
||||
}
|
||||
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()))
|
||||
{
|
||||
AddStatusResult(row, result, true);
|
||||
}
|
||||
LogQueryTime("GetSyncedItemProgresses", commandText, now);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private void LogQueryTime(string methodName, string commandText, DateTime startDate)
|
||||
{
|
||||
var elapsed = (DateTime.UtcNow - startDate).TotalMilliseconds;
|
||||
|
||||
var slowThreshold = 1000;
|
||||
|
||||
#if DEBUG
|
||||
slowThreshold = 50;
|
||||
#endif
|
||||
|
||||
if (elapsed >= slowThreshold)
|
||||
{
|
||||
Logger.Debug("{2} query time (slow): {0}ms. Query: {1}",
|
||||
Convert.ToInt32(elapsed),
|
||||
commandText,
|
||||
methodName);
|
||||
}
|
||||
else
|
||||
{
|
||||
//Logger.Debug("{2} query time: {0}ms. Query: {1}",
|
||||
// Convert.ToInt32(elapsed),
|
||||
// cmd.CommandText,
|
||||
// methodName);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddStatusResult(IReadOnlyList<IResultSetValue> reader, Dictionary<string, SyncedItemProgress> result, bool multipleIds)
|
||||
{
|
||||
if (reader[0].SQLiteType == SQLiteType.Null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var itemIds = new List<string>();
|
||||
|
||||
var ids = reader[0].ToString();
|
||||
|
||||
if (multipleIds)
|
||||
{
|
||||
itemIds = ids.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
itemIds.Add(ids);
|
||||
}
|
||||
|
||||
if (reader[1].SQLiteType != SQLiteType.Null)
|
||||
{
|
||||
SyncJobItemStatus status;
|
||||
var statusString = reader[1].ToString();
|
||||
if (string.Equals(statusString, "Completed", StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(statusString, "CompletedWithError", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
status = SyncJobItemStatus.Synced;
|
||||
}
|
||||
else
|
||||
{
|
||||
status = (SyncJobItemStatus)Enum.Parse(typeof(SyncJobItemStatus), statusString, true);
|
||||
}
|
||||
|
||||
if (status == SyncJobItemStatus.Synced)
|
||||
{
|
||||
foreach (var itemId in itemIds)
|
||||
{
|
||||
result[itemId] = new SyncedItemProgress
|
||||
{
|
||||
Status = SyncJobItemStatus.Synced
|
||||
};
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
double progress = reader[2].SQLiteType == SQLiteType.Null ? 0.0 : reader[2].ToDouble();
|
||||
|
||||
foreach (var itemId in itemIds)
|
||||
{
|
||||
SyncedItemProgress currentStatus;
|
||||
if (!result.TryGetValue(itemId, out currentStatus) || (currentStatus.Status != SyncJobItemStatus.Synced && progress >= currentStatus.Progress))
|
||||
{
|
||||
result[itemId] = new SyncedItemProgress
|
||||
{
|
||||
Status = status,
|
||||
Progress = progress
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public QueryResult<SyncJobItem> GetJobItems(SyncJobItemQuery query)
|
||||
{
|
||||
return GetJobItemReader(query, BaseJobItemSelectText, GetJobItem);
|
||||
}
|
||||
|
||||
public Task Create(SyncJobItem jobItem)
|
||||
{
|
||||
return InsertOrUpdate(jobItem, true);
|
||||
}
|
||||
|
||||
public Task Update(SyncJobItem jobItem)
|
||||
{
|
||||
return InsertOrUpdate(jobItem, false);
|
||||
}
|
||||
|
||||
private async Task InsertOrUpdate(SyncJobItem jobItem, bool insert)
|
||||
{
|
||||
if (jobItem == null)
|
||||
{
|
||||
throw new ArgumentNullException("jobItem");
|
||||
}
|
||||
|
||||
CheckDisposed();
|
||||
|
||||
using (WriteLock.Write())
|
||||
{
|
||||
using (var connection = CreateConnection())
|
||||
{
|
||||
string commandText;
|
||||
|
||||
if (insert)
|
||||
{
|
||||
commandText = "insert into SyncJobItems (Id, ItemId, ItemName, MediaSourceId, JobId, TemporaryPath, OutputPath, Status, TargetId, DateCreated, Progress, AdditionalFiles, MediaSource, IsMarkedForRemoval, JobItemIndex, ItemDateModifiedTicks) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
}
|
||||
else
|
||||
{
|
||||
// cmd
|
||||
commandText = "update SyncJobItems set ItemId=?,ItemName=?,MediaSourceId=?,JobId=?,TemporaryPath=?,OutputPath=?,Status=?,TargetId=?,DateCreated=?,Progress=?,AdditionalFiles=?,MediaSource=?,IsMarkedForRemoval=?,JobItemIndex=?,ItemDateModifiedTicks=? where Id=?";
|
||||
}
|
||||
|
||||
var paramList = new List<object>();
|
||||
paramList.Add(jobItem.Id.ToGuidParamValue());
|
||||
paramList.Add(jobItem.ItemId);
|
||||
paramList.Add(jobItem.ItemName);
|
||||
paramList.Add(jobItem.MediaSourceId);
|
||||
paramList.Add(jobItem.JobId);
|
||||
paramList.Add(jobItem.TemporaryPath);
|
||||
paramList.Add(jobItem.OutputPath);
|
||||
paramList.Add(jobItem.Status.ToString());
|
||||
|
||||
paramList.Add(jobItem.TargetId);
|
||||
paramList.Add(jobItem.DateCreated.ToDateTimeParamValue());
|
||||
paramList.Add(jobItem.Progress);
|
||||
paramList.Add(_json.SerializeToString(jobItem.AdditionalFiles));
|
||||
paramList.Add(jobItem.MediaSource == null ? null : _json.SerializeToString(jobItem.MediaSource));
|
||||
paramList.Add(jobItem.IsMarkedForRemoval);
|
||||
paramList.Add(jobItem.JobItemIndex);
|
||||
paramList.Add(jobItem.ItemDateModifiedTicks);
|
||||
|
||||
connection.RunInTransaction(conn =>
|
||||
{
|
||||
conn.Execute(commandText, paramList.ToArray());
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private SyncJobItem GetJobItem(IReadOnlyList<IResultSetValue> reader)
|
||||
{
|
||||
var info = new SyncJobItem
|
||||
{
|
||||
Id = reader[0].ReadGuid().ToString("N"),
|
||||
ItemId = reader[1].ToString()
|
||||
};
|
||||
|
||||
if (reader[2].SQLiteType != SQLiteType.Null)
|
||||
{
|
||||
info.ItemName = reader[2].ToString();
|
||||
}
|
||||
|
||||
if (reader[3].SQLiteType != SQLiteType.Null)
|
||||
{
|
||||
info.MediaSourceId = reader[3].ToString();
|
||||
}
|
||||
|
||||
info.JobId = reader[4].ToString();
|
||||
|
||||
if (reader[5].SQLiteType != SQLiteType.Null)
|
||||
{
|
||||
info.TemporaryPath = reader[5].ToString();
|
||||
}
|
||||
if (reader[6].SQLiteType != SQLiteType.Null)
|
||||
{
|
||||
info.OutputPath = reader[6].ToString();
|
||||
}
|
||||
|
||||
if (reader[7].SQLiteType != SQLiteType.Null)
|
||||
{
|
||||
info.Status = (SyncJobItemStatus)Enum.Parse(typeof(SyncJobItemStatus), reader[7].ToString(), true);
|
||||
}
|
||||
|
||||
info.TargetId = reader[8].ToString();
|
||||
|
||||
info.DateCreated = reader[9].ReadDateTime();
|
||||
|
||||
if (reader[10].SQLiteType != SQLiteType.Null)
|
||||
{
|
||||
info.Progress = reader[10].ToDouble();
|
||||
}
|
||||
|
||||
if (reader[11].SQLiteType != SQLiteType.Null)
|
||||
{
|
||||
var json = reader[11].ToString();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(json))
|
||||
{
|
||||
info.AdditionalFiles = _json.DeserializeFromString<List<ItemFileInfo>>(json);
|
||||
}
|
||||
}
|
||||
|
||||
if (reader[12].SQLiteType != SQLiteType.Null)
|
||||
{
|
||||
var json = reader[12].ToString();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(json))
|
||||
{
|
||||
info.MediaSource = _json.DeserializeFromString<MediaSourceInfo>(json);
|
||||
}
|
||||
}
|
||||
|
||||
info.IsMarkedForRemoval = reader[13].ToBool();
|
||||
info.JobItemIndex = reader[14].ToInt();
|
||||
|
||||
if (reader[15].SQLiteType != SQLiteType.Null)
|
||||
{
|
||||
info.ItemDateModifiedTicks = reader[15].ToInt64();
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
}
|
||||
}
|
@ -148,10 +148,6 @@ namespace Emby.Server.Implementations.TV
|
||||
|
||||
private string GetUniqueSeriesKey(BaseItem series)
|
||||
{
|
||||
if (_config.Configuration.SchemaVersion < 97)
|
||||
{
|
||||
return series.Id.ToString("N");
|
||||
}
|
||||
return series.GetPresentationUniqueKey();
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,6 @@
|
||||
<package id="Emby.XmlTv" version="1.0.1" targetFramework="portable45-net45+win8" />
|
||||
<package id="MediaBrowser.Naming" version="1.0.2" targetFramework="portable45-net45+win8" />
|
||||
<package id="SQLitePCL.pretty" version="1.1.0" targetFramework="portable45-net45+win8" />
|
||||
<package id="SQLitePCLRaw.core" version="1.1.0" targetFramework="portable45-net45+win8" />
|
||||
<package id="SQLitePCLRaw.core" version="1.1.1-pre20161109081005" targetFramework="portable45-net45+win8" />
|
||||
<package id="UniversalDetector" version="1.0.1" targetFramework="portable45-net45+win8" />
|
||||
</packages>
|
@ -115,7 +115,6 @@ namespace MediaBrowser.Api
|
||||
config.EnableStandaloneMusicKeys = true;
|
||||
config.EnableCaseSensitiveItemIds = true;
|
||||
config.EnableFolderView = true;
|
||||
config.SchemaVersion = 109;
|
||||
config.EnableSimpleArtistDetection = true;
|
||||
config.SkipDeserializationForBasicTypes = true;
|
||||
config.SkipDeserializationForPrograms = true;
|
||||
|
@ -70,6 +70,7 @@
|
||||
<Compile Include="Security\IRequiresRegistration.cs" />
|
||||
<Compile Include="Security\ISecurityManager.cs" />
|
||||
<Compile Include="Security\PaymentRequiredException.cs" />
|
||||
<Compile Include="Updates\GithubUpdater.cs" />
|
||||
<Compile Include="Updates\IInstallationManager.cs" />
|
||||
<Compile Include="Updates\InstallationEventArgs.cs" />
|
||||
<Compile Include="Updates\InstallationFailedEventArgs.cs" />
|
||||
|
@ -8,7 +8,7 @@ using MediaBrowser.Common.Net;
|
||||
using MediaBrowser.Model.Serialization;
|
||||
using MediaBrowser.Model.Updates;
|
||||
|
||||
namespace Emby.Common.Implementations.Updates
|
||||
namespace MediaBrowser.Common.Updates
|
||||
{
|
||||
public class GithubUpdater
|
||||
{
|
@ -123,7 +123,6 @@ namespace MediaBrowser.Controller.Entities
|
||||
public int? MinParentalRating { get; set; }
|
||||
public int? MaxParentalRating { get; set; }
|
||||
|
||||
public bool? IsCurrentSchema { get; set; }
|
||||
public bool? HasDeadParentId { get; set; }
|
||||
public bool? IsOffline { get; set; }
|
||||
public bool? IsVirtualItem { get; set; }
|
||||
|
@ -126,10 +126,6 @@ namespace MediaBrowser.Controller.Entities.TV
|
||||
|
||||
private static string GetUniqueSeriesKey(BaseItem series)
|
||||
{
|
||||
if (ConfigurationManager.Configuration.SchemaVersion < 97)
|
||||
{
|
||||
return series.Id.ToString("N");
|
||||
}
|
||||
return series.GetPresentationUniqueKey();
|
||||
}
|
||||
|
||||
|
@ -81,8 +81,9 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||
{
|
||||
output = GetProcessOutput(encoderAppPath, "-decoders");
|
||||
}
|
||||
catch
|
||||
catch (Exception )
|
||||
{
|
||||
//_logger.ErrorException("Error detecting available decoders", ex);
|
||||
}
|
||||
|
||||
var found = new List<string>();
|
||||
|
@ -932,7 +932,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||
var process = _processFactory.Create(new ProcessOptions
|
||||
{
|
||||
CreateNoWindow = true,
|
||||
UseShellExecute = false,
|
||||
UseShellExecute = true,
|
||||
FileName = FFMpegPath,
|
||||
Arguments = args,
|
||||
IsHidden = true,
|
||||
@ -1035,7 +1035,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||
var process = _processFactory.Create(new ProcessOptions
|
||||
{
|
||||
CreateNoWindow = true,
|
||||
UseShellExecute = false,
|
||||
UseShellExecute = true,
|
||||
FileName = FFMpegPath,
|
||||
Arguments = args,
|
||||
IsHidden = true,
|
||||
|
@ -996,7 +996,7 @@ namespace MediaBrowser.MediaEncoding.Probing
|
||||
{
|
||||
_splitWhiteList = new List<string>
|
||||
{
|
||||
"AC/DV"
|
||||
"AC/DC"
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -451,7 +451,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||
var process = _processFactory.Create(new ProcessOptions
|
||||
{
|
||||
CreateNoWindow = true,
|
||||
UseShellExecute = false,
|
||||
UseShellExecute = true,
|
||||
FileName = _mediaEncoder.EncoderPath,
|
||||
Arguments = string.Format("{0} -i \"{1}\" -c:s srt \"{2}\"", encodingParam, inputPath, outputPath),
|
||||
|
||||
@ -582,7 +582,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||
var process = _processFactory.Create(new ProcessOptions
|
||||
{
|
||||
CreateNoWindow = true,
|
||||
UseShellExecute = false,
|
||||
UseShellExecute = true,
|
||||
|
||||
FileName = _mediaEncoder.EncoderPath,
|
||||
Arguments = processArgs,
|
||||
|
@ -192,9 +192,6 @@ namespace MediaBrowser.Model.Configuration
|
||||
|
||||
public int SharingExpirationDays { get; set; }
|
||||
|
||||
public string[] Migrations { get; set; }
|
||||
|
||||
public int MigrationVersion { get; set; }
|
||||
public int SchemaVersion { get; set; }
|
||||
public int SqliteCacheSize { get; set; }
|
||||
|
||||
@ -218,7 +215,6 @@ namespace MediaBrowser.Model.Configuration
|
||||
public ServerConfiguration()
|
||||
{
|
||||
LocalNetworkAddresses = new string[] { };
|
||||
Migrations = new string[] { };
|
||||
CodecsUsed = new string[] { };
|
||||
SqliteCacheSize = 0;
|
||||
ImageExtractionTimeoutMs = 0;
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
|
||||
namespace MediaBrowser.Model.Reflection
|
||||
{
|
||||
@ -7,5 +8,7 @@ namespace MediaBrowser.Model.Reflection
|
||||
{
|
||||
Stream GetManifestResourceStream(Type type, string resource);
|
||||
string[] GetManifestResourceNames(Type type);
|
||||
|
||||
Assembly[] GetCurrentAssemblies();
|
||||
}
|
||||
}
|
||||
|
@ -74,7 +74,5 @@ namespace MediaBrowser.Model.Tasks
|
||||
|
||||
event EventHandler<GenericEventArgs<IScheduledTaskWorker>> TaskExecuting;
|
||||
event EventHandler<TaskCompletionEventArgs> TaskCompleted;
|
||||
|
||||
bool SuspendTriggers { get; set; }
|
||||
}
|
||||
}
|
@ -87,9 +87,34 @@
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="XamMac" />
|
||||
<Reference Include="Mono.Posix">
|
||||
<Reference Include="Mono.Posix, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\Mono.Posix.4.0.0.0\lib\net40\Mono.Posix.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NLog.4.4.0-betaV15\lib\net45\NLog.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="ServiceStack.Text, Version=4.5.4.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\ServiceStack.Text.4.5.4\lib\net45\ServiceStack.Text.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="SharpCompress, Version=0.14.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\SharpCompress.0.14.0\lib\net45\SharpCompress.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="SimpleInjector, Version=3.2.4.0, Culture=neutral, PublicKeyToken=984cb50dea722e99, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\SimpleInjector.3.2.4\lib\net45\SimpleInjector.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="SQLitePCLRaw.core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1488e028ca7ab535, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\SQLitePCLRaw.core.1.1.0\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.0\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>
|
||||
@ -1508,6 +1533,15 @@
|
||||
<BundleResource Include="..\MediaBrowser.WebDashboard\dashboard-ui\bower_components\emby-webcomponents\multiselect\multiselect.js">
|
||||
<Link>Resources\dashboard-ui\bower_components\emby-webcomponents\multiselect\multiselect.js</Link>
|
||||
</BundleResource>
|
||||
<BundleResource Include="..\MediaBrowser.WebDashboard\dashboard-ui\bower_components\emby-webcomponents\native-promise-only\README.md">
|
||||
<Link>Resources\dashboard-ui\bower_components\emby-webcomponents\native-promise-only\README.md</Link>
|
||||
</BundleResource>
|
||||
<BundleResource Include="..\MediaBrowser.WebDashboard\dashboard-ui\bower_components\emby-webcomponents\native-promise-only\test_adapter.js">
|
||||
<Link>Resources\dashboard-ui\bower_components\emby-webcomponents\native-promise-only\test_adapter.js</Link>
|
||||
</BundleResource>
|
||||
<BundleResource Include="..\MediaBrowser.WebDashboard\dashboard-ui\bower_components\emby-webcomponents\native-promise-only\lib\npo.src.js">
|
||||
<Link>Resources\dashboard-ui\bower_components\emby-webcomponents\native-promise-only\lib\npo.src.js</Link>
|
||||
</BundleResource>
|
||||
<BundleResource Include="..\MediaBrowser.WebDashboard\dashboard-ui\bower_components\emby-webcomponents\notifications\badge.png">
|
||||
<Link>Resources\dashboard-ui\bower_components\emby-webcomponents\notifications\badge.png</Link>
|
||||
</BundleResource>
|
||||
@ -2393,30 +2427,6 @@
|
||||
<BundleResource Include="..\MediaBrowser.WebDashboard\dashboard-ui\bower_components\libjass\package.json">
|
||||
<Link>Resources\dashboard-ui\bower_components\libjass\package.json</Link>
|
||||
</BundleResource>
|
||||
<BundleResource Include="..\MediaBrowser.WebDashboard\dashboard-ui\bower_components\native-promise-only\.bower.json">
|
||||
<Link>Resources\dashboard-ui\bower_components\native-promise-only\.bower.json</Link>
|
||||
</BundleResource>
|
||||
<BundleResource Include="..\MediaBrowser.WebDashboard\dashboard-ui\bower_components\native-promise-only\.gitignore">
|
||||
<Link>Resources\dashboard-ui\bower_components\native-promise-only\.gitignore</Link>
|
||||
</BundleResource>
|
||||
<BundleResource Include="..\MediaBrowser.WebDashboard\dashboard-ui\bower_components\native-promise-only\.npmignore">
|
||||
<Link>Resources\dashboard-ui\bower_components\native-promise-only\.npmignore</Link>
|
||||
</BundleResource>
|
||||
<BundleResource Include="..\MediaBrowser.WebDashboard\dashboard-ui\bower_components\native-promise-only\README.md">
|
||||
<Link>Resources\dashboard-ui\bower_components\native-promise-only\README.md</Link>
|
||||
</BundleResource>
|
||||
<BundleResource Include="..\MediaBrowser.WebDashboard\dashboard-ui\bower_components\native-promise-only\build.js">
|
||||
<Link>Resources\dashboard-ui\bower_components\native-promise-only\build.js</Link>
|
||||
</BundleResource>
|
||||
<BundleResource Include="..\MediaBrowser.WebDashboard\dashboard-ui\bower_components\native-promise-only\package.json">
|
||||
<Link>Resources\dashboard-ui\bower_components\native-promise-only\package.json</Link>
|
||||
</BundleResource>
|
||||
<BundleResource Include="..\MediaBrowser.WebDashboard\dashboard-ui\bower_components\native-promise-only\test_adapter.js">
|
||||
<Link>Resources\dashboard-ui\bower_components\native-promise-only\test_adapter.js</Link>
|
||||
</BundleResource>
|
||||
<BundleResource Include="..\MediaBrowser.WebDashboard\dashboard-ui\bower_components\native-promise-only\lib\npo.src.js">
|
||||
<Link>Resources\dashboard-ui\bower_components\native-promise-only\lib\npo.src.js</Link>
|
||||
</BundleResource>
|
||||
<BundleResource Include="..\MediaBrowser.WebDashboard\dashboard-ui\bower_components\query-string\.bower.json">
|
||||
<Link>Resources\dashboard-ui\bower_components\query-string\.bower.json</Link>
|
||||
</BundleResource>
|
||||
|
@ -39,7 +39,9 @@ namespace MediaBrowser.Server.Mac
|
||||
|
||||
static void Main (string[] args)
|
||||
{
|
||||
var applicationPath = Assembly.GetEntryAssembly().Location;
|
||||
SQLitePCL.raw.SetProvider(new SQLitePCL.SQLite3Provider_sqlite3());
|
||||
|
||||
var applicationPath = Assembly.GetEntryAssembly().Location;
|
||||
|
||||
var options = new StartupOptions();
|
||||
|
||||
|
@ -85,11 +85,11 @@
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="SQLitePCLRaw.core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1488e028ca7ab535, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\SQLitePCLRaw.core.1.1.0\lib\net45\SQLitePCLRaw.core.dll</HintPath>
|
||||
<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.0\lib\net45\SQLitePCLRaw.provider.sqlite3.dll</HintPath>
|
||||
<HintPath>..\packages\SQLitePCLRaw.provider.sqlite3.net45.1.1.1-pre20161109081005\lib\net45\SQLitePCLRaw.provider.sqlite3.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
|
@ -3,7 +3,8 @@ using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using Emby.Server.Core;
|
||||
using Emby.Server.Core.Data;
|
||||
using Emby.Server.Core.FFMpeg;
|
||||
using Emby.Server.Implementations;
|
||||
using Emby.Server.Implementations.FFMpeg;
|
||||
using MediaBrowser.IsoMounter;
|
||||
using MediaBrowser.Model.IO;
|
||||
using MediaBrowser.Model.Logging;
|
||||
@ -91,6 +92,32 @@ namespace MediaBrowser.Server.Mono
|
||||
MainClass.Shutdown();
|
||||
}
|
||||
|
||||
protected override bool SupportsDualModeSockets
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetMonoVersion() >= new Version(4, 6);
|
||||
}
|
||||
}
|
||||
|
||||
private static Version GetMonoVersion()
|
||||
{
|
||||
Type type = Type.GetType("Mono.Runtime");
|
||||
if (type != null)
|
||||
{
|
||||
MethodInfo displayName = type.GetTypeInfo().GetMethod("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static);
|
||||
var displayNameValue = displayName.Invoke(null, null).ToString().Trim().Split(' ')[0];
|
||||
|
||||
Version version;
|
||||
if (Version.TryParse(displayNameValue, out version))
|
||||
{
|
||||
return version;
|
||||
}
|
||||
}
|
||||
|
||||
return new Version(1, 0);
|
||||
}
|
||||
|
||||
protected override void AuthorizeServer()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
|
@ -6,7 +6,8 @@ namespace MediaBrowser.Server.Mono.Native
|
||||
{
|
||||
public class MonoFileSystem : ManagedFileSystem
|
||||
{
|
||||
public MonoFileSystem(ILogger logger, bool supportsAsyncFileStreams, bool enableManagedInvalidFileNameChars) : base(logger, supportsAsyncFileStreams, enableManagedInvalidFileNameChars, false)
|
||||
public MonoFileSystem(ILogger logger, bool supportsAsyncFileStreams, bool enableManagedInvalidFileNameChars)
|
||||
: base(logger, supportsAsyncFileStreams, enableManagedInvalidFileNameChars, true)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@ using Emby.Common.Implementations.Logging;
|
||||
using Emby.Common.Implementations.Networking;
|
||||
using Emby.Common.Implementations.Security;
|
||||
using Emby.Server.Core;
|
||||
using Emby.Server.Implementations;
|
||||
using Emby.Server.Implementations.IO;
|
||||
using MediaBrowser.Model.System;
|
||||
using MediaBrowser.Server.Startup.Common.IO;
|
||||
@ -38,7 +39,7 @@ namespace MediaBrowser.Server.Mono
|
||||
|
||||
var applicationPath = Assembly.GetEntryAssembly().Location;
|
||||
|
||||
var options = new StartupOptions();
|
||||
var options = new StartupOptions(Environment.GetCommandLineArgs());
|
||||
|
||||
// Allow this to be specified on the command line.
|
||||
var customProgramDataPath = options.GetOption("-programdata");
|
||||
|
@ -5,6 +5,6 @@
|
||||
<package id="ServiceStack.Text" version="4.5.4" targetFramework="net46" />
|
||||
<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.0" targetFramework="net46" />
|
||||
<package id="SQLitePCLRaw.provider.sqlite3.net45" version="1.1.0" 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>
|
@ -3,6 +3,7 @@ using Emby.Drawing;
|
||||
using Emby.Drawing.Net;
|
||||
using Emby.Drawing.ImageMagick;
|
||||
using Emby.Server.Core;
|
||||
using Emby.Server.Implementations;
|
||||
using MediaBrowser.Common.Configuration;
|
||||
using MediaBrowser.Common.Net;
|
||||
using MediaBrowser.Controller.Drawing;
|
||||
|
@ -23,7 +23,8 @@ using Emby.Common.Implementations.Logging;
|
||||
using Emby.Common.Implementations.Networking;
|
||||
using Emby.Common.Implementations.Security;
|
||||
using Emby.Server.Core;
|
||||
using Emby.Server.Core.Browser;
|
||||
using Emby.Server.Implementations;
|
||||
using Emby.Server.Implementations.Browser;
|
||||
using Emby.Server.Implementations.IO;
|
||||
using ImageMagickSharp;
|
||||
using MediaBrowser.Common.Net;
|
||||
@ -73,7 +74,7 @@ namespace MediaBrowser.ServerApplication
|
||||
/// </summary>
|
||||
public static void Main()
|
||||
{
|
||||
var options = new StartupOptions();
|
||||
var options = new StartupOptions(Environment.GetCommandLineArgs());
|
||||
IsRunningAsService = options.ContainsOption("-service");
|
||||
|
||||
if (IsRunningAsService)
|
||||
|
@ -91,11 +91,11 @@
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="SQLitePCLRaw.core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1488e028ca7ab535, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\SQLitePCLRaw.core.1.1.0\lib\net45\SQLitePCLRaw.core.dll</HintPath>
|
||||
<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.0\lib\net45\SQLitePCLRaw.provider.sqlite3.dll</HintPath>
|
||||
<HintPath>..\packages\SQLitePCLRaw.provider.sqlite3.net45.1.1.1-pre20161109081005\lib\net45\SQLitePCLRaw.provider.sqlite3.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
|
@ -4,7 +4,7 @@ using MediaBrowser.Model.Logging;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Windows.Forms;
|
||||
using Emby.Server.Core.Browser;
|
||||
using Emby.Server.Implementations.Browser;
|
||||
using MediaBrowser.Model.Globalization;
|
||||
|
||||
namespace MediaBrowser.ServerApplication
|
||||
|
@ -5,8 +5,9 @@ using System.IO;
|
||||
using System.Reflection;
|
||||
using Emby.Server.Core;
|
||||
using Emby.Server.Core.Data;
|
||||
using Emby.Server.Core.FFMpeg;
|
||||
using Emby.Server.Implementations;
|
||||
using Emby.Server.Implementations.EntryPoints;
|
||||
using Emby.Server.Implementations.FFMpeg;
|
||||
using MediaBrowser.Model.IO;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.Model.System;
|
||||
@ -116,6 +117,14 @@ namespace MediaBrowser.ServerApplication
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool SupportsDualModeSockets
|
||||
{
|
||||
get
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public override void LaunchUrl(string url)
|
||||
{
|
||||
var process = new Process
|
||||
@ -136,6 +145,7 @@ namespace MediaBrowser.ServerApplication
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error launching url: {0}", url);
|
||||
Logger.ErrorException("Error launching url: {0}", ex, url);
|
||||
|
||||
throw;
|
||||
|
@ -5,6 +5,6 @@
|
||||
<package id="ServiceStack.Text" version="4.5.4" targetFramework="net462" />
|
||||
<package id="SharpCompress" version="0.14.0" targetFramework="net462" />
|
||||
<package id="SimpleInjector" version="3.2.4" targetFramework="net462" />
|
||||
<package id="SQLitePCLRaw.core" version="1.1.0" targetFramework="net462" />
|
||||
<package id="SQLitePCLRaw.provider.sqlite3.net45" version="1.1.0" targetFramework="net462" />
|
||||
<package id="SQLitePCLRaw.core" version="1.1.1-pre20161109081005" targetFramework="net462" />
|
||||
<package id="SQLitePCLRaw.provider.sqlite3.net45" version="1.1.1-pre20161109081005" targetFramework="net462" />
|
||||
</packages>
|
Loading…
Reference in New Issue
Block a user