From 85a58fd655240fd0ddd10bdaaad4a9bb8cd7051d Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Sun, 27 Jan 2019 15:40:37 +0100 Subject: Start startup tasks async --- Emby.Server.Implementations/IO/LibraryMonitor.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'Emby.Server.Implementations/IO/LibraryMonitor.cs') diff --git a/Emby.Server.Implementations/IO/LibraryMonitor.cs b/Emby.Server.Implementations/IO/LibraryMonitor.cs index 204f9d949..e432b31da 100644 --- a/Emby.Server.Implementations/IO/LibraryMonitor.cs +++ b/Emby.Server.Implementations/IO/LibraryMonitor.cs @@ -627,9 +627,10 @@ namespace Emby.Server.Implementations.IO _monitor = monitor; } - public void Run() + public Task RunAsync() { _monitor.Start(); + return Task.CompletedTask; } public void Dispose() -- cgit v1.2.3 From 5ac6d0ae59731cdf9de0a5565d0cd894695bdc12 Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Fri, 1 Feb 2019 21:56:50 +0100 Subject: Fix more warnings --- Emby.Server.Implementations/IO/LibraryMonitor.cs | 14 ++++++++++---- Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs | 16 ++++++++-------- .../LiveTv/TunerHosts/SharedHttpStream.cs | 2 +- .../Updates/InstallationManager.cs | 4 ++-- Jellyfin.Server/Program.cs | 8 ++++---- MediaBrowser.Api/PackageService.cs | 2 +- MediaBrowser.Api/UserLibrary/PlaystateService.cs | 10 +++++----- 7 files changed, 31 insertions(+), 25 deletions(-) (limited to 'Emby.Server.Implementations/IO/LibraryMonitor.cs') diff --git a/Emby.Server.Implementations/IO/LibraryMonitor.cs b/Emby.Server.Implementations/IO/LibraryMonitor.cs index dad81c195..ed5fddb52 100644 --- a/Emby.Server.Implementations/IO/LibraryMonitor.cs +++ b/Emby.Server.Implementations/IO/LibraryMonitor.cs @@ -601,20 +601,26 @@ namespace Emby.Server.Implementations.IO /// public void Dispose() { - _disposed = true; Dispose(true); } /// /// Releases unmanaged and - optionally - managed resources. /// - /// true to release both managed and unmanaged resources; false to release only unmanaged resources. - protected virtual void Dispose(bool dispose) + /// true to release both managed and unmanaged resources; false to release only unmanaged resources. + protected virtual void Dispose(bool disposing) { - if (dispose) + if (_disposed) + { + return; + } + + if (disposing) { Stop(); } + + _disposed = true; } } diff --git a/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs b/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs index 4e68bb545..bce9c240d 100644 --- a/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs +++ b/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs @@ -35,7 +35,6 @@ using MediaBrowser.Model.Providers; using MediaBrowser.Model.Querying; using MediaBrowser.Model.Reflection; using MediaBrowser.Model.Serialization; -using MediaBrowser.Model.System; using MediaBrowser.Model.Threading; using Microsoft.Extensions.Logging; @@ -275,7 +274,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV foreach (var timer in seriesTimers) { - await UpdateTimersForSeriesTimer(timer, false, true).ConfigureAwait(false); + UpdateTimersForSeriesTimer(timer, false, true); } } @@ -763,12 +762,12 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV _timerProvider.AddOrUpdate(timer, false); } - await UpdateTimersForSeriesTimer(info, true, false).ConfigureAwait(false); + UpdateTimersForSeriesTimer(info, true, false); return info.Id; } - public async Task UpdateSeriesTimerAsync(SeriesTimerInfo info, CancellationToken cancellationToken) + public Task UpdateSeriesTimerAsync(SeriesTimerInfo info, CancellationToken cancellationToken) { var instance = _seriesTimerProvider.GetAll().FirstOrDefault(i => string.Equals(i.Id, info.Id, StringComparison.OrdinalIgnoreCase)); @@ -792,8 +791,10 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV _seriesTimerProvider.Update(instance); - await UpdateTimersForSeriesTimer(instance, true, true).ConfigureAwait(false); + UpdateTimersForSeriesTimer(instance, true, true); } + + return Task.CompletedTask; } public Task UpdateTimerAsync(TimerInfo updatedTimer, CancellationToken cancellationToken) @@ -2346,10 +2347,9 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV } } - private async Task UpdateTimersForSeriesTimer(SeriesTimerInfo seriesTimer, bool updateTimerSettings, bool deleteInvalidTimers) + private void UpdateTimersForSeriesTimer(SeriesTimerInfo seriesTimer, bool updateTimerSettings, bool deleteInvalidTimers) { - var allTimers = GetTimersForSeries(seriesTimer) - .ToList(); + var allTimers = GetTimersForSeries(seriesTimer).ToList(); var enabledTimersForSeries = new List(); diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/SharedHttpStream.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/SharedHttpStream.cs index 716417ccb..4eff9252e 100644 --- a/Emby.Server.Implementations/LiveTv/TunerHosts/SharedHttpStream.cs +++ b/Emby.Server.Implementations/LiveTv/TunerHosts/SharedHttpStream.cs @@ -94,7 +94,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts var now = DateTime.UtcNow; - StartStreaming(response, taskCompletionSource, LiveStreamCancellationTokenSource.Token); + var _ = StartStreaming(response, taskCompletionSource, LiveStreamCancellationTokenSource.Token); //OpenedMediaSource.Protocol = MediaProtocol.File; //OpenedMediaSource.Path = tempFile; diff --git a/Emby.Server.Implementations/Updates/InstallationManager.cs b/Emby.Server.Implementations/Updates/InstallationManager.cs index 552155635..9a49b97c7 100644 --- a/Emby.Server.Implementations/Updates/InstallationManager.cs +++ b/Emby.Server.Implementations/Updates/InstallationManager.cs @@ -164,7 +164,7 @@ namespace Emby.Server.Implementations.Updates /// Gets all available packages. /// /// Task{List{PackageInfo}}. - public async Task> GetAvailablePackages(CancellationToken cancellationToken, + public Task> GetAvailablePackages(CancellationToken cancellationToken, bool withRegistration = true, string packageType = null, Version applicationVersion = null) @@ -172,7 +172,7 @@ namespace Emby.Server.Implementations.Updates // TODO cvium: when plugins get back this would need to be fixed // var packages = await GetAvailablePackagesWithoutRegistrationInfo(cancellationToken).ConfigureAwait(false); - return new List(); //FilterPackages(packages, packageType, applicationVersion); + return Task.FromResult(new List()); //FilterPackages(packages, packageType, applicationVersion); } /// diff --git a/Jellyfin.Server/Program.cs b/Jellyfin.Server/Program.cs index 2f1828336..88b10cdbe 100644 --- a/Jellyfin.Server/Program.cs +++ b/Jellyfin.Server/Program.cs @@ -62,7 +62,7 @@ namespace Jellyfin.Server // $JELLYFIN_LOG_DIR needs to be set for the logger configuration manager Environment.SetEnvironmentVariable("JELLYFIN_LOG_DIR", appPaths.LogDirectoryPath); - await createLogger(appPaths); + await CreateLogger(appPaths); _logger = _loggerFactory.CreateLogger("Main"); AppDomain.CurrentDomain.UnhandledException += (sender, e) @@ -95,7 +95,7 @@ namespace Jellyfin.Server _logger.LogInformation("Jellyfin version: {Version}", Assembly.GetEntryAssembly().GetName().Version); - EnvironmentInfo environmentInfo = new EnvironmentInfo(getOperatingSystem()); + EnvironmentInfo environmentInfo = new EnvironmentInfo(GetOperatingSystem()); ApplicationHost.LogEnvironmentInfo(_logger, appPaths, environmentInfo); SQLitePCL.Batteries_V2.Init(); @@ -226,7 +226,7 @@ namespace Jellyfin.Server return new ServerApplicationPaths(programDataPath, appPath, appPath, logDir, configDir); } - private static async Task createLogger(IApplicationPaths appPaths) + private static async Task CreateLogger(IApplicationPaths appPaths) { try { @@ -286,7 +286,7 @@ namespace Jellyfin.Server return new NullImageEncoder(); } - private static MediaBrowser.Model.System.OperatingSystem getOperatingSystem() + private static MediaBrowser.Model.System.OperatingSystem GetOperatingSystem() { switch (Environment.OSVersion.Platform) { diff --git a/MediaBrowser.Api/PackageService.cs b/MediaBrowser.Api/PackageService.cs index 16819ee37..fbb876dea 100644 --- a/MediaBrowser.Api/PackageService.cs +++ b/MediaBrowser.Api/PackageService.cs @@ -197,7 +197,7 @@ namespace MediaBrowser.Api throw new ResourceNotFoundException(string.Format("Package not found: {0}", request.Name)); } - Task.Run(() => _installationManager.InstallPackage(package, true, new SimpleProgress(), CancellationToken.None)); + await _installationManager.InstallPackage(package, true, new SimpleProgress(), CancellationToken.None); } /// diff --git a/MediaBrowser.Api/UserLibrary/PlaystateService.cs b/MediaBrowser.Api/UserLibrary/PlaystateService.cs index 72a943092..a133bc8e9 100644 --- a/MediaBrowser.Api/UserLibrary/PlaystateService.cs +++ b/MediaBrowser.Api/UserLibrary/PlaystateService.cs @@ -247,14 +247,14 @@ namespace MediaBrowser.Api.UserLibrary /// Posts the specified request. /// /// The request. - public async Task Post(MarkPlayedItem request) + public object Post(MarkPlayedItem request) { - var result = await MarkPlayed(request).ConfigureAwait(false); + var result = MarkPlayed(request); return ToOptimizedResult(result); } - private async Task MarkPlayed(MarkPlayedItem request) + private UserItemDataDto MarkPlayed(MarkPlayedItem request) { var user = _userManager.GetUserById(request.UserId); @@ -403,10 +403,10 @@ namespace MediaBrowser.Api.UserLibrary { var task = MarkUnplayed(request); - return ToOptimizedResult(task.Result); + return ToOptimizedResult(task); } - private async Task MarkUnplayed(MarkUnplayedItem request) + private UserItemDataDto MarkUnplayed(MarkUnplayedItem request) { var user = _userManager.GetUserById(request.UserId); -- cgit v1.2.3 From 0ef2b46106937c8acbab8e2a6a1e08affb823d31 Mon Sep 17 00:00:00 2001 From: Claus Vium Date: Tue, 5 Feb 2019 09:49:46 +0100 Subject: Remove custom Threading --- Emby.Dlna/Main/DlnaEntryPoint.cs | 11 ++----- Emby.Dlna/PlayTo/Device.cs | 14 +++------ Emby.Dlna/PlayTo/PlayToManager.cs | 7 ++--- Emby.Dlna/Ssdp/DeviceDiscovery.cs | 8 ++--- Emby.Notifications/Notifications.cs | 9 ++---- Emby.Server.Implementations/ApplicationHost.cs | 14 +++------ .../EntryPoints/AutomaticRestartEntryPoint.cs | 9 ++---- .../EntryPoints/ExternalPortForwarding.cs | 9 ++---- .../EntryPoints/LibraryChangedNotifier.cs | 13 +++----- .../EntryPoints/UserDataChangeNotifier.cs | 9 ++---- Emby.Server.Implementations/IO/FileRefresher.cs | 10 +++--- Emby.Server.Implementations/IO/LibraryMonitor.cs | 6 +--- .../Library/MediaSourceManager.cs | 4 --- .../LiveTv/EmbyTV/EmbyTV.cs | 4 +-- .../LiveTv/EmbyTV/TimerManager.cs | 10 +++--- .../Session/SessionManager.cs | 14 +++------ .../Threading/CommonTimer.cs | 36 ---------------------- .../Threading/TimerFactory.cs | 18 ----------- MediaBrowser.Api/ApiEntryPoint.cs | 15 +++------ MediaBrowser.Api/Playback/BaseStreamingService.cs | 2 +- MediaBrowser.Api/Playback/TranscodingThrottler.cs | 10 +++--- .../Net/BasePeriodicWebSocketListener.cs | 19 +++++------- MediaBrowser.Controller/Session/SessionInfo.cs | 8 ++--- MediaBrowser.Model/Threading/ITimer.cs | 10 ------ MediaBrowser.Model/Threading/ITimerFactory.cs | 10 ------ RSSDP/SsdpDeviceLocator.cs | 9 ++---- RSSDP/SsdpDevicePublisher.cs | 9 ++---- 27 files changed, 75 insertions(+), 222 deletions(-) delete mode 100644 Emby.Server.Implementations/Threading/CommonTimer.cs delete mode 100644 Emby.Server.Implementations/Threading/TimerFactory.cs delete mode 100644 MediaBrowser.Model/Threading/ITimer.cs delete mode 100644 MediaBrowser.Model/Threading/ITimerFactory.cs (limited to 'Emby.Server.Implementations/IO/LibraryMonitor.cs') diff --git a/Emby.Dlna/Main/DlnaEntryPoint.cs b/Emby.Dlna/Main/DlnaEntryPoint.cs index 7398b24cd..a20006578 100644 --- a/Emby.Dlna/Main/DlnaEntryPoint.cs +++ b/Emby.Dlna/Main/DlnaEntryPoint.cs @@ -20,7 +20,6 @@ using MediaBrowser.Model.Dlna; using MediaBrowser.Model.Globalization; using MediaBrowser.Model.Net; using MediaBrowser.Model.System; -using MediaBrowser.Model.Threading; using MediaBrowser.Model.Xml; using Microsoft.Extensions.Logging; using Rssdp; @@ -49,8 +48,7 @@ namespace Emby.Dlna.Main private readonly IDeviceDiscovery _deviceDiscovery; private SsdpDevicePublisher _Publisher; - - private readonly ITimerFactory _timerFactory; + private readonly ISocketFactory _socketFactory; private readonly IEnvironmentInfo _environmentInfo; private readonly INetworkManager _networkManager; @@ -78,7 +76,6 @@ namespace Emby.Dlna.Main IDeviceDiscovery deviceDiscovery, IMediaEncoder mediaEncoder, ISocketFactory socketFactory, - ITimerFactory timerFactory, IEnvironmentInfo environmentInfo, INetworkManager networkManager, IUserViewManager userViewManager, @@ -99,7 +96,6 @@ namespace Emby.Dlna.Main _deviceDiscovery = deviceDiscovery; _mediaEncoder = mediaEncoder; _socketFactory = socketFactory; - _timerFactory = timerFactory; _environmentInfo = environmentInfo; _networkManager = networkManager; _logger = loggerFactory.CreateLogger("Dlna"); @@ -233,7 +229,7 @@ namespace Emby.Dlna.Main try { - _Publisher = new SsdpDevicePublisher(_communicationsServer, _timerFactory, _environmentInfo.OperatingSystemName, _environmentInfo.OperatingSystemVersion); + _Publisher = new SsdpDevicePublisher(_communicationsServer, _environmentInfo.OperatingSystemName, _environmentInfo.OperatingSystemVersion); _Publisher.LogFunction = LogMessage; _Publisher.SupportPnpRootDevice = false; @@ -353,8 +349,7 @@ namespace Emby.Dlna.Main _userDataManager, _localization, _mediaSourceManager, - _mediaEncoder, - _timerFactory); + _mediaEncoder); _manager.Start(); } diff --git a/Emby.Dlna/PlayTo/Device.cs b/Emby.Dlna/PlayTo/Device.cs index 85a522d1c..e49168d34 100644 --- a/Emby.Dlna/PlayTo/Device.cs +++ b/Emby.Dlna/PlayTo/Device.cs @@ -10,7 +10,6 @@ using Emby.Dlna.Server; using Emby.Dlna.Ssdp; using MediaBrowser.Common.Net; using MediaBrowser.Controller.Configuration; -using MediaBrowser.Model.Threading; using Microsoft.Extensions.Logging; namespace Emby.Dlna.PlayTo @@ -19,7 +18,7 @@ namespace Emby.Dlna.PlayTo { #region Fields & Properties - private ITimer _timer; + private Timer _timer; public DeviceInfo Properties { get; set; } @@ -64,21 +63,18 @@ namespace Emby.Dlna.PlayTo public DateTime DateLastActivity { get; private set; } public Action OnDeviceUnavailable { get; set; } - private readonly ITimerFactory _timerFactory; - - public Device(DeviceInfo deviceProperties, IHttpClient httpClient, ILogger logger, IServerConfigurationManager config, ITimerFactory timerFactory) + public Device(DeviceInfo deviceProperties, IHttpClient httpClient, ILogger logger, IServerConfigurationManager config) { Properties = deviceProperties; _httpClient = httpClient; _logger = logger; _config = config; - _timerFactory = timerFactory; } public void Start() { _logger.LogDebug("Dlna Device.Start"); - _timer = _timerFactory.Create(TimerCallback, null, 1000, Timeout.Infinite); + _timer = new Timer(TimerCallback, null, 1000, Timeout.Infinite); } private DateTime _lastVolumeRefresh; @@ -890,7 +886,7 @@ namespace Emby.Dlna.PlayTo set; } - public static async Task CreateuPnpDeviceAsync(Uri url, IHttpClient httpClient, IServerConfigurationManager config, ILogger logger, ITimerFactory timerFactory, CancellationToken cancellationToken) + public static async Task CreateuPnpDeviceAsync(Uri url, IHttpClient httpClient, IServerConfigurationManager config, ILogger logger, CancellationToken cancellationToken) { var ssdpHttpClient = new SsdpHttpClient(httpClient, config); @@ -1001,7 +997,7 @@ namespace Emby.Dlna.PlayTo } } - var device = new Device(deviceProperties, httpClient, logger, config, timerFactory); + var device = new Device(deviceProperties, httpClient, logger, config); return device; } diff --git a/Emby.Dlna/PlayTo/PlayToManager.cs b/Emby.Dlna/PlayTo/PlayToManager.cs index 790625705..6cce312ee 100644 --- a/Emby.Dlna/PlayTo/PlayToManager.cs +++ b/Emby.Dlna/PlayTo/PlayToManager.cs @@ -16,7 +16,6 @@ using MediaBrowser.Model.Events; using MediaBrowser.Model.Globalization; using MediaBrowser.Model.Net; using MediaBrowser.Model.Session; -using MediaBrowser.Model.Threading; using Microsoft.Extensions.Logging; namespace Emby.Dlna.PlayTo @@ -39,13 +38,12 @@ namespace Emby.Dlna.PlayTo private readonly IDeviceDiscovery _deviceDiscovery; private readonly IMediaSourceManager _mediaSourceManager; private readonly IMediaEncoder _mediaEncoder; - private readonly ITimerFactory _timerFactory; private bool _disposed; private SemaphoreSlim _sessionLock = new SemaphoreSlim(1, 1); private CancellationTokenSource _disposeCancellationTokenSource = new CancellationTokenSource(); - public PlayToManager(ILogger logger, ISessionManager sessionManager, ILibraryManager libraryManager, IUserManager userManager, IDlnaManager dlnaManager, IServerApplicationHost appHost, IImageProcessor imageProcessor, IDeviceDiscovery deviceDiscovery, IHttpClient httpClient, IServerConfigurationManager config, IUserDataManager userDataManager, ILocalizationManager localization, IMediaSourceManager mediaSourceManager, IMediaEncoder mediaEncoder, ITimerFactory timerFactory) + public PlayToManager(ILogger logger, ISessionManager sessionManager, ILibraryManager libraryManager, IUserManager userManager, IDlnaManager dlnaManager, IServerApplicationHost appHost, IImageProcessor imageProcessor, IDeviceDiscovery deviceDiscovery, IHttpClient httpClient, IServerConfigurationManager config, IUserDataManager userDataManager, ILocalizationManager localization, IMediaSourceManager mediaSourceManager, IMediaEncoder mediaEncoder) { _logger = logger; _sessionManager = sessionManager; @@ -61,7 +59,6 @@ namespace Emby.Dlna.PlayTo _localization = localization; _mediaSourceManager = mediaSourceManager; _mediaEncoder = mediaEncoder; - _timerFactory = timerFactory; } public void Start() @@ -168,7 +165,7 @@ namespace Emby.Dlna.PlayTo if (controller == null) { - var device = await Device.CreateuPnpDeviceAsync(uri, _httpClient, _config, _logger, _timerFactory, cancellationToken).ConfigureAwait(false); + var device = await Device.CreateuPnpDeviceAsync(uri, _httpClient, _config, _logger, cancellationToken).ConfigureAwait(false); string deviceName = device.Properties.Name; diff --git a/Emby.Dlna/Ssdp/DeviceDiscovery.cs b/Emby.Dlna/Ssdp/DeviceDiscovery.cs index 89a88705f..298f68a28 100644 --- a/Emby.Dlna/Ssdp/DeviceDiscovery.cs +++ b/Emby.Dlna/Ssdp/DeviceDiscovery.cs @@ -5,7 +5,6 @@ using MediaBrowser.Controller.Configuration; using MediaBrowser.Model.Dlna; using MediaBrowser.Model.Events; using MediaBrowser.Model.Net; -using MediaBrowser.Model.Threading; using Microsoft.Extensions.Logging; using Rssdp; using Rssdp.Infrastructure; @@ -48,20 +47,17 @@ namespace Emby.Dlna.Ssdp private SsdpDeviceLocator _deviceLocator; - private readonly ITimerFactory _timerFactory; private readonly ISocketFactory _socketFactory; private ISsdpCommunicationsServer _commsServer; public DeviceDiscovery( ILoggerFactory loggerFactory, IServerConfigurationManager config, - ISocketFactory socketFactory, - ITimerFactory timerFactory) + ISocketFactory socketFactory) { _logger = loggerFactory.CreateLogger(nameof(DeviceDiscovery)); _config = config; _socketFactory = socketFactory; - _timerFactory = timerFactory; } // Call this method from somewhere in your code to start the search. @@ -78,7 +74,7 @@ namespace Emby.Dlna.Ssdp { if (_listenerCount > 0 && _deviceLocator == null) { - _deviceLocator = new SsdpDeviceLocator(_commsServer, _timerFactory); + _deviceLocator = new SsdpDeviceLocator(_commsServer); // (Optional) Set the filter so we only see notifications for devices we care about // (can be any search target value i.e device type, uuid value etc - any value that appears in the diff --git a/Emby.Notifications/Notifications.cs b/Emby.Notifications/Notifications.cs index 045aa6f16..d3290479f 100644 --- a/Emby.Notifications/Notifications.cs +++ b/Emby.Notifications/Notifications.cs @@ -20,7 +20,6 @@ using MediaBrowser.Model.Events; using MediaBrowser.Model.Globalization; using MediaBrowser.Model.Notifications; using MediaBrowser.Model.Tasks; -using MediaBrowser.Model.Threading; using Microsoft.Extensions.Logging; namespace Emby.Notifications @@ -40,9 +39,8 @@ namespace Emby.Notifications private readonly ILibraryManager _libraryManager; private readonly ISessionManager _sessionManager; private readonly IServerApplicationHost _appHost; - private readonly ITimerFactory _timerFactory; - private ITimer LibraryUpdateTimer { get; set; } + private Timer LibraryUpdateTimer { get; set; } private readonly object _libraryChangedSyncLock = new object(); private readonly IConfigurationManager _config; @@ -52,7 +50,7 @@ namespace Emby.Notifications private string[] _coreNotificationTypes; - public Notifications(IInstallationManager installationManager, IActivityManager activityManager, ILocalizationManager localization, IUserManager userManager, ILogger logger, ITaskManager taskManager, INotificationManager notificationManager, ILibraryManager libraryManager, ISessionManager sessionManager, IServerApplicationHost appHost, IConfigurationManager config, IDeviceManager deviceManager, ITimerFactory timerFactory) + public Notifications(IInstallationManager installationManager, IActivityManager activityManager, ILocalizationManager localization, IUserManager userManager, ILogger logger, ITaskManager taskManager, INotificationManager notificationManager, ILibraryManager libraryManager, ISessionManager sessionManager, IServerApplicationHost appHost, IConfigurationManager config, IDeviceManager deviceManager) { _installationManager = installationManager; _userManager = userManager; @@ -64,7 +62,6 @@ namespace Emby.Notifications _appHost = appHost; _config = config; _deviceManager = deviceManager; - _timerFactory = timerFactory; _localization = localization; _activityManager = activityManager; @@ -159,7 +156,7 @@ namespace Emby.Notifications { if (LibraryUpdateTimer == null) { - LibraryUpdateTimer = _timerFactory.Create(LibraryUpdateTimerCallback, null, 5000, + LibraryUpdateTimer = new Timer(LibraryUpdateTimerCallback, null, 5000, Timeout.Infinite); } else diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 365eb5856..3808810cf 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -43,7 +43,6 @@ using Emby.Server.Implementations.ScheduledTasks; using Emby.Server.Implementations.Security; using Emby.Server.Implementations.Serialization; using Emby.Server.Implementations.Session; -using Emby.Server.Implementations.Threading; using Emby.Server.Implementations.TV; using Emby.Server.Implementations.Updates; using Emby.Server.Implementations.Xml; @@ -99,7 +98,6 @@ using MediaBrowser.Model.Serialization; using MediaBrowser.Model.Services; using MediaBrowser.Model.System; using MediaBrowser.Model.Tasks; -using MediaBrowser.Model.Threading; using MediaBrowser.Model.Updates; using MediaBrowser.Model.Xml; using MediaBrowser.Providers.Chapters; @@ -347,7 +345,6 @@ namespace Emby.Server.Implementations internal IImageEncoder ImageEncoder { get; private set; } protected IProcessFactory ProcessFactory { get; private set; } - protected ITimerFactory TimerFactory { get; private set; } protected ICryptoProvider CryptographyProvider = new CryptographyProvider(); protected readonly IXmlSerializer XmlSerializer; @@ -772,9 +769,6 @@ namespace Emby.Server.Implementations ProcessFactory = new ProcessFactory(); RegisterSingleInstance(ProcessFactory); - TimerFactory = new TimerFactory(); - RegisterSingleInstance(TimerFactory); - var streamHelper = CreateStreamHelper(); ApplicationHost.StreamHelper = streamHelper; RegisterSingleInstance(streamHelper); @@ -837,7 +831,7 @@ namespace Emby.Server.Implementations var musicManager = new MusicManager(LibraryManager); RegisterSingleInstance(new MusicManager(LibraryManager)); - LibraryMonitor = new LibraryMonitor(LoggerFactory, TaskManager, LibraryManager, ServerConfigurationManager, FileSystemManager, TimerFactory, EnvironmentInfo); + LibraryMonitor = new LibraryMonitor(LoggerFactory, TaskManager, LibraryManager, ServerConfigurationManager, FileSystemManager, EnvironmentInfo); RegisterSingleInstance(LibraryMonitor); RegisterSingleInstance(() => new SearchEngine(LoggerFactory, LibraryManager, UserManager)); @@ -869,7 +863,7 @@ namespace Emby.Server.Implementations DeviceManager = new DeviceManager(AuthenticationRepository, JsonSerializer, LibraryManager, LocalizationManager, UserManager, FileSystemManager, LibraryMonitor, ServerConfigurationManager, LoggerFactory, NetworkManager); RegisterSingleInstance(DeviceManager); - MediaSourceManager = new MediaSourceManager(ItemRepository, ApplicationPaths, LocalizationManager, UserManager, LibraryManager, LoggerFactory, JsonSerializer, FileSystemManager, UserDataManager, TimerFactory, () => MediaEncoder); + MediaSourceManager = new MediaSourceManager(ItemRepository, ApplicationPaths, LocalizationManager, UserManager, LibraryManager, LoggerFactory, JsonSerializer, FileSystemManager, UserDataManager, () => MediaEncoder); RegisterSingleInstance(MediaSourceManager); SubtitleManager = new SubtitleManager(LoggerFactory, FileSystemManager, LibraryMonitor, MediaSourceManager, LocalizationManager); @@ -884,7 +878,7 @@ namespace Emby.Server.Implementations ChannelManager = new ChannelManager(UserManager, DtoService, LibraryManager, LoggerFactory, ServerConfigurationManager, FileSystemManager, UserDataManager, JsonSerializer, LocalizationManager, HttpClient, ProviderManager); RegisterSingleInstance(ChannelManager); - SessionManager = new SessionManager(UserDataManager, LoggerFactory, LibraryManager, UserManager, musicManager, DtoService, ImageProcessor, JsonSerializer, this, HttpClient, AuthenticationRepository, DeviceManager, MediaSourceManager, TimerFactory); + SessionManager = new SessionManager(UserDataManager, LoggerFactory, LibraryManager, UserManager, musicManager, DtoService, ImageProcessor, JsonSerializer, this, HttpClient, AuthenticationRepository, DeviceManager, MediaSourceManager); RegisterSingleInstance(SessionManager); var dlnaManager = new DlnaManager(XmlSerializer, FileSystemManager, ApplicationPaths, LoggerFactory, JsonSerializer, this, assemblyInfo); @@ -905,7 +899,7 @@ namespace Emby.Server.Implementations NotificationManager = new NotificationManager(LoggerFactory, UserManager, ServerConfigurationManager); RegisterSingleInstance(NotificationManager); - RegisterSingleInstance(new DeviceDiscovery(LoggerFactory, ServerConfigurationManager, SocketFactory, TimerFactory)); + RegisterSingleInstance(new DeviceDiscovery(LoggerFactory, ServerConfigurationManager, SocketFactory)); ChapterManager = new ChapterManager(LibraryManager, LoggerFactory, ServerConfigurationManager, ItemRepository); RegisterSingleInstance(ChapterManager); diff --git a/Emby.Server.Implementations/EntryPoints/AutomaticRestartEntryPoint.cs b/Emby.Server.Implementations/EntryPoints/AutomaticRestartEntryPoint.cs index 361656ff2..19ea09359 100644 --- a/Emby.Server.Implementations/EntryPoints/AutomaticRestartEntryPoint.cs +++ b/Emby.Server.Implementations/EntryPoints/AutomaticRestartEntryPoint.cs @@ -9,7 +9,6 @@ using MediaBrowser.Controller.Plugins; using MediaBrowser.Controller.Session; using MediaBrowser.Model.LiveTv; using MediaBrowser.Model.Tasks; -using MediaBrowser.Model.Threading; using Microsoft.Extensions.Logging; namespace Emby.Server.Implementations.EntryPoints @@ -22,11 +21,10 @@ namespace Emby.Server.Implementations.EntryPoints private readonly ISessionManager _sessionManager; private readonly IServerConfigurationManager _config; private readonly ILiveTvManager _liveTvManager; - private readonly ITimerFactory _timerFactory; - private ITimer _timer; + private Timer _timer; - public AutomaticRestartEntryPoint(IServerApplicationHost appHost, ILogger logger, ITaskManager iTaskManager, ISessionManager sessionManager, IServerConfigurationManager config, ILiveTvManager liveTvManager, ITimerFactory timerFactory) + public AutomaticRestartEntryPoint(IServerApplicationHost appHost, ILogger logger, ITaskManager iTaskManager, ISessionManager sessionManager, IServerConfigurationManager config, ILiveTvManager liveTvManager) { _appHost = appHost; _logger = logger; @@ -34,7 +32,6 @@ namespace Emby.Server.Implementations.EntryPoints _sessionManager = sessionManager; _config = config; _liveTvManager = liveTvManager; - _timerFactory = timerFactory; } public Task RunAsync() @@ -53,7 +50,7 @@ namespace Emby.Server.Implementations.EntryPoints if (_appHost.HasPendingRestart) { - _timer = _timerFactory.Create(TimerCallback, null, TimeSpan.FromMinutes(15), TimeSpan.FromMinutes(15)); + _timer = new Timer(TimerCallback, null, TimeSpan.FromMinutes(15), TimeSpan.FromMinutes(15)); } } diff --git a/Emby.Server.Implementations/EntryPoints/ExternalPortForwarding.cs b/Emby.Server.Implementations/EntryPoints/ExternalPortForwarding.cs index 56c730c80..f26a70586 100644 --- a/Emby.Server.Implementations/EntryPoints/ExternalPortForwarding.cs +++ b/Emby.Server.Implementations/EntryPoints/ExternalPortForwarding.cs @@ -10,7 +10,6 @@ using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Plugins; using MediaBrowser.Model.Dlna; using MediaBrowser.Model.Events; -using MediaBrowser.Model.Threading; using Microsoft.Extensions.Logging; using Mono.Nat; @@ -24,19 +23,17 @@ namespace Emby.Server.Implementations.EntryPoints private readonly IServerConfigurationManager _config; private readonly IDeviceDiscovery _deviceDiscovery; - private ITimer _timer; - private readonly ITimerFactory _timerFactory; + private Timer _timer; private NatManager _natManager; - public ExternalPortForwarding(ILoggerFactory loggerFactory, IServerApplicationHost appHost, IServerConfigurationManager config, IDeviceDiscovery deviceDiscovery, IHttpClient httpClient, ITimerFactory timerFactory) + public ExternalPortForwarding(ILoggerFactory loggerFactory, IServerApplicationHost appHost, IServerConfigurationManager config, IDeviceDiscovery deviceDiscovery, IHttpClient httpClient) { _logger = loggerFactory.CreateLogger("PortMapper"); _appHost = appHost; _config = config; _deviceDiscovery = deviceDiscovery; _httpClient = httpClient; - _timerFactory = timerFactory; _config.ConfigurationUpdated += _config_ConfigurationUpdated1; } @@ -94,7 +91,7 @@ namespace Emby.Server.Implementations.EntryPoints _natManager.StartDiscovery(); } - _timer = _timerFactory.Create(ClearCreatedRules, null, TimeSpan.FromMinutes(10), TimeSpan.FromMinutes(10)); + _timer = new Timer(ClearCreatedRules, null, TimeSpan.FromMinutes(10), TimeSpan.FromMinutes(10)); _deviceDiscovery.DeviceDiscovered += _deviceDiscovery_DeviceDiscovered; diff --git a/Emby.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs b/Emby.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs index 9b61809c7..038965647 100644 --- a/Emby.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs +++ b/Emby.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs @@ -14,7 +14,6 @@ using MediaBrowser.Controller.Session; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Events; using MediaBrowser.Model.Extensions; -using MediaBrowser.Model.Threading; using Microsoft.Extensions.Logging; namespace Emby.Server.Implementations.EntryPoints @@ -29,7 +28,6 @@ namespace Emby.Server.Implementations.EntryPoints private readonly ISessionManager _sessionManager; private readonly IUserManager _userManager; private readonly ILogger _logger; - private readonly ITimerFactory _timerFactory; /// /// The _library changed sync lock @@ -47,7 +45,7 @@ namespace Emby.Server.Implementations.EntryPoints /// Gets or sets the library update timer. /// /// The library update timer. - private ITimer LibraryUpdateTimer { get; set; } + private Timer LibraryUpdateTimer { get; set; } /// /// The library update duration @@ -56,13 +54,12 @@ namespace Emby.Server.Implementations.EntryPoints private readonly IProviderManager _providerManager; - public LibraryChangedNotifier(ILibraryManager libraryManager, ISessionManager sessionManager, IUserManager userManager, ILogger logger, ITimerFactory timerFactory, IProviderManager providerManager) + public LibraryChangedNotifier(ILibraryManager libraryManager, ISessionManager sessionManager, IUserManager userManager, ILogger logger, IProviderManager providerManager) { _libraryManager = libraryManager; _sessionManager = sessionManager; _userManager = userManager; _logger = logger; - _timerFactory = timerFactory; _providerManager = providerManager; } @@ -191,7 +188,7 @@ namespace Emby.Server.Implementations.EntryPoints { if (LibraryUpdateTimer == null) { - LibraryUpdateTimer = _timerFactory.Create(LibraryUpdateTimerCallback, null, LibraryUpdateDuration, + LibraryUpdateTimer = new Timer(LibraryUpdateTimerCallback, null, LibraryUpdateDuration, Timeout.Infinite); } else @@ -225,7 +222,7 @@ namespace Emby.Server.Implementations.EntryPoints { if (LibraryUpdateTimer == null) { - LibraryUpdateTimer = _timerFactory.Create(LibraryUpdateTimerCallback, null, LibraryUpdateDuration, + LibraryUpdateTimer = new Timer(LibraryUpdateTimerCallback, null, LibraryUpdateDuration, Timeout.Infinite); } else @@ -253,7 +250,7 @@ namespace Emby.Server.Implementations.EntryPoints { if (LibraryUpdateTimer == null) { - LibraryUpdateTimer = _timerFactory.Create(LibraryUpdateTimerCallback, null, LibraryUpdateDuration, + LibraryUpdateTimer = new Timer(LibraryUpdateTimerCallback, null, LibraryUpdateDuration, Timeout.Infinite); } else diff --git a/Emby.Server.Implementations/EntryPoints/UserDataChangeNotifier.cs b/Emby.Server.Implementations/EntryPoints/UserDataChangeNotifier.cs index d91a2d581..774ed09da 100644 --- a/Emby.Server.Implementations/EntryPoints/UserDataChangeNotifier.cs +++ b/Emby.Server.Implementations/EntryPoints/UserDataChangeNotifier.cs @@ -10,7 +10,6 @@ using MediaBrowser.Controller.Session; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Extensions; using MediaBrowser.Model.Session; -using MediaBrowser.Model.Threading; using Microsoft.Extensions.Logging; namespace Emby.Server.Implementations.EntryPoints @@ -23,19 +22,17 @@ namespace Emby.Server.Implementations.EntryPoints private readonly IUserManager _userManager; private readonly object _syncLock = new object(); - private ITimer UpdateTimer { get; set; } - private readonly ITimerFactory _timerFactory; + private Timer UpdateTimer { get; set; } private const int UpdateDuration = 500; private readonly Dictionary> _changedItems = new Dictionary>(); - public UserDataChangeNotifier(IUserDataManager userDataManager, ISessionManager sessionManager, ILogger logger, IUserManager userManager, ITimerFactory timerFactory) + public UserDataChangeNotifier(IUserDataManager userDataManager, ISessionManager sessionManager, ILogger logger, IUserManager userManager) { _userDataManager = userDataManager; _sessionManager = sessionManager; _logger = logger; _userManager = userManager; - _timerFactory = timerFactory; } public Task RunAsync() @@ -56,7 +53,7 @@ namespace Emby.Server.Implementations.EntryPoints { if (UpdateTimer == null) { - UpdateTimer = _timerFactory.Create(UpdateTimerCallback, null, UpdateDuration, + UpdateTimer = new Timer(UpdateTimerCallback, null, UpdateDuration, Timeout.Infinite); } else diff --git a/Emby.Server.Implementations/IO/FileRefresher.cs b/Emby.Server.Implementations/IO/FileRefresher.cs index 1cac0ba5c..3668f6a7a 100644 --- a/Emby.Server.Implementations/IO/FileRefresher.cs +++ b/Emby.Server.Implementations/IO/FileRefresher.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Threading; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; @@ -9,7 +10,6 @@ using MediaBrowser.Model.Extensions; using MediaBrowser.Model.IO; using MediaBrowser.Model.System; using MediaBrowser.Model.Tasks; -using MediaBrowser.Model.Threading; using Microsoft.Extensions.Logging; namespace Emby.Server.Implementations.IO @@ -22,8 +22,7 @@ namespace Emby.Server.Implementations.IO private IServerConfigurationManager ConfigurationManager { get; set; } private readonly IFileSystem _fileSystem; private readonly List _affectedPaths = new List(); - private ITimer _timer; - private readonly ITimerFactory _timerFactory; + private Timer _timer; private readonly object _timerLock = new object(); public string Path { get; private set; } @@ -31,7 +30,7 @@ namespace Emby.Server.Implementations.IO private readonly IEnvironmentInfo _environmentInfo; private readonly ILibraryManager _libraryManager; - public FileRefresher(string path, IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, ITaskManager taskManager, ILogger logger, ITimerFactory timerFactory, IEnvironmentInfo environmentInfo, ILibraryManager libraryManager1) + public FileRefresher(string path, IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, ITaskManager taskManager, ILogger logger, IEnvironmentInfo environmentInfo, ILibraryManager libraryManager1) { logger.LogDebug("New file refresher created for {0}", path); Path = path; @@ -41,7 +40,6 @@ namespace Emby.Server.Implementations.IO LibraryManager = libraryManager; TaskManager = taskManager; Logger = logger; - _timerFactory = timerFactory; _environmentInfo = environmentInfo; _libraryManager = libraryManager1; AddPath(path); @@ -90,7 +88,7 @@ namespace Emby.Server.Implementations.IO if (_timer == null) { - _timer = _timerFactory.Create(OnTimerCallback, null, TimeSpan.FromSeconds(ConfigurationManager.Configuration.LibraryMonitorDelay), TimeSpan.FromMilliseconds(-1)); + _timer = new Timer(OnTimerCallback, null, TimeSpan.FromSeconds(ConfigurationManager.Configuration.LibraryMonitorDelay), TimeSpan.FromMilliseconds(-1)); } else { diff --git a/Emby.Server.Implementations/IO/LibraryMonitor.cs b/Emby.Server.Implementations/IO/LibraryMonitor.cs index 3a746ef60..11c684b12 100644 --- a/Emby.Server.Implementations/IO/LibraryMonitor.cs +++ b/Emby.Server.Implementations/IO/LibraryMonitor.cs @@ -11,7 +11,6 @@ using MediaBrowser.Controller.Plugins; using MediaBrowser.Model.IO; using MediaBrowser.Model.System; using MediaBrowser.Model.Tasks; -using MediaBrowser.Model.Threading; using Microsoft.Extensions.Logging; namespace Emby.Server.Implementations.IO @@ -134,7 +133,6 @@ namespace Emby.Server.Implementations.IO private IServerConfigurationManager ConfigurationManager { get; set; } private readonly IFileSystem _fileSystem; - private readonly ITimerFactory _timerFactory; private readonly IEnvironmentInfo _environmentInfo; /// @@ -146,7 +144,6 @@ namespace Emby.Server.Implementations.IO ILibraryManager libraryManager, IServerConfigurationManager configurationManager, IFileSystem fileSystem, - ITimerFactory timerFactory, IEnvironmentInfo environmentInfo) { if (taskManager == null) @@ -159,7 +156,6 @@ namespace Emby.Server.Implementations.IO Logger = loggerFactory.CreateLogger(GetType().Name); ConfigurationManager = configurationManager; _fileSystem = fileSystem; - _timerFactory = timerFactory; _environmentInfo = environmentInfo; } @@ -545,7 +541,7 @@ namespace Emby.Server.Implementations.IO } } - var newRefresher = new FileRefresher(path, _fileSystem, ConfigurationManager, LibraryManager, TaskManager, Logger, _timerFactory, _environmentInfo, LibraryManager); + var newRefresher = new FileRefresher(path, _fileSystem, ConfigurationManager, LibraryManager, TaskManager, Logger, _environmentInfo, LibraryManager); newRefresher.Completed += NewRefresher_Completed; _activeRefreshers.Add(newRefresher); } diff --git a/Emby.Server.Implementations/Library/MediaSourceManager.cs b/Emby.Server.Implementations/Library/MediaSourceManager.cs index 4f72651d4..24ab8e761 100644 --- a/Emby.Server.Implementations/Library/MediaSourceManager.cs +++ b/Emby.Server.Implementations/Library/MediaSourceManager.cs @@ -20,7 +20,6 @@ using MediaBrowser.Model.Globalization; using MediaBrowser.Model.IO; using MediaBrowser.Model.MediaInfo; using MediaBrowser.Model.Serialization; -using MediaBrowser.Model.Threading; using Microsoft.Extensions.Logging; namespace Emby.Server.Implementations.Library @@ -36,7 +35,6 @@ namespace Emby.Server.Implementations.Library private IMediaSourceProvider[] _providers; private readonly ILogger _logger; private readonly IUserDataManager _userDataManager; - private readonly ITimerFactory _timerFactory; private readonly Func _mediaEncoder; private ILocalizationManager _localizationManager; private IApplicationPaths _appPaths; @@ -51,7 +49,6 @@ namespace Emby.Server.Implementations.Library IJsonSerializer jsonSerializer, IFileSystem fileSystem, IUserDataManager userDataManager, - ITimerFactory timerFactory, Func mediaEncoder) { _itemRepo = itemRepo; @@ -61,7 +58,6 @@ namespace Emby.Server.Implementations.Library _jsonSerializer = jsonSerializer; _fileSystem = fileSystem; _userDataManager = userDataManager; - _timerFactory = timerFactory; _mediaEncoder = mediaEncoder; _localizationManager = localizationManager; _appPaths = applicationPaths; diff --git a/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs b/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs index b9a42a6ff..84ca130b7 100644 --- a/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs +++ b/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs @@ -35,7 +35,6 @@ using MediaBrowser.Model.Providers; using MediaBrowser.Model.Querying; using MediaBrowser.Model.Reflection; using MediaBrowser.Model.Serialization; -using MediaBrowser.Model.Threading; using Microsoft.Extensions.Logging; namespace Emby.Server.Implementations.LiveTv.EmbyTV @@ -86,7 +85,6 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV ILibraryMonitor libraryMonitor, IProviderManager providerManager, IMediaEncoder mediaEncoder, - ITimerFactory timerFactory, IProcessFactory processFactory) { Current = this; @@ -108,7 +106,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV _streamHelper = streamHelper; _seriesTimerProvider = new SeriesTimerManager(fileSystem, jsonSerializer, _logger, Path.Combine(DataPath, "seriestimers")); - _timerProvider = new TimerManager(fileSystem, jsonSerializer, _logger, Path.Combine(DataPath, "timers"), _logger, timerFactory); + _timerProvider = new TimerManager(fileSystem, jsonSerializer, _logger, Path.Combine(DataPath, "timers"), _logger); _timerProvider.TimerFired += _timerProvider_TimerFired; _config.NamedConfigurationUpdated += _config_NamedConfigurationUpdated; diff --git a/Emby.Server.Implementations/LiveTv/EmbyTV/TimerManager.cs b/Emby.Server.Implementations/LiveTv/EmbyTV/TimerManager.cs index 7f67d70a9..1dcb02f43 100644 --- a/Emby.Server.Implementations/LiveTv/EmbyTV/TimerManager.cs +++ b/Emby.Server.Implementations/LiveTv/EmbyTV/TimerManager.cs @@ -2,29 +2,27 @@ using System; using System.Collections.Concurrent; using System.Globalization; using System.Linq; +using System.Threading; using MediaBrowser.Controller.LiveTv; using MediaBrowser.Model.Events; using MediaBrowser.Model.IO; using MediaBrowser.Model.LiveTv; using MediaBrowser.Model.Serialization; -using MediaBrowser.Model.Threading; using Microsoft.Extensions.Logging; namespace Emby.Server.Implementations.LiveTv.EmbyTV { public class TimerManager : ItemDataProvider { - private readonly ConcurrentDictionary _timers = new ConcurrentDictionary(StringComparer.OrdinalIgnoreCase); + private readonly ConcurrentDictionary _timers = new ConcurrentDictionary(StringComparer.OrdinalIgnoreCase); private readonly ILogger _logger; public event EventHandler> TimerFired; - private readonly ITimerFactory _timerFactory; - public TimerManager(IFileSystem fileSystem, IJsonSerializer jsonSerializer, ILogger logger, string dataPath, ILogger logger1, ITimerFactory timerFactory) + public TimerManager(IFileSystem fileSystem, IJsonSerializer jsonSerializer, ILogger logger, string dataPath, ILogger logger1) : base(fileSystem, jsonSerializer, logger, dataPath, (r1, r2) => string.Equals(r1.Id, r2.Id, StringComparison.OrdinalIgnoreCase)) { _logger = logger1; - _timerFactory = timerFactory; } public void RestartTimers() @@ -125,7 +123,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV private void StartTimer(TimerInfo item, TimeSpan dueTime) { - var timer = _timerFactory.Create(TimerCallback, item.Id, dueTime, TimeSpan.Zero); + var timer = new Timer(TimerCallback, item.Id, dueTime, TimeSpan.Zero); if (_timers.TryAdd(item.Id, timer)) { diff --git a/Emby.Server.Implementations/Session/SessionManager.cs b/Emby.Server.Implementations/Session/SessionManager.cs index b03345e03..fa0ab62d3 100644 --- a/Emby.Server.Implementations/Session/SessionManager.cs +++ b/Emby.Server.Implementations/Session/SessionManager.cs @@ -27,7 +27,6 @@ using MediaBrowser.Model.Library; using MediaBrowser.Model.Querying; using MediaBrowser.Model.Serialization; using MediaBrowser.Model.Session; -using MediaBrowser.Model.Threading; using Microsoft.Extensions.Logging; namespace Emby.Server.Implementations.Session @@ -60,7 +59,6 @@ namespace Emby.Server.Implementations.Session private readonly IAuthenticationRepository _authRepo; private readonly IDeviceManager _deviceManager; - private readonly ITimerFactory _timerFactory; /// /// The _active connections @@ -103,8 +101,7 @@ namespace Emby.Server.Implementations.Session IHttpClient httpClient, IAuthenticationRepository authRepo, IDeviceManager deviceManager, - IMediaSourceManager mediaSourceManager, - ITimerFactory timerFactory) + IMediaSourceManager mediaSourceManager) { _userDataManager = userDataManager; _logger = loggerFactory.CreateLogger(nameof(SessionManager)); @@ -119,7 +116,6 @@ namespace Emby.Server.Implementations.Session _authRepo = authRepo; _deviceManager = deviceManager; _mediaSourceManager = mediaSourceManager; - _timerFactory = timerFactory; _deviceManager.DeviceOptionsUpdated += _deviceManager_DeviceOptionsUpdated; } @@ -503,13 +499,13 @@ namespace Emby.Server.Implementations.Session return users; } - private ITimer _idleTimer; + private Timer _idleTimer; private void StartIdleCheckTimer() { if (_idleTimer == null) { - _idleTimer = _timerFactory.Create(CheckForIdlePlayback, null, TimeSpan.FromMinutes(5), TimeSpan.FromMinutes(5)); + _idleTimer = new Timer(CheckForIdlePlayback, null, TimeSpan.FromMinutes(5), TimeSpan.FromMinutes(5)); } } private void StopIdleCheckTimer() @@ -606,7 +602,7 @@ namespace Emby.Server.Implementations.Session ClearTranscodingInfo(session.DeviceId); } - session.StartAutomaticProgress(_timerFactory, info); + session.StartAutomaticProgress(info); var users = GetUsers(session); @@ -717,7 +713,7 @@ namespace Emby.Server.Implementations.Session if (!isAutomated) { - session.StartAutomaticProgress(_timerFactory, info); + session.StartAutomaticProgress(info); } StartIdleCheckTimer(); diff --git a/Emby.Server.Implementations/Threading/CommonTimer.cs b/Emby.Server.Implementations/Threading/CommonTimer.cs deleted file mode 100644 index 5a05da564..000000000 --- a/Emby.Server.Implementations/Threading/CommonTimer.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System; -using System.Threading; -using MediaBrowser.Model.Threading; - -namespace Emby.Server.Implementations.Threading -{ - public class CommonTimer : ITimer - { - private readonly Timer _timer; - - public CommonTimer(Action callback, object state, TimeSpan dueTime, TimeSpan period) - { - _timer = new Timer(new TimerCallback(callback), state, dueTime, period); - } - - public CommonTimer(Action callback, object state, int dueTimeMs, int periodMs) - { - _timer = new Timer(new TimerCallback(callback), state, dueTimeMs, periodMs); - } - - public void Change(TimeSpan dueTime, TimeSpan period) - { - _timer.Change(dueTime, period); - } - - public void Change(int dueTimeMs, int periodMs) - { - _timer.Change(dueTimeMs, periodMs); - } - - public void Dispose() - { - _timer.Dispose(); - } - } -} diff --git a/Emby.Server.Implementations/Threading/TimerFactory.cs b/Emby.Server.Implementations/Threading/TimerFactory.cs deleted file mode 100644 index ca50064c7..000000000 --- a/Emby.Server.Implementations/Threading/TimerFactory.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using MediaBrowser.Model.Threading; - -namespace Emby.Server.Implementations.Threading -{ - public class TimerFactory : ITimerFactory - { - public ITimer Create(Action callback, object state, TimeSpan dueTime, TimeSpan period) - { - return new CommonTimer(callback, state, dueTime, period); - } - - public ITimer Create(Action callback, object state, int dueTimeMs, int periodMs) - { - return new CommonTimer(callback, state, dueTimeMs, periodMs); - } - } -} diff --git a/MediaBrowser.Api/ApiEntryPoint.cs b/MediaBrowser.Api/ApiEntryPoint.cs index c1f753190..8dbc26356 100644 --- a/MediaBrowser.Api/ApiEntryPoint.cs +++ b/MediaBrowser.Api/ApiEntryPoint.cs @@ -18,7 +18,6 @@ using MediaBrowser.Model.Diagnostics; using MediaBrowser.Model.Dto; using MediaBrowser.Model.IO; using MediaBrowser.Model.Session; -using MediaBrowser.Model.Threading; using Microsoft.Extensions.Logging; namespace MediaBrowser.Api @@ -48,7 +47,6 @@ namespace MediaBrowser.Api private readonly ISessionManager _sessionManager; private readonly IFileSystem _fileSystem; private readonly IMediaSourceManager _mediaSourceManager; - public readonly ITimerFactory TimerFactory; public readonly IProcessFactory ProcessFactory; /// @@ -75,7 +73,6 @@ namespace MediaBrowser.Api IServerConfigurationManager config, IFileSystem fileSystem, IMediaSourceManager mediaSourceManager, - ITimerFactory timerFactory, IProcessFactory processFactory, IHttpResultFactory resultFactory) { @@ -84,7 +81,6 @@ namespace MediaBrowser.Api _config = config; _fileSystem = fileSystem; _mediaSourceManager = mediaSourceManager; - TimerFactory = timerFactory; ProcessFactory = processFactory; ResultFactory = resultFactory; @@ -260,7 +256,7 @@ namespace MediaBrowser.Api { lock (_activeTranscodingJobs) { - var job = new TranscodingJob(Logger, TimerFactory) + var job = new TranscodingJob(Logger) { Type = type, Path = path, @@ -765,9 +761,7 @@ namespace MediaBrowser.Api /// Gets or sets the kill timer. /// /// The kill timer. - private ITimer KillTimer { get; set; } - - private readonly ITimerFactory _timerFactory; + private Timer KillTimer { get; set; } public string DeviceId { get; set; } @@ -797,10 +791,9 @@ namespace MediaBrowser.Api public DateTime LastPingDate { get; set; } public int PingTimeout { get; set; } - public TranscodingJob(ILogger logger, ITimerFactory timerFactory) + public TranscodingJob(ILogger logger) { Logger = logger; - _timerFactory = timerFactory; } public void StopKillTimer() @@ -843,7 +836,7 @@ namespace MediaBrowser.Api if (KillTimer == null) { //Logger.LogDebug("Starting kill timer at {0}ms. JobId {1} PlaySessionId {2}", intervalMs, Id, PlaySessionId); - KillTimer = _timerFactory.Create(callback, this, intervalMs, Timeout.Infinite); + KillTimer = new Timer(new TimerCallback(callback), this, intervalMs, Timeout.Infinite); } else { diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs index 641d539f2..073686298 100644 --- a/MediaBrowser.Api/Playback/BaseStreamingService.cs +++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs @@ -336,7 +336,7 @@ namespace MediaBrowser.Api.Playback { if (EnableThrottling(state)) { - transcodingJob.TranscodingThrottler = state.TranscodingThrottler = new TranscodingThrottler(transcodingJob, Logger, ServerConfigurationManager, ApiEntryPoint.Instance.TimerFactory, FileSystem); + transcodingJob.TranscodingThrottler = state.TranscodingThrottler = new TranscodingThrottler(transcodingJob, Logger, ServerConfigurationManager, FileSystem); state.TranscodingThrottler.Start(); } } diff --git a/MediaBrowser.Api/Playback/TranscodingThrottler.cs b/MediaBrowser.Api/Playback/TranscodingThrottler.cs index 9f416098a..0e73d77ef 100644 --- a/MediaBrowser.Api/Playback/TranscodingThrottler.cs +++ b/MediaBrowser.Api/Playback/TranscodingThrottler.cs @@ -1,9 +1,9 @@ using System; +using System.Threading; using System.Threading.Tasks; using MediaBrowser.Common.Configuration; using MediaBrowser.Model.Configuration; using MediaBrowser.Model.IO; -using MediaBrowser.Model.Threading; using Microsoft.Extensions.Logging; namespace MediaBrowser.Api.Playback @@ -12,18 +12,16 @@ namespace MediaBrowser.Api.Playback { private readonly TranscodingJob _job; private readonly ILogger _logger; - private ITimer _timer; + private Timer _timer; private bool _isPaused; private readonly IConfigurationManager _config; - private readonly ITimerFactory _timerFactory; private readonly IFileSystem _fileSystem; - public TranscodingThrottler(TranscodingJob job, ILogger logger, IConfigurationManager config, ITimerFactory timerFactory, IFileSystem fileSystem) + public TranscodingThrottler(TranscodingJob job, ILogger logger, IConfigurationManager config, IFileSystem fileSystem) { _job = job; _logger = logger; _config = config; - _timerFactory = timerFactory; _fileSystem = fileSystem; } @@ -34,7 +32,7 @@ namespace MediaBrowser.Api.Playback public void Start() { - _timer = _timerFactory.Create(TimerCallback, null, 5000, 5000); + _timer = new Timer(TimerCallback, null, 5000, 5000); } private async void TimerCallback(object state) diff --git a/MediaBrowser.Controller/Net/BasePeriodicWebSocketListener.cs b/MediaBrowser.Controller/Net/BasePeriodicWebSocketListener.cs index 4e7e1c8ed..4242a00e2 100644 --- a/MediaBrowser.Controller/Net/BasePeriodicWebSocketListener.cs +++ b/MediaBrowser.Controller/Net/BasePeriodicWebSocketListener.cs @@ -6,7 +6,6 @@ using System.Net.WebSockets; using System.Threading; using System.Threading.Tasks; using MediaBrowser.Model.Net; -using MediaBrowser.Model.Threading; using Microsoft.Extensions.Logging; namespace MediaBrowser.Controller.Net @@ -23,8 +22,8 @@ namespace MediaBrowser.Controller.Net /// /// The _active connections /// - protected readonly List> ActiveConnections = - new List>(); + protected readonly List> ActiveConnections = + new List>(); /// /// Gets the name. @@ -44,8 +43,6 @@ namespace MediaBrowser.Controller.Net /// protected ILogger Logger; - protected ITimerFactory TimerFactory { get; private set; } - protected BasePeriodicWebSocketListener(ILogger logger) { if (logger == null) @@ -111,7 +108,7 @@ namespace MediaBrowser.Controller.Net Logger.LogDebug("{1} Begin transmitting over websocket to {0}", message.Connection.RemoteEndPoint, GetType().Name); var timer = SendOnTimer ? - TimerFactory.Create(TimerCallback, message.Connection, Timeout.Infinite, Timeout.Infinite) : + new Timer(TimerCallback, message.Connection, Timeout.Infinite, Timeout.Infinite) : null; var state = new TStateType @@ -122,7 +119,7 @@ namespace MediaBrowser.Controller.Net lock (ActiveConnections) { - ActiveConnections.Add(new Tuple(message.Connection, cancellationTokenSource, timer, state)); + ActiveConnections.Add(new Tuple(message.Connection, cancellationTokenSource, timer, state)); } if (timer != null) @@ -139,7 +136,7 @@ namespace MediaBrowser.Controller.Net { var connection = (IWebSocketConnection)state; - Tuple tuple; + Tuple tuple; lock (ActiveConnections) { @@ -162,7 +159,7 @@ namespace MediaBrowser.Controller.Net protected void SendData(bool force) { - Tuple[] tuples; + Tuple[] tuples; lock (ActiveConnections) { @@ -190,7 +187,7 @@ namespace MediaBrowser.Controller.Net } } - private async void SendData(Tuple tuple) + private async void SendData(Tuple tuple) { var connection = tuple.Item1; @@ -249,7 +246,7 @@ namespace MediaBrowser.Controller.Net /// Disposes the connection. /// /// The connection. - private void DisposeConnection(Tuple connection) + private void DisposeConnection(Tuple connection) { Logger.LogDebug("{1} stop transmitting over websocket to {0}", connection.Item1.RemoteEndPoint, GetType().Name); diff --git a/MediaBrowser.Controller/Session/SessionInfo.cs b/MediaBrowser.Controller/Session/SessionInfo.cs index d698795dd..f0e81e8e7 100644 --- a/MediaBrowser.Controller/Session/SessionInfo.cs +++ b/MediaBrowser.Controller/Session/SessionInfo.cs @@ -1,10 +1,10 @@ using System; using System.Linq; +using System.Threading; using MediaBrowser.Controller.Entities; using MediaBrowser.Model.Dto; using MediaBrowser.Model.Serialization; using MediaBrowser.Model.Session; -using MediaBrowser.Model.Threading; using Microsoft.Extensions.Logging; namespace MediaBrowser.Controller.Session @@ -268,10 +268,10 @@ namespace MediaBrowser.Controller.Session } private readonly object _progressLock = new object(); - private ITimer _progressTimer; + private Timer _progressTimer; private PlaybackProgressInfo _lastProgressInfo; - public void StartAutomaticProgress(ITimerFactory timerFactory, PlaybackProgressInfo progressInfo) + public void StartAutomaticProgress(PlaybackProgressInfo progressInfo) { if (_disposed) { @@ -284,7 +284,7 @@ namespace MediaBrowser.Controller.Session if (_progressTimer == null) { - _progressTimer = timerFactory.Create(OnProgressTimerCallback, null, 1000, 1000); + _progressTimer = new Timer(OnProgressTimerCallback, null, 1000, 1000); } else { diff --git a/MediaBrowser.Model/Threading/ITimer.cs b/MediaBrowser.Model/Threading/ITimer.cs deleted file mode 100644 index 2bec22266..000000000 --- a/MediaBrowser.Model/Threading/ITimer.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; - -namespace MediaBrowser.Model.Threading -{ - public interface ITimer : IDisposable - { - void Change(TimeSpan dueTime, TimeSpan period); - void Change(int dueTimeMs, int periodMs); - } -} diff --git a/MediaBrowser.Model/Threading/ITimerFactory.cs b/MediaBrowser.Model/Threading/ITimerFactory.cs deleted file mode 100644 index 1161958a4..000000000 --- a/MediaBrowser.Model/Threading/ITimerFactory.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; - -namespace MediaBrowser.Model.Threading -{ - public interface ITimerFactory - { - ITimer Create(Action callback, object state, TimeSpan dueTime, TimeSpan period); - ITimer Create(Action callback, object state, int dueTimeMs, int periodMs); - } -} diff --git a/RSSDP/SsdpDeviceLocator.cs b/RSSDP/SsdpDeviceLocator.cs index 1348cce8d..128bdfcbb 100644 --- a/RSSDP/SsdpDeviceLocator.cs +++ b/RSSDP/SsdpDeviceLocator.cs @@ -8,7 +8,6 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using MediaBrowser.Model.Net; -using MediaBrowser.Model.Threading; namespace Rssdp.Infrastructure { @@ -23,8 +22,7 @@ namespace Rssdp.Infrastructure private List _Devices; private ISsdpCommunicationsServer _CommunicationsServer; - private ITimer _BroadcastTimer; - private ITimerFactory _timerFactory; + private Timer _BroadcastTimer; private object _timerLock = new object(); private readonly TimeSpan DefaultSearchWaitTime = TimeSpan.FromSeconds(4); @@ -37,12 +35,11 @@ namespace Rssdp.Infrastructure /// /// Default constructor. /// - public SsdpDeviceLocator(ISsdpCommunicationsServer communicationsServer, ITimerFactory timerFactory) + public SsdpDeviceLocator(ISsdpCommunicationsServer communicationsServer) { if (communicationsServer == null) throw new ArgumentNullException(nameof(communicationsServer)); _CommunicationsServer = communicationsServer; - _timerFactory = timerFactory; _CommunicationsServer.ResponseReceived += CommsServer_ResponseReceived; _Devices = new List(); @@ -94,7 +91,7 @@ namespace Rssdp.Infrastructure { if (_BroadcastTimer == null) { - _BroadcastTimer = _timerFactory.Create(OnBroadcastTimerCallback, null, dueTime, period); + _BroadcastTimer = new Timer(OnBroadcastTimerCallback, null, dueTime, period); } else { diff --git a/RSSDP/SsdpDevicePublisher.cs b/RSSDP/SsdpDevicePublisher.cs index 8a73e6a2d..ce64ba117 100644 --- a/RSSDP/SsdpDevicePublisher.cs +++ b/RSSDP/SsdpDevicePublisher.cs @@ -7,7 +7,6 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using MediaBrowser.Model.Net; -using MediaBrowser.Model.Threading; using Rssdp; namespace Rssdp.Infrastructure @@ -27,8 +26,7 @@ namespace Rssdp.Infrastructure private IList _Devices; private IReadOnlyList _ReadOnlyDevices; - private ITimer _RebroadcastAliveNotificationsTimer; - private ITimerFactory _timerFactory; + private Timer _RebroadcastAliveNotificationsTimer; private IDictionary _RecentSearchRequests; @@ -39,7 +37,7 @@ namespace Rssdp.Infrastructure /// /// Default constructor. /// - public SsdpDevicePublisher(ISsdpCommunicationsServer communicationsServer, ITimerFactory timerFactory, string osName, string osVersion) + public SsdpDevicePublisher(ISsdpCommunicationsServer communicationsServer, string osName, string osVersion) { if (communicationsServer == null) throw new ArgumentNullException(nameof(communicationsServer)); if (osName == null) throw new ArgumentNullException(nameof(osName)); @@ -48,7 +46,6 @@ namespace Rssdp.Infrastructure if (osVersion.Length == 0) throw new ArgumentException("osVersion cannot be an empty string.", nameof(osName)); _SupportPnpRootDevice = true; - _timerFactory = timerFactory; _Devices = new List(); _ReadOnlyDevices = new ReadOnlyCollection(_Devices); _RecentSearchRequests = new Dictionary(StringComparer.OrdinalIgnoreCase); @@ -64,7 +61,7 @@ namespace Rssdp.Infrastructure public void StartBroadcastingAliveMessages(TimeSpan interval) { - _RebroadcastAliveNotificationsTimer = _timerFactory.Create(SendAllAliveNotifications, null, TimeSpan.FromSeconds(5), interval); + _RebroadcastAliveNotificationsTimer = new Timer(SendAllAliveNotifications, null, TimeSpan.FromSeconds(5), interval); } /// -- cgit v1.2.3 From 70c85925af31ee341f87fced39a67ab7fb4eed77 Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Wed, 6 Feb 2019 21:31:41 +0100 Subject: Move some arrays to generics --- Emby.Drawing/ImageProcessor.cs | 18 +++++++++--------- Emby.Drawing/NullImageEncoder.cs | 15 ++++++--------- Emby.Server.Implementations/IO/LibraryMonitor.cs | 8 ++++---- .../Library/Resolvers/PhotoResolver.cs | 7 ++++--- Emby.Server.Implementations/Services/ResponseHelper.cs | 2 +- Emby.Server.Implementations/Services/ServiceExec.cs | 2 -- Jellyfin.Drawing.Skia/SkiaEncoder.cs | 13 ++++++++----- MediaBrowser.Controller/Drawing/IImageEncoder.cs | 5 +++-- MediaBrowser.Controller/Drawing/IImageProcessor.cs | 6 +++--- 9 files changed, 38 insertions(+), 38 deletions(-) (limited to 'Emby.Server.Implementations/IO/LibraryMonitor.cs') diff --git a/Emby.Drawing/ImageProcessor.cs b/Emby.Drawing/ImageProcessor.cs index 097b4c40b..1e4646227 100644 --- a/Emby.Drawing/ImageProcessor.cs +++ b/Emby.Drawing/ImageProcessor.cs @@ -83,8 +83,8 @@ namespace Emby.Drawing } } - public string[] SupportedInputFormats => - new string[] + public IReadOnlyCollection SupportedInputFormats => + new HashSet(StringComparer.OrdinalIgnoreCase) { "tiff", "tif", @@ -137,14 +137,14 @@ namespace Emby.Drawing } } - public ImageFormat[] GetSupportedImageOutputFormats() - { - return _imageEncoder.SupportedOutputFormats; - } + public IReadOnlyCollection GetSupportedImageOutputFormats() + => _imageEncoder.SupportedOutputFormats; + + private static readonly HashSet TransparentImageTypes + = new HashSet(StringComparer.OrdinalIgnoreCase) { ".png", ".webp", ".gif" }; - private static readonly string[] TransparentImageTypes = new string[] { ".png", ".webp", ".gif" }; public bool SupportsTransparency(string path) - => TransparentImageTypes.Contains(Path.GetExtension(path).ToLowerInvariant()); + => TransparentImageTypes.Contains(Path.GetExtension(path)); public async Task<(string path, string mimeType, DateTime dateModified)> ProcessImage(ImageProcessingOptions options) { @@ -472,7 +472,7 @@ namespace Emby.Drawing return (originalImagePath, dateModified); } - if (!_imageEncoder.SupportedInputFormats.Contains(inputFormat, StringComparer.OrdinalIgnoreCase)) + if (!_imageEncoder.SupportedInputFormats.Contains(inputFormat)) { try { diff --git a/Emby.Drawing/NullImageEncoder.cs b/Emby.Drawing/NullImageEncoder.cs index 14f0424ac..fc4a5af9f 100644 --- a/Emby.Drawing/NullImageEncoder.cs +++ b/Emby.Drawing/NullImageEncoder.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using MediaBrowser.Controller.Drawing; using MediaBrowser.Model.Drawing; @@ -6,15 +7,11 @@ namespace Emby.Drawing { public class NullImageEncoder : IImageEncoder { - public string[] SupportedInputFormats => - new[] - { - "png", - "jpeg", - "jpg" - }; - - public ImageFormat[] SupportedOutputFormats => new[] { ImageFormat.Jpg, ImageFormat.Png }; + public IReadOnlyCollection SupportedInputFormats + => new HashSet(StringComparer.OrdinalIgnoreCase) { "png", "jpeg", "jpg" }; + + public IReadOnlyCollection SupportedOutputFormats + => new HashSet() { ImageFormat.Jpg, ImageFormat.Png }; public void CropWhiteSpace(string inputPath, string outputPath) { diff --git a/Emby.Server.Implementations/IO/LibraryMonitor.cs b/Emby.Server.Implementations/IO/LibraryMonitor.cs index 11c684b12..607a4d333 100644 --- a/Emby.Server.Implementations/IO/LibraryMonitor.cs +++ b/Emby.Server.Implementations/IO/LibraryMonitor.cs @@ -34,7 +34,7 @@ namespace Emby.Server.Implementations.IO /// /// Any file name ending in any of these will be ignored by the watchers /// - private readonly string[] _alwaysIgnoreFiles = new string[] + private readonly HashSet _alwaysIgnoreFiles = new HashSet(StringComparer.OrdinalIgnoreCase) { "small.jpg", "albumart.jpg", @@ -53,7 +53,7 @@ namespace Emby.Server.Implementations.IO ".actors" }; - private readonly string[] _alwaysIgnoreExtensions = new string[] + private readonly HashSet _alwaysIgnoreExtensions = new HashSet(StringComparer.OrdinalIgnoreCase) { // thumbs.db ".db", @@ -456,8 +456,8 @@ namespace Emby.Server.Implementations.IO var filename = Path.GetFileName(path); var monitorPath = !string.IsNullOrEmpty(filename) && - !_alwaysIgnoreFiles.Contains(filename, StringComparer.OrdinalIgnoreCase) && - !_alwaysIgnoreExtensions.Contains(Path.GetExtension(path) ?? string.Empty, StringComparer.OrdinalIgnoreCase) && + !_alwaysIgnoreFiles.Contains(filename) && + !_alwaysIgnoreExtensions.Contains(Path.GetExtension(path)) && _alwaysIgnoreSubstrings.All(i => path.IndexOf(i, StringComparison.OrdinalIgnoreCase) == -1); // Ignore certain files diff --git a/Emby.Server.Implementations/Library/Resolvers/PhotoResolver.cs b/Emby.Server.Implementations/Library/Resolvers/PhotoResolver.cs index 9de766767..a3298c580 100644 --- a/Emby.Server.Implementations/Library/Resolvers/PhotoResolver.cs +++ b/Emby.Server.Implementations/Library/Resolvers/PhotoResolver.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.IO; using System.Linq; using MediaBrowser.Controller.Drawing; @@ -85,7 +86,7 @@ namespace Emby.Server.Implementations.Library.Resolvers return false; } - private static readonly string[] IgnoreFiles = + private static readonly HashSet IgnoreFiles = new HashSet(StringComparer.OrdinalIgnoreCase) { "folder", "thumb", @@ -102,7 +103,7 @@ namespace Emby.Server.Implementations.Library.Resolvers { var filename = Path.GetFileNameWithoutExtension(path) ?? string.Empty; - if (IgnoreFiles.Contains(filename, StringComparer.OrdinalIgnoreCase)) + if (IgnoreFiles.Contains(filename)) { return false; } @@ -112,7 +113,7 @@ namespace Emby.Server.Implementations.Library.Resolvers return false; } - return imageProcessor.SupportedInputFormats.Contains((Path.GetExtension(path) ?? string.Empty).TrimStart('.'), StringComparer.OrdinalIgnoreCase); + return imageProcessor.SupportedInputFormats.Contains((Path.GetExtension(path) ?? string.Empty).TrimStart('.')); } } diff --git a/Emby.Server.Implementations/Services/ResponseHelper.cs b/Emby.Server.Implementations/Services/ResponseHelper.cs index 16de1a083..dc9975347 100644 --- a/Emby.Server.Implementations/Services/ResponseHelper.cs +++ b/Emby.Server.Implementations/Services/ResponseHelper.cs @@ -70,7 +70,7 @@ namespace Emby.Server.Implementations.Services response.ContentType = defaultContentType; } - if (new HashSet { "application/json", }.Contains(response.ContentType)) + if (response.ContentType == "application/json") { response.ContentType += "; charset=utf-8"; } diff --git a/Emby.Server.Implementations/Services/ServiceExec.cs b/Emby.Server.Implementations/Services/ServiceExec.cs index aa67a3601..79f5c59e6 100644 --- a/Emby.Server.Implementations/Services/ServiceExec.cs +++ b/Emby.Server.Implementations/Services/ServiceExec.cs @@ -23,8 +23,6 @@ namespace Emby.Server.Implementations.Services "POLL", "SUBSCRIBE", "UNSUBSCRIBE" }; - public static HashSet AllVerbsSet = new HashSet(AllVerbs); - public static List GetActions(this Type serviceType) { var list = new List(); diff --git a/Jellyfin.Drawing.Skia/SkiaEncoder.cs b/Jellyfin.Drawing.Skia/SkiaEncoder.cs index f1b886ec6..dc714ed18 100644 --- a/Jellyfin.Drawing.Skia/SkiaEncoder.cs +++ b/Jellyfin.Drawing.Skia/SkiaEncoder.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; @@ -35,8 +36,8 @@ namespace Jellyfin.Drawing.Skia LogVersion(); } - public string[] SupportedInputFormats => - new[] + public IReadOnlyCollection SupportedInputFormats => + new HashSet(StringComparer.OrdinalIgnoreCase) { "jpeg", "jpg", @@ -62,7 +63,8 @@ namespace Jellyfin.Drawing.Skia "arw" }; - public ImageFormat[] SupportedOutputFormats => new[] { ImageFormat.Webp, ImageFormat.Jpg, ImageFormat.Png }; + public IReadOnlyCollection SupportedOutputFormats + => new HashSet() { ImageFormat.Webp, ImageFormat.Jpg, ImageFormat.Png }; private void LogVersion() { @@ -253,7 +255,8 @@ namespace Jellyfin.Drawing.Skia } } - private static string[] TransparentImageTypes = new string[] { ".png", ".gif", ".webp" }; + private static readonly HashSet TransparentImageTypes + = new HashSet(StringComparer.OrdinalIgnoreCase) { ".png", ".gif", ".webp" }; internal static SKBitmap Decode(string path, bool forceCleanBitmap, IFileSystem fileSystem, ImageOrientation? orientation, out SKEncodedOrigin origin) { @@ -262,7 +265,7 @@ namespace Jellyfin.Drawing.Skia throw new FileNotFoundException("File not found", path); } - var requiresTransparencyHack = TransparentImageTypes.Contains(Path.GetExtension(path) ?? string.Empty); + var requiresTransparencyHack = TransparentImageTypes.Contains(Path.GetExtension(path)); if (requiresTransparencyHack || forceCleanBitmap) { diff --git a/MediaBrowser.Controller/Drawing/IImageEncoder.cs b/MediaBrowser.Controller/Drawing/IImageEncoder.cs index 5b8c9da6f..4eaecd0a0 100644 --- a/MediaBrowser.Controller/Drawing/IImageEncoder.cs +++ b/MediaBrowser.Controller/Drawing/IImageEncoder.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using MediaBrowser.Model.Drawing; namespace MediaBrowser.Controller.Drawing @@ -9,12 +10,12 @@ namespace MediaBrowser.Controller.Drawing /// Gets the supported input formats. /// /// The supported input formats. - string[] SupportedInputFormats { get; } + IReadOnlyCollection SupportedInputFormats { get; } /// /// Gets the supported output formats. /// /// The supported output formats. - ImageFormat[] SupportedOutputFormats { get; } + IReadOnlyCollection SupportedOutputFormats { get; } /// /// Encodes the image. diff --git a/MediaBrowser.Controller/Drawing/IImageProcessor.cs b/MediaBrowser.Controller/Drawing/IImageProcessor.cs index 783182730..b713d50b1 100644 --- a/MediaBrowser.Controller/Drawing/IImageProcessor.cs +++ b/MediaBrowser.Controller/Drawing/IImageProcessor.cs @@ -18,7 +18,7 @@ namespace MediaBrowser.Controller.Drawing /// Gets the supported input formats. /// /// The supported input formats. - string[] SupportedInputFormats { get; } + IReadOnlyCollection SupportedInputFormats { get; } /// /// Gets the image enhancers. @@ -96,8 +96,8 @@ namespace MediaBrowser.Controller.Drawing /// /// Gets the supported image output formats. /// - /// ImageOutputFormat[]. - ImageFormat[] GetSupportedImageOutputFormats(); + /// IReadOnlyCollection{ImageOutput}. + IReadOnlyCollection GetSupportedImageOutputFormats(); /// /// Creates the image collage. -- cgit v1.2.3