diff --git a/RequestPlex.Api/MovieBase.cs b/RequestPlex.Api/MovieBase.cs
index 27c518964..6a4b719dd 100644
--- a/RequestPlex.Api/MovieBase.cs
+++ b/RequestPlex.Api/MovieBase.cs
@@ -1,14 +1,37 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+#region Copyright
+// /************************************************************************
+// Copyright (c) 2016 Jamie Rees
+// File: MovieBase.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 RequestPlex.Helpers;
namespace RequestPlex.Api
{
public abstract class MovieBase
{
- protected string ApiKey = "b8eabaf5608b88d0298aa189dd90bf00";
+ private static readonly string Encrypted = "0T3QNSseexLO7n7UPiJvl70Y+KKnvbeTlsusl7Kwq0hPH0BHOuFNGwksNCjkwqWedyDdI/MJeUR4wtL4bIl0Z+//uHXEaYM/4H2pjeLbH5EWdUe5TTj1AhaIR5PQweamvcienRyFD/3YPCC/+qL5mHkKXBkPumMod3Zb/4yN0Ik=";
+ protected string ApiKey = StringCipher.Decrypt(Encrypted, "ApiKey");
protected string Url = "http://api.themoviedb.org/3";
}
}
diff --git a/RequestPlex.Api/PlexApi.cs b/RequestPlex.Api/PlexApi.cs
index 79690949e..77b4bcdc4 100644
--- a/RequestPlex.Api/PlexApi.cs
+++ b/RequestPlex.Api/PlexApi.cs
@@ -21,7 +21,7 @@ namespace RequestPlex.Api
Method = Method.POST,
};
- request.AddHeader("X-Plex-Client-Identifier", "Test213");
+ request.AddHeader("X-Plex-Client-Identifier", "Test213"); // TODO need something unique to the users version/installation
request.AddHeader("X-Plex-Product", "Request Plex");
request.AddHeader("X-Plex-Version", "0.0.1");
request.AddHeader("Content-Type", "application/json");
diff --git a/RequestPlex.Api/RequestPlex.Api.csproj b/RequestPlex.Api/RequestPlex.Api.csproj
index c04ba5870..714860b3e 100644
--- a/RequestPlex.Api/RequestPlex.Api.csproj
+++ b/RequestPlex.Api/RequestPlex.Api.csproj
@@ -76,6 +76,10 @@
{95834072-A675-415D-AA8F-877C91623810}RequestPlex.Api.Interfaces
+
+ {1252336D-42A3-482A-804C-836E60173DFA}
+ RequestPlex.Helpers
+
diff --git a/RequestPlex.Core/ISettingsService.cs b/RequestPlex.Core/ISettingsService.cs
new file mode 100644
index 000000000..78e4a07ef
--- /dev/null
+++ b/RequestPlex.Core/ISettingsService.cs
@@ -0,0 +1,35 @@
+#region Copyright
+// /************************************************************************
+// Copyright (c) 2016 Jamie Rees
+// File: ISettingsService.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 RequestPlex.Core
+{
+ public interface ISettingsService
+ {
+ T GetSettings();
+ bool SaveSettings(T model);
+ bool Delete(T model);
+ }
+}
\ No newline at end of file
diff --git a/RequestPlex.Core/RequestPlex.Core.csproj b/RequestPlex.Core/RequestPlex.Core.csproj
index 67157151c..76b5f7074 100644
--- a/RequestPlex.Core/RequestPlex.Core.csproj
+++ b/RequestPlex.Core/RequestPlex.Core.csproj
@@ -41,6 +41,14 @@
..\packages\Nancy.Authentication.Forms.1.4.1\lib\net40\Nancy.Authentication.Forms.dllTrue
+
+ ..\packages\Newtonsoft.Json.8.0.2\lib\net45\Newtonsoft.Json.dll
+ True
+
+
+ ..\packages\valueinjecter.3.1.1.2\lib\net40\Omu.ValueInjecter.dll
+ True
+
@@ -51,7 +59,12 @@
+
+
+
+
+
@@ -61,6 +74,10 @@
+
+ {1252336D-42A3-482A-804C-836E60173DFA}
+ RequestPlex.Helpers
+ {92433867-2B7B-477B-A566-96C382427525}RequestPlex.Store
diff --git a/RequestPlex.Core/RequestService.cs b/RequestPlex.Core/RequestService.cs
new file mode 100644
index 000000000..51845784d
--- /dev/null
+++ b/RequestPlex.Core/RequestService.cs
@@ -0,0 +1,65 @@
+#region Copyright
+// /************************************************************************
+// Copyright (c) 2016 Jamie Rees
+// File: RequestService.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.Linq;
+
+using RequestPlex.Store;
+
+namespace RequestPlex.Core
+{
+ public class RequestService
+ {
+ public RequestService(ISqliteConfiguration db, IRepository repo)
+ {
+ Db = db;
+ Repo = repo;
+ }
+ private ISqliteConfiguration Db { get; set; }
+ private IRepository Repo { get; set; }
+ public void AddRequest(int tmdbid, RequestType type)
+ {
+ var model = new RequestedModel
+ {
+ Tmdbid = tmdbid,
+ Type = type
+ };
+
+ Repo.Insert(model);
+ }
+
+ public bool CheckRequest(int tmdbid)
+ {
+ return Repo.GetAll().Any(x => x.Tmdbid == tmdbid);
+ }
+
+ public void DeleteRequest(int tmdbId)
+ {
+ var entity = Repo.GetAll().FirstOrDefault(x => x.Tmdbid == tmdbId);
+ Repo.Delete(entity);
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/RequestPlex.Core/SettingModels/Settings.cs b/RequestPlex.Core/SettingModels/Settings.cs
new file mode 100644
index 000000000..af3194b42
--- /dev/null
+++ b/RequestPlex.Core/SettingModels/Settings.cs
@@ -0,0 +1,33 @@
+#region Copyright
+// /************************************************************************
+// Copyright (c) 2016 Jamie Rees
+// File: Settings.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 RequestPlex.Core.SettingModels
+{
+ public class Settings
+ {
+ public int Id { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/RequestPlex.Core/SettingsService.cs b/RequestPlex.Core/SettingsService.cs
index c9d86a44e..bb12e0d21 100644
--- a/RequestPlex.Core/SettingsService.cs
+++ b/RequestPlex.Core/SettingsService.cs
@@ -1,8 +1,30 @@
-using System;
-using System.Collections.Generic;
+#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.Linq;
-using System.Text;
-using System.Threading.Tasks;
using Mono.Data.Sqlite;
@@ -12,21 +34,6 @@ namespace RequestPlex.Core
{
public class SettingsService
{
- public void SaveSettings(SettingsModel model)
- {
- var db = new DbConfiguration(new SqliteFactory());
- var repo = new GenericRepository(db);
-
- var existingSettings = repo.GetAll().FirstOrDefault();
- if (existingSettings != null)
- {
- existingSettings = model;
- repo.Update(existingSettings);
- return;
- }
-
- repo.Insert(model);
- }
public SettingsModel GetSettings()
{
diff --git a/RequestPlex.Core/SettingsServiceV2.cs b/RequestPlex.Core/SettingsServiceV2.cs
new file mode 100644
index 000000000..e0245e8a8
--- /dev/null
+++ b/RequestPlex.Core/SettingsServiceV2.cs
@@ -0,0 +1,114 @@
+#region Copyright
+// /************************************************************************
+// Copyright (c) 2016 Jamie Rees
+// File: SettingsServiceV2.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 Newtonsoft.Json;
+
+using Omu.ValueInjecter;
+
+using RequestPlex.Core.SettingModels;
+using RequestPlex.Helpers;
+using RequestPlex.Store;
+using RequestPlex.Store.Models;
+
+namespace RequestPlex.Core
+{
+ public class SettingsServiceV2 : ISettingsService
+ where T : Settings, new()
+ {
+
+ public SettingsServiceV2(ISettingsRepository repo)
+ {
+ Repo = repo;
+ EntityName = typeof(T).Name;
+ }
+
+ private ISettingsRepository Repo { get; set; }
+ private string EntityName { get; set; }
+
+ public T GetSettings()
+ {
+ var result = Repo.Get(EntityName);
+ if (result == null)
+ {
+ return new T();
+ }
+ result.Content = DecryptSettings(result);
+ var obj = string.IsNullOrEmpty(result.Content) ? null : JsonConvert.DeserializeObject(result.Content, SerializerSettings.Settings);
+
+ var model = obj;
+
+ return model;
+ }
+
+ public bool SaveSettings(T model)
+ {
+ var entity = Repo.Get(EntityName);
+
+ if (entity == null)
+ {
+ var newEntity = model;
+
+ var settings = new GlobalSettings { SettingsName = EntityName, Content = JsonConvert.SerializeObject(newEntity, SerializerSettings.Settings) };
+ settings.Content = EncryptSettings(settings);
+ var insertResult = Repo.Insert(settings);
+
+ return insertResult != long.MinValue;
+ }
+
+
+ var modified = model;
+ modified.Id = entity.Id;
+
+ var globalSettings = new GlobalSettings { SettingsName = EntityName, Content = JsonConvert.SerializeObject(modified, SerializerSettings.Settings), Id = entity.Id };
+ globalSettings.Content = EncryptSettings(globalSettings);
+ var result = Repo.Update(globalSettings);
+
+ return result;
+ }
+
+ public bool Delete(T model)
+ {
+ var entity = Repo.Get(EntityName);
+ if (entity != null)
+ {
+ return Repo.Delete(entity);
+ }
+
+ // Entity does not exist so nothing to delete
+ return true;
+ }
+
+ private string EncryptSettings(GlobalSettings settings)
+ {
+ return StringCipher.Encrypt(settings.Content, settings.SettingsName);
+ }
+
+ private string DecryptSettings(GlobalSettings settings)
+ {
+ return StringCipher.Decrypt(settings.Content, settings.SettingsName);
+ }
+ }
+}
diff --git a/RequestPlex.Core/UserMapper.cs b/RequestPlex.Core/UserMapper.cs
index 89f724143..083aba90b 100644
--- a/RequestPlex.Core/UserMapper.cs
+++ b/RequestPlex.Core/UserMapper.cs
@@ -1,4 +1,30 @@
-using System;
+#region Copyright
+// /************************************************************************
+// Copyright (c) 2016 Jamie Rees
+// File: UserMapper.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;
@@ -13,11 +39,14 @@ namespace RequestPlex.Core
{
public class UserMapper : IUserMapper
{
-
+ public UserMapper(ISqliteConfiguration db)
+ {
+ Db = db;
+ }
+ private static ISqliteConfiguration Db { get; set; }
public IUserIdentity GetUserFromIdentifier(Guid identifier, NancyContext context)
{
- var db = new DbConfiguration(new SqliteFactory());
- var repo = new UserRepository(db);
+ var repo = new UserRepository(Db);
var user = repo.Get(identifier.ToString());
@@ -35,7 +64,7 @@ namespace RequestPlex.Core
public static Guid? ValidateUser(string username, string password)
{
var db = new DbConfiguration(new SqliteFactory());
- var repo = new UserRepository(db);
+ var repo = new UserRepository(Db);
var users = repo.GetAll();
var userRecord = users.FirstOrDefault(u => u.UserName.Equals(username, StringComparison.InvariantCultureIgnoreCase) && u.Password.Equals(password)); // TODO hashing
@@ -50,7 +79,7 @@ namespace RequestPlex.Core
public static bool DoUsersExist()
{
var db = new DbConfiguration(new SqliteFactory());
- var repo = new UserRepository(db);
+ var repo = new UserRepository(Db);
var users = repo.GetAll();
return users.Any();
}
@@ -58,7 +87,7 @@ namespace RequestPlex.Core
public static Guid? CreateUser(string username, string password)
{
var db = new DbConfiguration(new SqliteFactory());
- var repo = new UserRepository(db);
+ var repo = new UserRepository(Db);
var userModel = new UserModel { UserName = username, User = Guid.NewGuid().ToString(), Password = password };
repo.Insert(userModel);
diff --git a/RequestPlex.Core/packages.config b/RequestPlex.Core/packages.config
index 22cd929ec..2d5fcc6ef 100644
--- a/RequestPlex.Core/packages.config
+++ b/RequestPlex.Core/packages.config
@@ -2,4 +2,6 @@
+
+
\ No newline at end of file
diff --git a/RequestPlex.Helpers/RequestPlex.Helpers.csproj b/RequestPlex.Helpers/RequestPlex.Helpers.csproj
index 113b5c9f9..4fd02c8e9 100644
--- a/RequestPlex.Helpers/RequestPlex.Helpers.csproj
+++ b/RequestPlex.Helpers/RequestPlex.Helpers.csproj
@@ -49,6 +49,7 @@
+
diff --git a/RequestPlex.Helpers/SerializerSettings.cs b/RequestPlex.Helpers/SerializerSettings.cs
new file mode 100644
index 000000000..f89668047
--- /dev/null
+++ b/RequestPlex.Helpers/SerializerSettings.cs
@@ -0,0 +1,45 @@
+#region Copyright
+// /************************************************************************
+// Copyright (c) 2016 Jamie Rees
+// File: SerializerSettings.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.Runtime.Serialization.Formatters;
+
+using Newtonsoft.Json;
+
+namespace RequestPlex.Helpers
+{
+ public static class SerializerSettings
+ {
+
+ public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
+ {
+ Formatting = Formatting.None,
+ TypeNameHandling = TypeNameHandling.Objects,
+ TypeNameAssemblyFormat = FormatterAssemblyStyle.Simple,
+ NullValueHandling = NullValueHandling.Ignore
+ };
+
+ }
+}
\ No newline at end of file
diff --git a/RequestPlex.Store/Entity.cs b/RequestPlex.Store/Entity.cs
index cca38fcfd..9f849518c 100644
--- a/RequestPlex.Store/Entity.cs
+++ b/RequestPlex.Store/Entity.cs
@@ -1,9 +1,29 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
+#region Copyright
+// /************************************************************************
+// Copyright (c) 2016 Jamie Rees
+// File: Entity.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 Dapper.Contrib.Extensions;
namespace RequestPlex.Store
diff --git a/RequestPlex.Store/GenericRepository.cs b/RequestPlex.Store/GenericRepository.cs
index 0707fe6ce..526c2bc96 100644
--- a/RequestPlex.Store/GenericRepository.cs
+++ b/RequestPlex.Store/GenericRepository.cs
@@ -1,8 +1,31 @@
-using System;
+#region Copyright
+// /************************************************************************
+// Copyright (c) 2016 Jamie Rees
+// File: GenericRepository.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 System.Linq;
-using System.Text;
-using System.Threading.Tasks;
using Dapper.Contrib.Extensions;
diff --git a/RequestPlex.Store/IRepository.cs b/RequestPlex.Store/IRepository.cs
index 22158e975..09ff3715d 100644
--- a/RequestPlex.Store/IRepository.cs
+++ b/RequestPlex.Store/IRepository.cs
@@ -1,8 +1,30 @@
-using System;
+#region Copyright
+// /************************************************************************
+// Copyright (c) 2016 Jamie Rees
+// File: IRepository.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 System.Text;
-using System.Threading.Tasks;
namespace RequestPlex.Store
{
diff --git a/RequestPlex.Store/SqlTables.sql b/RequestPlex.Store/SqlTables.sql
index 90cdc81ac..0df12cec5 100644
--- a/RequestPlex.Store/SqlTables.sql
+++ b/RequestPlex.Store/SqlTables.sql
@@ -21,4 +21,11 @@ CREATE TABLE IF NOT EXISTS Requested
Id INTEGER PRIMARY KEY AUTOINCREMENT,
Type INTEGER NOT NULL,
Tmdbid INTEGER NOT NULL
+);
+
+CREATE TABLE IF NOT EXISTS GlobalSettings
+(
+ Id INTEGER PRIMARY KEY AUTOINCREMENT,
+ SettingsName varchar(50) NOT NULL,
+ Content varchar(100) NOT NULL
);
\ No newline at end of file
diff --git a/RequestPlex.Store/UserRepository.cs b/RequestPlex.Store/UserRepository.cs
index 3e7d11e9f..ca7bae605 100644
--- a/RequestPlex.Store/UserRepository.cs
+++ b/RequestPlex.Store/UserRepository.cs
@@ -1,8 +1,32 @@
-using System;
+#region Copyright
+// /************************************************************************
+// Copyright (c) 2016 Jamie Rees
+// File: UserRepository.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 System.Linq;
-using System.Text;
-using System.Threading.Tasks;
using Dapper.Contrib.Extensions;
diff --git a/RequestPlex.UI/Bootstrapper.cs b/RequestPlex.UI/Bootstrapper.cs
index e32a8b177..75e06ebaf 100644
--- a/RequestPlex.UI/Bootstrapper.cs
+++ b/RequestPlex.UI/Bootstrapper.cs
@@ -1,9 +1,16 @@
-using Nancy;
+using Mono.Data.Sqlite;
+
+using Nancy;
using Nancy.Authentication.Forms;
using Nancy.Bootstrapper;
using Nancy.TinyIoc;
using RequestPlex.Core;
+using RequestPlex.Core.SettingModels;
+using RequestPlex.Helpers;
+using RequestPlex.Store;
+using RequestPlex.Store.Models;
+using RequestPlex.Store.Repository.NZBDash.DataAccessLayer.Repository;
using FormsAuthentication = Nancy.Authentication.Forms.FormsAuthentication;
@@ -17,8 +24,21 @@ namespace RequestPlex.UI
protected override void ConfigureRequestContainer(TinyIoCContainer container, NancyContext context)
{
- base.ConfigureRequestContainer(container, context);
+
container.Register();
+ base.ConfigureRequestContainer(container, context);
+
+ container.Register(new DbConfiguration(new SqliteFactory()));
+
+ container.Register();
+ container.Register();
+
+
+ container.Register, SettingsServiceV2>();
+
+
+
+
}
protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
diff --git a/RequestPlex.UI/Modules/AdminModule.cs b/RequestPlex.UI/Modules/AdminModule.cs
index 1aa0a6392..8b5bfa836 100644
--- a/RequestPlex.UI/Modules/AdminModule.cs
+++ b/RequestPlex.UI/Modules/AdminModule.cs
@@ -1,16 +1,38 @@
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.ComponentModel;
+#region Copyright
+// /************************************************************************
+// Copyright (c) 2016 Jamie Rees
+// File: AdminModule.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.Dynamic;
-using System.Linq;
+
using Nancy;
using Nancy.Extensions;
using Nancy.ModelBinding;
-using Nancy.Security;
-using Newtonsoft.Json;
+
using RequestPlex.Api;
using RequestPlex.Core;
+using RequestPlex.Core.SettingModels;
using RequestPlex.Store;
using RequestPlex.UI.Models;
@@ -18,7 +40,7 @@ namespace RequestPlex.UI.Modules
{
public class AdminModule : NancyModule
{
- public AdminModule()
+ public AdminModule(ISettingsService service)
{
#if !DEBUG
this.RequiresAuthentication();
@@ -28,8 +50,8 @@ namespace RequestPlex.UI.Modules
dynamic model = new ExpandoObject();
model.Errored = Request.Query.error.HasValue;
model.Port = null;
- var s = new SettingsService();
- var settings = s.GetSettings();
+
+ var settings = service.GetSettings();
if (settings != null)
{
model.Port = settings.Port;
@@ -41,10 +63,9 @@ namespace RequestPlex.UI.Modules
Post["admin/"] = _ =>
{
- var model = this.Bind();
+ var model = this.Bind();
- var s = new SettingsService();
- s.SaveSettings(model);
+ service.SaveSettings(model);
return Context.GetRedirect("~/admin");
@@ -61,20 +82,19 @@ namespace RequestPlex.UI.Modules
var plex = new PlexApi();
var model = plex.GetToken(user.username, user.password);
- var s = new SettingsService();
- var oldSettings = s.GetSettings();
+ var oldSettings = service.GetSettings();
if (oldSettings != null)
{
oldSettings.PlexAuthToken = model.user.authentication_token;
- s.SaveSettings(oldSettings);
+ service.SaveSettings(oldSettings);
}
else
{
- var newModel = new SettingsModel
+ var newModel = new RequestPlexSettings
{
PlexAuthToken = model.user.authentication_token
};
- s.SaveSettings(newModel);
+ service.SaveSettings(newModel);
}
diff --git a/RequestPlex.UI/Modules/RequestsModule.cs b/RequestPlex.UI/Modules/RequestsModule.cs
index 4b46dd03b..2906d23eb 100644
--- a/RequestPlex.UI/Modules/RequestsModule.cs
+++ b/RequestPlex.UI/Modules/RequestsModule.cs
@@ -1,12 +1,28 @@
using Nancy;
+using RequestPlex.Core;
+using RequestPlex.Core.SettingModels;
+
namespace RequestPlex.UI.Modules
{
public class RequestsModule : NancyModule
{
- public RequestsModule()
+ public RequestsModule(ISettingsService s)
{
Get["requests/"] = _ => "Hello!";
+ Get["requests/test"] = _ =>
+ {
+ var se = new RequestPlexSettings
+ {
+ PlexAuthToken = "abc",
+ Port = 2344,
+ UserAuthentication = false
+ };
+ s.SaveSettings(se);
+ var a = s.GetSettings();
+ return "Hi!";
+ };
+
}
}
}
\ No newline at end of file
diff --git a/RequestPlex.UI/Modules/SearchModule.cs b/RequestPlex.UI/Modules/SearchModule.cs
index 8cc46f583..1f177499e 100644
--- a/RequestPlex.UI/Modules/SearchModule.cs
+++ b/RequestPlex.UI/Modules/SearchModule.cs
@@ -49,7 +49,6 @@ namespace RequestPlex.UI.Modules
private Response SearchMovie(string searchTerm)
{
- var s = new SettingsService();
var api = new TheMovieDbApi();
var movies = api.SearchMovie(searchTerm);
var result = movies.Result;
diff --git a/RequestPlex.UI/Program.cs b/RequestPlex.UI/Program.cs
index e6ec8423c..73fba9091 100644
--- a/RequestPlex.UI/Program.cs
+++ b/RequestPlex.UI/Program.cs
@@ -2,9 +2,15 @@
using Microsoft.Owin.Hosting;
+using Mono.Data.Sqlite;
+
using Nancy.Hosting.Self;
using RequestPlex.Core;
+using RequestPlex.Core.SettingModels;
+using RequestPlex.Helpers;
+using RequestPlex.Store;
+using RequestPlex.Store.Repository.NZBDash.DataAccessLayer.Repository;
namespace RequestPlex.UI
{
@@ -16,7 +22,7 @@ namespace RequestPlex.UI
var s = new Setup();
s.SetupDb();
- var service = new SettingsService();
+ var service = new SettingsServiceV2(new JsonRepository(new DbConfiguration(new SqliteFactory()), new MemoryCacheProvider()));
var settings = service.GetSettings();
if (settings != null)
diff --git a/RequestPlex.UI/RequestPlex.UI.csproj b/RequestPlex.UI/RequestPlex.UI.csproj
index fe38dc27e..6355c6548 100644
--- a/RequestPlex.UI/RequestPlex.UI.csproj
+++ b/RequestPlex.UI/RequestPlex.UI.csproj
@@ -50,6 +50,10 @@
..\packages\Microsoft.Owin.Hosting.3.0.1\lib\net45\Microsoft.Owin.Hosting.dllTrue
+
+ False
+ ..\Assemblies\Mono.Data.Sqlite.dll
+ ..\packages\Nancy.1.4.1\lib\net40\Nancy.dll
@@ -71,10 +75,6 @@
..\packages\Nancy.Viewengines.Razor.1.4.1\lib\net40\Nancy.ViewEngines.Razor.dll
-
- ..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll
- True
- ..\packages\Owin.1.0\lib\net40\Owin.dllTrue
@@ -85,6 +85,7 @@
+ True
@@ -208,6 +209,10 @@
{DD7DC444-D3BF-4027-8AB9-EFC71F5EC581}RequestPlex.Core
+
+ {1252336D-42A3-482A-804C-836E60173DFA}
+ RequestPlex.Helpers
+ {92433867-2B7B-477B-A566-96C382427525}RequestPlex.Store
diff --git a/RequestPlex.UI/Startup.cs b/RequestPlex.UI/Startup.cs
index 2402a70b7..a6015ed39 100644
--- a/RequestPlex.UI/Startup.cs
+++ b/RequestPlex.UI/Startup.cs
@@ -1,4 +1,6 @@
-using Owin;
+using System;
+
+using Owin;
namespace RequestPlex.UI
{
@@ -6,7 +8,16 @@ namespace RequestPlex.UI
{
public void Configuration(IAppBuilder app)
{
+ try
+ {
app.UseNancy();
+ }
+ catch (Exception exception)
+ {
+ Console.WriteLine(exception.Message);
+ throw;
+ }
+
}
}
}
diff --git a/RequestPlex.UI/Views/Admin/Settings.cshtml b/RequestPlex.UI/Views/Admin/Settings.cshtml
index df14a4ed9..bcddbb872 100644
--- a/RequestPlex.UI/Views/Admin/Settings.cshtml
+++ b/RequestPlex.UI/Views/Admin/Settings.cshtml
@@ -44,7 +44,7 @@
-
+
@@ -60,8 +60,7 @@
Current users that are allowed to authenticate:
-
+
@@ -69,10 +68,10 @@
-
-
-
-
+
+
+
+
Please note, you will have to restart after changing these settings.