Removed the DI part of the service. TinyIOC doesn't want to work with FluentScheduler.

pull/13/head
tidusjar 8 years ago
parent 7636409790
commit 5363cf6891

@ -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<PlexSettings>(repo), new SettingsServiceV2<AuthenticationSettings>(repo), new RequestService(new GenericRepository<RequestedModel>(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);
}
}

@ -36,6 +36,10 @@
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Build.Framework" />
<Reference Include="Mono.Data.Sqlite, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Assemblies\Mono.Data.Sqlite.dll</HintPath>
</Reference>
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\packages\NLog.4.2.3\lib\net45\NLog.dll</HintPath>
<Private>True</Private>
@ -89,6 +93,10 @@
<Project>{dd7dc444-d3bf-4027-8ab9-efc71f5ec581}</Project>
<Name>PlexRequests.Core</Name>
</ProjectReference>
<ProjectReference Include="..\PlexRequests.Helpers\PlexRequests.Helpers.csproj">
<Project>{1252336D-42A3-482A-804C-836E60173DFA}</Project>
<Name>PlexRequests.Helpers</Name>
</ProjectReference>
<ProjectReference Include="..\PlexRequests.Store\PlexRequests.Store.csproj">
<Project>{92433867-2b7b-477b-a566-96c382427525}</Project>
<Name>PlexRequests.Store</Name>

@ -65,7 +65,6 @@
</Choose>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TaskFactoryTests.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />

@ -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<AvailabilityUpdateService>();
Assert.That(result, Is.Not.Null);
}
}
}

@ -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<IUserMapper, UserMapper>();
container.Register<ISqliteConfiguration, DbConfiguration>(new DbConfiguration(new SqliteFactory()));
container.Register<ISettingsRepository, JsonRepository>();
container.Register<ICacheProvider, MemoryCacheProvider>();
@ -71,13 +68,11 @@ namespace PlexRequests.UI
container.Register<ISettingsService<AuthenticationSettings>, SettingsServiceV2<AuthenticationSettings>>();
container.Register<ISettingsService<PlexSettings>, SettingsServiceV2<PlexSettings>>();
container.Register<IRepository<RequestedModel>, GenericRepository<RequestedModel>>();
container.Register<IAvailabilityChecker, PlexAvailabilityChecker>();
container.Register<IRequestService, RequestService>();
container.Register<IAvailabilityChecker, PlexAvailabilityChecker>();
container.Register<IConfigurationReader, ConfigurationReader>();
container.Register<IIntervals, UpdateInterval>();
base.ConfigureRequestContainer(container, context);
}

@ -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();
}
}

@ -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> plexSettings, ISettingsService<AuthenticationSettings> auth, IRequestService request)
{
Plex = plexSettings;
Auth = auth;
RequestService = request;
HostingEnvironment.RegisterObject(this);
}
private readonly object _lock = new object();
private bool _shuttingDown;
private ISettingsService<PlexSettings> Plex { get; }
private ISettingsService<AuthenticationSettings> 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);
}
}
}

@ -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;

@ -161,8 +161,6 @@
<Content Include="Content\custom.css">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Compile Include="Jobs\IAvailabilityChecker.cs" />
<Compile Include="Jobs\PlexAvailabilityChecker.cs" />
<Compile Include="Jobs\PlexRegistry.cs" />
<Compile Include="Jobs\PlexTaskFactory.cs" />
<Compile Include="Models\PlexAuth.cs" />

Loading…
Cancel
Save