From 14cc7d91ee42bcb3944c72ea501ac3a5c9ebb374 Mon Sep 17 00:00:00 2001 From: Victor Usoltsev Date: Thu, 6 Oct 2022 01:06:57 +1300 Subject: [PATCH 1/2] Upgrades nuget packages. Removes deprecated packages. Fixes build warnings. --- .../Ombi.Api.Mattermost.csproj | 2 +- src/Ombi.Api.MusicBrainz/MusicBrainzApi.cs | 22 ++--- .../Ombi.Api.MusicBrainz.csproj | 2 +- .../Ombi.Api.Notifications.csproj | 2 +- src/Ombi.Api.Radarr/Ombi.Api.Radarr.csproj | 2 +- src/Ombi.Api.Twilio/Ombi.Api.Twilio.csproj | 2 +- src/Ombi.Api/Ombi.Api.csproj | 6 +- .../Engine/MovieRequestEngineTests.cs | 3 +- .../Engine/MovieRequestLimitsTests.cs | 29 +++---- .../Engine/MusicRequestLimitTests.cs | 29 +++---- .../Engine/TvRequestLimitsTests.cs | 37 ++++---- src/Ombi.Core.Tests/Engine/VoteEngineTests.cs | 7 +- src/Ombi.Core.Tests/Ombi.Core.Tests.csproj | 14 +-- .../Request/ExistingMovieRequestRuleTests.cs | 18 ++-- .../Request/ExistingPlexRequestRuleTests.cs | 8 +- .../Request/ExistingTvRequestRuleTests.cs | 6 +- .../Senders/MassEmailSenderTests.cs | 10 +-- .../Services/PlexServiceTests.cs | 6 +- .../Services/RecentlyRequestedServiceTests.cs | 25 +++--- src/Ombi.Core/Ombi.Core.csproj | 13 ++- src/Ombi.DependencyInjection/IocExtensions.cs | 11 ++- .../Ombi.DependencyInjection.csproj | 2 +- .../Ombi.HealthChecks.csproj | 2 +- .../Ombi.Helpers.Tests.csproj | 6 +- src/Ombi.Helpers/AssemblyHelper.cs | 9 +- src/Ombi.Helpers/Ombi.Helpers.csproj | 13 ++- src/Ombi.Hubs/INotificationHubService.cs | 12 +++ src/Ombi.Hubs/NotificationHub.cs | 87 +++++++------------ src/Ombi.Hubs/NotificationHubService.cs | 44 ++++++++++ src/Ombi.Hubs/NotificationHubUser.cs | 9 ++ src/Ombi.Hubs/Ombi.Hubs.csproj | 3 +- src/Ombi.Mapping/Ombi.Mapping.csproj | 6 +- .../Ombi.Notifications.Tests.csproj | 14 +-- .../Ombi.Notifications.csproj | 4 +- .../AvailabilityCheckerTests.cs | 9 +- src/Ombi.Schedule.Tests/IssuesPurgeTests.cs | 7 +- .../Ombi.Schedule.Tests.csproj | 14 +-- .../PlexAvailabilityCheckerTests.cs | 29 +++---- .../PlexContentSyncTests.cs | 10 +-- .../PlexWatchlistImportTests.cs | 7 +- .../Jobs/ArrAvailabilityChecker.cs | 9 +- src/Ombi.Schedule/Jobs/AvailabilityChecker.cs | 10 +-- .../Jobs/Couchpotato/CouchPotatoSync.cs | 16 ++-- .../Jobs/Emby/EmbyAvaliabilityChecker.cs | 9 +- .../Jobs/Emby/EmbyContentSync.cs | 15 ++-- .../Jobs/Emby/EmbyEpisodeSync.cs | 11 +-- .../Jobs/Emby/EmbyUserImporter.cs | 11 +-- .../Jellyfin/JellyfinAvaliabilityChecker.cs | 9 +- .../Jobs/Jellyfin/JellyfinContentSync.cs | 15 ++-- .../Jobs/Jellyfin/JellyfinEpisodeSync.cs | 11 +-- .../Jobs/Jellyfin/JellyfinUserImporter.cs | 11 +-- .../Jobs/Lidarr/LidarrAlbumSync.cs | 15 ++-- .../Jobs/Lidarr/LidarrArtistSync.cs | 14 ++- .../Jobs/Lidarr/LidarrAvailabilityChecker.cs | 13 ++- src/Ombi.Schedule/Jobs/Ombi/NewsletterJob.cs | 17 ++-- .../Jobs/Ombi/RefreshMetadata.cs | 14 ++- .../Jobs/Plex/PlexAvailabilityChecker.cs | 14 ++- .../Jobs/Plex/PlexContentSync.cs | 11 +-- .../Jobs/Plex/PlexEpisodeSync.cs | 16 ++-- .../Jobs/Plex/PlexUserImporter.cs | 13 ++- .../Jobs/Plex/PlexWatchlistImport.cs | 17 ++-- src/Ombi.Schedule/Ombi.Schedule.csproj | 12 +-- .../Ombi.Settings.Tests.csproj | 6 +- src/Ombi.Settings/Ombi.Settings.csproj | 4 +- src/Ombi.Store/Ombi.Store.csproj | 14 +-- src/Ombi.Test.Common/MockHelper.cs | 2 +- src/Ombi.Test.Common/Ombi.Test.Common.csproj | 4 +- src/Ombi.Tests/Ombi.Tests.csproj | 16 ++-- src/Ombi.Tests/SignalRHelper.cs | 4 +- .../Models/MovieDbSearchResult.cs | 2 +- .../Ombi.Api.TheMovieDb.csproj | 2 +- src/Ombi.Updater/Ombi.Updater.csproj | 11 ++- src/Ombi.Updater/Program.cs | 3 +- src/Ombi/Controllers/V2/HubController.cs | 28 +++--- src/Ombi/Ombi.csproj | 37 ++++---- src/Ombi/Startup.cs | 9 +- 76 files changed, 446 insertions(+), 520 deletions(-) create mode 100644 src/Ombi.Hubs/INotificationHubService.cs create mode 100644 src/Ombi.Hubs/NotificationHubService.cs create mode 100644 src/Ombi.Hubs/NotificationHubUser.cs diff --git a/src/Ombi.Api.Mattermost/Ombi.Api.Mattermost.csproj b/src/Ombi.Api.Mattermost/Ombi.Api.Mattermost.csproj index 16c3a8558..2dd241a24 100644 --- a/src/Ombi.Api.Mattermost/Ombi.Api.Mattermost.csproj +++ b/src/Ombi.Api.Mattermost/Ombi.Api.Mattermost.csproj @@ -11,7 +11,7 @@ - + diff --git a/src/Ombi.Api.MusicBrainz/MusicBrainzApi.cs b/src/Ombi.Api.MusicBrainz/MusicBrainzApi.cs index e870eb07f..e667d8ef1 100644 --- a/src/Ombi.Api.MusicBrainz/MusicBrainzApi.cs +++ b/src/Ombi.Api.MusicBrainz/MusicBrainzApi.cs @@ -1,12 +1,10 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using System.Net.Http; using System.Threading; using System.Threading.Tasks; using Hqub.MusicBrainz.API; using Hqub.MusicBrainz.API.Entities; -using Hqub.MusicBrainz.API.Entities.Collections; using Newtonsoft.Json; using Ombi.Api.MusicBrainz.Models; @@ -14,28 +12,30 @@ namespace Ombi.Api.MusicBrainz { public class MusicBrainzApi : IMusicBrainzApi { + private readonly MusicBrainzClient _client; private readonly IApi _api; - public MusicBrainzApi(IApi api) + public MusicBrainzApi(MusicBrainzClient client, IApi api) { + _client = client; _api = api; } public Task GetAlbumInformation(string albumId) { - var album = Release.GetAsync(albumId); + var album = _client.Releases.GetAsync(albumId); return album; } public async Task> SearchArtist(string artistQuery) { - var artist = await Artist.SearchAsync(artistQuery, 10); + var artist = await _client.Artists.SearchAsync(artistQuery, 10); return artist.Items.Where(x => x.Type != null); } public async Task GetArtistInformation(string artistId) { - var artist = await Artist.GetAsync(artistId, "artist-rels", "url-rels", "releases", "release-groups"); + var artist = await _client.Artists.GetAsync(artistId, "artist-rels", "url-rels", "releases", "release-groups"); return artist; } @@ -49,8 +49,7 @@ public async Task> GetReleaseForArtist(string artistId) }; // Search for a release by title. - var releases = await Release.SearchAsync(query); - + var releases = await _client.Releases.SearchAsync(query); return releases.Items; } @@ -65,10 +64,5 @@ public async Task GetCoverArtForReleaseGroup(string musicBrainz } return null; } - - private void AddHeaders(Request req) - { - req.AddHeader("Accept", "application/json"); - } } } diff --git a/src/Ombi.Api.MusicBrainz/Ombi.Api.MusicBrainz.csproj b/src/Ombi.Api.MusicBrainz/Ombi.Api.MusicBrainz.csproj index c8a78e491..1a6497ceb 100644 --- a/src/Ombi.Api.MusicBrainz/Ombi.Api.MusicBrainz.csproj +++ b/src/Ombi.Api.MusicBrainz/Ombi.Api.MusicBrainz.csproj @@ -7,7 +7,7 @@ - + diff --git a/src/Ombi.Api.Notifications/Ombi.Api.Notifications.csproj b/src/Ombi.Api.Notifications/Ombi.Api.Notifications.csproj index 6406ef9de..029acb3c5 100644 --- a/src/Ombi.Api.Notifications/Ombi.Api.Notifications.csproj +++ b/src/Ombi.Api.Notifications/Ombi.Api.Notifications.csproj @@ -7,7 +7,7 @@ - + diff --git a/src/Ombi.Api.Radarr/Ombi.Api.Radarr.csproj b/src/Ombi.Api.Radarr/Ombi.Api.Radarr.csproj index 889aa0ea6..97d0cb959 100644 --- a/src/Ombi.Api.Radarr/Ombi.Api.Radarr.csproj +++ b/src/Ombi.Api.Radarr/Ombi.Api.Radarr.csproj @@ -11,7 +11,7 @@ - + diff --git a/src/Ombi.Api.Twilio/Ombi.Api.Twilio.csproj b/src/Ombi.Api.Twilio/Ombi.Api.Twilio.csproj index 8e12c7c67..17dc14c25 100644 --- a/src/Ombi.Api.Twilio/Ombi.Api.Twilio.csproj +++ b/src/Ombi.Api.Twilio/Ombi.Api.Twilio.csproj @@ -6,7 +6,7 @@ - + diff --git a/src/Ombi.Api/Ombi.Api.csproj b/src/Ombi.Api/Ombi.Api.csproj index 7670d4d14..ab0d14b5e 100644 --- a/src/Ombi.Api/Ombi.Api.csproj +++ b/src/Ombi.Api/Ombi.Api.csproj @@ -12,9 +12,9 @@ - - - + + + diff --git a/src/Ombi.Core.Tests/Engine/MovieRequestEngineTests.cs b/src/Ombi.Core.Tests/Engine/MovieRequestEngineTests.cs index f8ced161f..8418cddbc 100644 --- a/src/Ombi.Core.Tests/Engine/MovieRequestEngineTests.cs +++ b/src/Ombi.Core.Tests/Engine/MovieRequestEngineTests.cs @@ -2,7 +2,6 @@ using Moq; using Moq.AutoMock; using NUnit.Framework; -using Ombi.Core.Authentication; using Ombi.Core.Engine; using Ombi.Core.Helpers; using Ombi.Core.Models.Requests; @@ -52,7 +51,7 @@ public void Setup() _subject = _mocker.CreateInstance(); var list = DbHelper.GetQueryableMockDbSet(new RequestSubscription()); - _mocker.Setup, IQueryable>(x => x.GetAll()).Returns(new List().AsQueryable().BuildMock().Object); + _mocker.Setup, IQueryable>(x => x.GetAll()).Returns(new List().AsQueryable().BuildMock()); } [Test] diff --git a/src/Ombi.Core.Tests/Engine/MovieRequestLimitsTests.cs b/src/Ombi.Core.Tests/Engine/MovieRequestLimitsTests.cs index 88e1c75d2..5bb4c69cb 100644 --- a/src/Ombi.Core.Tests/Engine/MovieRequestLimitsTests.cs +++ b/src/Ombi.Core.Tests/Engine/MovieRequestLimitsTests.cs @@ -3,7 +3,6 @@ using Moq.AutoMock; using NUnit.Framework; using Ombi.Core.Authentication; -using Ombi.Core.Engine; using Ombi.Core.Helpers; using Ombi.Core.Models; using Ombi.Core.Services; @@ -64,7 +63,7 @@ public async Task No_UserPassedIn_UsernotExist_No_MovieLimit_Set() var user = new OmbiUser(); var um = _mocker.GetMock(); - um.SetupGet(x => x.Users).Returns(new List { user }.AsQueryable().BuildMock().Object); + um.SetupGet(x => x.Users).Returns(new List { user }.AsQueryable().BuildMock()); @@ -82,7 +81,7 @@ public async Task No_UserPassedIn_No_MovieLimit_Set() }; var um = _mocker.GetMock(); - um.SetupGet(x => x.Users).Returns(new List { user }.AsQueryable().BuildMock().Object); + um.SetupGet(x => x.Users).Returns(new List { user }.AsQueryable().BuildMock()); @@ -100,7 +99,7 @@ public async Task UserPassedIn_MovieLimit_Set_No_Requests() MovieRequestLimit = 1 }; var repoMock = _mocker.GetMock>(); - repoMock.Setup(x => x.GetAll()).Returns(new List().AsQueryable().BuildMock().Object); + repoMock.Setup(x => x.GetAll()).Returns(new List().AsQueryable().BuildMock()); var result = await _subject.GetRemainingMovieRequests(user); @@ -131,7 +130,7 @@ public async Task UserPassedIn_MovieLimit_Set_Limit() } }; var repoMock = _mocker.GetMock>(); - repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object); + repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock()); var result = await _subject.GetRemainingMovieRequests(user); @@ -206,7 +205,7 @@ public async Task UserPassedIn_MovieLimit_Set_Limit_MultipleRequests() }, }; var repoMock = _mocker.GetMock>(); - repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object); + repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock()); var result = await _subject.GetRemainingMovieRequests(user); @@ -239,7 +238,7 @@ public async Task UserPassedIn_MovieLimit_Set_Limit_Daily_NoRequestsToday() } }; var repoMock = _mocker.GetMock>(); - repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object); + repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock()); var result = await _subject.GetRemainingMovieRequests(user); @@ -272,7 +271,7 @@ public async Task UserPassedIn_MovieLimit_Set_Limit_Daily_OneRequestsToday() } }; var repoMock = _mocker.GetMock>(); - repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object); + repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock()); var result = await _subject.GetRemainingMovieRequests(user); @@ -311,7 +310,7 @@ public async Task UserPassedIn_MovieLimit_Set_Limit_Daily_AllRequestsToday() }, }; var repoMock = _mocker.GetMock>(); - repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object); + repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock()); var result = await _subject.GetRemainingMovieRequests(user); @@ -344,7 +343,7 @@ public async Task UserPassedIn_MovieLimit_Set_Limit_Weekly_NoRequests() } }; var repoMock = _mocker.GetMock>(); - repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object); + repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock()); var result = await _subject.GetRemainingMovieRequests(user); @@ -376,7 +375,7 @@ public async Task UserPassedIn_MovieLimit_Set_Limit_Weekly_OneRequestsWeek() } }; var repoMock = _mocker.GetMock>(); - repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object); + repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock()); var result = await _subject.GetRemainingMovieRequests(user, today); @@ -415,7 +414,7 @@ public async Task UserPassedIn_MovieLimit_Set_Limit_Weekly_AllRequestsWeek() }, }; var repoMock = _mocker.GetMock>(); - repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object); + repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock()); var result = await _subject.GetRemainingMovieRequests(user, today); @@ -448,7 +447,7 @@ public async Task UserPassedIn_MovieLimit_Set_Limit_Monthly_NoRequests() } }; var repoMock = _mocker.GetMock>(); - repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object); + repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock()); var result = await _subject.GetRemainingMovieRequests(user, today); @@ -481,7 +480,7 @@ public async Task UserPassedIn_MovieLimit_Set_Limit_Monthly_OneRequests() } }; var repoMock = _mocker.GetMock>(); - repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object); + repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock()); var result = await _subject.GetRemainingMovieRequests(user, today); @@ -521,7 +520,7 @@ public async Task UserPassedIn_MovieLimit_Set_Limit_Monthly_AllRequests() }, }; var repoMock = _mocker.GetMock>(); - repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object); + repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock()); var result = await _subject.GetRemainingMovieRequests(user, today); diff --git a/src/Ombi.Core.Tests/Engine/MusicRequestLimitTests.cs b/src/Ombi.Core.Tests/Engine/MusicRequestLimitTests.cs index 93dd5050d..477ab7502 100644 --- a/src/Ombi.Core.Tests/Engine/MusicRequestLimitTests.cs +++ b/src/Ombi.Core.Tests/Engine/MusicRequestLimitTests.cs @@ -3,7 +3,6 @@ using Moq.AutoMock; using NUnit.Framework; using Ombi.Core.Authentication; -using Ombi.Core.Engine; using Ombi.Core.Helpers; using Ombi.Core.Models; using Ombi.Core.Services; @@ -62,7 +61,7 @@ public async Task No_UserPassedIn_UsernotExist_No_MusicLimit_Set() var user = new OmbiUser(); var um = _mocker.GetMock(); - um.SetupGet(x => x.Users).Returns(new List { user }.AsQueryable().BuildMock().Object); + um.SetupGet(x => x.Users).Returns(new List { user }.AsQueryable().BuildMock()); @@ -80,7 +79,7 @@ public async Task No_UserPassedIn_No_MusicLimit_Set() }; var um = _mocker.GetMock(); - um.SetupGet(x => x.Users).Returns(new List { user }.AsQueryable().BuildMock().Object); + um.SetupGet(x => x.Users).Returns(new List { user }.AsQueryable().BuildMock()); @@ -98,7 +97,7 @@ public async Task UserPassedIn_MusicLimit_Set_No_Requests() MusicRequestLimit = 1 }; var repoMock = _mocker.GetMock>(); - repoMock.Setup(x => x.GetAll()).Returns(new List().AsQueryable().BuildMock().Object); + repoMock.Setup(x => x.GetAll()).Returns(new List().AsQueryable().BuildMock()); var result = await _subject.GetRemainingMusicRequests(user); @@ -129,7 +128,7 @@ public async Task UserPassedIn_MusicLimit_Set_Limit() } }; var repoMock = _mocker.GetMock>(); - repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object); + repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock()); var result = await _subject.GetRemainingMusicRequests(user); @@ -204,7 +203,7 @@ public async Task UserPassedIn_MusicLimit_Set_Limit_MultipleRequests() }, }; var repoMock = _mocker.GetMock>(); - repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object); + repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock()); var result = await _subject.GetRemainingMusicRequests(user); @@ -237,7 +236,7 @@ public async Task UserPassedIn_MusicLimit_Set_Limit_Daily_NoRequestsToday() } }; var repoMock = _mocker.GetMock>(); - repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object); + repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock()); var result = await _subject.GetRemainingMusicRequests(user); @@ -270,7 +269,7 @@ public async Task UserPassedIn_MusicLimit_Set_Limit_Daily_OneRequestsToday() } }; var repoMock = _mocker.GetMock>(); - repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object); + repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock()); var result = await _subject.GetRemainingMusicRequests(user); @@ -309,7 +308,7 @@ public async Task UserPassedIn_MusicLimit_Set_Limit_Daily_AllRequestsToday() }, }; var repoMock = _mocker.GetMock>(); - repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object); + repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock()); var result = await _subject.GetRemainingMusicRequests(user); @@ -342,7 +341,7 @@ public async Task UserPassedIn_MusicLimit_Set_Limit_Weekly_NoRequests() } }; var repoMock = _mocker.GetMock>(); - repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object); + repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock()); var result = await _subject.GetRemainingMusicRequests(user); @@ -374,7 +373,7 @@ public async Task UserPassedIn_MusicLimit_Set_Limit_Weekly_OneRequestsWeek() } }; var repoMock = _mocker.GetMock>(); - repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object); + repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock()); var result = await _subject.GetRemainingMusicRequests(user, today); @@ -413,7 +412,7 @@ public async Task UserPassedIn_MusicLimit_Set_Limit_Weekly_AllRequestsWeek() }, }; var repoMock = _mocker.GetMock>(); - repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object); + repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock()); var result = await _subject.GetRemainingMusicRequests(user); @@ -445,7 +444,7 @@ public async Task UserPassedIn_MusicLimit_Set_Limit_Monthly_NoRequests() } }; var repoMock = _mocker.GetMock>(); - repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object); + repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock()); var result = await _subject.GetRemainingMusicRequests(user); @@ -478,7 +477,7 @@ public async Task UserPassedIn_MusicLimit_Set_Limit_Monthly_OneRequests() } }; var repoMock = _mocker.GetMock>(); - repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object); + repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock()); var result = await _subject.GetRemainingMusicRequests(user); @@ -518,7 +517,7 @@ public async Task UserPassedIn_MusicLimit_Set_Limit_Monthly_AllRequests() }, }; var repoMock = _mocker.GetMock>(); - repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object); + repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock()); var result = await _subject.GetRemainingMusicRequests(user, today); diff --git a/src/Ombi.Core.Tests/Engine/TvRequestLimitsTests.cs b/src/Ombi.Core.Tests/Engine/TvRequestLimitsTests.cs index ba383da6c..201251960 100644 --- a/src/Ombi.Core.Tests/Engine/TvRequestLimitsTests.cs +++ b/src/Ombi.Core.Tests/Engine/TvRequestLimitsTests.cs @@ -3,7 +3,6 @@ using Moq.AutoMock; using NUnit.Framework; using Ombi.Core.Authentication; -using Ombi.Core.Engine; using Ombi.Core.Helpers; using Ombi.Core.Models; using Ombi.Core.Services; @@ -59,7 +58,7 @@ public async Task No_UserPassedIn_UsernotExist_No_TvLimit_Set() var user = new OmbiUser(); var um = _mocker.GetMock(); - um.SetupGet(x => x.Users).Returns(new List { user }.AsQueryable().BuildMock().Object); + um.SetupGet(x => x.Users).Returns(new List { user }.AsQueryable().BuildMock()); @@ -77,7 +76,7 @@ public async Task No_UserPassedIn_No_TvLimit_Set() }; var um = _mocker.GetMock(); - um.SetupGet(x => x.Users).Returns(new List { user }.AsQueryable().BuildMock().Object); + um.SetupGet(x => x.Users).Returns(new List { user }.AsQueryable().BuildMock()); @@ -95,7 +94,7 @@ public async Task UserPassedIn_TvLimit_Set_No_Requests() EpisodeRequestLimit = 1 }; var repoMock = _mocker.GetMock>(); - repoMock.Setup(x => x.GetAll()).Returns(new List().AsQueryable().BuildMock().Object); + repoMock.Setup(x => x.GetAll()).Returns(new List().AsQueryable().BuildMock()); var result = await _subject.GetRemainingTvRequests(user); @@ -126,7 +125,7 @@ public async Task UserPassedIn_TvLimit_Set_Limit() } }; var repoMock = _mocker.GetMock>(); - repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object); + repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock()); var result = await _subject.GetRemainingTvRequests(user); @@ -209,7 +208,7 @@ public async Task UserPassedIn_TvLimit_Set_Limit_MultipleRequests() }, }; var repoMock = _mocker.GetMock>(); - repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object); + repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock()); var result = await _subject.GetRemainingTvRequests(user); @@ -243,7 +242,7 @@ public async Task UserPassedIn_TvLimit_Set_Limit_Daily_NoRequestsToday() } }; var repoMock = _mocker.GetMock>(); - repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object); + repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock()); var result = await _subject.GetRemainingTvRequests(user); @@ -276,7 +275,7 @@ public async Task UserPassedIn_TvLimit_Set_Limit_Daily_OneRequestsToday() } }; var repoMock = _mocker.GetMock>(); - repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object); + repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock()); var result = await _subject.GetRemainingTvRequests(user); @@ -317,7 +316,7 @@ public async Task UserPassedIn_TvLimit_Set_Limit_Daily_AllRequestsToday() }, }; var repoMock = _mocker.GetMock>(); - repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object); + repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock()); var result = await _subject.GetRemainingTvRequests(user); @@ -358,7 +357,7 @@ public async Task UserPassedIn_TvLimit_Set_Limit_Daily_MultipleEpisodeRequests() }, }; var repoMock = _mocker.GetMock>(); - repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object); + repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock()); var result = await _subject.GetRemainingTvRequests(user); @@ -380,7 +379,7 @@ public async Task UserPassedIn_TvLimit_Set_Limit_Weekly_NoRequests() EpisodeRequestLimitType = RequestLimitType.Week, Id = "id1" }; - var lastWeek = DateTime.Now.AddDays(-8); + var lastWeek = DateTime.UtcNow.AddDays(-8); var log = new List { new RequestLog @@ -392,7 +391,7 @@ public async Task UserPassedIn_TvLimit_Set_Limit_Weekly_NoRequests() } }; var repoMock = _mocker.GetMock>(); - repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object); + repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock()); var result = await _subject.GetRemainingTvRequests(user); @@ -425,7 +424,7 @@ public async Task UserPassedIn_TvLimit_Set_Limit_Weekly_OneRequestsWeek() } }; var repoMock = _mocker.GetMock>(); - repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object); + repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock()); var result = await _subject.GetRemainingTvRequests(user); @@ -466,7 +465,7 @@ public async Task UserPassedIn_TvLimit_Set_Limit_Weekly_AllRequestsWeek() }, }; var repoMock = _mocker.GetMock>(); - repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object); + repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock()); var result = await _subject.GetRemainingTvRequests(user); @@ -507,7 +506,7 @@ public async Task UserPassedIn_TvLimit_Set_Limit_Weekly_MultipleEpisodeRequests( }, }; var repoMock = _mocker.GetMock>(); - repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object); + repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock()); var result = await _subject.GetRemainingTvRequests(user); @@ -541,7 +540,7 @@ public async Task UserPassedIn_TvLimit_Set_Limit_Monthly_NoRequests() } }; var repoMock = _mocker.GetMock>(); - repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object); + repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock()); var result = await _subject.GetRemainingTvRequests(user); @@ -574,7 +573,7 @@ public async Task UserPassedIn_TvLimit_Set_Limit_Monthly_OneRequests() } }; var repoMock = _mocker.GetMock>(); - repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object); + repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock()); var result = await _subject.GetRemainingTvRequests(user); @@ -615,7 +614,7 @@ public async Task UserPassedIn_TvLimit_Set_Limit_Monthly_AllRequests() }, }; var repoMock = _mocker.GetMock>(); - repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object); + repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock()); var result = await _subject.GetRemainingTvRequests(user); @@ -656,7 +655,7 @@ public async Task UserPassedIn_TvLimit_Set_Limit_Monthly_MultipleEpisodeReuests( }, }; var repoMock = _mocker.GetMock>(); - repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock().Object); + repoMock.Setup(x => x.GetAll()).Returns(log.AsQueryable().BuildMock()); var result = await _subject.GetRemainingTvRequests(user); diff --git a/src/Ombi.Core.Tests/Engine/VoteEngineTests.cs b/src/Ombi.Core.Tests/Engine/VoteEngineTests.cs index 4194ae0ea..a3c42197e 100644 --- a/src/Ombi.Core.Tests/Engine/VoteEngineTests.cs +++ b/src/Ombi.Core.Tests/Engine/VoteEngineTests.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using System.Linq; -using System.Security.Principal; using System.Threading.Tasks; using AutoFixture; using MockQueryable.Moq; @@ -71,7 +70,7 @@ public async Task Vote(VoteType type, RequestType request) VoteRepository.Setup(x => x.GetAll()).Returns(new EnumerableQuery(votes) .AsQueryable() - .BuildMock().Object); + .BuildMock()); var result = new VoteEngineResult(); if (type == VoteType.Downvote) { @@ -118,7 +117,7 @@ public async Task Attempted_Twice(VoteType type, RequestType request) }); VoteRepository.Setup(x => x.GetAll()).Returns(new EnumerableQuery(votes) .AsQueryable() - .BuildMock().Object); + .BuildMock()); var result = new VoteEngineResult(); if (type == VoteType.Downvote) { @@ -163,7 +162,7 @@ public async Task Downvote_Converted_To_Upvote(VoteType type, RequestType reques }); VoteRepository.Setup(x => x.GetAll()).Returns(new EnumerableQuery(votes) .AsQueryable() - .BuildMock().Object); + .BuildMock()); var result = new VoteEngineResult(); if (type == VoteType.Downvote) diff --git a/src/Ombi.Core.Tests/Ombi.Core.Tests.csproj b/src/Ombi.Core.Tests/Ombi.Core.Tests.csproj index 4e01e32cd..40956f5fc 100644 --- a/src/Ombi.Core.Tests/Ombi.Core.Tests.csproj +++ b/src/Ombi.Core.Tests/Ombi.Core.Tests.csproj @@ -8,18 +8,18 @@ - + - - - - - + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/src/Ombi.Core.Tests/Rule/Request/ExistingMovieRequestRuleTests.cs b/src/Ombi.Core.Tests/Rule/Request/ExistingMovieRequestRuleTests.cs index 682d4bf4d..ae54bc805 100644 --- a/src/Ombi.Core.Tests/Rule/Request/ExistingMovieRequestRuleTests.cs +++ b/src/Ombi.Core.Tests/Rule/Request/ExistingMovieRequestRuleTests.cs @@ -1,21 +1,15 @@ -using System; using System.Collections.Generic; using System.Linq; -using System.Security.Principal; using System.Threading.Tasks; using MockQueryable.Moq; using Moq; using NUnit.Framework; -using Ombi.Core.Authentication; -using Ombi.Core.Rule.Rules; using Ombi.Core.Rule.Rules.Request; using Ombi.Core.Services; -using Ombi.Helpers; using Ombi.Settings.Settings.Models; using Ombi.Store.Entities; using Ombi.Store.Entities.Requests; using Ombi.Store.Repository.Requests; -using Ombi.Test.Common; namespace Ombi.Core.Tests.Rule.Request { @@ -45,7 +39,7 @@ public async Task ExistingRequestRule_Movie_Has_Been_Requested_With_TheMovieDBId TheMovieDbId = 1, RequestType = RequestType.Movie } - }.AsQueryable().BuildMock().Object); + }.AsQueryable().BuildMock()); var o = new MovieRequests { TheMovieDbId = 1, @@ -67,7 +61,7 @@ public async Task ExistingRequestRule_Movie_Has_Been_Requested_With_ImdbId() ImdbId = 1.ToString(), RequestType = RequestType.Movie } - }.AsQueryable().BuildMock().Object); + }.AsQueryable().BuildMock()); var o = new MovieRequests { ImdbId = 1.ToString(), @@ -89,7 +83,7 @@ public async Task ExistingRequestRule_Movie_HasNot_Been_Requested() ImdbId = "2", RequestType = RequestType.Movie } - }.AsQueryable().BuildMock().Object); + }.AsQueryable().BuildMock()); var o = new MovieRequests { TheMovieDbId = 1, @@ -113,7 +107,7 @@ public async Task ExistingRequestRule_Movie_HasAlready4K_Request() RequestType = RequestType.Movie, Is4kRequest = true } - }.AsQueryable().BuildMock().Object); + }.AsQueryable().BuildMock()); var o = new MovieRequests { TheMovieDbId = 2, @@ -139,7 +133,7 @@ public async Task ExistingRequestRule_Movie_4K_Request() RequestType = RequestType.Movie, Is4kRequest = false } - }.AsQueryable().BuildMock().Object); + }.AsQueryable().BuildMock()); var o = new MovieRequests { TheMovieDbId = 2, @@ -165,7 +159,7 @@ public async Task ExistingRequestRule_Movie_4K_Request_FeatureNotEnabled() RequestType = RequestType.Movie, Is4kRequest = false } - }.AsQueryable().BuildMock().Object); + }.AsQueryable().BuildMock()); var o = new MovieRequests { TheMovieDbId = 2, diff --git a/src/Ombi.Core.Tests/Rule/Request/ExistingPlexRequestRuleTests.cs b/src/Ombi.Core.Tests/Rule/Request/ExistingPlexRequestRuleTests.cs index 314b543b8..838b11497 100644 --- a/src/Ombi.Core.Tests/Rule/Request/ExistingPlexRequestRuleTests.cs +++ b/src/Ombi.Core.Tests/Rule/Request/ExistingPlexRequestRuleTests.cs @@ -7,10 +7,8 @@ using Ombi.Store.Entities.Requests; using Ombi.Store.Repository; using Ombi.Store.Repository.Requests; -using System; using System.Collections.Generic; using System.Linq; -using System.Text; using System.Threading.Tasks; namespace Ombi.Core.Tests.Rule.Request @@ -31,7 +29,7 @@ public void SetUp() [Test] public async Task RequestShow_DoesNotExistAtAll_IsSuccessful() { - PlexContentRepo.Setup(x => x.GetAll()).Returns(new List().AsQueryable().BuildMock().Object); + PlexContentRepo.Setup(x => x.GetAll()).Returns(new List().AsQueryable().BuildMock()); var req = new ChildRequests { SeasonRequests = new List @@ -203,7 +201,7 @@ public async Task RequestMovie_IsAlreadyAvailable() TheMovieDbId = 123.ToString(), } }; - PlexContentRepo.Setup(x => x.GetAll()).Returns(content.AsQueryable().BuildMock().Object); + PlexContentRepo.Setup(x => x.GetAll()).Returns(content.AsQueryable().BuildMock()); var req = new MovieRequests { @@ -245,7 +243,7 @@ private void SetupMockData() } } }; - PlexContentRepo.Setup(x => x.GetAll()).Returns(childRequests.AsQueryable().BuildMock().Object); + PlexContentRepo.Setup(x => x.GetAll()).Returns(childRequests.AsQueryable().BuildMock()); } } } diff --git a/src/Ombi.Core.Tests/Rule/Request/ExistingTvRequestRuleTests.cs b/src/Ombi.Core.Tests/Rule/Request/ExistingTvRequestRuleTests.cs index d5ca903bf..fcaaf44a5 100644 --- a/src/Ombi.Core.Tests/Rule/Request/ExistingTvRequestRuleTests.cs +++ b/src/Ombi.Core.Tests/Rule/Request/ExistingTvRequestRuleTests.cs @@ -5,10 +5,8 @@ using Ombi.Store.Entities; using Ombi.Store.Entities.Requests; using Ombi.Store.Repository.Requests; -using System; using System.Collections.Generic; using System.Linq; -using System.Text; using System.Threading.Tasks; namespace Ombi.Core.Tests.Rule.Request @@ -29,7 +27,7 @@ public void SetUp() [Test] public async Task RequestShow_DoesNotExistAtAll_IsSuccessful() { - TvRequestRepo.Setup(x => x.GetChild()).Returns(new List().AsQueryable().BuildMock().Object); + TvRequestRepo.Setup(x => x.GetChild()).Returns(new List().AsQueryable().BuildMock()); var req = new ChildRequests { SeasonRequests = new List @@ -209,7 +207,7 @@ private void SetupMockData() } } }; - TvRequestRepo.Setup(x => x.GetChild()).Returns(childRequests.AsQueryable().BuildMock().Object); + TvRequestRepo.Setup(x => x.GetChild()).Returns(childRequests.AsQueryable().BuildMock()); } } } diff --git a/src/Ombi.Core.Tests/Senders/MassEmailSenderTests.cs b/src/Ombi.Core.Tests/Senders/MassEmailSenderTests.cs index 5c5cedabe..bdd9899a7 100644 --- a/src/Ombi.Core.Tests/Senders/MassEmailSenderTests.cs +++ b/src/Ombi.Core.Tests/Senders/MassEmailSenderTests.cs @@ -54,7 +54,7 @@ public async Task SendMassEmail_SingleUser() Id = "a", Email = "Test@test.com" } - }.AsQueryable().BuildMock().Object); + }.AsQueryable().BuildMock()); var result = await _subject.SendMassEmail(model); @@ -95,7 +95,7 @@ public async Task SendMassEmail_MultipleUsers() Id = "b", Email = "b@test.com" } - }.AsQueryable().BuildMock().Object); + }.AsQueryable().BuildMock()); var result = await _subject.SendMassEmail(model); @@ -129,7 +129,7 @@ public async Task SendMassEmail_UserNoEmail() { Id = "a", } - }.AsQueryable().BuildMock().Object); + }.AsQueryable().BuildMock()); var result = await _subject.SendMassEmail(model); _mocker.Verify>( @@ -177,7 +177,7 @@ public async Task SendMassEmail_Bcc() Id = "b", Email = "b@test.com" } - }.AsQueryable().BuildMock().Object); + }.AsQueryable().BuildMock()); var result = await _subject.SendMassEmail(model); @@ -217,7 +217,7 @@ public async Task SendMassEmail_Bcc_NoEmails() { Id = "b", } - }.AsQueryable().BuildMock().Object); + }.AsQueryable().BuildMock()); var result = await _subject.SendMassEmail(model); diff --git a/src/Ombi.Core.Tests/Services/PlexServiceTests.cs b/src/Ombi.Core.Tests/Services/PlexServiceTests.cs index a61c86b2e..8056cab97 100644 --- a/src/Ombi.Core.Tests/Services/PlexServiceTests.cs +++ b/src/Ombi.Core.Tests/Services/PlexServiceTests.cs @@ -59,7 +59,7 @@ public async Task GetWatchListUsers_AllUsersSynced() _subject = _mocker.CreateInstance(); _mocker.Setup, IQueryable>(x => x.GetAll()) - .Returns(new List().AsQueryable().BuildMock().Object); + .Returns(new List().AsQueryable().BuildMock()); var result = await _subject.GetWatchlistUsers(CancellationToken.None); @@ -95,7 +95,7 @@ public async Task GetWatchListUsers_NotEnabled() _subject = _mocker.CreateInstance(); _mocker.Setup, IQueryable>(x => x.GetAll()) - .Returns(new List().AsQueryable().BuildMock().Object); + .Returns(new List().AsQueryable().BuildMock()); var result = await _subject.GetWatchlistUsers(CancellationToken.None); @@ -132,7 +132,7 @@ public async Task GetWatchListUsers_Failed() UserId = "1", MediaServerToken = "test", } - }.AsQueryable().BuildMock().Object); + }.AsQueryable().BuildMock()); var result = await _subject.GetWatchlistUsers(CancellationToken.None); diff --git a/src/Ombi.Core.Tests/Services/RecentlyRequestedServiceTests.cs b/src/Ombi.Core.Tests/Services/RecentlyRequestedServiceTests.cs index fd67e4e33..018ee99e9 100644 --- a/src/Ombi.Core.Tests/Services/RecentlyRequestedServiceTests.cs +++ b/src/Ombi.Core.Tests/Services/RecentlyRequestedServiceTests.cs @@ -15,7 +15,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; using System.Threading; using System.Threading.Tasks; @@ -70,9 +69,9 @@ public async Task GetRecentlyRequested_Movies() }; var albums = new List(); var chilRequests = new List(); - _mocker.Setup>(x => x.GetAll()).Returns(movies.AsQueryable().BuildMock().Object); - _mocker.Setup>(x => x.GetAll()).Returns(albums.AsQueryable().BuildMock().Object); - _mocker.Setup>(x => x.GetChild()).Returns(chilRequests.AsQueryable().BuildMock().Object); + _mocker.Setup>(x => x.GetAll()).Returns(movies.AsQueryable().BuildMock()); + _mocker.Setup>(x => x.GetAll()).Returns(albums.AsQueryable().BuildMock()); + _mocker.Setup>(x => x.GetChild()).Returns(chilRequests.AsQueryable().BuildMock()); var result = await _subject.GetRecentlyRequested(CancellationToken.None); @@ -132,9 +131,9 @@ public async Task GetRecentlyRequested_Movies_HideAvailable() }; var albums = new List(); var chilRequests = new List(); - _mocker.Setup>(x => x.GetAll()).Returns(movies.AsQueryable().BuildMock().Object); - _mocker.Setup>(x => x.GetAll()).Returns(albums.AsQueryable().BuildMock().Object); - _mocker.Setup>(x => x.GetChild()).Returns(chilRequests.AsQueryable().BuildMock().Object); + _mocker.Setup>(x => x.GetAll()).Returns(movies.AsQueryable().BuildMock()); + _mocker.Setup>(x => x.GetAll()).Returns(albums.AsQueryable().BuildMock()); + _mocker.Setup>(x => x.GetChild()).Returns(chilRequests.AsQueryable().BuildMock()); var result = await _subject.GetRecentlyRequested(CancellationToken.None); @@ -163,9 +162,9 @@ public async Task GetRecentlyRequested() var albums = _fixture.CreateMany(10); var chilRequests = _fixture.CreateMany(10); - _mocker.Setup>(x => x.GetAll()).Returns(movies.AsQueryable().BuildMock().Object); - _mocker.Setup>(x => x.GetAll()).Returns(albums.AsQueryable().BuildMock().Object); - _mocker.Setup>(x => x.GetChild()).Returns(chilRequests.AsQueryable().BuildMock().Object); + _mocker.Setup>(x => x.GetAll()).Returns(movies.AsQueryable().BuildMock()); + _mocker.Setup>(x => x.GetAll()).Returns(albums.AsQueryable().BuildMock()); + _mocker.Setup>(x => x.GetChild()).Returns(chilRequests.AsQueryable().BuildMock()); var result = await _subject.GetRecentlyRequested(CancellationToken.None); @@ -187,9 +186,9 @@ public async Task GetRecentlyRequested_HideUsernames() var albums = _fixture.CreateMany(10); var chilRequests = _fixture.CreateMany(10); - _mocker.Setup>(x => x.GetAll()).Returns(movies.AsQueryable().BuildMock().Object); - _mocker.Setup>(x => x.GetAll()).Returns(albums.AsQueryable().BuildMock().Object); - _mocker.Setup>(x => x.GetChild()).Returns(chilRequests.AsQueryable().BuildMock().Object); + _mocker.Setup>(x => x.GetAll()).Returns(movies.AsQueryable().BuildMock()); + _mocker.Setup>(x => x.GetAll()).Returns(albums.AsQueryable().BuildMock()); + _mocker.Setup>(x => x.GetChild()).Returns(chilRequests.AsQueryable().BuildMock()); _mocker.Setup>(x => x.GetUser()).ReturnsAsync(new OmbiUser { UserName = "test", Alias = "alias", UserType = UserType.LocalUser }); _mocker.Setup(x => x.Username).Returns("test"); _mocker.Setup>(x => x.IsInRoleAsync(It.IsAny(), It.IsAny())).ReturnsAsync(false); diff --git a/src/Ombi.Core/Ombi.Core.csproj b/src/Ombi.Core/Ombi.Core.csproj index 67ecdbe13..e4826d3c9 100644 --- a/src/Ombi.Core/Ombi.Core.csproj +++ b/src/Ombi.Core/Ombi.Core.csproj @@ -11,14 +11,13 @@ - - - - - - + + + + + + - diff --git a/src/Ombi.DependencyInjection/IocExtensions.cs b/src/Ombi.DependencyInjection/IocExtensions.cs index 9e47042de..09d99d4b7 100644 --- a/src/Ombi.DependencyInjection/IocExtensions.cs +++ b/src/Ombi.DependencyInjection/IocExtensions.cs @@ -71,6 +71,8 @@ using Microsoft.Extensions.Logging; using Ombi.Core.Services; using Ombi.Core.Helpers; +using Ombi.Hubs; +using Hqub.MusicBrainz.API; namespace Ombi.DependencyInjection { @@ -86,6 +88,7 @@ public static void RegisterApplicationDependencies(this IServiceCollection servi services.RegisterServices(); services.RegisterStore(); services.RegisterJobs(); + services.RegisterHubs(); } public static void RegisterEngines(this IServiceCollection services) @@ -171,6 +174,7 @@ public static void RegisterApi(this IServiceCollection services) services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(_ => new MusicBrainzClient()); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -231,7 +235,7 @@ public static void RegisterServices(this IServiceCollection services) services.AddTransient(); services.AddTransient(); } - + public static void RegisterJobs(this IServiceCollection services) { services.AddSingleton(); @@ -268,5 +272,10 @@ public static void RegisterJobs(this IServiceCollection services) services.AddTransient(); services.AddTransient(); } + + public static void RegisterHubs(this IServiceCollection services) + { + services.AddScoped(); + } } } diff --git a/src/Ombi.DependencyInjection/Ombi.DependencyInjection.csproj b/src/Ombi.DependencyInjection/Ombi.DependencyInjection.csproj index 93b839c07..221afe19a 100644 --- a/src/Ombi.DependencyInjection/Ombi.DependencyInjection.csproj +++ b/src/Ombi.DependencyInjection/Ombi.DependencyInjection.csproj @@ -11,7 +11,7 @@ - + diff --git a/src/Ombi.HealthChecks/Ombi.HealthChecks.csproj b/src/Ombi.HealthChecks/Ombi.HealthChecks.csproj index e228dd0d2..fd4ee1900 100644 --- a/src/Ombi.HealthChecks/Ombi.HealthChecks.csproj +++ b/src/Ombi.HealthChecks/Ombi.HealthChecks.csproj @@ -6,7 +6,7 @@ - + diff --git a/src/Ombi.Helpers.Tests/Ombi.Helpers.Tests.csproj b/src/Ombi.Helpers.Tests/Ombi.Helpers.Tests.csproj index 370440d1c..ba571a1a4 100644 --- a/src/Ombi.Helpers.Tests/Ombi.Helpers.Tests.csproj +++ b/src/Ombi.Helpers.Tests/Ombi.Helpers.Tests.csproj @@ -9,10 +9,10 @@ - + - - + + diff --git a/src/Ombi.Helpers/AssemblyHelper.cs b/src/Ombi.Helpers/AssemblyHelper.cs index 9abc3bf92..472b2a70c 100644 --- a/src/Ombi.Helpers/AssemblyHelper.cs +++ b/src/Ombi.Helpers/AssemblyHelper.cs @@ -1,6 +1,4 @@ -using Microsoft.Extensions.PlatformAbstractions; -using System.Linq; -using System.Reflection; +using System; namespace Ombi.Helpers { @@ -8,9 +6,8 @@ public static class AssemblyHelper { public static string GetRuntimeVersion() { - ApplicationEnvironment app = PlatformServices.Default.Application; - var split = app.ApplicationVersion.Split('.'); - return string.Join('.', split.Take(3)); + Version version = System.Reflection.Assembly.GetEntryAssembly()?.GetName().Version; + return version == null ? "1.0.0" : $"{version.Major}.{version.Minor}.{version.Build}"; } } } \ No newline at end of file diff --git a/src/Ombi.Helpers/Ombi.Helpers.csproj b/src/Ombi.Helpers/Ombi.Helpers.csproj index 2098fa51f..fd99de0c1 100644 --- a/src/Ombi.Helpers/Ombi.Helpers.csproj +++ b/src/Ombi.Helpers/Ombi.Helpers.csproj @@ -11,15 +11,14 @@ - - + + - - - - + + + + - \ No newline at end of file diff --git a/src/Ombi.Hubs/INotificationHubService.cs b/src/Ombi.Hubs/INotificationHubService.cs new file mode 100644 index 000000000..ad97c82aa --- /dev/null +++ b/src/Ombi.Hubs/INotificationHubService.cs @@ -0,0 +1,12 @@ +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; + +namespace Ombi.Hubs; + +public interface INotificationHubService +{ + IEnumerable GetOnlineUsers(); + Task SendNotificationToAdmins(string data, CancellationToken token = default); + Task SendNotificationToAll(string data, CancellationToken token = default); +} \ No newline at end of file diff --git a/src/Ombi.Hubs/NotificationHub.cs b/src/Ombi.Hubs/NotificationHub.cs index 5e211b093..cb2ebab0e 100644 --- a/src/Ombi.Hubs/NotificationHub.cs +++ b/src/Ombi.Hubs/NotificationHub.cs @@ -1,77 +1,50 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; -using System.Threading.Tasks; -using Microsoft.AspNetCore.SignalR; using System.Linq; using System.Security.Claims; +using System.Threading.Tasks; +using Microsoft.AspNetCore.SignalR; using Microsoft.EntityFrameworkCore; using Ombi.Core.Authentication; -using Ombi.Helpers; +using Ombi.Store.Entities; + +namespace Ombi.Hubs; -namespace Ombi.Hubs +public class NotificationHub : Hub { - public class NotificationHub : Hub + private readonly OmbiUserManager _userManager; + public static readonly ConcurrentDictionary UsersOnline = new(); + + public NotificationHub(OmbiUserManager userManager) { - public NotificationHub(OmbiUserManager um) - { - _userManager = um; - } - - public static ConcurrentDictionary UsersOnline = new ConcurrentDictionary(); - - public static List AdminConnectionIds - { - get - { - if (UsersOnline.Any()) - { - return UsersOnline.Where(x => x.Value.Roles.Contains(OmbiRoles.Admin)).Select(x => x.Key).ToList(); - } - return Enumerable.Empty().ToList(); - } - } - - public const string NotificationEvent = "Notification"; - - private readonly OmbiUserManager _userManager; + _userManager = userManager; + } - public override async Task OnConnectedAsync() + public override async Task OnConnectedAsync() + { + ClaimsIdentity identity = (ClaimsIdentity)Context.User?.Identity; + Claim userIdClaim = identity?.Claims + .FirstOrDefault(x => x.Type.Equals("Id", StringComparison.InvariantCultureIgnoreCase)); + if (userIdClaim == null) { - var identity = (ClaimsIdentity) Context.User.Identity; - var userIdClaim = identity.Claims.FirstOrDefault(x => x.Type.Equals("Id", StringComparison.InvariantCultureIgnoreCase)); - if (userIdClaim == null) - { - await base.OnConnectedAsync(); - return; - } - - var user = await _userManager.Users. - FirstOrDefaultAsync(x => x.Id == userIdClaim.Value); - var claims = await _userManager.GetRolesAsync(user); - UsersOnline.TryAdd(Context.ConnectionId, new HubUsers - { - UserId = userIdClaim.Value, - Roles = claims - }); await base.OnConnectedAsync(); + return; } - public override Task OnDisconnectedAsync(Exception exception) + OmbiUser user = await _userManager.Users.FirstOrDefaultAsync(x => x.Id == userIdClaim.Value); + IList claims = await _userManager.GetRolesAsync(user); + UsersOnline.TryAdd(Context.ConnectionId, new NotificationHubUser { - UsersOnline.TryRemove(Context.ConnectionId, out _); - return base.OnDisconnectedAsync(exception); - } - - public Task Notification(string data) - { - return Clients.All.SendAsync(NotificationEvent, data); - } + UserId = userIdClaim.Value, + Roles = claims + }); + await base.OnConnectedAsync(); } - public class HubUsers + public override async Task OnDisconnectedAsync(Exception exception) { - public string UserId { get; set; } - public IList Roles { get; set; } = new List(); + UsersOnline.TryRemove(Context.ConnectionId, out _); + await base.OnDisconnectedAsync(exception); } -} +} \ No newline at end of file diff --git a/src/Ombi.Hubs/NotificationHubService.cs b/src/Ombi.Hubs/NotificationHubService.cs new file mode 100644 index 000000000..2544dbeb3 --- /dev/null +++ b/src/Ombi.Hubs/NotificationHubService.cs @@ -0,0 +1,44 @@ +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNetCore.SignalR; +using Ombi.Helpers; + +namespace Ombi.Hubs; + +public class NotificationHubService : INotificationHubService +{ + public const string NotificationEvent = "Notification"; + + private readonly IHubContext _hubContext; + + public NotificationHubService(IHubContext hubContext) + { + _hubContext = hubContext; + } + + public IEnumerable GetOnlineUsers() + { + return NotificationHub.UsersOnline.Values; + } + + public Task SendNotificationToAdmins(string data, CancellationToken token = default) + { + return _hubContext.Clients + .Clients(GetConnectionIdsWithRole(OmbiRoles.Admin)) + .SendAsync(NotificationEvent, data, token); + } + + public Task SendNotificationToAll(string data, CancellationToken token = default) + { + return _hubContext.Clients.All.SendAsync(NotificationEvent, data, token); + } + + private static List GetConnectionIdsWithRole(string role) + { + return NotificationHub.UsersOnline + .Where(x => x.Value.Roles.Contains(role)) + .Select(x => x.Key).ToList(); + } +} \ No newline at end of file diff --git a/src/Ombi.Hubs/NotificationHubUser.cs b/src/Ombi.Hubs/NotificationHubUser.cs new file mode 100644 index 000000000..036fda59d --- /dev/null +++ b/src/Ombi.Hubs/NotificationHubUser.cs @@ -0,0 +1,9 @@ +using System.Collections.Generic; + +namespace Ombi.Hubs; + +public class NotificationHubUser +{ + public string UserId { get; set; } + public IList Roles { get; init; } = new List(); +} \ No newline at end of file diff --git a/src/Ombi.Hubs/Ombi.Hubs.csproj b/src/Ombi.Hubs/Ombi.Hubs.csproj index f6bee2eb1..f8f03b5d0 100644 --- a/src/Ombi.Hubs/Ombi.Hubs.csproj +++ b/src/Ombi.Hubs/Ombi.Hubs.csproj @@ -7,8 +7,7 @@ - - + diff --git a/src/Ombi.Mapping/Ombi.Mapping.csproj b/src/Ombi.Mapping/Ombi.Mapping.csproj index 322942cf2..ff8194d40 100644 --- a/src/Ombi.Mapping/Ombi.Mapping.csproj +++ b/src/Ombi.Mapping/Ombi.Mapping.csproj @@ -11,9 +11,9 @@ - - - + + + diff --git a/src/Ombi.Notifications.Tests/Ombi.Notifications.Tests.csproj b/src/Ombi.Notifications.Tests/Ombi.Notifications.Tests.csproj index e936c9072..a87b1fafc 100644 --- a/src/Ombi.Notifications.Tests/Ombi.Notifications.Tests.csproj +++ b/src/Ombi.Notifications.Tests/Ombi.Notifications.Tests.csproj @@ -6,14 +6,14 @@ - - - - + + + + - - - + + + diff --git a/src/Ombi.Notifications/Ombi.Notifications.csproj b/src/Ombi.Notifications/Ombi.Notifications.csproj index 41fd3ae17..d061707fe 100644 --- a/src/Ombi.Notifications/Ombi.Notifications.csproj +++ b/src/Ombi.Notifications/Ombi.Notifications.csproj @@ -11,8 +11,8 @@ - - + + diff --git a/src/Ombi.Schedule.Tests/AvailabilityCheckerTests.cs b/src/Ombi.Schedule.Tests/AvailabilityCheckerTests.cs index d909b7519..1e015b632 100644 --- a/src/Ombi.Schedule.Tests/AvailabilityCheckerTests.cs +++ b/src/Ombi.Schedule.Tests/AvailabilityCheckerTests.cs @@ -1,5 +1,4 @@ -using Microsoft.AspNetCore.SignalR; -using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging; using MockQueryable.Moq; using Moq; using Moq.AutoMock; @@ -83,7 +82,7 @@ public async Task All_Episodes_Are_Available_In_Request() EpisodeNumber = 2, SeasonNumber = 1, }, - }.AsQueryable().BuildMock().Object; + }.AsQueryable().BuildMock(); await _subject.ProcessTvShow(databaseEpisodes, request); @@ -160,7 +159,7 @@ public async Task All_One_Episode_Is_Available_In_Request() EpisodeNumber = 3, SeasonNumber = 1, }, - }.AsQueryable().BuildMock().Object; + }.AsQueryable().BuildMock(); await _subject.ProcessTvShow(databaseEpisodes, request); @@ -183,7 +182,7 @@ public async Task All_One_Episode_Is_Available_In_Request() public class TestAvailabilityChecker : AvailabilityChecker { - public TestAvailabilityChecker(ITvRequestRepository tvRequest, INotificationHelper notification, ILogger log, IHubContext hub) : base(tvRequest, notification, log, hub) + public TestAvailabilityChecker(ITvRequestRepository tvRequest, INotificationHelper notification, ILogger log, INotificationHubService notificationHubService) : base(tvRequest, notification, log, notificationHubService) { } diff --git a/src/Ombi.Schedule.Tests/IssuesPurgeTests.cs b/src/Ombi.Schedule.Tests/IssuesPurgeTests.cs index 712fdabee..dbba08d21 100644 --- a/src/Ombi.Schedule.Tests/IssuesPurgeTests.cs +++ b/src/Ombi.Schedule.Tests/IssuesPurgeTests.cs @@ -9,7 +9,6 @@ using Ombi.Store.Entities.Requests; using Ombi.Store.Repository; using System.Threading.Tasks; -using MockQueryable; using MockQueryable.Moq; namespace Ombi.Schedule.Tests @@ -51,7 +50,7 @@ public async Task Deletes_Correct_Issue() }; Settings.Setup(x => x.GetSettingsAsync()).ReturnsAsync(new IssueSettings { DeleteIssues = true, DaysAfterResolvedToDelete = 5 }); - Repo.Setup(x => x.GetAll()).Returns(new List(issues).AsQueryable().BuildMock().Object); + Repo.Setup(x => x.GetAll()).Returns(new List(issues).AsQueryable().BuildMock()); await Job.Execute(null); Assert.That(issues.First().Status, Is.EqualTo(IssueStatus.Deleted)); @@ -76,7 +75,7 @@ public async Task DoesNot_Delete_AllIssues() }; Settings.Setup(x => x.GetSettingsAsync()).ReturnsAsync(new IssueSettings { DeleteIssues = true, DaysAfterResolvedToDelete = 5 }); - Repo.Setup(x => x.GetAll()).Returns(new EnumerableQuery(issues).AsQueryable().BuildMock().Object); + Repo.Setup(x => x.GetAll()).Returns(new EnumerableQuery(issues).AsQueryable().BuildMock()); await Job.Execute(null); Assert.That(issues[0].Status, Is.Not.EqualTo(IssueStatus.Deleted)); @@ -102,7 +101,7 @@ public async Task DoesNot_Delete_AnyIssues() }; Settings.Setup(x => x.GetSettingsAsync()).ReturnsAsync(new IssueSettings { DeleteIssues = true, DaysAfterResolvedToDelete = 5 }); - Repo.Setup(x => x.GetAll()).Returns(new EnumerableQuery(issues).AsQueryable().BuildMock().Object); + Repo.Setup(x => x.GetAll()).Returns(new EnumerableQuery(issues).AsQueryable().BuildMock()); await Job.Execute(null); Assert.That(issues[0].Status, Is.Not.EqualTo(IssueStatus.Deleted)); diff --git a/src/Ombi.Schedule.Tests/Ombi.Schedule.Tests.csproj b/src/Ombi.Schedule.Tests/Ombi.Schedule.Tests.csproj index d2215c5f1..bb222da71 100644 --- a/src/Ombi.Schedule.Tests/Ombi.Schedule.Tests.csproj +++ b/src/Ombi.Schedule.Tests/Ombi.Schedule.Tests.csproj @@ -7,14 +7,14 @@ - - - - + + + + - - - + + + diff --git a/src/Ombi.Schedule.Tests/PlexAvailabilityCheckerTests.cs b/src/Ombi.Schedule.Tests/PlexAvailabilityCheckerTests.cs index d25bb8413..4e48c7d94 100644 --- a/src/Ombi.Schedule.Tests/PlexAvailabilityCheckerTests.cs +++ b/src/Ombi.Schedule.Tests/PlexAvailabilityCheckerTests.cs @@ -1,16 +1,11 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; -using System.Linq.Expressions; -using System.Threading; using System.Threading.Tasks; using Castle.Components.DictionaryAdapter; -using Microsoft.AspNetCore.SignalR; using Moq; using MockQueryable.Moq; using NUnit.Framework; using Ombi.Core; -using Ombi.Core.Notifications; using Ombi.Hubs; using Ombi.Schedule.Jobs.Plex; using Ombi.Store.Entities; @@ -50,7 +45,7 @@ public async Task ProcessMovies_ShouldMarkAvailable_WhenInPlex_WithImdbId() { ImdbId = "test" }; - _mocker.Setup(x => x.GetAll()).Returns(new List { request }.AsQueryable()); + _mocker.Setup>(x => x.GetAll()).Returns(new List { request }.AsQueryable()); _mocker.Setup>(x => x.Get("test", ProviderType.ImdbId)).ReturnsAsync(new PlexServerContent()); await _subject.Execute(null); @@ -77,7 +72,7 @@ public async Task ProcessMovies_ShouldMarkAvailable_WhenInPlex_WithTheMovieDbId( ImdbId = null, TheMovieDbId = 33 }; - _mocker.Setup(x => x.GetAll()).Returns(new List { request }.AsQueryable()); + _mocker.Setup>(x => x.GetAll()).Returns(new List { request }.AsQueryable()); _mocker.Setup>(x => x.Get(It.IsAny(), ProviderType.ImdbId)).ReturnsAsync((PlexServerContent)null); _mocker.Setup>(x => x.Get("33", ProviderType.TheMovieDbId)).ReturnsAsync(new PlexServerContent()); @@ -105,7 +100,7 @@ public async Task ProcessMovies_ShouldMarkAvailable_WhenInPlex_WithTheMovieDbId_ { ImdbId = "test" }; - _mocker.Setup(x => x.GetAll()).Returns(new List { request }.AsQueryable()); + _mocker.Setup>(x => x.GetAll()).Returns(new List { request }.AsQueryable()); _mocker.Setup>(x => x.Get("test", ProviderType.ImdbId)).ReturnsAsync(new PlexServerContent { Quality = "1080p" }); await _subject.Execute(null); @@ -134,7 +129,7 @@ public async Task ProcessMovies_4K_ShouldMarkAvailable_WhenInPlex_WithImdbId_And Is4kRequest = true, Has4KRequest = true, }; - _mocker.Setup(x => x.GetAll()).Returns(new List { request }.AsQueryable()); + _mocker.Setup>(x => x.GetAll()).Returns(new List { request }.AsQueryable()); _mocker.Setup>(x => x.Get("test", ProviderType.ImdbId)).ReturnsAsync(new PlexServerContent { Has4K = true }); await _subject.Execute(null); @@ -162,7 +157,7 @@ public async Task ProcessMovies_ShouldNotBeAvailable_WhenInNotPlex() { ImdbId = "test" }; - _mocker.Setup(x => x.GetAll()).Returns(new List { request }.AsQueryable()); + _mocker.Setup>(x => x.GetAll()).Returns(new List { request }.AsQueryable()); await _subject.Execute(null); @@ -173,7 +168,7 @@ public async Task ProcessMovies_ShouldNotBeAvailable_WhenInNotPlex() public async Task ProcessTv_ShouldMark_Episode_Available_WhenInPlex_MovieDbId() { var request = CreateChildRequest(null, 33, 99); - _mocker.Setup(x => x.GetChild()).Returns(new List { request }.AsQueryable().BuildMock().Object); + _mocker.Setup>(x => x.GetChild()).Returns(new List { request }.AsQueryable().BuildMock()); _mocker.Setup>(x => x.GetAllEpisodes()).Returns(new List { new PlexEpisode @@ -186,7 +181,7 @@ public async Task ProcessTv_ShouldMark_Episode_Available_WhenInPlex_MovieDbId() EpisodeNumber = 1, SeasonNumber = 2, } - }.AsQueryable().BuildMock().Object); + }.AsQueryable().BuildMock()); await _subject.Execute(null); @@ -199,7 +194,7 @@ public async Task ProcessTv_ShouldMark_Episode_Available_WhenInPlex_MovieDbId() public async Task ProcessTv_ShouldMark_Episode_Available_WhenInPlex_ImdbId() { var request = CreateChildRequest("abc", -1, 99); - _mocker.Setup(x => x.GetChild()).Returns(new List { request }.AsQueryable().BuildMock().Object); + _mocker.Setup>(x => x.GetChild()).Returns(new List { request }.AsQueryable().BuildMock()); _mocker.Setup>(x => x.GetAllEpisodes()).Returns(new List { new PlexEpisode @@ -211,7 +206,7 @@ public async Task ProcessTv_ShouldMark_Episode_Available_WhenInPlex_ImdbId() EpisodeNumber = 1, SeasonNumber = 2, } - }.AsQueryable().BuildMock().Object); + }.AsQueryable().BuildMock()); await _subject.Execute(null); @@ -224,7 +219,7 @@ public async Task ProcessTv_ShouldMark_Episode_Available_WhenInPlex_ImdbId() public async Task ProcessTv_ShouldMark_Episode_Available_By_TitleMatch() { var request = CreateChildRequest("abc", -1, 99); - _mocker.Setup(x => x.GetChild()).Returns(new List { request }.AsQueryable().BuildMock().Object); + _mocker.Setup>(x => x.GetChild()).Returns(new List { request }.AsQueryable().BuildMock()); _mocker.Setup>(x => x.GetAllEpisodes()).Returns(new List { new PlexEpisode @@ -237,7 +232,7 @@ public async Task ProcessTv_ShouldMark_Episode_Available_By_TitleMatch() EpisodeNumber = 1, SeasonNumber = 2, } - }.AsQueryable().BuildMock().Object); + }.AsQueryable().BuildMock()); await _subject.Execute(null); diff --git a/src/Ombi.Schedule.Tests/PlexContentSyncTests.cs b/src/Ombi.Schedule.Tests/PlexContentSyncTests.cs index 8540f0037..f72971606 100644 --- a/src/Ombi.Schedule.Tests/PlexContentSyncTests.cs +++ b/src/Ombi.Schedule.Tests/PlexContentSyncTests.cs @@ -2,9 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; -using System.Text; using System.Threading.Tasks; -using Microsoft.Extensions.Logging; using Moq; using Moq.AutoMock; using NUnit.Framework; @@ -48,7 +46,7 @@ public async Task DoesNotSyncExistingMovie() }; var contentToAdd = new HashSet(); var contentProcessed = new Dictionary(); - _mocker.Setup(x => + _mocker.Setup>(x => x.GetFirstContentByCustom(It.IsAny>>())) .Returns(Task.FromResult(new PlexServerContent())); @@ -108,7 +106,7 @@ public async Task SyncsMovieWithGuidFromCallToApi() }; var contentToAdd = new HashSet(); var contentProcessed = new Dictionary(); - _mocker.Setup(x => x.GetMetadata(It.IsAny(), It.IsAny(), It.IsAny())) + _mocker.Setup>(x => x.GetMetadata(It.IsAny(), It.IsAny(), It.IsAny())) .Returns(Task.FromResult(new PlexMetadata { MediaContainer = new Mediacontainer @@ -166,7 +164,7 @@ public async Task UpdatesExistingMovieWhen_WeFindAnotherQuality() }; var contentToAdd = new HashSet(); var contentProcessed = new Dictionary(); - _mocker.Setup(x => + _mocker.Setup>(x => x.GetFirstContentByCustom(It.IsAny>>())) .Returns(Task.FromResult(new PlexServerContent { @@ -204,7 +202,7 @@ public async Task DoesNotUpdatesExistingMovieWhen_WeFindSameQuality() }; var contentToAdd = new HashSet(); var contentProcessed = new Dictionary(); - _mocker.Setup(x => + _mocker.Setup>(x => x.GetFirstContentByCustom(It.IsAny>>())) .Returns(Task.FromResult(new PlexServerContent { diff --git a/src/Ombi.Schedule.Tests/PlexWatchlistImportTests.cs b/src/Ombi.Schedule.Tests/PlexWatchlistImportTests.cs index 64794f010..5e724b6f8 100644 --- a/src/Ombi.Schedule.Tests/PlexWatchlistImportTests.cs +++ b/src/Ombi.Schedule.Tests/PlexWatchlistImportTests.cs @@ -9,7 +9,6 @@ using Ombi.Core.Models.Requests; using Ombi.Core.Settings; using Ombi.Core.Settings.Models.External; -using Ombi.Core.Tests; using Ombi.Schedule.Jobs.Plex; using Ombi.Store.Entities; using Ombi.Store.Repository; @@ -39,7 +38,7 @@ public void Setup() _context = _mocker.GetMock(); _context.Setup(x => x.CancellationToken).Returns(CancellationToken.None); _subject = _mocker.CreateInstance(); - _mocker.Setup, IQueryable>(x => x.GetAll()).Returns(new List().AsQueryable().BuildMock().Object); + _mocker.Setup, IQueryable>(x => x.GetAll()).Returns(new List().AsQueryable().BuildMock()); } [Test] @@ -104,7 +103,7 @@ public async Task FailedWatchListUser_NewToken_ShouldBeRemoved() UserId = "abc", MediaServerToken = "dead" } - }.AsQueryable().BuildMock().Object); + }.AsQueryable().BuildMock()); _mocker.Setup, Task>(x => x.GetSettingsAsync()).ReturnsAsync(new PlexSettings { Enable = true, EnableWatchlistImport = true }); _mocker.Setup>(x => x.GetWatchlist(It.IsAny(), It.IsAny())).ReturnsAsync(new PlexWatchlistContainer { AuthError = false }); @@ -128,7 +127,7 @@ public async Task FailedWatchListUser_OldToken_ShouldSkip() UserId = "abc", MediaServerToken = "token1" } - }.AsQueryable().BuildMock().Object); + }.AsQueryable().BuildMock()); _mocker.Setup, Task>(x => x.GetSettingsAsync()).ReturnsAsync(new PlexSettings { Enable = true, EnableWatchlistImport = true }); _mocker.Setup>(x => x.GetWatchlist(It.IsAny(), It.IsAny())).ReturnsAsync(new PlexWatchlistContainer { AuthError = false }); diff --git a/src/Ombi.Schedule/Jobs/ArrAvailabilityChecker.cs b/src/Ombi.Schedule/Jobs/ArrAvailabilityChecker.cs index c40d4fc46..36a6ace89 100644 --- a/src/Ombi.Schedule/Jobs/ArrAvailabilityChecker.cs +++ b/src/Ombi.Schedule/Jobs/ArrAvailabilityChecker.cs @@ -3,7 +3,6 @@ using System.Collections.Immutable; using System.Linq; using System.Threading.Tasks; -using Microsoft.AspNetCore.SignalR; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Ombi.Core; @@ -32,12 +31,12 @@ public ArrAvailabilityChecker( IExternalRepository radarrRepo, IExternalRepository sonarrRepo, IExternalRepository sonarrEpisodeRepo, - INotificationHelper notification, IHubContext hub, + INotificationHelper notification, INotificationHubService notificationHubService, ITvRequestRepository tvRequest, IMovieRequestRepository movies, ILogger log, ISettingsService radarrSettings, ISettingsService sonarrSettings) - : base(tvRequest, notification, log, hub) + : base(tvRequest, notification, log, notificationHubService) { _radarrRepo = radarrRepo; _sonarrRepo = sonarrRepo; @@ -101,9 +100,9 @@ private async Task ProcessMovies() if (itemsForAvailability.Any()) { - await _hub.Clients.Clients(NotificationHub.AdminConnectionIds) - .SendAsync(NotificationHub.NotificationEvent, "Radarr Availability Checker found some new available movies!"); + await NotificationHubService.SendNotificationToAdmins("Radarr Availability Checker found some new available movies!"); } + foreach (var item in itemsForAvailability) { await _notificationService.Notify(new NotificationOptions diff --git a/src/Ombi.Schedule/Jobs/AvailabilityChecker.cs b/src/Ombi.Schedule/Jobs/AvailabilityChecker.cs index 1ea87a76d..db42778a8 100644 --- a/src/Ombi.Schedule/Jobs/AvailabilityChecker.cs +++ b/src/Ombi.Schedule/Jobs/AvailabilityChecker.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using Microsoft.AspNetCore.SignalR; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Ombi.Core; @@ -20,15 +19,15 @@ public abstract class AvailabilityChecker protected readonly ITvRequestRepository _tvRepo; protected readonly INotificationHelper _notificationService; protected readonly ILogger _log; - protected readonly IHubContext _hub; + protected readonly INotificationHubService NotificationHubService; public AvailabilityChecker(ITvRequestRepository tvRequest, INotificationHelper notification, - ILogger log, IHubContext hub) + ILogger log, INotificationHubService notificationHubService) { _tvRepo = tvRequest; _notificationService = notification; _log = log; - _hub = hub; + NotificationHubService = notificationHubService; } protected async Task ProcessTvShow(IQueryable seriesEpisodes, ChildRequests child) @@ -71,8 +70,7 @@ protected async Task ProcessTvShow(IQueryable seriesEpi // We have ful-fulled this request! child.Available = true; child.MarkedAsAvailable = DateTime.UtcNow; - await _hub?.Clients?.Clients(NotificationHub.AdminConnectionIds)? - .SendAsync(NotificationHub.NotificationEvent, "Availability Checker found some new available Shows!"); + await NotificationHubService.SendNotificationToAdmins("Availability Checker found some new available Shows!"); _log.LogInformation("Child request {0} is now available, sending notification", $"{child.Title} - {child.Id}"); await _tvRepo.Save(); diff --git a/src/Ombi.Schedule/Jobs/Couchpotato/CouchPotatoSync.cs b/src/Ombi.Schedule/Jobs/Couchpotato/CouchPotatoSync.cs index cc05b711a..2137dd329 100644 --- a/src/Ombi.Schedule/Jobs/Couchpotato/CouchPotatoSync.cs +++ b/src/Ombi.Schedule/Jobs/Couchpotato/CouchPotatoSync.cs @@ -28,7 +28,6 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using Microsoft.AspNetCore.SignalR; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Ombi.Api.CouchPotato; @@ -45,13 +44,13 @@ namespace Ombi.Schedule.Jobs.Couchpotato public class CouchPotatoSync : ICouchPotatoSync { public CouchPotatoSync(ISettingsService cpSettings, - ICouchPotatoApi api, ILogger log, ExternalContext ctx, IHubContext hub) + ICouchPotatoApi api, ILogger log, ExternalContext ctx, INotificationHubService notificationHubService) { _settings = cpSettings; _api = api; _log = log; _ctx = ctx; - _notification = hub; + _notification = notificationHubService; _settings.ClearCache(); } @@ -59,7 +58,7 @@ public CouchPotatoSync(ISettingsService cpSettings, private readonly ICouchPotatoApi _api; private readonly ILogger _log; private readonly ExternalContext _ctx; - private readonly IHubContext _notification; + private readonly INotificationHubService _notification; public async Task Execute(IJobExecutionContext job) { @@ -69,8 +68,7 @@ public async Task Execute(IJobExecutionContext job) return; } - await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) - .SendAsync(NotificationHub.NotificationEvent, "Couch Potato Sync Started"); + await _notification.SendNotificationToAdmins("Couch Potato Sync Started"); try { _log.LogInformation(LoggingEvents.CouchPotatoCacher, "Getting all active movies from CP"); @@ -118,14 +116,12 @@ await strat.ExecuteAsync(async () => } }); - await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) - .SendAsync(NotificationHub.NotificationEvent, "Couch Potato Sync Finished"); + await _notification.SendNotificationToAdmins("Couch Potato Sync Finished"); } } catch (Exception e) { - await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) - .SendAsync(NotificationHub.NotificationEvent, "Couch Potato Sync Failed"); + await _notification.SendNotificationToAdmins("Couch Potato Sync Failed"); _log.LogError(LoggingEvents.CouchPotatoCacher, e, "error when trying to get movies from CP"); throw; } diff --git a/src/Ombi.Schedule/Jobs/Emby/EmbyAvaliabilityChecker.cs b/src/Ombi.Schedule/Jobs/Emby/EmbyAvaliabilityChecker.cs index edcc853bb..5394c3c20 100644 --- a/src/Ombi.Schedule/Jobs/Emby/EmbyAvaliabilityChecker.cs +++ b/src/Ombi.Schedule/Jobs/Emby/EmbyAvaliabilityChecker.cs @@ -1,7 +1,6 @@ using System; using System.Linq; using System.Threading.Tasks; -using Microsoft.AspNetCore.SignalR; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Ombi.Core; @@ -20,7 +19,7 @@ namespace Ombi.Schedule.Jobs.Emby public class EmbyAvaliabilityChecker : AvailabilityChecker, IEmbyAvaliabilityChecker { public EmbyAvaliabilityChecker(IEmbyContentRepository repo, ITvRequestRepository t, IMovieRequestRepository m, - INotificationHelper n, ILogger log, IHubContext notification, IFeatureService featureService) + INotificationHelper n, ILogger log, INotificationHubService notification, IFeatureService featureService) : base(t, n, log, notification) { _repo = repo; @@ -35,14 +34,12 @@ public EmbyAvaliabilityChecker(IEmbyContentRepository repo, ITvRequestRepository public async Task Execute(IJobExecutionContext job) { _log.LogInformation("Starting Emby Availability Check"); - await _hub.Clients.Clients(NotificationHub.AdminConnectionIds) - .SendAsync(NotificationHub.NotificationEvent, "Emby Availability Checker Started"); + await NotificationHubService.SendNotificationToAdmins("Emby Availability Checker Started"); await ProcessMovies(); await ProcessTv(); _log.LogInformation("Finished Emby Availability Check"); - await _hub.Clients.Clients(NotificationHub.AdminConnectionIds) - .SendAsync(NotificationHub.NotificationEvent, "Emby Availability Checker Finished"); + await NotificationHubService.SendNotificationToAdmins("Emby Availability Checker Finished"); } private async Task ProcessMovies() diff --git a/src/Ombi.Schedule/Jobs/Emby/EmbyContentSync.cs b/src/Ombi.Schedule/Jobs/Emby/EmbyContentSync.cs index 27cdf0f3a..35cc66be4 100644 --- a/src/Ombi.Schedule/Jobs/Emby/EmbyContentSync.cs +++ b/src/Ombi.Schedule/Jobs/Emby/EmbyContentSync.cs @@ -3,7 +3,6 @@ using System.Globalization; using System.Linq; using System.Threading.Tasks; -using Microsoft.AspNetCore.SignalR; using Microsoft.Extensions.Logging; using Ombi.Api.Emby; using Ombi.Api.Emby.Models; @@ -13,7 +12,6 @@ using Ombi.Core.Settings.Models.External; using Ombi.Helpers; using Ombi.Hubs; -using Ombi.Schedule.Jobs.Ombi; using Ombi.Store.Entities; using Ombi.Store.Repository; using Quartz; @@ -24,7 +22,7 @@ namespace Ombi.Schedule.Jobs.Emby public class EmbyContentSync : IEmbyContentSync { public EmbyContentSync(ISettingsService settings, IEmbyApiFactory api, ILogger logger, - IEmbyContentRepository repo, IHubContext notification) + IEmbyContentRepository repo, INotificationHubService notification) { _logger = logger; _settings = settings; @@ -37,7 +35,7 @@ public EmbyContentSync(ISettingsService settings, IEmbyApiFactory private readonly ISettingsService _settings; private readonly IEmbyApiFactory _apiFactory; private readonly IEmbyContentRepository _repo; - private readonly IHubContext _notification; + private readonly INotificationHubService _notification; private const int AmountToTake = 100; @@ -58,8 +56,7 @@ public async Task Execute(IJobExecutionContext context) Api = _apiFactory.CreateClient(embySettings); - await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) - .SendAsync(NotificationHub.NotificationEvent, recentlyAddedSearch ? "Emby Recently Added Started" : "Emby Content Sync Started"); + await _notification.SendNotificationToAdmins(recentlyAddedSearch ? "Emby Recently Added Started" : "Emby Content Sync Started"); foreach (var server in embySettings.Servers) { @@ -69,14 +66,12 @@ await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) } catch (Exception e) { - await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) - .SendAsync(NotificationHub.NotificationEvent, "Emby Content Sync Failed"); + await _notification.SendNotificationToAdmins("Emby Content Sync Failed"); _logger.LogError(e, "Exception when caching Emby for server {0}", server.Name); } } - await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) - .SendAsync(NotificationHub.NotificationEvent, "Emby Content Sync Finished"); + await _notification.SendNotificationToAdmins("Emby Content Sync Finished"); // Episodes diff --git a/src/Ombi.Schedule/Jobs/Emby/EmbyEpisodeSync.cs b/src/Ombi.Schedule/Jobs/Emby/EmbyEpisodeSync.cs index 5293d30b4..01541ea20 100644 --- a/src/Ombi.Schedule/Jobs/Emby/EmbyEpisodeSync.cs +++ b/src/Ombi.Schedule/Jobs/Emby/EmbyEpisodeSync.cs @@ -29,7 +29,6 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using Microsoft.AspNetCore.SignalR; using Microsoft.Extensions.Logging; using Ombi.Api.Emby; using Ombi.Core.Settings; @@ -48,7 +47,7 @@ namespace Ombi.Schedule.Jobs.Emby public class EmbyEpisodeSync : IEmbyEpisodeSync { public EmbyEpisodeSync(ISettingsService s, IEmbyApiFactory api, ILogger l, IEmbyContentRepository repo - , IHubContext notification) + , INotificationHubService notification) { _apiFactory = api; _logger = l; @@ -61,7 +60,7 @@ public EmbyEpisodeSync(ISettingsService s, IEmbyApiFactory api, IL private readonly IEmbyApiFactory _apiFactory; private readonly ILogger _logger; private readonly IEmbyContentRepository _repo; - private readonly IHubContext _notification; + private readonly INotificationHubService _notification; private const int AmountToTake = 100; @@ -80,8 +79,7 @@ public async Task Execute(IJobExecutionContext context) var settings = await _settings.GetSettingsAsync(); Api = _apiFactory.CreateClient(settings); - await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) - .SendAsync(NotificationHub.NotificationEvent, "Emby Episode Sync Started"); + await _notification.SendNotificationToAdmins("Emby Episode Sync Started"); foreach (var server in settings.Servers) { if (server.EmbySelectedLibraries.Any() && server.EmbySelectedLibraries.Any(x => x.Enabled)) @@ -99,8 +97,7 @@ await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) } } - await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) - .SendAsync(NotificationHub.NotificationEvent, "Emby Episode Sync Finished"); + await _notification.SendNotificationToAdmins("Emby Episode Sync Finished"); _logger.LogInformation("Emby Episode Sync Finished - Triggering Metadata refresh"); await OmbiQuartz.TriggerJob(nameof(IRefreshMetadata), "System"); } diff --git a/src/Ombi.Schedule/Jobs/Emby/EmbyUserImporter.cs b/src/Ombi.Schedule/Jobs/Emby/EmbyUserImporter.cs index e85cdb9c4..c5ae7102f 100644 --- a/src/Ombi.Schedule/Jobs/Emby/EmbyUserImporter.cs +++ b/src/Ombi.Schedule/Jobs/Emby/EmbyUserImporter.cs @@ -29,7 +29,6 @@ using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Identity; -using Microsoft.AspNetCore.SignalR; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Ombi.Api.Emby; @@ -46,7 +45,7 @@ namespace Ombi.Schedule.Jobs.Emby public class EmbyUserImporter : IEmbyUserImporter { public EmbyUserImporter(IEmbyApiFactory api, UserManager um, ILogger log, - ISettingsService embySettings, ISettingsService ums, IHubContext notification) + ISettingsService embySettings, ISettingsService ums, INotificationHubService notification) { _apiFactory = api; _userManager = um; @@ -61,7 +60,7 @@ public EmbyUserImporter(IEmbyApiFactory api, UserManager um, ILogger _log; private readonly ISettingsService _embySettings; private readonly ISettingsService _userManagementSettings; - private readonly IHubContext _notification; + private readonly INotificationHubService _notification; private IEmbyApi Api { get; set; } public async Task Execute(IJobExecutionContext job) @@ -79,8 +78,7 @@ public async Task Execute(IJobExecutionContext job) Api = _apiFactory.CreateClient(settings); - await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) - .SendAsync(NotificationHub.NotificationEvent, $"Emby User Importer Started"); + await _notification.SendNotificationToAdmins("Emby User Importer Started"); var allUsers = await _userManager.Users.Where(x => x.UserType == UserType.EmbyUser || x.UserType == UserType.EmbyConnectUser).ToListAsync(); foreach (var server in settings.Servers) { @@ -160,8 +158,7 @@ await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) } } - await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) - .SendAsync(NotificationHub.NotificationEvent, "Emby User Importer Finished"); + await _notification.SendNotificationToAdmins("Emby User Importer Finished"); } private bool _disposed; diff --git a/src/Ombi.Schedule/Jobs/Jellyfin/JellyfinAvaliabilityChecker.cs b/src/Ombi.Schedule/Jobs/Jellyfin/JellyfinAvaliabilityChecker.cs index 4c54fc25e..4a12f9383 100644 --- a/src/Ombi.Schedule/Jobs/Jellyfin/JellyfinAvaliabilityChecker.cs +++ b/src/Ombi.Schedule/Jobs/Jellyfin/JellyfinAvaliabilityChecker.cs @@ -28,7 +28,6 @@ using System; using System.Linq; using System.Threading.Tasks; -using Microsoft.AspNetCore.SignalR; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Ombi.Core; @@ -47,7 +46,7 @@ namespace Ombi.Schedule.Jobs.Jellyfin public class JellyfinAvaliabilityChecker : AvailabilityChecker, IJellyfinAvaliabilityChecker { public JellyfinAvaliabilityChecker(IJellyfinContentRepository repo, ITvRequestRepository t, IMovieRequestRepository m, - INotificationHelper n, ILogger log, IHubContext notification, IFeatureService featureService) + INotificationHelper n, ILogger log, INotificationHubService notification, IFeatureService featureService) : base(t, n, log, notification) { _repo = repo; @@ -62,14 +61,12 @@ public JellyfinAvaliabilityChecker(IJellyfinContentRepository repo, ITvRequestRe public async Task Execute(IJobExecutionContext job) { _log.LogInformation("Starting Jellyfin Availability Check"); - await _hub.Clients.Clients(NotificationHub.AdminConnectionIds) - .SendAsync(NotificationHub.NotificationEvent, "Jellyfin Availability Checker Started"); + await NotificationHubService.SendNotificationToAdmins("Jellyfin Availability Checker Started"); await ProcessMovies(); await ProcessTv(); _log.LogInformation("Finished Jellyfin Availability Check"); - await _hub.Clients.Clients(NotificationHub.AdminConnectionIds) - .SendAsync(NotificationHub.NotificationEvent, "Jellyfin Availability Checker Finished"); + await NotificationHubService.SendNotificationToAdmins("Jellyfin Availability Checker Finished"); } private async Task ProcessMovies() diff --git a/src/Ombi.Schedule/Jobs/Jellyfin/JellyfinContentSync.cs b/src/Ombi.Schedule/Jobs/Jellyfin/JellyfinContentSync.cs index 5519b3413..58dacaed5 100644 --- a/src/Ombi.Schedule/Jobs/Jellyfin/JellyfinContentSync.cs +++ b/src/Ombi.Schedule/Jobs/Jellyfin/JellyfinContentSync.cs @@ -3,7 +3,6 @@ using System.Globalization; using System.Linq; using System.Threading.Tasks; -using Microsoft.AspNetCore.SignalR; using Microsoft.Extensions.Logging; using Ombi.Api.Jellyfin; using Ombi.Api.Jellyfin.Models.Movie; @@ -11,7 +10,6 @@ using Ombi.Core.Settings.Models.External; using Ombi.Helpers; using Ombi.Hubs; -using Ombi.Schedule.Jobs.Ombi; using Ombi.Store.Entities; using Ombi.Store.Repository; using Quartz; @@ -22,7 +20,7 @@ namespace Ombi.Schedule.Jobs.Jellyfin public class JellyfinContentSync : IJellyfinContentSync { public JellyfinContentSync(ISettingsService settings, IJellyfinApiFactory api, ILogger logger, - IJellyfinContentRepository repo, IHubContext notification) + IJellyfinContentRepository repo, INotificationHubService notification) { _logger = logger; _settings = settings; @@ -35,7 +33,7 @@ public JellyfinContentSync(ISettingsService settings, IJellyfi private readonly ISettingsService _settings; private readonly IJellyfinApiFactory _apiFactory; private readonly IJellyfinContentRepository _repo; - private readonly IHubContext _notification; + private readonly INotificationHubService _notification; private IJellyfinApi Api { get; set; } @@ -47,8 +45,7 @@ public async Task Execute(IJobExecutionContext job) Api = _apiFactory.CreateClient(jellyfinSettings); - await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) - .SendAsync(NotificationHub.NotificationEvent, "Jellyfin Content Sync Started"); + await _notification.SendNotificationToAdmins("Jellyfin Content Sync Started"); foreach (var server in jellyfinSettings.Servers) { @@ -58,13 +55,11 @@ await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) } catch (Exception e) { - await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) - .SendAsync(NotificationHub.NotificationEvent, "Jellyfin Content Sync Failed"); + await _notification.SendNotificationToAdmins("Jellyfin Content Sync Failed"); _logger.LogError(e, "Exception when caching Jellyfin for server {0}", server.Name); } } - await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) - .SendAsync(NotificationHub.NotificationEvent, "Jellyfin Content Sync Finished"); + await _notification.SendNotificationToAdmins("Jellyfin Content Sync Finished"); // Episodes await OmbiQuartz.TriggerJob(nameof(IJellyfinEpisodeSync), "Jellyfin"); diff --git a/src/Ombi.Schedule/Jobs/Jellyfin/JellyfinEpisodeSync.cs b/src/Ombi.Schedule/Jobs/Jellyfin/JellyfinEpisodeSync.cs index 31b880114..bfc90624c 100644 --- a/src/Ombi.Schedule/Jobs/Jellyfin/JellyfinEpisodeSync.cs +++ b/src/Ombi.Schedule/Jobs/Jellyfin/JellyfinEpisodeSync.cs @@ -29,7 +29,6 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using Microsoft.AspNetCore.SignalR; using Microsoft.Extensions.Logging; using Ombi.Api.Jellyfin; using Ombi.Core.Settings; @@ -46,7 +45,7 @@ namespace Ombi.Schedule.Jobs.Jellyfin public class JellyfinEpisodeSync : IJellyfinEpisodeSync { public JellyfinEpisodeSync(ISettingsService s, IJellyfinApiFactory api, ILogger l, IJellyfinContentRepository repo - , IHubContext notification) + , INotificationHubService notification) { _apiFactory = api; _logger = l; @@ -59,7 +58,7 @@ public JellyfinEpisodeSync(ISettingsService s, IJellyfinApiFac private readonly IJellyfinApiFactory _apiFactory; private readonly ILogger _logger; private readonly IJellyfinContentRepository _repo; - private readonly IHubContext _notification; + private readonly INotificationHubService _notification; private IJellyfinApi Api { get; set; } @@ -68,8 +67,7 @@ public async Task Execute(IJobExecutionContext job) var settings = await _settings.GetSettingsAsync(); Api = _apiFactory.CreateClient(settings); - await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) - .SendAsync(NotificationHub.NotificationEvent, "Jellyfin Episode Sync Started"); + await _notification.SendNotificationToAdmins("Jellyfin Episode Sync Started"); foreach (var server in settings.Servers) { @@ -88,8 +86,7 @@ await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) } } - await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) - .SendAsync(NotificationHub.NotificationEvent, "Jellyfin Episode Sync Finished"); + await _notification.SendNotificationToAdmins("Jellyfin Episode Sync Finished"); _logger.LogInformation("Jellyfin Episode Sync Finished - Triggering Metadata refresh"); await OmbiQuartz.TriggerJob(nameof(IRefreshMetadata), "System"); } diff --git a/src/Ombi.Schedule/Jobs/Jellyfin/JellyfinUserImporter.cs b/src/Ombi.Schedule/Jobs/Jellyfin/JellyfinUserImporter.cs index 96973580d..6208d0c1a 100644 --- a/src/Ombi.Schedule/Jobs/Jellyfin/JellyfinUserImporter.cs +++ b/src/Ombi.Schedule/Jobs/Jellyfin/JellyfinUserImporter.cs @@ -29,7 +29,6 @@ using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Identity; -using Microsoft.AspNetCore.SignalR; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Ombi.Api.Jellyfin; @@ -46,7 +45,7 @@ namespace Ombi.Schedule.Jobs.Jellyfin public class JellyfinUserImporter : IJellyfinUserImporter { public JellyfinUserImporter(IJellyfinApiFactory api, UserManager um, ILogger log, - ISettingsService jellyfinSettings, ISettingsService ums, IHubContext notification) + ISettingsService jellyfinSettings, ISettingsService ums, INotificationHubService notification) { _apiFactory = api; _userManager = um; @@ -61,7 +60,7 @@ public JellyfinUserImporter(IJellyfinApiFactory api, UserManager um, I private readonly ILogger _log; private readonly ISettingsService _jellyfinSettings; private readonly ISettingsService _userManagementSettings; - private readonly IHubContext _notification; + private readonly INotificationHubService _notification; private IJellyfinApi Api { get; set; } public async Task Execute(IJobExecutionContext job) @@ -79,8 +78,7 @@ public async Task Execute(IJobExecutionContext job) Api = _apiFactory.CreateClient(settings); - await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) - .SendAsync(NotificationHub.NotificationEvent, $"Jellyfin User Importer Started"); + await _notification.SendNotificationToAdmins("Jellyfin User Importer Started"); var allUsers = await _userManager.Users.Where(x => x.UserType == UserType.JellyfinUser).ToListAsync(); foreach (var server in settings.Servers) { @@ -146,8 +144,7 @@ await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) } } - await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) - .SendAsync(NotificationHub.NotificationEvent, "Jellyfin User Importer Finished"); + await _notification.SendNotificationToAdmins("Jellyfin User Importer Finished"); } private bool _disposed; diff --git a/src/Ombi.Schedule/Jobs/Lidarr/LidarrAlbumSync.cs b/src/Ombi.Schedule/Jobs/Lidarr/LidarrAlbumSync.cs index 0cb1c441b..87922efd9 100644 --- a/src/Ombi.Schedule/Jobs/Lidarr/LidarrAlbumSync.cs +++ b/src/Ombi.Schedule/Jobs/Lidarr/LidarrAlbumSync.cs @@ -2,9 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using Microsoft.AspNetCore.SignalR; using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Internal; using Microsoft.Extensions.Logging; using Ombi.Api.Lidarr; using Ombi.Core.Settings; @@ -21,7 +19,7 @@ namespace Ombi.Schedule.Jobs.Lidarr public class LidarrAlbumSync : ILidarrAlbumSync { public LidarrAlbumSync(ISettingsService lidarr, ILidarrApi lidarrApi, ILogger log, ExternalContext ctx, - IHubContext notification) + INotificationHubService notification) { _lidarrSettings = lidarr; _lidarrApi = lidarrApi; @@ -34,7 +32,7 @@ public LidarrAlbumSync(ISettingsService lidarr, ILidarrApi lidar private readonly ILidarrApi _lidarrApi; private readonly ILogger _logger; private readonly ExternalContext _ctx; - private readonly IHubContext _notification; + private readonly INotificationHubService _notification; public async Task Execute(IJobExecutionContext ctx) { @@ -44,8 +42,7 @@ public async Task Execute(IJobExecutionContext ctx) if (settings.Enabled) { - await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) - .SendAsync(NotificationHub.NotificationEvent, "Lidarr Album Sync Started"); + await _notification.SendNotificationToAdmins("Lidarr Album Sync Started"); try { var albums = await _lidarrApi.GetAllAlbums(settings.ApiKey, settings.FullUri); @@ -95,13 +92,11 @@ await strat.ExecuteAsync(async () => } catch (System.Exception ex) { - await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) - .SendAsync(NotificationHub.NotificationEvent, "Lidarr Album Sync Failed"); + await _notification.SendNotificationToAdmins("Lidarr Album Sync Failed"); _logger.LogError(LoggingEvents.Cacher, ex, "Failed caching queued items from Lidarr Album"); } - await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) - .SendAsync(NotificationHub.NotificationEvent, "Lidarr Album Sync Finished"); + await _notification.SendNotificationToAdmins("Lidarr Album Sync Finished"); await OmbiQuartz.TriggerJob(nameof(ILidarrAvailabilityChecker), "DVR"); } diff --git a/src/Ombi.Schedule/Jobs/Lidarr/LidarrArtistSync.cs b/src/Ombi.Schedule/Jobs/Lidarr/LidarrArtistSync.cs index 06577beb6..c4d9a3ee2 100644 --- a/src/Ombi.Schedule/Jobs/Lidarr/LidarrArtistSync.cs +++ b/src/Ombi.Schedule/Jobs/Lidarr/LidarrArtistSync.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using Microsoft.AspNetCore.SignalR; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Ombi.Api.Lidarr; @@ -20,7 +19,7 @@ namespace Ombi.Schedule.Jobs.Lidarr public class LidarrArtistSync : ILidarrArtistSync { public LidarrArtistSync(ISettingsService lidarr, ILidarrApi lidarrApi, ILogger log, ExternalContext ctx - , IHubContext notification) + , INotificationHubService notification) { _lidarrSettings = lidarr; _lidarrApi = lidarrApi; @@ -33,7 +32,7 @@ public LidarrArtistSync(ISettingsService lidarr, ILidarrApi lida private readonly ILidarrApi _lidarrApi; private readonly ILogger _logger; private readonly ExternalContext _ctx; - private readonly IHubContext _notification; + private readonly INotificationHubService _notification; public async Task Execute(IJobExecutionContext job) { @@ -43,8 +42,7 @@ public async Task Execute(IJobExecutionContext job) if (settings.Enabled) { - await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) - .SendAsync(NotificationHub.NotificationEvent, "Lidarr Artist Sync Started"); + await _notification.SendNotificationToAdmins("Lidarr Artist Sync Started"); try { var artists = await _lidarrApi.GetArtists(settings.ApiKey, settings.FullUri); @@ -90,13 +88,11 @@ await strat.ExecuteAsync(async () => } catch (Exception ex) { - await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) - .SendAsync(NotificationHub.NotificationEvent, "Lidarr Artist Sync Failed"); + await _notification.SendNotificationToAdmins("Lidarr Artist Sync Failed"); _logger.LogError(LoggingEvents.Cacher, ex, "Failed caching queued items from Lidarr"); } - await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) - .SendAsync(NotificationHub.NotificationEvent, "Lidarr Artist Sync Finished"); + await _notification.SendNotificationToAdmins("Lidarr Artist Sync Finished"); await OmbiQuartz.TriggerJob(nameof(ILidarrAlbumSync), "DVR"); } diff --git a/src/Ombi.Schedule/Jobs/Lidarr/LidarrAvailabilityChecker.cs b/src/Ombi.Schedule/Jobs/Lidarr/LidarrAvailabilityChecker.cs index 99b27fec7..321db3fda 100644 --- a/src/Ombi.Schedule/Jobs/Lidarr/LidarrAvailabilityChecker.cs +++ b/src/Ombi.Schedule/Jobs/Lidarr/LidarrAvailabilityChecker.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using Microsoft.AspNetCore.SignalR; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Ombi.Core; @@ -20,26 +19,25 @@ namespace Ombi.Schedule.Jobs.Lidarr public class LidarrAvailabilityChecker : ILidarrAvailabilityChecker { public LidarrAvailabilityChecker(IMusicRequestRepository requests, IExternalRepository albums, ILogger log, - INotificationHelper notification, IHubContext notificationHub) + INotificationHelper notification, INotificationHubService notificationHubService) { _cachedAlbums = albums; _requestRepository = requests; _logger = log; _notificationService = notification; - _notification = notificationHub; + _notification = notificationHubService; } private readonly IMusicRequestRepository _requestRepository; private readonly IExternalRepository _cachedAlbums; private readonly ILogger _logger; private readonly INotificationHelper _notificationService; - private readonly IHubContext _notification; + private readonly INotificationHubService _notification; public async Task Execute(IJobExecutionContext ctx) { - await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) - .SendAsync(NotificationHub.NotificationEvent, "Lidarr Availability Check Started"); + await _notification.SendNotificationToAdmins("Lidarr Availability Check Started"); var allAlbumRequests = _requestRepository.GetAll().Include(x => x.RequestedUser).Where(x => !x.Available); var albumsToUpdate = new List(); foreach (var request in allAlbumRequests) @@ -75,8 +73,7 @@ await _notificationService.Notify(new NotificationOptions }); } - await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) - .SendAsync(NotificationHub.NotificationEvent, "Lidarr Availability Check Finished"); + await _notification.SendNotificationToAdmins("Lidarr Availability Check Finished"); } } } diff --git a/src/Ombi.Schedule/Jobs/Ombi/NewsletterJob.cs b/src/Ombi.Schedule/Jobs/Ombi/NewsletterJob.cs index 0782a796a..0a082bfe6 100644 --- a/src/Ombi.Schedule/Jobs/Ombi/NewsletterJob.cs +++ b/src/Ombi.Schedule/Jobs/Ombi/NewsletterJob.cs @@ -4,7 +4,6 @@ using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Identity; -using Microsoft.AspNetCore.SignalR; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using MimeKit; @@ -38,7 +37,7 @@ public NewsletterJob(IPlexContentRepository plex, IEmbyContentRepository emby, I UserManager um, ISettingsService newsletter, ILogger log, ILidarrApi lidarrApi, IExternalRepository albumCache, ISettingsService lidarrSettings, ISettingsService ombiSettings, ISettingsService plexSettings, ISettingsService embySettings, ISettingsService jellyfinSettings, - IHubContext notification, IRefreshMetadata refreshMetadata) + INotificationHubService notification, IRefreshMetadata refreshMetadata) { _plex = plex; _emby = emby; @@ -86,7 +85,7 @@ public NewsletterJob(IPlexContentRepository plex, IEmbyContentRepository emby, I private readonly ISettingsService _plexSettings; private readonly ISettingsService _embySettings; private readonly ISettingsService _jellyfinSettings; - private readonly IHubContext _notification; + private readonly INotificationHubService _notification; private readonly IRefreshMetadata _refreshMetadata; public async Task Start(NewsletterSettings settings, bool test) @@ -101,13 +100,11 @@ public async Task Start(NewsletterSettings settings, bool test) return; } - await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) - .SendAsync(NotificationHub.NotificationEvent, "Newsletter Started"); + await _notification.SendNotificationToAdmins("Newsletter Started"); var emailSettings = await _emailSettings.GetSettingsAsync(); if (!ValidateConfiguration(emailSettings)) { - await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) - .SendAsync(NotificationHub.NotificationEvent, "Newsletter Email Settings Not Configured"); + await _notification.SendNotificationToAdmins("Newsletter Email Settings Not Configured"); return; } @@ -230,14 +227,12 @@ await _email.Send( } catch (Exception e) { - await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) - .SendAsync(NotificationHub.NotificationEvent, "Newsletter Failed"); + await _notification.SendNotificationToAdmins( "Newsletter Failed"); _log.LogError(e, "Error when attempting to create newsletter"); throw; } - await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) - .SendAsync(NotificationHub.NotificationEvent, "Newsletter Finished"); + await _notification.SendNotificationToAdmins("Newsletter Finished"); } private void AddToRecentlyAddedLog(ICollection moviesContents, diff --git a/src/Ombi.Schedule/Jobs/Ombi/RefreshMetadata.cs b/src/Ombi.Schedule/Jobs/Ombi/RefreshMetadata.cs index 64abb2aac..d7c05d71e 100644 --- a/src/Ombi.Schedule/Jobs/Ombi/RefreshMetadata.cs +++ b/src/Ombi.Schedule/Jobs/Ombi/RefreshMetadata.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using Microsoft.AspNetCore.SignalR; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Ombi.Api.Emby; @@ -31,7 +30,7 @@ public RefreshMetadata(IPlexContentRepository plexRepo, IEmbyContentRepository e IMovieDbApi movieApi, ISettingsService embySettings, IEmbyApiFactory embyApi, ISettingsService jellyfinSettings, IJellyfinApiFactory jellyfinApi, - IHubContext notification, IMediaCacheService mediaCacheService, + INotificationHubService notification, IMediaCacheService mediaCacheService, IPlexApi plexApi) { _plexRepo = plexRepo; @@ -61,7 +60,7 @@ public RefreshMetadata(IPlexContentRepository plexRepo, IEmbyContentRepository e private readonly ISettingsService _jellyfinSettings; private readonly IEmbyApiFactory _embyApiFactory; private readonly IJellyfinApiFactory _jellyfinApiFactory; - private readonly IHubContext _notification; + private readonly INotificationHubService _notification; private readonly IMediaCacheService _mediaCacheService; private readonly IPlexApi _plexApi; @@ -72,8 +71,7 @@ public async Task Execute(IJobExecutionContext job) { _log.LogInformation("Starting the Metadata refresh"); - await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) - .SendAsync(NotificationHub.NotificationEvent, "Metadata Refresh Started"); + await _notification.SendNotificationToAdmins("Metadata Refresh Started"); try { var settings = await _plexSettings.GetSettingsAsync(); @@ -104,16 +102,14 @@ await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) { _log.LogError(e, $"Exception when refreshing the Metadata Refresh"); - await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) - .SendAsync(NotificationHub.NotificationEvent, "Metadata Refresh Failed"); + await _notification.SendNotificationToAdmins("Metadata Refresh Failed"); return; } await _mediaCacheService.Purge(); _log.LogInformation("Metadata refresh finished"); - await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) - .SendAsync(NotificationHub.NotificationEvent, "Metadata Refresh Finished"); + await _notification.SendNotificationToAdmins("Metadata Refresh Finished"); } private async Task StartPlex(PlexSettings settings) diff --git a/src/Ombi.Schedule/Jobs/Plex/PlexAvailabilityChecker.cs b/src/Ombi.Schedule/Jobs/Plex/PlexAvailabilityChecker.cs index 70a500298..8172db205 100644 --- a/src/Ombi.Schedule/Jobs/Plex/PlexAvailabilityChecker.cs +++ b/src/Ombi.Schedule/Jobs/Plex/PlexAvailabilityChecker.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using Microsoft.AspNetCore.SignalR; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Ombi.Core; @@ -22,8 +21,8 @@ namespace Ombi.Schedule.Jobs.Plex public class PlexAvailabilityChecker : AvailabilityChecker, IPlexAvailabilityChecker { public PlexAvailabilityChecker(IPlexContentRepository repo, ITvRequestRepository tvRequest, IMovieRequestRepository movies, - INotificationHelper notification, ILogger log, IHubContext hub, IFeatureService featureService) - : base(tvRequest, notification, log, hub) + INotificationHelper notification, ILogger log, INotificationHubService notificationHubService, IFeatureService featureService) + : base(tvRequest, notification, log, notificationHubService) { _repo = repo; _movieRepo = movies; @@ -38,21 +37,18 @@ public async Task Execute(IJobExecutionContext job) { try { - await _hub.Clients.Clients(NotificationHub.AdminConnectionIds) - .SendAsync(NotificationHub.NotificationEvent, "Plex Availability Check Started"); + await NotificationHubService.SendNotificationToAdmins( "Plex Availability Check Started"); await ProcessMovies(); await ProcessTv(); } catch (Exception e) { - await _hub.Clients.Clients(NotificationHub.AdminConnectionIds) - .SendAsync(NotificationHub.NotificationEvent, "Plex Availability Check Failed"); + await NotificationHubService.SendNotificationToAdmins( "Plex Availability Check Failed"); _log.LogError(e, "Exception thrown in Plex availbility checker"); return; } - await _hub.Clients.Clients(NotificationHub.AdminConnectionIds) - .SendAsync(NotificationHub.NotificationEvent, "Plex Availability Check Finished"); + await NotificationHubService.SendNotificationToAdmins("Plex Availability Check Finished"); } private async Task ProcessTv() diff --git a/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs b/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs index d5aac7379..388686548 100644 --- a/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs +++ b/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs @@ -29,7 +29,6 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using Microsoft.AspNetCore.SignalR; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Ombi.Api.Plex; @@ -40,7 +39,6 @@ using Ombi.Core.Settings.Models.External; using Ombi.Helpers; using Ombi.Hubs; -using Ombi.Schedule.Jobs.Ombi; using Ombi.Schedule.Jobs.Plex.Interfaces; using Ombi.Schedule.Jobs.Plex.Models; using Ombi.Store.Entities; @@ -55,14 +53,14 @@ public class PlexContentSync : IPlexContentSync private readonly IMediaCacheService _mediaCacheService; public PlexContentSync(ISettingsService plex, IPlexApi plexApi, ILogger logger, IPlexContentRepository repo, - IPlexEpisodeSync epsiodeSync, IHubContext hub, IMovieDbApi movieDbApi, IMediaCacheService mediaCacheService) + IPlexEpisodeSync epsiodeSync, INotificationHubService notificationHubService, IMovieDbApi movieDbApi, IMediaCacheService mediaCacheService) { Plex = plex; PlexApi = plexApi; Logger = logger; Repo = repo; EpisodeSync = epsiodeSync; - Notification = hub; + Notification = notificationHubService; _movieApi = movieDbApi; _mediaCacheService = mediaCacheService; Plex.ClearCache(); @@ -73,7 +71,7 @@ public PlexContentSync(ISettingsService plex, IPlexApi plexApi, IL private ILogger Logger { get; } private IPlexContentRepository Repo { get; } private IPlexEpisodeSync EpisodeSync { get; } - private IHubContext Notification { get; set; } + private INotificationHubService Notification { get; set; } public async Task Execute(IJobExecutionContext context) { @@ -743,8 +741,7 @@ private async Task> GetAllContent(PlexServers plexSettings, private async Task NotifyClient(string message) { - await Notification.Clients.Clients(NotificationHub.AdminConnectionIds) - .SendAsync(NotificationHub.NotificationEvent, $"Plex Sync - {message}"); + await Notification.SendNotificationToAdmins($"Plex Sync - {message}"); } private static bool ValidateSettings(PlexSettings plex) diff --git a/src/Ombi.Schedule/Jobs/Plex/PlexEpisodeSync.cs b/src/Ombi.Schedule/Jobs/Plex/PlexEpisodeSync.cs index c17af088c..4d18e580f 100644 --- a/src/Ombi.Schedule/Jobs/Plex/PlexEpisodeSync.cs +++ b/src/Ombi.Schedule/Jobs/Plex/PlexEpisodeSync.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using Microsoft.AspNetCore.SignalR; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Ombi.Api.Plex; @@ -22,13 +21,13 @@ namespace Ombi.Schedule.Jobs.Plex public class PlexEpisodeSync : IPlexEpisodeSync { public PlexEpisodeSync(ISettingsService s, ILogger log, IPlexApi plexApi, - IPlexContentRepository repo, IHubContext hub) + IPlexContentRepository repo, INotificationHubService notificationHubService) { _settings = s; _log = log; _api = plexApi; _repo = repo; - _notification = hub; + _notification = notificationHubService; _settings.ClearCache(); } @@ -36,7 +35,7 @@ public PlexEpisodeSync(ISettingsService s, ILogger _log; private readonly IPlexApi _api; private readonly IPlexContentRepository _repo; - private readonly IHubContext _notification; + private readonly INotificationHubService _notification; public async Task Execute(IJobExecutionContext job) { @@ -47,8 +46,7 @@ public async Task Execute(IJobExecutionContext job) { return; } - await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) - .SendAsync(NotificationHub.NotificationEvent, "Plex Episode Sync Started"); + await _notification.SendNotificationToAdmins("Plex Episode Sync Started"); foreach (var server in s.Servers) { @@ -58,8 +56,7 @@ await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) } catch (Exception e) { - await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) - .SendAsync(NotificationHub.NotificationEvent, "Plex Episode Sync Failed"); + await _notification.SendNotificationToAdmins("Plex Episode Sync Failed"); _log.LogError(LoggingEvents.Cacher, e, "Caching Episodes Failed"); } @@ -67,8 +64,7 @@ await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) _log.LogInformation("Plex Episode Sync Finished - Triggering Metadata refresh"); await OmbiQuartz.TriggerJob(nameof(IRefreshMetadata), "System"); - await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) - .SendAsync(NotificationHub.NotificationEvent, "Plex Episode Sync Finished"); + await _notification.SendNotificationToAdmins("Plex Episode Sync Finished"); } private async Task Cache(PlexServers settings) diff --git a/src/Ombi.Schedule/Jobs/Plex/PlexUserImporter.cs b/src/Ombi.Schedule/Jobs/Plex/PlexUserImporter.cs index 4e9df54fc..4cbf73d60 100644 --- a/src/Ombi.Schedule/Jobs/Plex/PlexUserImporter.cs +++ b/src/Ombi.Schedule/Jobs/Plex/PlexUserImporter.cs @@ -3,7 +3,6 @@ using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Identity; -using Microsoft.AspNetCore.SignalR; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Ombi.Api.Plex; @@ -21,14 +20,14 @@ namespace Ombi.Schedule.Jobs.Plex public class PlexUserImporter : IPlexUserImporter { public PlexUserImporter(IPlexApi api, OmbiUserManager um, ILogger log, - ISettingsService plexSettings, ISettingsService ums, IHubContext hub) + ISettingsService plexSettings, ISettingsService ums, INotificationHubService notificationHubService) { _api = api; _userManager = um; _log = log; _plexSettings = plexSettings; _userManagementSettings = ums; - _notification = hub; + _notification = notificationHubService; _plexSettings.ClearCache(); _userManagementSettings.ClearCache(); } @@ -38,7 +37,7 @@ public PlexUserImporter(IPlexApi api, OmbiUserManager um, ILogger _log; private readonly ISettingsService _plexSettings; private readonly ISettingsService _userManagementSettings; - private readonly IHubContext _notification; + private readonly INotificationHubService _notification; public async Task Execute(IJobExecutionContext job) @@ -55,8 +54,7 @@ public async Task Execute(IJobExecutionContext job) return; } - await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) - .SendAsync(NotificationHub.NotificationEvent, "Plex User Importer Started"); + await _notification.SendNotificationToAdmins("Plex User Importer Started"); var allUsers = await _userManager.Users.Where(x => x.UserType == UserType.PlexUser).ToListAsync(); foreach (var server in settings.Servers) { @@ -75,8 +73,7 @@ await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) } } - await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) - .SendAsync(NotificationHub.NotificationEvent, "Plex User Importer Finished"); + await _notification.SendNotificationToAdmins("Plex User Importer Finished"); } private async Task ImportPlexUsers(UserManagementSettings userManagementSettings, List allUsers, PlexServers server) diff --git a/src/Ombi.Schedule/Jobs/Plex/PlexWatchlistImport.cs b/src/Ombi.Schedule/Jobs/Plex/PlexWatchlistImport.cs index 82b5a6d1a..3891723b7 100644 --- a/src/Ombi.Schedule/Jobs/Plex/PlexWatchlistImport.cs +++ b/src/Ombi.Schedule/Jobs/Plex/PlexWatchlistImport.cs @@ -1,5 +1,4 @@ -using Microsoft.AspNetCore.SignalR; -using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Ombi.Api.Plex; using Ombi.Api.Plex.Models; @@ -30,13 +29,13 @@ public class PlexWatchlistImport : IPlexWatchlistImport private readonly OmbiUserManager _ombiUserManager; private readonly IMovieRequestEngine _movieRequestEngine; private readonly ITvRequestEngine _tvRequestEngine; - private readonly IHubContext _hub; + private readonly INotificationHubService _notificationHubService; private readonly ILogger _logger; private readonly IExternalRepository _watchlistRepo; private readonly IRepository _userError; public PlexWatchlistImport(IPlexApi plexApi, ISettingsService settings, OmbiUserManager ombiUserManager, - IMovieRequestEngine movieRequestEngine, ITvRequestEngine tvRequestEngine, IHubContext hub, + IMovieRequestEngine movieRequestEngine, ITvRequestEngine tvRequestEngine, INotificationHubService notificationHubService, ILogger logger, IExternalRepository watchlistRepo, IRepository userError) { _plexApi = plexApi; @@ -44,7 +43,7 @@ public PlexWatchlistImport(IPlexApi plexApi, ISettingsService sett _ombiUserManager = ombiUserManager; _movieRequestEngine = movieRequestEngine; _tvRequestEngine = tvRequestEngine; - _hub = hub; + _notificationHubService = notificationHubService; _logger = logger; _watchlistRepo = watchlistRepo; _userError = userError; @@ -228,13 +227,9 @@ private async Task GetProviderIds(string authToken, Metadata movie, private async Task NotifyClient(string message) { - if (_hub?.Clients == null) - { - return; - } - await _hub?.Clients?.Clients(NotificationHub.AdminConnectionIds)? - .SendAsync(NotificationHub.NotificationEvent, $"Plex Watchlist Import - {message}"); + await _notificationHubService.SendNotificationToAdmins($"Plex Watchlist Import - {message}"); } + public void Dispose() { } } } diff --git a/src/Ombi.Schedule/Ombi.Schedule.csproj b/src/Ombi.Schedule/Ombi.Schedule.csproj index a972aa6bb..97477dea1 100644 --- a/src/Ombi.Schedule/Ombi.Schedule.csproj +++ b/src/Ombi.Schedule/Ombi.Schedule.csproj @@ -11,13 +11,13 @@ - - - + + + - - - + + + diff --git a/src/Ombi.Settings.Tests/Ombi.Settings.Tests.csproj b/src/Ombi.Settings.Tests/Ombi.Settings.Tests.csproj index 5f93b4b68..e36ef61ee 100644 --- a/src/Ombi.Settings.Tests/Ombi.Settings.Tests.csproj +++ b/src/Ombi.Settings.Tests/Ombi.Settings.Tests.csproj @@ -8,10 +8,10 @@ - - + + - + diff --git a/src/Ombi.Settings/Ombi.Settings.csproj b/src/Ombi.Settings/Ombi.Settings.csproj index 3821892f0..fae107ca8 100644 --- a/src/Ombi.Settings/Ombi.Settings.csproj +++ b/src/Ombi.Settings/Ombi.Settings.csproj @@ -12,8 +12,8 @@ - - + + diff --git a/src/Ombi.Store/Ombi.Store.csproj b/src/Ombi.Store/Ombi.Store.csproj index 1c145f55a..9828351f5 100644 --- a/src/Ombi.Store/Ombi.Store.csproj +++ b/src/Ombi.Store/Ombi.Store.csproj @@ -12,16 +12,16 @@ - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - + + + + + diff --git a/src/Ombi.Test.Common/MockHelper.cs b/src/Ombi.Test.Common/MockHelper.cs index 8d3f5ce8d..1180a3464 100644 --- a/src/Ombi.Test.Common/MockHelper.cs +++ b/src/Ombi.Test.Common/MockHelper.cs @@ -20,7 +20,7 @@ public static Mock MockUserManager(List ls) var userMock = ls.AsQueryable().BuildMock(); - mgr.Setup(x => x.Users).Returns(userMock.Object); + mgr.Setup(x => x.Users).Returns(userMock); mgr.Setup(x => x.DeleteAsync(It.IsAny())).ReturnsAsync(IdentityResult.Success); mgr.Setup(x => x.CreateAsync(It.IsAny(), It.IsAny())).ReturnsAsync(IdentityResult.Success).Callback((x, y) => ls.Add(x)); mgr.Setup(x => x.UpdateAsync(It.IsAny())).ReturnsAsync(IdentityResult.Success); diff --git a/src/Ombi.Test.Common/Ombi.Test.Common.csproj b/src/Ombi.Test.Common/Ombi.Test.Common.csproj index 512055143..066d32a15 100644 --- a/src/Ombi.Test.Common/Ombi.Test.Common.csproj +++ b/src/Ombi.Test.Common/Ombi.Test.Common.csproj @@ -8,8 +8,8 @@ - - + + diff --git a/src/Ombi.Tests/Ombi.Tests.csproj b/src/Ombi.Tests/Ombi.Tests.csproj index c38756445..ce3b45533 100644 --- a/src/Ombi.Tests/Ombi.Tests.csproj +++ b/src/Ombi.Tests/Ombi.Tests.csproj @@ -2,21 +2,19 @@ net6.0 - false - Debug;Release;NonUiBuild - - - - - + + + + + - - + + diff --git a/src/Ombi.Tests/SignalRHelper.cs b/src/Ombi.Tests/SignalRHelper.cs index 80a7fcdd0..5beaa4a0d 100644 --- a/src/Ombi.Tests/SignalRHelper.cs +++ b/src/Ombi.Tests/SignalRHelper.cs @@ -1,6 +1,6 @@ -using Microsoft.AspNetCore.SignalR; -using Moq; +using Moq; using System.Collections.Generic; +using Microsoft.AspNetCore.SignalR; namespace Ombi.Tests { diff --git a/src/Ombi.TheMovieDbApi/Models/MovieDbSearchResult.cs b/src/Ombi.TheMovieDbApi/Models/MovieDbSearchResult.cs index e936578e9..88ad79884 100644 --- a/src/Ombi.TheMovieDbApi/Models/MovieDbSearchResult.cs +++ b/src/Ombi.TheMovieDbApi/Models/MovieDbSearchResult.cs @@ -9,7 +9,7 @@ public class MovieDbSearchResult public bool Adult { get; set; } public string Overview { get; set; } public string ReleaseDate { get; set; } - public int?[] GenreIds { get; set; } + public int[] GenreIds { get; set; } public int Id { get; set; } public string OriginalTitle { get; set; } public string OriginalLanguage { get; set; } diff --git a/src/Ombi.TheMovieDbApi/Ombi.Api.TheMovieDb.csproj b/src/Ombi.TheMovieDbApi/Ombi.Api.TheMovieDb.csproj index ddab7e3f8..db1509ef8 100644 --- a/src/Ombi.TheMovieDbApi/Ombi.Api.TheMovieDb.csproj +++ b/src/Ombi.TheMovieDbApi/Ombi.Api.TheMovieDb.csproj @@ -13,7 +13,7 @@ - + diff --git a/src/Ombi.Updater/Ombi.Updater.csproj b/src/Ombi.Updater/Ombi.Updater.csproj index d31229b62..493990ac0 100644 --- a/src/Ombi.Updater/Ombi.Updater.csproj +++ b/src/Ombi.Updater/Ombi.Updater.csproj @@ -12,8 +12,8 @@ - - + + @@ -21,9 +21,8 @@ - - - - + + + \ No newline at end of file diff --git a/src/Ombi.Updater/Program.cs b/src/Ombi.Updater/Program.cs index 40586b219..9a4a5e91b 100644 --- a/src/Ombi.Updater/Program.cs +++ b/src/Ombi.Updater/Program.cs @@ -3,7 +3,6 @@ using CommandLine; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; using Serilog; namespace Ombi.Updater @@ -40,7 +39,7 @@ private static void ConfigureServices(IServiceCollection serviceCollection) Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() - .WriteTo.RollingFile(Path.Combine("Logs", "log-{Date}.txt")) + .WriteTo.File(Path.Combine("Logs", "log.txt"), rollingInterval: RollingInterval.Day) .Enrich.FromLogContext() .CreateLogger(); diff --git a/src/Ombi/Controllers/V2/HubController.cs b/src/Ombi/Controllers/V2/HubController.cs index 3520595a6..6fa85fe11 100644 --- a/src/Ombi/Controllers/V2/HubController.cs +++ b/src/Ombi/Controllers/V2/HubController.cs @@ -1,25 +1,30 @@ -using System; +using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; -using System.Collections.Generic; using Microsoft.EntityFrameworkCore; using Ombi.Attributes; using Ombi.Core.Authentication; using Ombi.Hubs; using Ombi.Models; +using Ombi.Store.Entities; namespace Ombi.Controllers.V2 { [Admin] public class HubController : V2Controller { - public HubController(OmbiUserManager um) + private readonly INotificationHubService _notificationHubService; + private readonly OmbiUserManager _userManager; + + public HubController( + INotificationHubService notificationHubService, + OmbiUserManager userManager + ) { - _um = um; + _notificationHubService = notificationHubService; + _userManager = userManager; } - private readonly OmbiUserManager _um; - /// /// Returns the currently connected users in Ombi /// @@ -27,13 +32,12 @@ public HubController(OmbiUserManager um) [HttpGet("Users")] public async Task> GetConnectedUsers() { - var users = NotificationHub.UsersOnline.Values; - var allUsers = _um.Users; - var model = new List(); - foreach (var user in users) + IEnumerable users = _notificationHubService.GetOnlineUsers(); + List model = new(); + foreach (NotificationHubUser user in users) { - var ombiUser = await allUsers.FirstOrDefaultAsync(x => x.Id == user.UserId); - + OmbiUser ombiUser = await _userManager.Users + .FirstOrDefaultAsync(x => x.Id == user.UserId); if (ombiUser == null) { continue; diff --git a/src/Ombi/Ombi.csproj b/src/Ombi/Ombi.csproj index f0091002a..25920a126 100644 --- a/src/Ombi/Ombi.csproj +++ b/src/Ombi/Ombi.csproj @@ -57,34 +57,31 @@ - - - - - - - + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - - - - - - - - - - + + + + + + + + - - - + + diff --git a/src/Ombi/Startup.cs b/src/Ombi/Startup.cs index 9fe01019e..433abd6cf 100644 --- a/src/Ombi/Startup.cs +++ b/src/Ombi/Startup.cs @@ -1,10 +1,8 @@ -using AutoMapper; -using AutoMapper.EquivalencyExpression; +using AutoMapper.EquivalencyExpression; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.HttpOverrides; using Microsoft.AspNetCore.Identity; -using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.StaticFiles; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -20,12 +18,10 @@ using Ombi.Settings.Settings.Models; using Ombi.Store.Context; using Ombi.Store.Entities; -using Ombi.Store.Repository; using Serilog; using System; using System.IO; using Microsoft.AspNetCore.StaticFiles.Infrastructure; -using Microsoft.Extensions.Hosting; using Newtonsoft.Json; using ILogger = Serilog.ILogger; using Microsoft.AspNetCore.Diagnostics.HealthChecks; @@ -50,7 +46,7 @@ public Startup(IWebHostEnvironment env) ILogger config = new LoggerConfiguration() .ReadFrom.Configuration(Configuration) - .WriteTo.RollingFile(Path.Combine(StoragePath.StoragePath.IsNullOrEmpty() ? env.ContentRootPath : StoragePath.StoragePath, "Logs", "log-{Date}.txt")) + .WriteTo.File(Path.Combine(StoragePath.StoragePath.IsNullOrEmpty() ? env.ContentRootPath : StoragePath.StoragePath, "Logs", "log.txt"), rollingInterval: RollingInterval.Day) .CreateLogger(); Log.Logger = config; @@ -112,7 +108,6 @@ public void ConfigureServices(IServiceCollection services) services.AddMvc(); services.AddSignalR(); services.AddSpaStaticFiles(configuration => configuration.RootPath = "ClientApp/dist"); - } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. From 5284075c1bbfda991c5b1fb499c610630e4eb468 Mon Sep 17 00:00:00 2001 From: Victor Usoltsev Date: Thu, 6 Oct 2022 12:57:51 +1300 Subject: [PATCH 2/2] Fixes the last few build warnings. --- src/Ombi.Api.Twilio/Ombi.Api.Twilio.csproj | 2 +- src/Ombi.Mapping/Ombi.Mapping.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Ombi.Api.Twilio/Ombi.Api.Twilio.csproj b/src/Ombi.Api.Twilio/Ombi.Api.Twilio.csproj index 17dc14c25..2b4bb3d8d 100644 --- a/src/Ombi.Api.Twilio/Ombi.Api.Twilio.csproj +++ b/src/Ombi.Api.Twilio/Ombi.Api.Twilio.csproj @@ -6,7 +6,7 @@ - + diff --git a/src/Ombi.Mapping/Ombi.Mapping.csproj b/src/Ombi.Mapping/Ombi.Mapping.csproj index ff8194d40..8f120cc6b 100644 --- a/src/Ombi.Mapping/Ombi.Mapping.csproj +++ b/src/Ombi.Mapping/Ombi.Mapping.csproj @@ -12,7 +12,7 @@ - +