Skip to content

Commit

Permalink
#254 Removed the cache, we are now storing the plex information into …
Browse files Browse the repository at this point in the history
…the database.

There is a big structure change around this, also increased the default check time to be in hours.
  • Loading branch information
tidusjar committed Aug 5, 2016
1 parent af1c936 commit 2608e53
Show file tree
Hide file tree
Showing 29 changed files with 479 additions and 170 deletions.
3 changes: 1 addition & 2 deletions PlexRequests.Api/PlexApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
using PlexRequests.Api.Interfaces;
using PlexRequests.Api.Models.Plex;
using PlexRequests.Helpers;
using PlexRequests.Helpers.Exceptions;

using RestSharp;

Expand Down Expand Up @@ -81,7 +80,7 @@ public PlexAuthentication SignIn(string username, string password)
request.AddJsonBody(userModel);

var obj = RetryHandler.Execute<PlexAuthentication>(() => Api.Execute<PlexAuthentication> (request, new Uri(SignInUri)),
(exception, timespan) => Log.Error (exception, "Exception when calling SignIn for Plex, Retrying {0}", timespan), null);
(exception, timespan) => Log.Error (exception, "Exception when calling SignIn for Plex, Retrying {0}", timespan));

return obj;
}
Expand Down
2 changes: 1 addition & 1 deletion PlexRequests.Core/SettingModels/ScheduledJobsSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public ScheduledJobsSettings()
StoreBackup = 24;
StoreCleanup = 24;
UserRequestLimitResetter = 12;
PlexEpisodeCacher = 20;
PlexEpisodeCacher = 2;
}

public int PlexAvailabilityChecker { get; set; }
Expand Down
10 changes: 10 additions & 0 deletions PlexRequests.Helpers.Tests/PlexRequests.Helpers.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,27 @@
<Compile Include="AssemblyHelperTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="PlexHelperTests.cs" />
<Compile Include="TypeHelperTests.cs" />
<Compile Include="StringHelperTests.cs" />
<Compile Include="UriHelperTests.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PlexRequests.Core\PlexRequests.Core.csproj">
<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>
</ProjectReference>
</ItemGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@
using NUnit.Framework;

using PlexRequests.Core.Models;
using PlexRequests.UI.Helpers;

namespace PlexRequests.UI.Tests
namespace PlexRequests.Helpers.Tests
{
[TestFixture]
public class StringHelperTests
Expand All @@ -48,6 +47,12 @@ public string ToCamelCaseWordsTest(string input)
return input.ToCamelCaseWords();
}

[TestCaseSource(nameof(PrefixData))]
public string AddPrefix(string[] input, string prefix, string separator)
{
return input.AddPrefix(prefix, separator);
}

private static IEnumerable<TestCaseData> StringData
{
get
Expand All @@ -71,5 +76,19 @@ private static IEnumerable<TestCaseData> StringCaseData
yield return new TestCaseData(IssueStatus.ResolvedIssue.ToString()).Returns("Resolved Issue").SetName("enum resolved");
}
}

private static IEnumerable<TestCaseData> PrefixData
{
get
{
yield return new TestCaseData(new[] {"abc","def","ghi"}, "@", ",").Returns("@abc,@def,@ghi").SetName("Happy Path");
yield return new TestCaseData(new[] {"abc","def","ghi"}, "!!", "").Returns("!!abc!!def!!ghi").SetName("Different Separator Path");
yield return new TestCaseData(new[] {"abc"}, "", "").Returns("abc").SetName("Single Item");
yield return new TestCaseData(new string[0], "", "").Returns(string.Empty).SetName("Empty Array");
yield return new TestCaseData(new [] {"abc","aaaa"}, null, ",").Returns("abc,aaaa").SetName("Null prefix");
yield return new TestCaseData(new [] {"abc","aaaa"}, "@", null).Returns("@abc@aaaa").SetName("Null separator test");
yield return new TestCaseData(new [] {"abc","aaaa"}, null, null).Returns("abcaaaa").SetName("Null separator and prefix");
}
}
}
}
73 changes: 73 additions & 0 deletions PlexRequests.Helpers.Tests/TypeHelperTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: StringHelperTests.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.Collections.Generic;

using NUnit.Framework;

using PlexRequests.Store;

namespace PlexRequests.Helpers.Tests
{
[TestFixture]
public class TypeHelperTests
{
[TestCaseSource(nameof(TypeData))]
public string[] FirstCharToUpperTest(Type input)
{
return input.GetPropertyNames();
}


private static IEnumerable<TestCaseData> TypeData
{
get
{
yield return new TestCaseData(typeof(TestClass1)).Returns(new[] { "Test1", "Test2", "Test3" }).SetName("Simple Class");
yield return new TestCaseData(typeof(int)).Returns(new string[0]).SetName("NoPropeties Class");
yield return new TestCaseData(typeof(IEnumerable<>)).Returns(new string[0]).SetName("Interface");
yield return new TestCaseData(typeof(string)).Returns(new[] { "Chars", "Length" }).SetName("String");
yield return new TestCaseData(typeof(RequestedModel)).Returns(
new[]
{
"ProviderId", "ImdbId", "TvDbId", "Overview", "Title", "PosterPath", "ReleaseDate", "Type",
"Status", "Approved", "RequestedBy", "RequestedDate", "Available", "Issues", "OtherMessage", "AdminNote",
"SeasonList", "SeasonCount", "SeasonsRequested", "MusicBrainzId", "RequestedUsers","ArtistName",
"ArtistId","IssueId","Episodes","AllUsers","CanApprove","Id"
}).SetName("Requested Model");
}
}


private sealed class TestClass1
{
public string Test1 { get; set; }
public int Test2 { get; set; }
public long[] Test3 { get; set; }
}
}
}
2 changes: 2 additions & 0 deletions PlexRequests.Helpers/PlexRequests.Helpers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@
<Compile Include="SerializerSettings.cs" />
<Compile Include="StringCipher.cs" />
<Compile Include="StringHasher.cs" />
<Compile Include="StringHelper.cs" />
<Compile Include="TypeHelper.cs" />
<Compile Include="UriHelper.cs" />
<Compile Include="UserClaims.cs" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
// ************************************************************************/
#endregion
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace PlexRequests.UI.Helpers
namespace PlexRequests.Helpers
{
public static class StringHelper
{
Expand All @@ -46,5 +47,22 @@ public static string ToCamelCaseWords(this string input)
return input;
return Regex.Replace(input.FirstCharToUpper(), "([a-z](?=[A-Z])|[A-Z](?=[A-Z][a-z]))", "$1 ");
}

public static string AddPrefix(this string[] values, string prefix, string separator)
{
var sb = new StringBuilder();
var len = values.Length;
for (var i = 0; i < len; i++)
{
sb.Append(prefix).Append(values[i]);

// If it's not the last item in the collection, then add a separator
if (i < len - 1)
{
sb.Append(separator);
}
}
return sb.ToString();
}
}
}
39 changes: 39 additions & 0 deletions PlexRequests.Helpers/TypeHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: TypeHelper.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;

namespace PlexRequests.Helpers
{
public static class TypeHelper
{
public static string[] GetPropertyNames(this Type t)
{
return t.GetProperties().Select(x => x.Name).ToArray();
}
}
}
4 changes: 3 additions & 1 deletion PlexRequests.Services.Tests/PlexAvailabilityCheckerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class PlexAvailabilityCheckerTests
private Mock<INotificationService> NotificationMock { get; set; }
private Mock<IJobRecord> JobRec { get; set; }
private Mock<IRepository<UsersToNotify>> NotifyUsers { get; set; }
private Mock<IRepository<PlexEpisodes>> PlexEpisodes { get; set; }

[SetUp]
public void Setup()
Expand All @@ -64,8 +65,9 @@ public void Setup()
NotificationMock = new Mock<INotificationService>();
CacheMock = new Mock<ICacheProvider>();
NotifyUsers = new Mock<IRepository<UsersToNotify>>();
PlexEpisodes = new Mock<IRepository<PlexEpisodes>>();
JobRec = new Mock<IJobRecord>();
Checker = new PlexAvailabilityChecker(SettingsMock.Object, RequestMock.Object, PlexMock.Object, CacheMock.Object, NotificationMock.Object, JobRec.Object, NotifyUsers.Object);
Checker = new PlexAvailabilityChecker(SettingsMock.Object, RequestMock.Object, PlexMock.Object, CacheMock.Object, NotificationMock.Object, JobRec.Object, NotifyUsers.Object, PlexEpisodes.Object);

}

Expand Down
7 changes: 5 additions & 2 deletions PlexRequests.Services/Interfaces/IAvailabilityChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
#endregion
using PlexRequests.Services.Models;
using System.Collections.Generic;
using System.Threading.Tasks;

using PlexRequests.Store.Models;

namespace PlexRequests.Services.Interfaces
{
Expand All @@ -43,12 +46,12 @@ public interface IAvailabilityChecker
/// Gets the episode's stored in the cache.
/// </summary>
/// <returns></returns>
HashSet<PlexEpisodeModel> GetEpisodeCache();
Task<IEnumerable<PlexEpisodes>> GetEpisodes();
/// <summary>
/// Gets the episode's stored in the cache and then filters on the TheTvDBId.
/// </summary>
/// <param name="theTvDbId">The tv database identifier.</param>
/// <returns></returns>
IEnumerable<PlexEpisodeModel> GetEpisodeCache(int theTvDbId);
Task<IEnumerable<PlexEpisodes>> GetEpisodes(int theTvDbId);
}
}
Loading

0 comments on commit 2608e53

Please sign in to comment.