From 76364097908cb7e20e7d7a92e344cf6c961359e7 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Mon, 7 Mar 2016 13:08:30 +0000 Subject: [PATCH] First pass at the plex update service --- PlexRequests.Core/IRequestService.cs | 1 + PlexRequests.Core/RequestService.cs | 10 ++ .../AvailabilityUpdateService.cs | 73 ++++++++++++ PlexRequests.Services/Configuration.cs | 40 +++++++ PlexRequests.Services/ConfigurationReader.cs | 38 +++++++ .../Interfaces/IAvailabilityChecker.cs | 33 ++++++ .../Interfaces/IConfigurationReader.cs | 33 ++++++ .../Interfaces/IIntervals.cs | 37 ++++++ .../PlexAvailabilityChecker.cs | 73 ++++++++++++ .../PlexRequests.Services.csproj | 105 ++++++++++++++++++ .../Properties/AssemblyInfo.cs | 36 ++++++ PlexRequests.Services/UpdateInterval.cs | 40 +++++++ PlexRequests.Services/packages.config | 10 ++ PlexRequests.Store/GenericRepository.cs | 15 +++ PlexRequests.Store/IRepository.cs | 7 ++ PlexRequests.Store/UserRepository.cs | 5 + .../PlexRequests.UI.Tests.csproj | 17 +++ PlexRequests.UI.Tests/TaskFactoryTests.cs | 46 ++++++++ PlexRequests.UI.Tests/app.config | 11 ++ PlexRequests.UI.Tests/packages.config | 1 + PlexRequests.UI/Bootstrapper.cs | 11 +- PlexRequests.UI/Jobs/PlexRegistry.cs | 4 +- .../{TaskFactory.cs => PlexTaskFactory.cs} | 8 +- PlexRequests.UI/PlexRequests.UI.csproj | 6 +- PlexRequests.sln | 17 +-- 25 files changed, 661 insertions(+), 16 deletions(-) create mode 100644 PlexRequests.Services/AvailabilityUpdateService.cs create mode 100644 PlexRequests.Services/Configuration.cs create mode 100644 PlexRequests.Services/ConfigurationReader.cs create mode 100644 PlexRequests.Services/Interfaces/IAvailabilityChecker.cs create mode 100644 PlexRequests.Services/Interfaces/IConfigurationReader.cs create mode 100644 PlexRequests.Services/Interfaces/IIntervals.cs create mode 100644 PlexRequests.Services/PlexAvailabilityChecker.cs create mode 100644 PlexRequests.Services/PlexRequests.Services.csproj create mode 100644 PlexRequests.Services/Properties/AssemblyInfo.cs create mode 100644 PlexRequests.Services/UpdateInterval.cs create mode 100644 PlexRequests.Services/packages.config create mode 100644 PlexRequests.UI.Tests/TaskFactoryTests.cs create mode 100644 PlexRequests.UI.Tests/app.config rename PlexRequests.UI/Jobs/{TaskFactory.cs => PlexTaskFactory.cs} (62%) diff --git a/PlexRequests.Core/IRequestService.cs b/PlexRequests.Core/IRequestService.cs index c2751ea21..ed000aa59 100644 --- a/PlexRequests.Core/IRequestService.cs +++ b/PlexRequests.Core/IRequestService.cs @@ -38,5 +38,6 @@ namespace PlexRequests.Core void UpdateRequest(int originalId, RequestedModel model); RequestedModel Get(int id); IEnumerable GetAll(); + bool BatchUpdate(List model); } } \ No newline at end of file diff --git a/PlexRequests.Core/RequestService.cs b/PlexRequests.Core/RequestService.cs index 3c158e5c1..dfa524d67 100644 --- a/PlexRequests.Core/RequestService.cs +++ b/PlexRequests.Core/RequestService.cs @@ -62,6 +62,16 @@ namespace PlexRequests.Core Repo.Update(model); } + /// + /// Updates all the entities. NOTE: we need to Id to be the original entity + /// + /// The model. + /// + public bool BatchUpdate(List model) + { + return Repo.UpdateAll(model); + } + public RequestedModel Get(int id) { return Repo.Get(id); diff --git a/PlexRequests.Services/AvailabilityUpdateService.cs b/PlexRequests.Services/AvailabilityUpdateService.cs new file mode 100644 index 000000000..e563e839e --- /dev/null +++ b/PlexRequests.Services/AvailabilityUpdateService.cs @@ -0,0 +1,73 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: AvailabilityUpdateService.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.Reactive.Linq; +using System.Runtime.Remoting.Messaging; +using System.Threading.Tasks; +using System.Web.Hosting; + +using FluentScheduler; + +using NLog; + +using PlexRequests.Services.Interfaces; + +namespace PlexRequests.Services +{ + public class AvailabilityUpdateService : ITask, IRegisteredObject + { + public AvailabilityUpdateService(IConfigurationReader reader, IAvailabilityChecker checker) + { + ConfigurationReader = reader; + Checker = checker; + HostingEnvironment.RegisterObject(this); + } + + private static Logger Log = LogManager.GetCurrentClassLogger(); + + private IConfigurationReader ConfigurationReader { get; } + private IAvailabilityChecker Checker { get; } + private IDisposable UpdateSubscription { get; set; } + + public void Start(Configuration c) + { + UpdateSubscription?.Dispose(); + + UpdateSubscription = Observable.Interval(c.Intervals.Measurement).Subscribe(Checker.CheckAndUpdateAll); + } + + public void Execute() + { + Start(ConfigurationReader.Read()); + } + + public void Stop(bool immediate) + { + throw new System.NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/PlexRequests.Services/Configuration.cs b/PlexRequests.Services/Configuration.cs new file mode 100644 index 000000000..d88789ecb --- /dev/null +++ b/PlexRequests.Services/Configuration.cs @@ -0,0 +1,40 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: Congifuration.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 PlexRequests.Services.Interfaces; + +namespace PlexRequests.Services +{ + public class Configuration + { + public Configuration(IIntervals intervals) + { + Intervals = intervals; + } + + public IIntervals Intervals { get; set; } + } +} \ No newline at end of file diff --git a/PlexRequests.Services/ConfigurationReader.cs b/PlexRequests.Services/ConfigurationReader.cs new file mode 100644 index 000000000..4c35ff2e7 --- /dev/null +++ b/PlexRequests.Services/ConfigurationReader.cs @@ -0,0 +1,38 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: ConfigurationReader.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 PlexRequests.Services.Interfaces; + +namespace PlexRequests.Services +{ + public class ConfigurationReader : IConfigurationReader + { + public Configuration Read() + { + return new Configuration(new UpdateInterval()); + } + } +} \ No newline at end of file diff --git a/PlexRequests.Services/Interfaces/IAvailabilityChecker.cs b/PlexRequests.Services/Interfaces/IAvailabilityChecker.cs new file mode 100644 index 000000000..75d593d94 --- /dev/null +++ b/PlexRequests.Services/Interfaces/IAvailabilityChecker.cs @@ -0,0 +1,33 @@ +#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.Services.Interfaces +{ + public interface IAvailabilityChecker + { + void CheckAndUpdateAll(long check); + } +} \ No newline at end of file diff --git a/PlexRequests.Services/Interfaces/IConfigurationReader.cs b/PlexRequests.Services/Interfaces/IConfigurationReader.cs new file mode 100644 index 000000000..179f66e96 --- /dev/null +++ b/PlexRequests.Services/Interfaces/IConfigurationReader.cs @@ -0,0 +1,33 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: IConfigurationReader.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.Services.Interfaces +{ + public interface IConfigurationReader + { + Configuration Read(); + } +} \ No newline at end of file diff --git a/PlexRequests.Services/Interfaces/IIntervals.cs b/PlexRequests.Services/Interfaces/IIntervals.cs new file mode 100644 index 000000000..260017689 --- /dev/null +++ b/PlexRequests.Services/Interfaces/IIntervals.cs @@ -0,0 +1,37 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: IIntervals.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; + +namespace PlexRequests.Services.Interfaces +{ + public interface IIntervals + { + TimeSpan CriticalNotification { get; } // notification interval for critical load + TimeSpan Measurement { get; } // how often to measure + TimeSpan Notification { get; } // notification interval for high load + } +} \ No newline at end of file diff --git a/PlexRequests.Services/PlexAvailabilityChecker.cs b/PlexRequests.Services/PlexAvailabilityChecker.cs new file mode 100644 index 000000000..4743b7cca --- /dev/null +++ b/PlexRequests.Services/PlexAvailabilityChecker.cs @@ -0,0 +1,73 @@ +#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.Collections.Generic; +using System.Linq; + +using PlexRequests.Api; +using PlexRequests.Core; +using PlexRequests.Core.SettingModels; +using PlexRequests.Services.Interfaces; +using PlexRequests.Store; + +namespace PlexRequests.Services +{ + public class PlexAvailabilityChecker : IAvailabilityChecker + { + public PlexAvailabilityChecker(ISettingsService plexSettings, ISettingsService auth, IRequestService request) + { + Plex = plexSettings; + Auth = auth; + RequestService = request; + } + + private ISettingsService Plex { get; } + private ISettingsService Auth { get; } + private IRequestService RequestService { get; } + + + public void CheckAndUpdateAll(long check) + { + var plexSettings = Plex.GetSettings(); + var authSettings = Auth.GetSettings(); + var requests = RequestService.GetAll(); + var api = new PlexApi(); + + var modifiedModel = new List(); + 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; + modifiedModel.Add(originalRequest); + } + + RequestService.BatchUpdate(modifiedModel); + } + } +} \ No newline at end of file diff --git a/PlexRequests.Services/PlexRequests.Services.csproj b/PlexRequests.Services/PlexRequests.Services.csproj new file mode 100644 index 000000000..3af5f2e34 --- /dev/null +++ b/PlexRequests.Services/PlexRequests.Services.csproj @@ -0,0 +1,105 @@ + + + + + Debug + AnyCPU + {566EFA49-68F8-4716-9693-A6B3F2624DEA} + Library + Properties + PlexRequests.Services + PlexRequests.Services + v4.6 + 512 + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\FluentScheduler.3.1.46\lib\net40\FluentScheduler.dll + True + + + + ..\packages\NLog.4.2.3\lib\net45\NLog.dll + True + + + + + ..\packages\Rx-Core.2.2.5\lib\net45\System.Reactive.Core.dll + True + + + ..\packages\Rx-Interfaces.2.2.5\lib\net45\System.Reactive.Interfaces.dll + True + + + ..\packages\Rx-Linq.2.2.5\lib\net45\System.Reactive.Linq.dll + True + + + ..\packages\Rx-PlatformServices.2.2.5\lib\net45\System.Reactive.PlatformServices.dll + True + + + + + + + + + + + + + + + + + + + + + + + + + + {8cb8d235-2674-442d-9c6a-35fcaeeb160d} + PlexRequests.Api + + + {dd7dc444-d3bf-4027-8ab9-efc71f5ec581} + PlexRequests.Core + + + {92433867-2b7b-477b-a566-96c382427525} + PlexRequests.Store + + + + + \ No newline at end of file diff --git a/PlexRequests.Services/Properties/AssemblyInfo.cs b/PlexRequests.Services/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..1307c1c3c --- /dev/null +++ b/PlexRequests.Services/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("PlexRequests.Services")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("PlexRequests.Services")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("566efa49-68f8-4716-9693-a6b3f2624dea")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/PlexRequests.Services/UpdateInterval.cs b/PlexRequests.Services/UpdateInterval.cs new file mode 100644 index 000000000..64c65610a --- /dev/null +++ b/PlexRequests.Services/UpdateInterval.cs @@ -0,0 +1,40 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: UpdateInterval.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 PlexRequests.Services.Interfaces; + +namespace PlexRequests.Services +{ + public class UpdateInterval : IIntervals + { + public TimeSpan Measurement => TimeSpan.FromSeconds(1); + public TimeSpan CriticalNotification { get; } + public TimeSpan Notification => TimeSpan.FromMinutes(2); + + } +} \ No newline at end of file diff --git a/PlexRequests.Services/packages.config b/PlexRequests.Services/packages.config new file mode 100644 index 000000000..a6c58be8f --- /dev/null +++ b/PlexRequests.Services/packages.config @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/PlexRequests.Store/GenericRepository.cs b/PlexRequests.Store/GenericRepository.cs index 78ddb4d39..a72ca45d7 100644 --- a/PlexRequests.Store/GenericRepository.cs +++ b/PlexRequests.Store/GenericRepository.cs @@ -26,6 +26,7 @@ #endregion using System; using System.Collections.Generic; +using System.Linq; using Dapper.Contrib.Extensions; @@ -89,5 +90,19 @@ namespace PlexRequests.Store return db.Update(entity); } } + + public bool UpdateAll(IEnumerable entity) + { + var result = new HashSet(); + using (var db = Config.DbConnection()) + { + db.Open(); + foreach (var e in entity) + { + result.Add(db.Update(e)); + } + } + return result.All(x => true); + } } } diff --git a/PlexRequests.Store/IRepository.cs b/PlexRequests.Store/IRepository.cs index 4df329a1b..d88f80aa0 100644 --- a/PlexRequests.Store/IRepository.cs +++ b/PlexRequests.Store/IRepository.cs @@ -61,5 +61,12 @@ namespace PlexRequests.Store /// The entity. /// bool Update(T entity); + + /// + /// Updates all. + /// + /// The entity. + /// + bool UpdateAll(IEnumerable entity); } } diff --git a/PlexRequests.Store/UserRepository.cs b/PlexRequests.Store/UserRepository.cs index addc7366a..4f2e6de90 100644 --- a/PlexRequests.Store/UserRepository.cs +++ b/PlexRequests.Store/UserRepository.cs @@ -92,6 +92,11 @@ namespace PlexRequests.Store return db.Update(entity); } } + + public bool UpdateAll(IEnumerable entity) + { + throw new NotSupportedException(); + } } } diff --git a/PlexRequests.UI.Tests/PlexRequests.UI.Tests.csproj b/PlexRequests.UI.Tests/PlexRequests.UI.Tests.csproj index 56517b10c..6b062fbc3 100644 --- a/PlexRequests.UI.Tests/PlexRequests.UI.Tests.csproj +++ b/PlexRequests.UI.Tests/PlexRequests.UI.Tests.csproj @@ -36,6 +36,10 @@ 4 + + ..\packages\FluentScheduler.3.1.46\lib\net40\FluentScheduler.dll + True + ..\packages\Moq.4.2.1510.2205\lib\net40\Moq.dll True @@ -49,6 +53,7 @@ True + @@ -60,10 +65,22 @@ + + + + + {566EFA49-68F8-4716-9693-A6B3F2624DEA} + PlexRequests.Services + + + {68F5F5F3-B8BB-4911-875F-6F00AAE04EA6} + PlexRequests.UI + + diff --git a/PlexRequests.UI.Tests/TaskFactoryTests.cs b/PlexRequests.UI.Tests/TaskFactoryTests.cs new file mode 100644 index 000000000..47a97b67a --- /dev/null +++ b/PlexRequests.UI.Tests/TaskFactoryTests.cs @@ -0,0 +1,46 @@ +#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.Tests/app.config b/PlexRequests.UI.Tests/app.config new file mode 100644 index 000000000..ac2586ac9 --- /dev/null +++ b/PlexRequests.UI.Tests/app.config @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/PlexRequests.UI.Tests/packages.config b/PlexRequests.UI.Tests/packages.config index 780aeade8..469cafc98 100644 --- a/PlexRequests.UI.Tests/packages.config +++ b/PlexRequests.UI.Tests/packages.config @@ -1,6 +1,7 @@  + \ No newline at end of file diff --git a/PlexRequests.UI/Bootstrapper.cs b/PlexRequests.UI/Bootstrapper.cs index f4111730a..c347dbe60 100644 --- a/PlexRequests.UI/Bootstrapper.cs +++ b/PlexRequests.UI/Bootstrapper.cs @@ -39,9 +39,14 @@ using Nancy.TinyIoc; using PlexRequests.Core; using PlexRequests.Core.SettingModels; using PlexRequests.Helpers; +using PlexRequests.Services; +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 @@ -69,12 +74,16 @@ namespace PlexRequests.UI container.Register(); container.Register(); + container.Register(); + container.Register(); + container.Register(); + base.ConfigureRequestContainer(container, context); } protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines) { - TaskManager.TaskFactory = new Jobs.TaskFactory(); + TaskManager.TaskFactory = new Jobs.PlexTaskFactory(); TaskManager.Initialize(new PlexRegistry()); CookieBasedSessions.Enable(pipelines, CryptographyConfiguration.Default); diff --git a/PlexRequests.UI/Jobs/PlexRegistry.cs b/PlexRequests.UI/Jobs/PlexRegistry.cs index acea7f3bf..f124cfaf0 100644 --- a/PlexRequests.UI/Jobs/PlexRegistry.cs +++ b/PlexRequests.UI/Jobs/PlexRegistry.cs @@ -27,13 +27,15 @@ using FluentScheduler; +using PlexRequests.Services; + namespace PlexRequests.UI.Jobs { public class PlexRegistry : Registry { public PlexRegistry() { - Schedule().ToRunNow(); + Schedule().ToRunNow(); } } } \ No newline at end of file diff --git a/PlexRequests.UI/Jobs/TaskFactory.cs b/PlexRequests.UI/Jobs/PlexTaskFactory.cs similarity index 62% rename from PlexRequests.UI/Jobs/TaskFactory.cs rename to PlexRequests.UI/Jobs/PlexTaskFactory.cs index d9e112098..e2e51e637 100644 --- a/PlexRequests.UI/Jobs/TaskFactory.cs +++ b/PlexRequests.UI/Jobs/PlexTaskFactory.cs @@ -1,13 +1,19 @@ using FluentScheduler; using Nancy.TinyIoc; +using PlexRequests.Services; + namespace PlexRequests.UI.Jobs { - public class TaskFactory : ITaskFactory + public class PlexTaskFactory : ITaskFactory { public ITask GetTaskInstance() where T : ITask { + //typeof(AvailabilityUpdateService); var container = TinyIoCContainer.Current; + + var a= container.ResolveAll(typeof(T)); + object outT; container.TryResolve(typeof(T), out outT); diff --git a/PlexRequests.UI/PlexRequests.UI.csproj b/PlexRequests.UI/PlexRequests.UI.csproj index 95dbc8111..7fddd035d 100644 --- a/PlexRequests.UI/PlexRequests.UI.csproj +++ b/PlexRequests.UI/PlexRequests.UI.csproj @@ -164,7 +164,7 @@ - + @@ -297,6 +297,10 @@ {1252336D-42A3-482A-804C-836E60173DFA} PlexRequests.Helpers + + {566EFA49-68F8-4716-9693-A6B3F2624DEA} + PlexRequests.Services + {92433867-2B7B-477B-A566-96C382427525} PlexRequests.Store diff --git a/PlexRequests.sln b/PlexRequests.sln index 3e124c7ef..4a2431cb7 100644 --- a/PlexRequests.sln +++ b/PlexRequests.sln @@ -27,9 +27,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlexRequests.UI.Tests", "Pl EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlexRequests.Core.Tests", "PlexRequests.Core.Tests\PlexRequests.Core.Tests.csproj", "{FCFECD5D-47F6-454D-8692-E27A921BE655}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlexRequests.Helpers.Tests", "PlexRequests.Helpers.Tests\PlexRequests.Helpers.Tests.csproj", "{0E6395D3-B074-49E8-898D-0EB99E507E0E}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{EC46BEB4-AEC4-42AE-B1D5-6B32FEA8154A}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlexRequests.Services", "PlexRequests.Services\PlexRequests.Services.csproj", "{566EFA49-68F8-4716-9693-A6B3F2624DEA}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -69,17 +67,12 @@ Global {FCFECD5D-47F6-454D-8692-E27A921BE655}.Debug|Any CPU.Build.0 = Debug|Any CPU {FCFECD5D-47F6-454D-8692-E27A921BE655}.Release|Any CPU.ActiveCfg = Release|Any CPU {FCFECD5D-47F6-454D-8692-E27A921BE655}.Release|Any CPU.Build.0 = Release|Any CPU - {0E6395D3-B074-49E8-898D-0EB99E507E0E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0E6395D3-B074-49E8-898D-0EB99E507E0E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {0E6395D3-B074-49E8-898D-0EB99E507E0E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0E6395D3-B074-49E8-898D-0EB99E507E0E}.Release|Any CPU.Build.0 = Release|Any CPU + {566EFA49-68F8-4716-9693-A6B3F2624DEA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {566EFA49-68F8-4716-9693-A6B3F2624DEA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {566EFA49-68F8-4716-9693-A6B3F2624DEA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {566EFA49-68F8-4716-9693-A6B3F2624DEA}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection - GlobalSection(NestedProjects) = preSolution - {A930E2CF-79E2-45F9-B06A-9A719A254CE4} = {EC46BEB4-AEC4-42AE-B1D5-6B32FEA8154A} - {FCFECD5D-47F6-454D-8692-E27A921BE655} = {EC46BEB4-AEC4-42AE-B1D5-6B32FEA8154A} - {0E6395D3-B074-49E8-898D-0EB99E507E0E} = {EC46BEB4-AEC4-42AE-B1D5-6B32FEA8154A} - EndGlobalSection EndGlobal