diff --git a/PlexRequests.Services/AvailabilityUpdateService.cs b/PlexRequests.Services/AvailabilityUpdateService.cs index e563e839e..a0fbee580 100644 --- a/PlexRequests.Services/AvailabilityUpdateService.cs +++ b/PlexRequests.Services/AvailabilityUpdateService.cs @@ -32,18 +32,27 @@ using System.Web.Hosting; using FluentScheduler; +using Mono.Data.Sqlite; + using NLog; +using PlexRequests.Api.Models; +using PlexRequests.Core; +using PlexRequests.Core.SettingModels; +using PlexRequests.Helpers; using PlexRequests.Services.Interfaces; +using PlexRequests.Store; +using PlexRequests.Store.Repository; namespace PlexRequests.Services { - public class AvailabilityUpdateService : ITask, IRegisteredObject + public class AvailabilityUpdateService : ITask, IRegisteredObject, IAvailabilityUpdateService { - public AvailabilityUpdateService(IConfigurationReader reader, IAvailabilityChecker checker) + public AvailabilityUpdateService() { - ConfigurationReader = reader; - Checker = checker; + ConfigurationReader = new ConfigurationReader(); + var repo = new JsonRepository(new DbConfiguration(new SqliteFactory()), new MemoryCacheProvider()); + Checker = new PlexAvailabilityChecker(new SettingsServiceV2(repo), new SettingsServiceV2(repo), new RequestService(new GenericRepository(new DbConfiguration(new SqliteFactory()))) ); HostingEnvironment.RegisterObject(this); } @@ -57,7 +66,7 @@ namespace PlexRequests.Services { UpdateSubscription?.Dispose(); - UpdateSubscription = Observable.Interval(c.Intervals.Measurement).Subscribe(Checker.CheckAndUpdateAll); + UpdateSubscription = Observable.Interval(c.Intervals.Notification).Subscribe(Checker.CheckAndUpdateAll); } public void Execute() @@ -70,4 +79,9 @@ namespace PlexRequests.Services throw new System.NotImplementedException(); } } + + public interface IAvailabilityUpdateService + { + void Start(Configuration c); + } } \ No newline at end of file diff --git a/PlexRequests.Services/PlexRequests.Services.csproj b/PlexRequests.Services/PlexRequests.Services.csproj index 3af5f2e34..163fbc612 100644 --- a/PlexRequests.Services/PlexRequests.Services.csproj +++ b/PlexRequests.Services/PlexRequests.Services.csproj @@ -36,6 +36,10 @@ True + + False + ..\Assemblies\Mono.Data.Sqlite.dll + ..\packages\NLog.4.2.3\lib\net45\NLog.dll True @@ -89,6 +93,10 @@ {dd7dc444-d3bf-4027-8ab9-efc71f5ec581} PlexRequests.Core + + {1252336D-42A3-482A-804C-836E60173DFA} + PlexRequests.Helpers + {92433867-2b7b-477b-a566-96c382427525} PlexRequests.Store diff --git a/PlexRequests.UI.Tests/PlexRequests.UI.Tests.csproj b/PlexRequests.UI.Tests/PlexRequests.UI.Tests.csproj index 6b062fbc3..c4f41f81a 100644 --- a/PlexRequests.UI.Tests/PlexRequests.UI.Tests.csproj +++ b/PlexRequests.UI.Tests/PlexRequests.UI.Tests.csproj @@ -65,7 +65,6 @@ - diff --git a/PlexRequests.UI.Tests/TaskFactoryTests.cs b/PlexRequests.UI.Tests/TaskFactoryTests.cs deleted file mode 100644 index 47a97b67a..000000000 --- a/PlexRequests.UI.Tests/TaskFactoryTests.cs +++ /dev/null @@ -1,46 +0,0 @@ -#region Copyright -// /************************************************************************ -// Copyright (c) 2016 Jamie Rees -// File: TaskFactoryTests.cs -// Created By: Jamie Rees -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// ************************************************************************/ -#endregion -using NUnit.Framework; - -using PlexRequests.Services; -using PlexRequests.UI.Jobs; - -namespace PlexRequests.UI.Tests -{ - [TestFixture] - public class TaskFactoryTests - { - [Test] - public void GetTaskInstanceTest() - { - var fact = new PlexTaskFactory(); - var result = fact.GetTaskInstance(); - - Assert.That(result, Is.Not.Null); - } - } -} \ No newline at end of file diff --git a/PlexRequests.UI/Bootstrapper.cs b/PlexRequests.UI/Bootstrapper.cs index c347dbe60..fda7a5a27 100644 --- a/PlexRequests.UI/Bootstrapper.cs +++ b/PlexRequests.UI/Bootstrapper.cs @@ -44,9 +44,6 @@ using PlexRequests.Services.Interfaces; using PlexRequests.Store; using PlexRequests.Store.Repository; using PlexRequests.UI.Jobs; - -using IAvailabilityChecker = PlexRequests.UI.Jobs.IAvailabilityChecker; -using PlexAvailabilityChecker = PlexRequests.UI.Jobs.PlexAvailabilityChecker; using TaskFactory = FluentScheduler.TaskFactory; namespace PlexRequests.UI @@ -62,7 +59,7 @@ namespace PlexRequests.UI container.Register(); container.Register(new DbConfiguration(new SqliteFactory())); - + container.Register(); container.Register(); @@ -71,13 +68,11 @@ namespace PlexRequests.UI container.Register, SettingsServiceV2>(); container.Register, SettingsServiceV2>(); container.Register, GenericRepository>(); - container.Register(); container.Register(); container.Register(); container.Register(); container.Register(); - base.ConfigureRequestContainer(container, context); } diff --git a/PlexRequests.UI/Jobs/IAvailabilityChecker.cs b/PlexRequests.UI/Jobs/IAvailabilityChecker.cs deleted file mode 100644 index ba75a5b43..000000000 --- a/PlexRequests.UI/Jobs/IAvailabilityChecker.cs +++ /dev/null @@ -1,34 +0,0 @@ -#region Copyright -// /************************************************************************ -// Copyright (c) 2016 Jamie Rees -// File: IAvailabilityChecker.cs -// Created By: Jamie Rees -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// ************************************************************************/ -#endregion -namespace PlexRequests.UI.Jobs -{ - public interface IAvailabilityChecker - { - void CheckAndUpdate(string searchTerm, int id); - void CheckAndUpdateAll(); - } -} \ No newline at end of file diff --git a/PlexRequests.UI/Jobs/PlexAvailabilityChecker.cs b/PlexRequests.UI/Jobs/PlexAvailabilityChecker.cs deleted file mode 100644 index 1da5aa1ef..000000000 --- a/PlexRequests.UI/Jobs/PlexAvailabilityChecker.cs +++ /dev/null @@ -1,110 +0,0 @@ -#region Copyright -// /************************************************************************ -// Copyright (c) 2016 Jamie Rees -// File: PlexAvailabilityChecker.cs -// Created By: Jamie Rees -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// ************************************************************************/ -#endregion - -using System; -using System.Linq; -using System.Web.Hosting; -using FluentScheduler; -using PlexRequests.Api; -using PlexRequests.Core; -using PlexRequests.Core.SettingModels; - -namespace PlexRequests.UI.Jobs -{ - public class PlexAvailabilityChecker : IAvailabilityChecker, ITask, IRegisteredObject - { - public PlexAvailabilityChecker(ISettingsService plexSettings, ISettingsService auth, IRequestService request) - { - Plex = plexSettings; - Auth = auth; - RequestService = request; - HostingEnvironment.RegisterObject(this); - } - private readonly object _lock = new object(); - - private bool _shuttingDown; - private ISettingsService Plex { get; } - private ISettingsService Auth { get; } - private IRequestService RequestService { get; } - public void CheckAndUpdate(string searchTerm, int id) - { - var plexSettings = Plex.GetSettings(); - var authSettings = Auth.GetSettings(); - - var api = new PlexApi(); - var results = api.SearchContent(authSettings.PlexAuthToken, searchTerm, plexSettings.FullUri); - - var result = results.Video.FirstOrDefault(x => x.Title == searchTerm); - var originalRequest = RequestService.Get(id); - - originalRequest.Available = result != null; - RequestService.UpdateRequest(id, originalRequest); - } - - public void CheckAndUpdateAll() - { - //TODO Observable collections to get and refresh the data every x minutes - var plexSettings = Plex.GetSettings(); - var authSettings = Auth.GetSettings(); - var requests = RequestService.GetAll(); - var api = new PlexApi(); - - - foreach (var r in requests) - { - var results = api.SearchContent(authSettings.PlexAuthToken, r.Title, plexSettings.FullUri); - var result = results.Video.FirstOrDefault(x => x.Title == r.Title); - var originalRequest = RequestService.Get(r.Id); - - originalRequest.Available = result != null; - RequestService.UpdateRequest(r.Id, originalRequest); - } - } - - public void Execute() - { - lock (_lock) - { - if (_shuttingDown) - return; - - CheckAndUpdateAll(); - } - - } - - public void Stop(bool immediate) - { - lock (_lock) - { - _shuttingDown = true; - } - - HostingEnvironment.UnregisterObject(this); - } - } -} \ No newline at end of file diff --git a/PlexRequests.UI/Modules/SearchModule.cs b/PlexRequests.UI/Modules/SearchModule.cs index 3b2b33957..5c5085ba2 100644 --- a/PlexRequests.UI/Modules/SearchModule.cs +++ b/PlexRequests.UI/Modules/SearchModule.cs @@ -35,6 +35,7 @@ using PlexRequests.Api; using PlexRequests.Core; using PlexRequests.Core.SettingModels; using PlexRequests.Helpers; +using PlexRequests.Services.Interfaces; using PlexRequests.Store; using PlexRequests.UI.Jobs; using PlexRequests.UI.Models; diff --git a/PlexRequests.UI/PlexRequests.UI.csproj b/PlexRequests.UI/PlexRequests.UI.csproj index 7fddd035d..5df11e9f0 100644 --- a/PlexRequests.UI/PlexRequests.UI.csproj +++ b/PlexRequests.UI/PlexRequests.UI.csproj @@ -161,8 +161,6 @@ PreserveNewest - -