diff options
Diffstat (limited to 'Emby.Server.Implementations')
14 files changed, 423 insertions, 380 deletions
diff --git a/Emby.Server.Implementations/Activity/ActivityLogEntryPoint.cs b/Emby.Server.Implementations/Activity/ActivityLogEntryPoint.cs index aef72c6972..a8e8f815a0 100644 --- a/Emby.Server.Implementations/Activity/ActivityLogEntryPoint.cs +++ b/Emby.Server.Implementations/Activity/ActivityLogEntryPoint.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; -using System.Threading.Tasks; using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Plugins; using MediaBrowser.Common.Updates; @@ -93,18 +92,18 @@ namespace Emby.Server.Implementations.Activity _appHost.ApplicationUpdated += _appHost_ApplicationUpdated; } - async void _deviceManager_CameraImageUploaded(object sender, GenericEventArgs<CameraImageUploadInfo> e) + void _deviceManager_CameraImageUploaded(object sender, GenericEventArgs<CameraImageUploadInfo> e) { - await CreateLogEntry(new ActivityLogEntry + CreateLogEntry(new ActivityLogEntry { Name = string.Format(_localization.GetLocalizedString("CameraImageUploadedFrom"), e.Argument.Device.Name), Type = NotificationType.CameraImageUploaded.ToString() }); } - async void _userManager_UserLockedOut(object sender, GenericEventArgs<User> e) + void _userManager_UserLockedOut(object sender, GenericEventArgs<User> e) { - await CreateLogEntry(new ActivityLogEntry + CreateLogEntry(new ActivityLogEntry { Name = string.Format(_localization.GetLocalizedString("UserLockedOutWithName"), e.Argument.Name), Type = NotificationType.UserLockedOut.ToString(), @@ -112,9 +111,9 @@ namespace Emby.Server.Implementations.Activity }); } - async void _subManager_SubtitleDownloadFailure(object sender, SubtitleDownloadFailureEventArgs e) + void _subManager_SubtitleDownloadFailure(object sender, SubtitleDownloadFailureEventArgs e) { - await CreateLogEntry(new ActivityLogEntry + CreateLogEntry(new ActivityLogEntry { Name = string.Format(_localization.GetLocalizedString("SubtitleDownloadFailureFromForItem"), e.Provider, Notifications.Notifications.GetItemName(e.Item)), Type = "SubtitleDownloadFailure", @@ -123,7 +122,7 @@ namespace Emby.Server.Implementations.Activity }); } - async void _sessionManager_PlaybackStopped(object sender, PlaybackStopEventArgs e) + void _sessionManager_PlaybackStopped(object sender, PlaybackStopEventArgs e) { var item = e.MediaInfo; @@ -146,7 +145,7 @@ namespace Emby.Server.Implementations.Activity var user = e.Users.First(); - await CreateLogEntry(new ActivityLogEntry + CreateLogEntry(new ActivityLogEntry { Name = string.Format(_localization.GetLocalizedString("UserStoppedPlayingItemWithValues"), user.Name, GetItemName(item), e.DeviceName), Type = GetPlaybackStoppedNotificationType(item.MediaType), @@ -154,7 +153,7 @@ namespace Emby.Server.Implementations.Activity }); } - async void _sessionManager_PlaybackStart(object sender, PlaybackProgressEventArgs e) + void _sessionManager_PlaybackStart(object sender, PlaybackProgressEventArgs e) { var item = e.MediaInfo; @@ -177,7 +176,7 @@ namespace Emby.Server.Implementations.Activity var user = e.Users.First(); - await CreateLogEntry(new ActivityLogEntry + CreateLogEntry(new ActivityLogEntry { Name = string.Format(_localization.GetLocalizedString("UserStartedPlayingItemWithValues"), user.Name, GetItemName(item), e.DeviceName), Type = GetPlaybackNotificationType(item.MediaType), @@ -238,7 +237,7 @@ namespace Emby.Server.Implementations.Activity return null; } - async void _sessionManager_SessionEnded(object sender, SessionEventArgs e) + void _sessionManager_SessionEnded(object sender, SessionEventArgs e) { string name; var session = e.SessionInfo; @@ -255,7 +254,7 @@ namespace Emby.Server.Implementations.Activity name = string.Format(_localization.GetLocalizedString("UserOfflineFromDevice"), session.UserName, session.DeviceName); } - await CreateLogEntry(new ActivityLogEntry + CreateLogEntry(new ActivityLogEntry { Name = name, Type = "SessionEnded", @@ -264,11 +263,11 @@ namespace Emby.Server.Implementations.Activity }); } - async void _sessionManager_AuthenticationSucceeded(object sender, GenericEventArgs<AuthenticationResult> e) + void _sessionManager_AuthenticationSucceeded(object sender, GenericEventArgs<AuthenticationResult> e) { var user = e.Argument.User; - await CreateLogEntry(new ActivityLogEntry + CreateLogEntry(new ActivityLogEntry { Name = string.Format(_localization.GetLocalizedString("AuthenticationSucceededWithUserName"), user.Name), Type = "AuthenticationSucceeded", @@ -277,9 +276,9 @@ namespace Emby.Server.Implementations.Activity }); } - async void _sessionManager_AuthenticationFailed(object sender, GenericEventArgs<AuthenticationRequest> e) + void _sessionManager_AuthenticationFailed(object sender, GenericEventArgs<AuthenticationRequest> e) { - await CreateLogEntry(new ActivityLogEntry + CreateLogEntry(new ActivityLogEntry { Name = string.Format(_localization.GetLocalizedString("FailedLoginAttemptWithUserName"), e.Argument.Username), Type = "AuthenticationFailed", @@ -288,9 +287,9 @@ namespace Emby.Server.Implementations.Activity }); } - async void _appHost_ApplicationUpdated(object sender, GenericEventArgs<PackageVersionInfo> e) + void _appHost_ApplicationUpdated(object sender, GenericEventArgs<PackageVersionInfo> e) { - await CreateLogEntry(new ActivityLogEntry + CreateLogEntry(new ActivityLogEntry { Name = string.Format(_localization.GetLocalizedString("MessageApplicationUpdatedTo"), e.Argument.versionStr), Type = NotificationType.ApplicationUpdateInstalled.ToString(), @@ -298,27 +297,27 @@ namespace Emby.Server.Implementations.Activity }); } - async void _config_NamedConfigurationUpdated(object sender, ConfigurationUpdateEventArgs e) + void _config_NamedConfigurationUpdated(object sender, ConfigurationUpdateEventArgs e) { - await CreateLogEntry(new ActivityLogEntry + CreateLogEntry(new ActivityLogEntry { Name = string.Format(_localization.GetLocalizedString("MessageNamedServerConfigurationUpdatedWithValue"), e.Key), Type = "NamedConfigurationUpdated" }); } - async void _config_ConfigurationUpdated(object sender, EventArgs e) + void _config_ConfigurationUpdated(object sender, EventArgs e) { - await CreateLogEntry(new ActivityLogEntry + CreateLogEntry(new ActivityLogEntry { Name = _localization.GetLocalizedString("MessageServerConfigurationUpdated"), Type = "ServerConfigurationUpdated" }); } - async void _userManager_UserPolicyUpdated(object sender, GenericEventArgs<User> e) + void _userManager_UserPolicyUpdated(object sender, GenericEventArgs<User> e) { - await CreateLogEntry(new ActivityLogEntry + CreateLogEntry(new ActivityLogEntry { Name = string.Format(_localization.GetLocalizedString("UserPolicyUpdatedWithName"), e.Argument.Name), Type = "UserPolicyUpdated", @@ -326,18 +325,18 @@ namespace Emby.Server.Implementations.Activity }); } - async void _userManager_UserDeleted(object sender, GenericEventArgs<User> e) + void _userManager_UserDeleted(object sender, GenericEventArgs<User> e) { - await CreateLogEntry(new ActivityLogEntry + CreateLogEntry(new ActivityLogEntry { Name = string.Format(_localization.GetLocalizedString("UserDeletedWithName"), e.Argument.Name), Type = "UserDeleted" }); } - async void _userManager_UserPasswordChanged(object sender, GenericEventArgs<User> e) + void _userManager_UserPasswordChanged(object sender, GenericEventArgs<User> e) { - await CreateLogEntry(new ActivityLogEntry + CreateLogEntry(new ActivityLogEntry { Name = string.Format(_localization.GetLocalizedString("UserPasswordChangedWithName"), e.Argument.Name), Type = "UserPasswordChanged", @@ -345,9 +344,9 @@ namespace Emby.Server.Implementations.Activity }); } - async void _userManager_UserCreated(object sender, GenericEventArgs<User> e) + void _userManager_UserCreated(object sender, GenericEventArgs<User> e) { - await CreateLogEntry(new ActivityLogEntry + CreateLogEntry(new ActivityLogEntry { Name = string.Format(_localization.GetLocalizedString("UserCreatedWithName"), e.Argument.Name), Type = "UserCreated", @@ -355,9 +354,9 @@ namespace Emby.Server.Implementations.Activity }); } - async void _subManager_SubtitlesDownloaded(object sender, SubtitleDownloadEventArgs e) + void _subManager_SubtitlesDownloaded(object sender, SubtitleDownloadEventArgs e) { - await CreateLogEntry(new ActivityLogEntry + CreateLogEntry(new ActivityLogEntry { Name = string.Format(_localization.GetLocalizedString("SubtitlesDownloadedForItem"), Notifications.Notifications.GetItemName(e.Item)), Type = "SubtitlesDownloaded", @@ -366,7 +365,7 @@ namespace Emby.Server.Implementations.Activity }); } - async void _sessionManager_SessionStarted(object sender, SessionEventArgs e) + void _sessionManager_SessionStarted(object sender, SessionEventArgs e) { string name; var session = e.SessionInfo; @@ -383,7 +382,7 @@ namespace Emby.Server.Implementations.Activity name = string.Format(_localization.GetLocalizedString("UserOnlineFromDevice"), session.UserName, session.DeviceName); } - await CreateLogEntry(new ActivityLogEntry + CreateLogEntry(new ActivityLogEntry { Name = name, Type = "SessionStarted", @@ -392,9 +391,9 @@ namespace Emby.Server.Implementations.Activity }); } - async void _installationManager_PluginUpdated(object sender, GenericEventArgs<Tuple<IPlugin, PackageVersionInfo>> e) + void _installationManager_PluginUpdated(object sender, GenericEventArgs<Tuple<IPlugin, PackageVersionInfo>> e) { - await CreateLogEntry(new ActivityLogEntry + CreateLogEntry(new ActivityLogEntry { Name = string.Format(_localization.GetLocalizedString("PluginUpdatedWithName"), e.Argument.Item1.Name), Type = NotificationType.PluginUpdateInstalled.ToString(), @@ -403,18 +402,18 @@ namespace Emby.Server.Implementations.Activity }); } - async void _installationManager_PluginUninstalled(object sender, GenericEventArgs<IPlugin> e) + void _installationManager_PluginUninstalled(object sender, GenericEventArgs<IPlugin> e) { - await CreateLogEntry(new ActivityLogEntry + CreateLogEntry(new ActivityLogEntry { Name = string.Format(_localization.GetLocalizedString("PluginUninstalledWithName"), e.Argument.Name), Type = NotificationType.PluginUninstalled.ToString() }); } - async void _installationManager_PluginInstalled(object sender, GenericEventArgs<PackageVersionInfo> e) + void _installationManager_PluginInstalled(object sender, GenericEventArgs<PackageVersionInfo> e) { - await CreateLogEntry(new ActivityLogEntry + CreateLogEntry(new ActivityLogEntry { Name = string.Format(_localization.GetLocalizedString("PluginInstalledWithName"), e.Argument.name), Type = NotificationType.PluginInstalled.ToString(), @@ -422,11 +421,11 @@ namespace Emby.Server.Implementations.Activity }); } - async void _installationManager_PackageInstallationFailed(object sender, InstallationFailedEventArgs e) + void _installationManager_PackageInstallationFailed(object sender, InstallationFailedEventArgs e) { var installationInfo = e.InstallationInfo; - await CreateLogEntry(new ActivityLogEntry + CreateLogEntry(new ActivityLogEntry { Name = string.Format(_localization.GetLocalizedString("NameInstallFailed"), installationInfo.Name), Type = NotificationType.InstallationFailed.ToString(), @@ -435,7 +434,7 @@ namespace Emby.Server.Implementations.Activity }); } - async void _taskManager_TaskCompleted(object sender, TaskCompletionEventArgs e) + void _taskManager_TaskCompleted(object sender, TaskCompletionEventArgs e) { var result = e.Result; var task = e.Task; @@ -462,7 +461,7 @@ namespace Emby.Server.Implementations.Activity vals.Add(e.Result.LongErrorMessage); } - await CreateLogEntry(new ActivityLogEntry + CreateLogEntry(new ActivityLogEntry { Name = string.Format(_localization.GetLocalizedString("ScheduledTaskFailedWithName"), task.Name), Type = NotificationType.TaskFailed.ToString(), @@ -473,11 +472,11 @@ namespace Emby.Server.Implementations.Activity } } - private async Task CreateLogEntry(ActivityLogEntry entry) + private void CreateLogEntry(ActivityLogEntry entry) { try { - await _activityManager.CreateAsync(entry); + _activityManager.Create(entry); } catch { diff --git a/Emby.Server.Implementations/Activity/ActivityManager.cs b/Emby.Server.Implementations/Activity/ActivityManager.cs index 8fcacb0024..6febcc2f7b 100644 --- a/Emby.Server.Implementations/Activity/ActivityManager.cs +++ b/Emby.Server.Implementations/Activity/ActivityManager.cs @@ -1,10 +1,9 @@ using System; -using System.Collections.Generic; using System.Linq; -using System.Threading.Tasks; using MediaBrowser.Controller.Library; using MediaBrowser.Model.Activity; using MediaBrowser.Model.Events; +using MediaBrowser.Model.Querying; using Microsoft.Extensions.Logging; namespace Emby.Server.Implementations.Activity @@ -27,38 +26,20 @@ namespace Emby.Server.Implementations.Activity _userManager = userManager; } - public async Task CreateAsync(ActivityLogEntry entry) + public void Create(ActivityLogEntry entry) { entry.Date = DateTime.UtcNow; - await _repo.CreateAsync(entry); + _repo.Create(entry); EntryCreated?.Invoke(this, new GenericEventArgs<ActivityLogEntry>(entry)); } - public IEnumerable<ActivityLogEntry> GetActivityLogEntries(DateTime? minDate, bool? hasUserId, int? startIndex, int? limit) + public QueryResult<ActivityLogEntry> GetActivityLogEntries(DateTime? minDate, bool? hasUserId, int? startIndex, int? limit) { - var result = _repo.GetActivityLogEntries(); + var result = _repo.GetActivityLogEntries(minDate, hasUserId, startIndex, limit); - if (minDate.HasValue) - { - result = result.Where(x => x.Date >= minDate.Value); - } - if (hasUserId.HasValue) - { - result = result.Where(x => x.UserId != null && x.UserId != Guid.Empty); - } - if (startIndex.HasValue) - { - result = result.Where(x => x.Id >= startIndex.Value); - } - if (limit.HasValue) - { - result = result.Take(limit.Value); - } - - // Add images for each user - foreach (var item in result) + foreach (var item in result.Items.Where(i => !i.UserId.Equals(Guid.Empty))) { var user = _userManager.GetUserById(item.UserId); @@ -69,7 +50,12 @@ namespace Emby.Server.Implementations.Activity } } - return result.AsEnumerable(); + return result; + } + + public QueryResult<ActivityLogEntry> GetActivityLogEntries(DateTime? minDate, int? startIndex, int? limit) + { + return GetActivityLogEntries(minDate, null, startIndex, limit); } } } diff --git a/Emby.Server.Implementations/Activity/ActivityRepository.cs b/Emby.Server.Implementations/Activity/ActivityRepository.cs index af0b20d921..aeed8b6f1a 100644 --- a/Emby.Server.Implementations/Activity/ActivityRepository.cs +++ b/Emby.Server.Implementations/Activity/ActivityRepository.cs @@ -1,37 +1,310 @@ +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.Model.Activity; -using Microsoft.EntityFrameworkCore; +using MediaBrowser.Model.IO; +using MediaBrowser.Model.Querying; +using Microsoft.Extensions.Logging; +using SQLitePCL.pretty; namespace Emby.Server.Implementations.Activity { - public class ActivityRepository : DbContext, IActivityRepository + public class ActivityRepository : BaseSqliteRepository, IActivityRepository { - protected string _dataDirPath; + private readonly CultureInfo _usCulture = new CultureInfo("en-US"); + protected IFileSystem FileSystem { get; private set; } - public DbSet<ActivityLogEntry> ActivityLogs { get; set; } + public ActivityRepository(ILoggerFactory loggerFactory, IServerApplicationPaths appPaths, IFileSystem fileSystem) + : base(loggerFactory.CreateLogger(nameof(ActivityRepository))) + { + DbFilePath = Path.Combine(appPaths.DataPath, "activitylog.db"); + FileSystem = fileSystem; + } - public ActivityRepository(string dataDirPath) + public void Initialize() { - _dataDirPath = dataDirPath; + try + { + InitializeInternal(); + } + catch (Exception ex) + { + Logger.LogError(ex, "Error loading database file. Will reset and retry."); + + FileSystem.DeleteFile(DbFilePath); + + InitializeInternal(); + } } - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + private void InitializeInternal() { - // Ensure the dir exists - Directory.CreateDirectory(_dataDirPath); + using (var connection = CreateConnection()) + { + RunDefaultInitialization(connection); + + connection.RunQueries(new[] + { + "create table if not exists ActivityLog (Id INTEGER PRIMARY KEY, Name TEXT NOT NULL, Overview TEXT, ShortOverview TEXT, Type TEXT NOT NULL, ItemId TEXT, UserId TEXT, DateCreated DATETIME NOT NULL, LogSeverity TEXT NOT NULL)", + "drop index if exists idx_ActivityLogEntries" + }); + + TryMigrate(connection); + } + } - optionsBuilder.UseSqlite($"Filename={Path.Combine(_dataDirPath, "activitylog.sqlite.db")}"); + private void TryMigrate(ManagedConnection connection) + { + try + { + if (TableExists(connection, "ActivityLogEntries")) + { + connection.RunQueries(new[] + { + "INSERT INTO ActivityLog (Name, Overview, ShortOverview, Type, ItemId, UserId, DateCreated, LogSeverity) SELECT Name, Overview, ShortOverview, Type, ItemId, UserId, DateCreated, LogSeverity FROM ActivityLogEntries", + "drop table if exists ActivityLogEntries" + }); + } + } + catch (Exception ex) + { + Logger.LogError(ex, "Error migrating activity log database"); + } } - public async Task CreateAsync(ActivityLogEntry entry) + private const string BaseActivitySelectText = "select Id, Name, Overview, ShortOverview, Type, ItemId, UserId, DateCreated, LogSeverity from ActivityLog"; + + public void Create(ActivityLogEntry entry) { - await ActivityLogs.AddAsync(entry); - await SaveChangesAsync(); + if (entry == null) + { + throw new ArgumentNullException(nameof(entry)); + } + + using (WriteLock.Write()) + using (var connection = CreateConnection()) + { + connection.RunInTransaction(db => + { + using (var statement = db.PrepareStatement("insert into ActivityLog (Name, Overview, ShortOverview, Type, ItemId, UserId, DateCreated, LogSeverity) values (@Name, @Overview, @ShortOverview, @Type, @ItemId, @UserId, @DateCreated, @LogSeverity)")) + { + statement.TryBind("@Name", entry.Name); + + statement.TryBind("@Overview", entry.Overview); + statement.TryBind("@ShortOverview", entry.ShortOverview); + statement.TryBind("@Type", entry.Type); + statement.TryBind("@ItemId", entry.ItemId); + + if (entry.UserId.Equals(Guid.Empty)) + { + statement.TryBindNull("@UserId"); + } + else + { + statement.TryBind("@UserId", entry.UserId.ToString("N")); + } + + statement.TryBind("@DateCreated", entry.Date.ToDateTimeParamValue()); + statement.TryBind("@LogSeverity", entry.Severity.ToString()); + + statement.MoveNext(); + } + }, TransactionMode); + } + } + + public void Update(ActivityLogEntry entry) + { + if (entry == null) + { + throw new ArgumentNullException(nameof(entry)); + } + + using (WriteLock.Write()) + using (var connection = CreateConnection()) + { + connection.RunInTransaction(db => + { + using (var statement = db.PrepareStatement("Update ActivityLog set Name=@Name,Overview=@Overview,ShortOverview=@ShortOverview,Type=@Type,ItemId=@ItemId,UserId=@UserId,DateCreated=@DateCreated,LogSeverity=@LogSeverity where Id=@Id")) + { + statement.TryBind("@Id", entry.Id); + + statement.TryBind("@Name", entry.Name); + statement.TryBind("@Overview", entry.Overview); + statement.TryBind("@ShortOverview", entry.ShortOverview); + statement.TryBind("@Type", entry.Type); + statement.TryBind("@ItemId", entry.ItemId); + + if (entry.UserId.Equals(Guid.Empty)) + { + statement.TryBindNull("@UserId"); + } + else + { + statement.TryBind("@UserId", entry.UserId.ToString("N")); + } + + statement.TryBind("@DateCreated", entry.Date.ToDateTimeParamValue()); + statement.TryBind("@LogSeverity", entry.Severity.ToString()); + + statement.MoveNext(); + } + }, TransactionMode); + } + } + + public QueryResult<ActivityLogEntry> GetActivityLogEntries(DateTime? minDate, bool? hasUserId, int? startIndex, int? limit) + { + using (WriteLock.Read()) + using (var connection = CreateConnection(true)) + { + var commandText = BaseActivitySelectText; + var whereClauses = new List<string>(); + + if (minDate.HasValue) + { + whereClauses.Add("DateCreated>=@DateCreated"); + } + if (hasUserId.HasValue) + { + if (hasUserId.Value) + { + whereClauses.Add("UserId not null"); + } + else + { + whereClauses.Add("UserId is null"); + } + } + + var whereTextWithoutPaging = whereClauses.Count == 0 ? + string.Empty : + " where " + string.Join(" AND ", whereClauses.ToArray()); + + if (startIndex.HasValue && startIndex.Value > 0) + { + var pagingWhereText = whereClauses.Count == 0 ? + string.Empty : + " where " + string.Join(" AND ", whereClauses.ToArray()); + + whereClauses.Add(string.Format("Id NOT IN (SELECT Id FROM ActivityLog {0} ORDER BY DateCreated DESC LIMIT {1})", + pagingWhereText, + startIndex.Value.ToString(_usCulture))); + } + + var whereText = whereClauses.Count == 0 ? + string.Empty : + " where " + string.Join(" AND ", whereClauses.ToArray()); + + commandText += whereText; + + commandText += " ORDER BY DateCreated DESC"; + + if (limit.HasValue) + { + commandText += " LIMIT " + limit.Value.ToString(_usCulture); + } + + var statementTexts = new List<string>(); + statementTexts.Add(commandText); + statementTexts.Add("select count (Id) from ActivityLog" + whereTextWithoutPaging); + + return connection.RunInTransaction(db => + { + var list = new List<ActivityLogEntry>(); + var result = new QueryResult<ActivityLogEntry>(); + + var statements = PrepareAllSafe(db, statementTexts).ToList(); + + using (var statement = statements[0]) + { + if (minDate.HasValue) + { + statement.TryBind("@DateCreated", minDate.Value.ToDateTimeParamValue()); + } + + foreach (var row in statement.ExecuteQuery()) + { + list.Add(GetEntry(row)); + } + } + + using (var statement = statements[1]) + { + if (minDate.HasValue) + { + statement.TryBind("@DateCreated", minDate.Value.ToDateTimeParamValue()); + } + + result.TotalRecordCount = statement.ExecuteQuery().SelectScalarInt().First(); + } + + result.Items = list.ToArray(); + return result; + + }, ReadTransactionMode); + } } - public IQueryable<ActivityLogEntry> GetActivityLogEntries() - => ActivityLogs; + private static ActivityLogEntry GetEntry(IReadOnlyList<IResultSetValue> reader) + { + var index = 0; + + var info = new ActivityLogEntry + { + Id = reader[index].ToInt64() + }; + + index++; + if (reader[index].SQLiteType != SQLiteType.Null) + { + info.Name = reader[index].ToString(); + } + + index++; + if (reader[index].SQLiteType != SQLiteType.Null) + { + info.Overview = reader[index].ToString(); + } + + index++; + if (reader[index].SQLiteType != SQLiteType.Null) + { + info.ShortOverview = reader[index].ToString(); + } + + index++; + if (reader[index].SQLiteType != SQLiteType.Null) + { + info.Type = reader[index].ToString(); + } + + index++; + if (reader[index].SQLiteType != SQLiteType.Null) + { + info.ItemId = reader[index].ToString(); + } + + index++; + if (reader[index].SQLiteType != SQLiteType.Null) + { + info.UserId = new Guid(reader[index].ToString()); + } + + index++; + info.Date = reader[index].ReadDateTime(); + + index++; + if (reader[index].SQLiteType != SQLiteType.Null) + { + info.Severity = (LogLevel)Enum.Parse(typeof(LogLevel), reader[index].ToString(), true); + } + + return info; + } } } diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index f29e732da9..25544cdaea 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -244,8 +244,6 @@ namespace Emby.Server.Implementations /// </summary> protected readonly SimpleInjector.Container Container = new SimpleInjector.Container(); - protected ISystemEvents SystemEvents { get; set; } - /// <summary> /// Gets the server configuration manager. /// </summary> @@ -371,7 +369,6 @@ namespace Emby.Server.Implementations IFileSystem fileSystem, IEnvironmentInfo environmentInfo, IImageEncoder imageEncoder, - ISystemEvents systemEvents, INetworkManager networkManager) { @@ -383,7 +380,6 @@ namespace Emby.Server.Implementations NetworkManager = networkManager; networkManager.LocalSubnetsFn = GetConfiguredLocalSubnets; EnvironmentInfo = environmentInfo; - SystemEvents = systemEvents; ApplicationPaths = applicationPaths; LoggerFactory = loggerFactory; @@ -708,7 +704,7 @@ namespace Emby.Server.Implementations } } - public async Task InitAsync() + public void Init() { HttpPort = ServerConfigurationManager.Configuration.HttpServerPortNumber; HttpsPort = ServerConfigurationManager.Configuration.HttpsPortNumber; @@ -738,7 +734,7 @@ namespace Emby.Server.Implementations SetHttpLimit(); - await RegisterResourcesAsync(); + RegisterResources(); FindParts(); } @@ -753,7 +749,7 @@ namespace Emby.Server.Implementations /// <summary> /// Registers resources that classes will depend on /// </summary> - protected async Task RegisterResourcesAsync() + protected void RegisterResources() { RegisterSingleInstance(ConfigurationManager); RegisterSingleInstance<IApplicationHost>(this); @@ -761,7 +757,6 @@ namespace Emby.Server.Implementations RegisterSingleInstance<IApplicationPaths>(ApplicationPaths); RegisterSingleInstance(JsonSerializer); - RegisterSingleInstance(SystemEvents); RegisterSingleInstance(LoggerFactory, false); RegisterSingleInstance(Logger); @@ -778,7 +773,7 @@ namespace Emby.Server.Implementations IsoManager = new IsoManager(); RegisterSingleInstance(IsoManager); - TaskManager = new TaskManager(ApplicationPaths, JsonSerializer, LoggerFactory, FileSystemManager, SystemEvents); + TaskManager = new TaskManager(ApplicationPaths, JsonSerializer, LoggerFactory, FileSystemManager); RegisterSingleInstance(TaskManager); RegisterSingleInstance(XmlSerializer); @@ -852,7 +847,7 @@ namespace Emby.Server.Implementations var musicManager = new MusicManager(LibraryManager); RegisterSingleInstance<IMusicManager>(new MusicManager(LibraryManager)); - LibraryMonitor = new LibraryMonitor(LoggerFactory, TaskManager, LibraryManager, ServerConfigurationManager, FileSystemManager, TimerFactory, SystemEvents, EnvironmentInfo); + LibraryMonitor = new LibraryMonitor(LoggerFactory, TaskManager, LibraryManager, ServerConfigurationManager, FileSystemManager, TimerFactory, EnvironmentInfo); RegisterSingleInstance(LibraryMonitor); RegisterSingleInstance<ISearchEngine>(() => new SearchEngine(LoggerFactory, LibraryManager, UserManager)); @@ -930,7 +925,7 @@ namespace Emby.Server.Implementations EncodingManager = new MediaEncoder.EncodingManager(FileSystemManager, LoggerFactory, MediaEncoder, ChapterManager, LibraryManager); RegisterSingleInstance(EncodingManager); - var activityLogRepo = await GetActivityLogRepositoryAsync(); + var activityLogRepo = GetActivityLogRepository(); RegisterSingleInstance(activityLogRepo); RegisterSingleInstance<IActivityManager>(new ActivityManager(LoggerFactory, activityLogRepo, UserManager)); @@ -1145,11 +1140,11 @@ namespace Emby.Server.Implementations return repo; } - private async Task<IActivityRepository> GetActivityLogRepositoryAsync() + private IActivityRepository GetActivityLogRepository() { - var repo = new ActivityRepository(ServerConfigurationManager.ApplicationPaths.DataPath); + var repo = new ActivityRepository(LoggerFactory, ServerConfigurationManager.ApplicationPaths, FileSystemManager); - await repo.Database.EnsureCreatedAsync(); + repo.Initialize(); return repo; } diff --git a/Emby.Server.Implementations/Dto/DtoService.cs b/Emby.Server.Implementations/Dto/DtoService.cs index 13febc2140..d0a7de11d7 100644 --- a/Emby.Server.Implementations/Dto/DtoService.cs +++ b/Emby.Server.Implementations/Dto/DtoService.cs @@ -1428,7 +1428,7 @@ namespace Emby.Server.Implementations.Dto var supportedEnhancers = _imageProcessor.GetSupportedEnhancers(item, ImageType.Primary); - ImageSize size; + ImageDimensions size; var defaultAspectRatio = item.GetDefaultPrimaryImageAspectRatio(); @@ -1439,9 +1439,9 @@ namespace Emby.Server.Implementations.Dto return defaultAspectRatio; } - double dummyWidth = 200; - double dummyHeight = dummyWidth / defaultAspectRatio; - size = new ImageSize(dummyWidth, dummyHeight); + int dummyWidth = 200; + int dummyHeight = Convert.ToInt32(dummyWidth / defaultAspectRatio); + size = new ImageDimensions(dummyWidth, dummyHeight); } else { @@ -1481,7 +1481,7 @@ namespace Emby.Server.Implementations.Dto var width = size.Width; var height = size.Height; - if (width.Equals(0) || height.Equals(0)) + if (width <= 0 || height <= 0) { return null; } diff --git a/Emby.Server.Implementations/Emby.Server.Implementations.csproj b/Emby.Server.Implementations/Emby.Server.Implementations.csproj index f2a5b2e386..3aa617b021 100644 --- a/Emby.Server.Implementations/Emby.Server.Implementations.csproj +++ b/Emby.Server.Implementations/Emby.Server.Implementations.csproj @@ -22,7 +22,6 @@ </ItemGroup> <ItemGroup> - <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.0" /> <PackageReference Include="ServiceStack.Text.Core" Version="5.4.0" /> <PackageReference Include="sharpcompress" Version="0.22.0" /> <PackageReference Include="SimpleInjector" Version="4.4.2" /> diff --git a/Emby.Server.Implementations/EntryPoints/SystemEvents.cs b/Emby.Server.Implementations/EntryPoints/SystemEvents.cs deleted file mode 100644 index 72c8acd9f0..0000000000 --- a/Emby.Server.Implementations/EntryPoints/SystemEvents.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using MediaBrowser.Controller; -using MediaBrowser.Controller.Plugins; -using MediaBrowser.Model.System; - -namespace Emby.Server.Implementations.EntryPoints -{ - public class SystemEvents : IServerEntryPoint - { - private readonly ISystemEvents _systemEvents; - private readonly IServerApplicationHost _appHost; - - public SystemEvents(ISystemEvents systemEvents, IServerApplicationHost appHost) - { - _systemEvents = systemEvents; - _appHost = appHost; - } - - public void Run() - { - _systemEvents.SystemShutdown += _systemEvents_SystemShutdown; - } - - private void _systemEvents_SystemShutdown(object sender, EventArgs e) - { - _appHost.Shutdown(); - } - - public void Dispose() - { - _systemEvents.SystemShutdown -= _systemEvents_SystemShutdown; - } - } -} diff --git a/Emby.Server.Implementations/IO/LibraryMonitor.cs b/Emby.Server.Implementations/IO/LibraryMonitor.cs index 6a32040110..204f9d949f 100644 --- a/Emby.Server.Implementations/IO/LibraryMonitor.cs +++ b/Emby.Server.Implementations/IO/LibraryMonitor.cs @@ -140,7 +140,14 @@ namespace Emby.Server.Implementations.IO /// <summary> /// Initializes a new instance of the <see cref="LibraryMonitor" /> class. /// </summary> - public LibraryMonitor(ILoggerFactory loggerFactory, ITaskManager taskManager, ILibraryManager libraryManager, IServerConfigurationManager configurationManager, IFileSystem fileSystem, ITimerFactory timerFactory, ISystemEvents systemEvents, IEnvironmentInfo environmentInfo) + public LibraryMonitor( + ILoggerFactory loggerFactory, + ITaskManager taskManager, + ILibraryManager libraryManager, + IServerConfigurationManager configurationManager, + IFileSystem fileSystem, + ITimerFactory timerFactory, + IEnvironmentInfo environmentInfo) { if (taskManager == null) { @@ -154,26 +161,9 @@ namespace Emby.Server.Implementations.IO _fileSystem = fileSystem; _timerFactory = timerFactory; _environmentInfo = environmentInfo; - - systemEvents.Resume += _systemEvents_Resume; - } - - private void _systemEvents_Resume(object sender, EventArgs e) - { - Restart(); - } - - private void Restart() - { - Stop(); - - if (!_disposed) - { - Start(); - } } - private bool IsLibraryMonitorEnabaled(BaseItem item) + private bool IsLibraryMonitorEnabled(BaseItem item) { if (item is BasePluginFolder) { @@ -200,7 +190,7 @@ namespace Emby.Server.Implementations.IO var paths = LibraryManager .RootFolder .Children - .Where(IsLibraryMonitorEnabaled) + .Where(IsLibraryMonitorEnabled) .OfType<Folder>() .SelectMany(f => f.PhysicalLocations) .Distinct(StringComparer.OrdinalIgnoreCase) @@ -223,7 +213,7 @@ namespace Emby.Server.Implementations.IO private void StartWatching(BaseItem item) { - if (IsLibraryMonitorEnabaled(item)) + if (IsLibraryMonitorEnabled(item)) { StartWatchingPath(item.Path); } diff --git a/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs b/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs index 9e11494c99..4805e54ddf 100644 --- a/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs +++ b/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs @@ -60,7 +60,6 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV private readonly IProviderManager _providerManager; private readonly IMediaEncoder _mediaEncoder; private readonly IProcessFactory _processFactory; - private readonly ISystemEvents _systemEvents; private readonly IAssemblyInfo _assemblyInfo; private IMediaSourceManager _mediaSourceManager; @@ -90,8 +89,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV IProviderManager providerManager, IMediaEncoder mediaEncoder, ITimerFactory timerFactory, - IProcessFactory processFactory, - ISystemEvents systemEvents) + IProcessFactory processFactory) { Current = this; @@ -105,7 +103,6 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV _providerManager = providerManager; _mediaEncoder = mediaEncoder; _processFactory = processFactory; - _systemEvents = systemEvents; _liveTvManager = (LiveTvManager)liveTvManager; _jsonSerializer = jsonSerializer; _assemblyInfo = assemblyInfo; @@ -131,15 +128,9 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV { _timerProvider.RestartTimers(); - _systemEvents.Resume += _systemEvents_Resume; await CreateRecordingFolders().ConfigureAwait(false); } - private void _systemEvents_Resume(object sender, EventArgs e) - { - _timerProvider.RestartTimers(); - } - private async void OnRecordingFoldersChanged() { await CreateRecordingFolders().ConfigureAwait(false); diff --git a/Emby.Server.Implementations/Localization/LocalizationManager.cs b/Emby.Server.Implementations/Localization/LocalizationManager.cs index af05cd7d7a..c408a47f62 100644 --- a/Emby.Server.Implementations/Localization/LocalizationManager.cs +++ b/Emby.Server.Implementations/Localization/LocalizationManager.cs @@ -502,58 +502,55 @@ namespace Emby.Server.Implementations.Localization return culture + ".json"; } - public LocalizatonOption[] GetLocalizationOptions() - { - return new LocalizatonOption[] + public LocalizationOption[] GetLocalizationOptions() + => new LocalizationOption[] { - new LocalizatonOption{ Name="Arabic", Value="ar"}, - new LocalizatonOption{ Name="Belarusian (Belarus)", Value="be-BY"}, - new LocalizatonOption{ Name="Bulgarian (Bulgaria)", Value="bg-BG"}, - new LocalizatonOption{ Name="Catalan", Value="ca"}, - new LocalizatonOption{ Name="Chinese Simplified", Value="zh-CN"}, - new LocalizatonOption{ Name="Chinese Traditional", Value="zh-TW"}, - new LocalizatonOption{ Name="Chinese Traditional (Hong Kong)", Value="zh-HK"}, - new LocalizatonOption{ Name="Croatian", Value="hr"}, - new LocalizatonOption{ Name="Czech", Value="cs"}, - new LocalizatonOption{ Name="Danish", Value="da"}, - new LocalizatonOption{ Name="Dutch", Value="nl"}, - new LocalizatonOption{ Name="English (United Kingdom)", Value="en-GB"}, - new LocalizatonOption{ Name="English (United States)", Value="en-US"}, - new LocalizatonOption{ Name="Finnish", Value="fi"}, - new LocalizatonOption{ Name="French", Value="fr"}, - new LocalizatonOption{ Name="French (Canada)", Value="fr-CA"}, - new LocalizatonOption{ Name="German", Value="de"}, - new LocalizatonOption{ Name="Greek", Value="el"}, - new LocalizatonOption{ Name="Hebrew", Value="he"}, - new LocalizatonOption{ Name="Hindi (India)", Value="hi-IN"}, - new LocalizatonOption{ Name="Hungarian", Value="hu"}, - new LocalizatonOption{ Name="Indonesian", Value="id"}, - new LocalizatonOption{ Name="Italian", Value="it"}, - new LocalizatonOption{ Name="Japanese", Value="ja"}, - new LocalizatonOption{ Name="Kazakh", Value="kk"}, - new LocalizatonOption{ Name="Korean", Value="ko"}, - new LocalizatonOption{ Name="Lithuanian", Value="lt-LT"}, - new LocalizatonOption{ Name="Malay", Value="ms"}, - new LocalizatonOption{ Name="Norwegian Bokmål", Value="nb"}, - new LocalizatonOption{ Name="Persian", Value="fa"}, - new LocalizatonOption{ Name="Polish", Value="pl"}, - new LocalizatonOption{ Name="Portuguese (Brazil)", Value="pt-BR"}, - new LocalizatonOption{ Name="Portuguese (Portugal)", Value="pt-PT"}, - new LocalizatonOption{ Name="Romanian", Value="ro"}, - new LocalizatonOption{ Name="Russian", Value="ru"}, - new LocalizatonOption{ Name="Slovak", Value="sk"}, - new LocalizatonOption{ Name="Slovenian (Slovenia)", Value="sl-SI"}, - new LocalizatonOption{ Name="Spanish", Value="es"}, - new LocalizatonOption{ Name="Spanish (Latin America)", Value="es-419"}, - new LocalizatonOption{ Name="Spanish (Mexico)", Value="es-MX"}, - new LocalizatonOption{ Name="Swedish", Value="sv"}, - new LocalizatonOption{ Name="Swiss German", Value="gsw"}, - new LocalizatonOption{ Name="Turkish", Value="tr"}, - new LocalizatonOption{ Name="Ukrainian", Value="uk"}, - new LocalizatonOption{ Name="Vietnamese", Value="vi"} - + new LocalizationOption("Arabic", "ar"), + new LocalizationOption("Belarusian (Belarus)", "be-BY"), + new LocalizationOption("Bulgarian (Bulgaria)", "bg-BG"), + new LocalizationOption("Catalan", "ca"), + new LocalizationOption("Chinese Simplified", "zh-CN"), + new LocalizationOption("Chinese Traditional", "zh-TW"), + new LocalizationOption("Chinese Traditional (Hong Kong)", "zh-HK"), + new LocalizationOption("Croatian", "hr"), + new LocalizationOption("Czech", "cs"), + new LocalizationOption("Danish", "da"), + new LocalizationOption("Dutch", "nl"), + new LocalizationOption("English (United Kingdom)", "en-GB"), + new LocalizationOption("English (United States)", "en-US"), + new LocalizationOption("Finnish", "fi"), + new LocalizationOption("French", "fr"), + new LocalizationOption("French (Canada)", "fr-CA"), + new LocalizationOption("German", "de"), + new LocalizationOption("Greek", "el"), + new LocalizationOption("Hebrew", "he"), + new LocalizationOption("Hindi (India)", "hi-IN"), + new LocalizationOption("Hungarian", "hu"), + new LocalizationOption("Indonesian", "id"), + new LocalizationOption("Italian", "it"), + new LocalizationOption("Japanese", "ja"), + new LocalizationOption("Kazakh", "kk"), + new LocalizationOption("Korean", "ko"), + new LocalizationOption("Lithuanian", "lt-LT"), + new LocalizationOption("Malay", "ms"), + new LocalizationOption("Norwegian Bokmål", "nb"), + new LocalizationOption("Persian", "fa"), + new LocalizationOption("Polish", "pl"), + new LocalizationOption("Portuguese (Brazil)", "pt-BR"), + new LocalizationOption("Portuguese (Portugal)", "pt-PT"), + new LocalizationOption("Romanian", "ro"), + new LocalizationOption("Russian", "ru"), + new LocalizationOption("Slovak", "sk"), + new LocalizationOption("Slovenian (Slovenia)", "sl-SI"), + new LocalizationOption("Spanish", "es"), + new LocalizationOption("Spanish (Latin America)", "es-419"), + new LocalizationOption("Spanish (Mexico)", "es-MX"), + new LocalizationOption("Swedish", "sv"), + new LocalizationOption("Swiss German", "gsw"), + new LocalizationOption("Turkish", "tr"), + new LocalizationOption("Ukrainian", "uk"), + new LocalizationOption("Vietnamese", "vi") }; - } } public interface ITextLocalizer diff --git a/Emby.Server.Implementations/ScheduledTasks/ScheduledTaskWorker.cs b/Emby.Server.Implementations/ScheduledTasks/ScheduledTaskWorker.cs index 44f6e2d7b3..93a9a0d814 100644 --- a/Emby.Server.Implementations/ScheduledTasks/ScheduledTaskWorker.cs +++ b/Emby.Server.Implementations/ScheduledTasks/ScheduledTaskWorker.cs @@ -53,7 +53,6 @@ namespace Emby.Server.Implementations.ScheduledTasks /// <value>The task manager.</value> private ITaskManager TaskManager { get; set; } private readonly IFileSystem _fileSystem; - private readonly ISystemEvents _systemEvents; /// <summary> /// Initializes a new instance of the <see cref="ScheduledTaskWorker" /> class. @@ -74,7 +73,7 @@ namespace Emby.Server.Implementations.ScheduledTasks /// or /// logger /// </exception> - public ScheduledTaskWorker(IScheduledTask scheduledTask, IApplicationPaths applicationPaths, ITaskManager taskManager, IJsonSerializer jsonSerializer, ILogger logger, IFileSystem fileSystem, ISystemEvents systemEvents) + public ScheduledTaskWorker(IScheduledTask scheduledTask, IApplicationPaths applicationPaths, ITaskManager taskManager, IJsonSerializer jsonSerializer, ILogger logger, IFileSystem fileSystem) { if (scheduledTask == null) { @@ -103,7 +102,6 @@ namespace Emby.Server.Implementations.ScheduledTasks JsonSerializer = jsonSerializer; Logger = logger; _fileSystem = fileSystem; - _systemEvents = systemEvents; InitTriggerEvents(); } @@ -762,20 +760,6 @@ namespace Emby.Server.Implementations.ScheduledTasks }; } - if (info.Type.Equals(typeof(SystemEventTrigger).Name, StringComparison.OrdinalIgnoreCase)) - { - if (!info.SystemEvent.HasValue) - { - throw new ArgumentException("Info did not contain a SystemEvent.", nameof(info)); - } - - return new SystemEventTrigger(_systemEvents) - { - SystemEvent = info.SystemEvent.Value, - TaskOptions = options - }; - } - if (info.Type.Equals(typeof(StartupTrigger).Name, StringComparison.OrdinalIgnoreCase)) { return new StartupTrigger(); diff --git a/Emby.Server.Implementations/ScheduledTasks/SystemEventTrigger.cs b/Emby.Server.Implementations/ScheduledTasks/SystemEventTrigger.cs deleted file mode 100644 index 7a88fc2b01..0000000000 --- a/Emby.Server.Implementations/ScheduledTasks/SystemEventTrigger.cs +++ /dev/null @@ -1,82 +0,0 @@ -using System; -using System.Threading.Tasks; -using MediaBrowser.Model.System; -using MediaBrowser.Model.Tasks; -using Microsoft.Extensions.Logging; - -namespace Emby.Server.Implementations.ScheduledTasks -{ - /// <summary> - /// Class SystemEventTrigger - /// </summary> - public class SystemEventTrigger : ITaskTrigger - { - /// <summary> - /// Gets or sets the system event. - /// </summary> - /// <value>The system event.</value> - public SystemEvent SystemEvent { get; set; } - - /// <summary> - /// Gets or sets the options of this task. - /// </summary> - public TaskOptions TaskOptions { get; set; } - - private readonly ISystemEvents _systemEvents; - - public SystemEventTrigger(ISystemEvents systemEvents) - { - _systemEvents = systemEvents; - } - - /// <summary> - /// Stars waiting for the trigger action - /// </summary> - /// <param name="lastResult">The last result.</param> - /// <param name="isApplicationStartup">if set to <c>true</c> [is application startup].</param> - public void Start(TaskResult lastResult, ILogger logger, string taskName, bool isApplicationStartup) - { - switch (SystemEvent) - { - case SystemEvent.WakeFromSleep: - _systemEvents.Resume += _systemEvents_Resume; - break; - } - } - - private async void _systemEvents_Resume(object sender, EventArgs e) - { - if (SystemEvent == SystemEvent.WakeFromSleep) - { - // This value is a bit arbitrary, but add a delay to help ensure network connections have been restored before running the task - await Task.Delay(10000).ConfigureAwait(false); - - OnTriggered(); - } - } - - /// <summary> - /// Stops waiting for the trigger action - /// </summary> - public void Stop() - { - _systemEvents.Resume -= _systemEvents_Resume; - } - - /// <summary> - /// Occurs when [triggered]. - /// </summary> - public event EventHandler<EventArgs> Triggered; - - /// <summary> - /// Called when [triggered]. - /// </summary> - private void OnTriggered() - { - if (Triggered != null) - { - Triggered(this, EventArgs.Empty); - } - } - } -} diff --git a/Emby.Server.Implementations/ScheduledTasks/TaskManager.cs b/Emby.Server.Implementations/ScheduledTasks/TaskManager.cs index 02a082d3fb..d74c8fe8c9 100644 --- a/Emby.Server.Implementations/ScheduledTasks/TaskManager.cs +++ b/Emby.Server.Implementations/ScheduledTasks/TaskManager.cs @@ -46,8 +46,6 @@ namespace Emby.Server.Implementations.ScheduledTasks /// <value>The application paths.</value> private IApplicationPaths ApplicationPaths { get; set; } - private readonly ISystemEvents _systemEvents; - /// <summary> /// Gets the logger. /// </summary> @@ -66,54 +64,16 @@ namespace Emby.Server.Implementations.ScheduledTasks IApplicationPaths applicationPaths, IJsonSerializer jsonSerializer, ILoggerFactory loggerFactory, - IFileSystem fileSystem, - ISystemEvents systemEvents) + IFileSystem fileSystem) { ApplicationPaths = applicationPaths; JsonSerializer = jsonSerializer; Logger = loggerFactory.CreateLogger(nameof(TaskManager)); _fileSystem = fileSystem; - _systemEvents = systemEvents; ScheduledTasks = new IScheduledTaskWorker[] { }; } - private void BindToSystemEvent() - { - _systemEvents.Resume += _systemEvents_Resume; - } - - private void _systemEvents_Resume(object sender, EventArgs e) - { - foreach (var task in ScheduledTasks) - { - task.ReloadTriggerEvents(); - } - } - - public void RunTaskOnNextStartup(string key) - { - var path = Path.Combine(ApplicationPaths.CachePath, "startuptasks.txt"); - - List<string> lines; - - try - { - lines = _fileSystem.ReadAllLines(path).ToList(); - } - catch - { - lines = new List<string>(); - } - - if (!lines.Contains(key, StringComparer.OrdinalIgnoreCase)) - { - lines.Add(key); - _fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(path)); - _fileSystem.WriteAllLines(path, lines); - } - } - private void RunStartupTasks() { var path = Path.Combine(ApplicationPaths.CachePath, "startuptasks.txt"); @@ -290,12 +250,10 @@ namespace Emby.Server.Implementations.ScheduledTasks var myTasks = ScheduledTasks.ToList(); var list = tasks.ToList(); - myTasks.AddRange(list.Select(t => new ScheduledTaskWorker(t, ApplicationPaths, this, JsonSerializer, Logger, _fileSystem, _systemEvents))); + myTasks.AddRange(list.Select(t => new ScheduledTaskWorker(t, ApplicationPaths, this, JsonSerializer, Logger, _fileSystem))); ScheduledTasks = myTasks.ToArray(); - BindToSystemEvent(); - RunStartupTasks(); } diff --git a/Emby.Server.Implementations/SystemEvents.cs b/Emby.Server.Implementations/SystemEvents.cs deleted file mode 100644 index e4c54c3c52..0000000000 --- a/Emby.Server.Implementations/SystemEvents.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using MediaBrowser.Model.System; - -namespace Emby.Server.Implementations -{ - public class SystemEvents : ISystemEvents - { - public event EventHandler Resume; - public event EventHandler Suspend; - public event EventHandler SessionLogoff; - public event EventHandler SystemShutdown; - } -} |
