Started to impliment the Plex checker. This will check plex every x minutes to see if there is any new content and then update the avalibility of the requests

This commit is contained in:
Jamie Rees 2016-03-06 01:25:54 +00:00
commit 3b0b0c521e
19 changed files with 329 additions and 160 deletions

View file

@ -0,0 +1,42 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: IRequestService.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 PlexRequests.Store;
namespace PlexRequests.Core
{
public interface IRequestService
{
long AddRequest(int providerId, RequestedModel model);
bool CheckRequest(int providerId);
void DeleteRequest(int tmdbId);
void UpdateRequest(int originalId, RequestedModel model);
RequestedModel Get(int id);
IEnumerable<RequestedModel> GetAll();
}
}

View file

@ -64,8 +64,8 @@
</ItemGroup>
<ItemGroup>
<Compile Include="CacheKeys.cs" />
<Compile Include="IRequestService.cs" />
<Compile Include="ISettingsService.cs" />
<Compile Include="RequestService.cs" />
<Compile Include="SettingModels\AuthenticationSettings.cs" />
<Compile Include="SettingModels\PlexSettings.cs" />
<Compile Include="SettingModels\SonarrSettings.cs" />
@ -73,7 +73,7 @@
<Compile Include="SettingModels\CouchPotatoSettings.cs" />
<Compile Include="SettingModels\PlexRequestSettings.cs" />
<Compile Include="SettingModels\Settings.cs" />
<Compile Include="SettingsService.cs" />
<Compile Include="RequestService.cs" />
<Compile Include="SettingsServiceV2.cs" />
<Compile Include="Setup.cs" />
<Compile Include="UserIdentity.cs" />

View file

@ -24,35 +24,30 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
using System.Linq;
using System.Collections.Generic;
using System.Linq;
using PlexRequests.Store;
namespace PlexRequests.Core
{
public class RequestService
public class RequestService : IRequestService
{
public RequestService(ISqliteConfiguration db, IRepository<RequestedModel> repo)
public RequestService(IRepository<RequestedModel> db)
{
Db = db;
Repo = repo;
Repo = db;
}
private ISqliteConfiguration Db { get; set; }
private IRepository<RequestedModel> Repo { get; set; }
public void AddRequest(int tmdbid, RequestType type)
{
var model = new RequestedModel
{
ProviderId = tmdbid,
Type = type
};
Repo.Insert(model);
public long AddRequest(int providerId, RequestedModel model)
{
return Repo.Insert(model);
}
public bool CheckRequest(int tmdbid)
public bool CheckRequest(int providerId)
{
return Repo.GetAll().Any(x => x.ProviderId == tmdbid);
return Repo.GetAll().Any(x => x.ProviderId == providerId);
}
public void DeleteRequest(int tmdbId)
@ -61,5 +56,20 @@ namespace PlexRequests.Core
Repo.Delete(entity);
}
public void UpdateRequest(int originalId, RequestedModel model)
{
model.Id = originalId;
Repo.Update(model);
}
public RequestedModel Get(int id)
{
return Repo.Get(id);
}
public IEnumerable<RequestedModel> GetAll()
{
return Repo.GetAll();
}
}
}
}

View file

@ -1,83 +0,0 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: SettingsService.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 Mono.Data.Sqlite;
using PlexRequests.Api;
using PlexRequests.Helpers;
using PlexRequests.Store;
namespace PlexRequests.Core
{
public class SettingsService
{
public SettingsService(ICacheProvider cache)
{
Cache = cache;
}
public SettingsModel GetSettings()
{
var db = new DbConfiguration(new SqliteFactory());
var repo = new GenericRepository<SettingsModel>(db);
var settings = repo.GetAll().FirstOrDefault();
return settings;
}
private ICacheProvider Cache { get; set; }
public void AddRequest(int providerId, RequestedModel model)
{
var db = new DbConfiguration(new SqliteFactory());
var repo = new GenericRepository<RequestedModel>(db);
repo.Insert(model);
}
public bool CheckRequest(int providerId)
{
var db = new DbConfiguration(new SqliteFactory());
var repo = new GenericRepository<RequestedModel>(db);
return repo.GetAll().Any(x => x.ProviderId == providerId);
}
public void DeleteRequest(int tmdbId)
{
var db = new DbConfiguration(new SqliteFactory());
var repo = new GenericRepository<RequestedModel>(db);
var entity = repo.GetAll().FirstOrDefault(x => x.ProviderId == tmdbId);
repo.Delete(entity);
}
}
}