From dcd06597a7cc1d4a7829ed75e0a6b1e52fd5c10e Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 13 Dec 2016 13:41:36 -0500 Subject: [PATCH] add missing files --- .../Data/ManagedConnection.cs | 82 +++++++++++++++++++ .../Migrations/LibraryScanMigration.cs | 49 +++++++++++ 2 files changed, 131 insertions(+) create mode 100644 Emby.Server.Implementations/Data/ManagedConnection.cs create mode 100644 Emby.Server.Implementations/Migrations/LibraryScanMigration.cs diff --git a/Emby.Server.Implementations/Data/ManagedConnection.cs b/Emby.Server.Implementations/Data/ManagedConnection.cs new file mode 100644 index 0000000000..91a2dfdf62 --- /dev/null +++ b/Emby.Server.Implementations/Data/ManagedConnection.cs @@ -0,0 +1,82 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SQLitePCL.pretty; + +namespace Emby.Server.Implementations.Data +{ + public class ManagedConnection : IDisposable + { + private SQLiteDatabaseConnection db; + private readonly bool _closeOnDispose; + + public ManagedConnection(SQLiteDatabaseConnection db, bool closeOnDispose) + { + this.db = db; + _closeOnDispose = closeOnDispose; + } + + public IStatement PrepareStatement(string sql) + { + return db.PrepareStatement(sql); + } + + public IEnumerable PrepareAll(string sql) + { + return db.PrepareAll(sql); + } + + public void ExecuteAll(string sql) + { + db.ExecuteAll(sql); + } + + public void Execute(string sql, params object[] values) + { + db.Execute(sql, values); + } + + public void RunQueries(string[] sql) + { + db.RunQueries(sql); + } + + public void RunInTransaction(Action action, TransactionMode mode) + { + db.RunInTransaction(action, mode); + } + + public T RunInTransaction(Func action, TransactionMode mode) + { + return db.RunInTransaction(action, mode); + } + + public IEnumerable> Query(string sql) + { + return db.Query(sql); + } + + public IEnumerable> Query(string sql, params object[] values) + { + return db.Query(sql, values); + } + + public void Close() + { + using (db) + { + + } + } + + public void Dispose() + { + if (_closeOnDispose) + { + Close(); + } + } + } +} diff --git a/Emby.Server.Implementations/Migrations/LibraryScanMigration.cs b/Emby.Server.Implementations/Migrations/LibraryScanMigration.cs new file mode 100644 index 0000000000..c494abc0bb --- /dev/null +++ b/Emby.Server.Implementations/Migrations/LibraryScanMigration.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +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.Tasks; +using MediaBrowser.Model.Updates; +using System.Linq; + +namespace Emby.Server.Implementations.Migrations +{ + public class LibraryScanMigration : IVersionMigration + { + private readonly IServerConfigurationManager _config; + private readonly ITaskManager _taskManager; + + public LibraryScanMigration(IServerConfigurationManager config, ITaskManager taskManager) + { + _config = config; + _taskManager = taskManager; + } + + public async Task Run() + { + var name = "LibraryScan6"; + + if (!_config.Configuration.Migrations.Contains(name, StringComparer.OrdinalIgnoreCase)) + { + Task.Run(() => + { + var task = _taskManager.ScheduledTasks.Select(i => i.ScheduledTask) + .First(i => string.Equals(i.Key, "RefreshLibrary", StringComparison.OrdinalIgnoreCase)); + + _taskManager.QueueScheduledTask(task); + }); + + var list = _config.Configuration.Migrations.ToList(); + list.Add(name); + _config.Configuration.Migrations = list.ToArray(); + _config.SaveConfiguration(); + } + } + } +}