From 83ce84660a62423ea6bd5af61bde55b7f47c5016 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Mon, 29 Feb 2016 11:40:41 +0000 Subject: [PATCH 1/8] added helpers --- RequestPlex.Helpers/ICacheProvider.cs | 66 ++++++++ RequestPlex.Helpers/MemoryCacheProvider.cs | 105 +++++++++++++ RequestPlex.Helpers/ObjectCopier.cs | 57 +++++++ .../Properties/AssemblyInfo.cs | 36 +++++ .../RequestPlex.Helpers.csproj | 65 ++++++++ RequestPlex.Helpers/StringCipher.cs | 145 ++++++++++++++++++ RequestPlex.Helpers/packages.config | 4 + RequestPlex.Store/ISettingsRepository.cs | 70 +++++++++ RequestPlex.Store/Models/GlobalSettings.cs | 39 +++++ .../Repository/JsonRepository.cs | 119 ++++++++++++++ RequestPlex.Store/RequestPlex.Store.csproj | 9 ++ RequestPlex.sln | 6 + 12 files changed, 721 insertions(+) create mode 100644 RequestPlex.Helpers/ICacheProvider.cs create mode 100644 RequestPlex.Helpers/MemoryCacheProvider.cs create mode 100644 RequestPlex.Helpers/ObjectCopier.cs create mode 100644 RequestPlex.Helpers/Properties/AssemblyInfo.cs create mode 100644 RequestPlex.Helpers/RequestPlex.Helpers.csproj create mode 100644 RequestPlex.Helpers/StringCipher.cs create mode 100644 RequestPlex.Helpers/packages.config create mode 100644 RequestPlex.Store/ISettingsRepository.cs create mode 100644 RequestPlex.Store/Models/GlobalSettings.cs create mode 100644 RequestPlex.Store/Repository/JsonRepository.cs diff --git a/RequestPlex.Helpers/ICacheProvider.cs b/RequestPlex.Helpers/ICacheProvider.cs new file mode 100644 index 000000000..0706502c5 --- /dev/null +++ b/RequestPlex.Helpers/ICacheProvider.cs @@ -0,0 +1,66 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: ICacheProvider.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 RequestPlex.Helpers +{ + public interface ICacheProvider + { + /// + /// Gets the item from the cache, if the item is not present + /// then we will get that item and store it in the cache. + /// + /// Type to store in the cache + /// The key + /// The item callback. This will be called if the item is not present in the cache. + /// The amount of time we want to cache the object + /// + T GetOrSet(string key, Func itemCallback, int cacheTime = 20) where T : class; + + /// + /// Gets the specified item from the cache. + /// + /// Type to get from the cache + /// The key. + /// + T Get(string key) where T : class; + + /// + /// Set/Store the specified object in the cache + /// + /// The key. + /// The object we want to store. + /// The amount of time we want to cache the object. + void Set(string key, object data, int cacheTime); + + /// + /// Removes the specified object from the cache. + /// + /// The key. + void Remove(string key); + } +} \ No newline at end of file diff --git a/RequestPlex.Helpers/MemoryCacheProvider.cs b/RequestPlex.Helpers/MemoryCacheProvider.cs new file mode 100644 index 000000000..cf125dec8 --- /dev/null +++ b/RequestPlex.Helpers/MemoryCacheProvider.cs @@ -0,0 +1,105 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: MemoryCacheProvider.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.Runtime.Caching; + +namespace RequestPlex.Helpers +{ + public class MemoryCacheProvider : ICacheProvider + { + private ObjectCache Cache => MemoryCache.Default; + + /// + /// Gets the item from the cache, if the item is not present + /// then we will get that item and store it in the cache. + /// + /// Type to store in the cache. + /// The key. + /// The item callback. This will be called if the item is not present in the cache. + /// + /// The amount of time we want to cache the object. + /// A copy of the cached object. + /// If the ]]> itemCallback is null and the item is not in the cache it will throw a . + /// If you do not want to change the object in the cache (since it's a copy returned and not a reference) you will need to + /// the cached item and then it, or just call this method. + public T GetOrSet(string key, Func itemCallback, int cacheTime = 20) where T : class + { + var item = Get(key); + if (item == null) + { + item = itemCallback(); + if (item != null) + { + Set(key, item, cacheTime); + } + } + + // Return a copy, not the stored cache reference + // The cached object will not change + // If we + return item.CloneJson(); + } + + /// + /// Gets the specified item from the cache. + /// + /// Type to get from the cache + /// The key. + /// + public T Get(string key) where T : class + { + var item = Cache.Get(key) as T; + return item; + } + + /// + /// Set/Store the specified object in the cache + /// + /// The key. + /// The object we want to store. + /// The amount of time we want to cache the object. + public void Set(string key, object data, int cacheTime) + { + var policy = new CacheItemPolicy { AbsoluteExpiration = DateTime.Now + TimeSpan.FromMinutes(cacheTime) }; + Cache.Add(new CacheItem(key, data), policy); + } + + /// + /// Removes the specified object from the cache. + /// + /// The key. + public void Remove(string key) + { + var keys = Cache.Where(x => x.Key.Contains(key)); + foreach (var k in keys) + { + Cache.Remove(k.Key); + } + } + } +} \ No newline at end of file diff --git a/RequestPlex.Helpers/ObjectCopier.cs b/RequestPlex.Helpers/ObjectCopier.cs new file mode 100644 index 000000000..dca1fa3aa --- /dev/null +++ b/RequestPlex.Helpers/ObjectCopier.cs @@ -0,0 +1,57 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: ObjectCopier.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; + +namespace RequestPlex.Helpers +{ + /// + /// Provides a method for performing a deep copy of an object. + /// Binary Serialization is used to perform the copy. + /// + public static class ObjectCopier + { + /// + /// Initialize inner objects individually + /// For example in default constructor some list property initialized with some values, + /// but in 'source' these items are cleaned - + /// without ObjectCreationHandling.Replace default constructor values will be added to result + /// + private static readonly JsonSerializerSettings Settings = new JsonSerializerSettings { ObjectCreationHandling = ObjectCreationHandling.Replace }; + + /// + /// Perform a deep Copy of the object, using Json as a serialisation method. + /// + /// The type of object being copied. + /// The object instance to copy. + /// The copied object. + public static T CloneJson(this T source) + { + // Don't serialize a null object, simply return the default for that object + return ReferenceEquals(source, null) ? default(T) : JsonConvert.DeserializeObject(JsonConvert.SerializeObject(source), Settings); + } + } +} \ No newline at end of file diff --git a/RequestPlex.Helpers/Properties/AssemblyInfo.cs b/RequestPlex.Helpers/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..e8c938896 --- /dev/null +++ b/RequestPlex.Helpers/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("RequestPlex.Helpers")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("RequestPlex.Helpers")] +[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("1252336d-42a3-482a-804c-836e60173dfa")] + +// 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/RequestPlex.Helpers/RequestPlex.Helpers.csproj b/RequestPlex.Helpers/RequestPlex.Helpers.csproj new file mode 100644 index 000000000..113b5c9f9 --- /dev/null +++ b/RequestPlex.Helpers/RequestPlex.Helpers.csproj @@ -0,0 +1,65 @@ + + + + + Debug + AnyCPU + {1252336D-42A3-482A-804C-836E60173DFA} + Library + Properties + RequestPlex.Helpers + RequestPlex.Helpers + v4.5.2 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\Newtonsoft.Json.8.0.2\lib\net45\Newtonsoft.Json.dll + True + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/RequestPlex.Helpers/StringCipher.cs b/RequestPlex.Helpers/StringCipher.cs new file mode 100644 index 000000000..47847fffe --- /dev/null +++ b/RequestPlex.Helpers/StringCipher.cs @@ -0,0 +1,145 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: StringCipher.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.IO; +using System.Linq; +using System.Security.Cryptography; +using System.Text; + +namespace RequestPlex.Helpers +{ + public class StringCipher + { + // This constant determines the number of iterations for the password bytes generation function. + private const int DerivationIterations = 1000; + // This constant is used to determine the keysize of the encryption algorithm in bits. + // We divide this by 8 within the code below to get the equivalent number of bytes. + private const int Keysize = 256; + + /// + /// Decrypts the specified cipher text. + /// + /// The cipher text. + /// The pass phrase. + /// + public static string Decrypt(string cipherText, string passPhrase) + { + // Get the complete stream of bytes that represent: + // [32 bytes of Salt] + [32 bytes of IV] + [n bytes of CipherText] + var cipherTextBytesWithSaltAndIv = Convert.FromBase64String(cipherText); + // Get the saltbytes by extracting the first 32 bytes from the supplied cipherText bytes. + var saltStringBytes = cipherTextBytesWithSaltAndIv.Take(Keysize / 8).ToArray(); + // Get the IV bytes by extracting the next 32 bytes from the supplied cipherText bytes. + var ivStringBytes = cipherTextBytesWithSaltAndIv.Skip(Keysize / 8).Take(Keysize / 8).ToArray(); + // Get the actual cipher text bytes by removing the first 64 bytes from the cipherText string. + var cipherTextBytes = cipherTextBytesWithSaltAndIv.Skip((Keysize / 8) * 2).Take(cipherTextBytesWithSaltAndIv.Length - ((Keysize / 8) * 2)).ToArray(); + + using (var password = new Rfc2898DeriveBytes(passPhrase, saltStringBytes, DerivationIterations)) + { + var keyBytes = password.GetBytes(Keysize / 8); + using (var symmetricKey = new RijndaelManaged()) + { + symmetricKey.BlockSize = 256; + symmetricKey.Mode = CipherMode.CBC; + symmetricKey.Padding = PaddingMode.PKCS7; + using (var decryptor = symmetricKey.CreateDecryptor(keyBytes, ivStringBytes)) + { + using (var memoryStream = new MemoryStream(cipherTextBytes)) + { + using (var cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read)) + { + var plainTextBytes = new byte[cipherTextBytes.Length]; + var decryptedByteCount = cryptoStream.Read(plainTextBytes, 0, plainTextBytes.Length); + memoryStream.Close(); + cryptoStream.Close(); + return Encoding.UTF8.GetString(plainTextBytes, 0, decryptedByteCount); + } + } + } + } + } + } + + /// + /// Encrypts the specified plain text. + /// + /// The plain text. + /// The pass phrase. + /// + public static string Encrypt(string plainText, string passPhrase) + { + // Salt and IV is randomly generated each time, but is preprended to encrypted cipher text + // so that the same Salt and IV values can be used when decrypting. + var saltStringBytes = Generate256BitsOfRandomEntropy(); + var ivStringBytes = Generate256BitsOfRandomEntropy(); + var plainTextBytes = Encoding.UTF8.GetBytes(plainText); + using (var password = new Rfc2898DeriveBytes(passPhrase, saltStringBytes, DerivationIterations)) + { + var keyBytes = password.GetBytes(Keysize / 8); + using (var symmetricKey = new RijndaelManaged()) + { + symmetricKey.BlockSize = 256; + symmetricKey.Mode = CipherMode.CBC; + symmetricKey.Padding = PaddingMode.PKCS7; + using (var encryptor = symmetricKey.CreateEncryptor(keyBytes, ivStringBytes)) + { + using (var memoryStream = new MemoryStream()) + { + using (var cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write)) + { + cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length); + cryptoStream.FlushFinalBlock(); + // Create the final bytes as a concatenation of the random salt bytes, the random iv bytes and the cipher bytes. + var cipherTextBytes = saltStringBytes; + cipherTextBytes = cipherTextBytes.Concat(ivStringBytes).ToArray(); + cipherTextBytes = cipherTextBytes.Concat(memoryStream.ToArray()).ToArray(); + memoryStream.Close(); + cryptoStream.Close(); + return Convert.ToBase64String(cipherTextBytes); + } + } + } + } + } + } + + /// + /// Generate256s the bits of random entropy. + /// + /// + private static byte[] Generate256BitsOfRandomEntropy() + { + var randomBytes = new byte[32]; // 32 Bytes will give us 256 bits. + using (var rngCsp = new RNGCryptoServiceProvider()) + { + // Fill the array with cryptographically secure random bytes. + rngCsp.GetBytes(randomBytes); + } + return randomBytes; + } + } +} \ No newline at end of file diff --git a/RequestPlex.Helpers/packages.config b/RequestPlex.Helpers/packages.config new file mode 100644 index 000000000..47cebb403 --- /dev/null +++ b/RequestPlex.Helpers/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/RequestPlex.Store/ISettingsRepository.cs b/RequestPlex.Store/ISettingsRepository.cs new file mode 100644 index 000000000..e85bb49f9 --- /dev/null +++ b/RequestPlex.Store/ISettingsRepository.cs @@ -0,0 +1,70 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: ISettingsRepository.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 RequestPlex.Store.Models; + +namespace RequestPlex.Store +{ + public interface ISettingsRepository + { + /// + /// Inserts the specified entity. + /// + /// The entity. + long Insert(GlobalSettings entity); + + /// + /// Gets all. + /// + /// + IEnumerable GetAll(); + + /// + /// Gets the specified identifier. + /// + /// Name of the settings. + /// + GlobalSettings Get(string settingsName); + + /// + /// Deletes the specified entity. + /// + /// The entity. + /// + bool Delete(GlobalSettings entity); + + /// + /// Updates the specified entity. + /// + /// The entity. + /// + bool Update(GlobalSettings entity); + + + } +} \ No newline at end of file diff --git a/RequestPlex.Store/Models/GlobalSettings.cs b/RequestPlex.Store/Models/GlobalSettings.cs new file mode 100644 index 000000000..26fce6a19 --- /dev/null +++ b/RequestPlex.Store/Models/GlobalSettings.cs @@ -0,0 +1,39 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: GlobalSettings.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.Models +{ + + [Table("GlobalSettings")] + public class GlobalSettings : Entity + { + public string Content { get; set; } + public string SettingsName { get; set; } + } + +} \ No newline at end of file diff --git a/RequestPlex.Store/Repository/JsonRepository.cs b/RequestPlex.Store/Repository/JsonRepository.cs new file mode 100644 index 000000000..4123aadc0 --- /dev/null +++ b/RequestPlex.Store/Repository/JsonRepository.cs @@ -0,0 +1,119 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: JsonRepository.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 Dapper.Contrib.Extensions; + +using RequestPlex.Helpers; +using RequestPlex.Store.Models; + +namespace RequestPlex.Store.Repository +{ + + + namespace NZBDash.DataAccessLayer.Repository + { + public class JsonRepository : ISettingsRepository + { + private ICacheProvider Cache { get; set; } + + private string TypeName { get; set; } + public JsonRepository(ISqliteConfiguration config, ICacheProvider cacheProvider) + { + Db = config; + Cache = cacheProvider; + TypeName = typeof(JsonRepository).Name; + } + + private ISqliteConfiguration Db { get; set; } + + public long Insert(GlobalSettings entity) + { + ResetCache(); + using (var con = Db.DbConnection()) + { + return con.Insert(entity); + } + } + + public IEnumerable GetAll() + { + var key = TypeName + "GetAll"; + var item = Cache.GetOrSet(key, () => + { + using (var con = Db.DbConnection()) + { + var page = con.GetAll(); + return page; + } + }, 5); + return item; + } + + public GlobalSettings Get(string pageName) + { + var key = pageName + "Get"; + var item = Cache.GetOrSet(key, () => + { + using (var con = Db.DbConnection()) + { + var page = con.GetAll().SingleOrDefault(x => x.SettingsName == pageName); + return page; + } + }, 5); + return item; + } + + public bool Delete(GlobalSettings entity) + { + ResetCache(); + using (var con = Db.DbConnection()) + { + return con.Delete(entity); + } + } + + public bool Update(GlobalSettings entity) + { + ResetCache(); + using (var con = Db.DbConnection()) + { + return con.Update(entity); + } + } + + private void ResetCache() + { + Cache.Remove("Get"); + Cache.Remove(TypeName + "GetAll"); + } + } + } +} \ No newline at end of file diff --git a/RequestPlex.Store/RequestPlex.Store.csproj b/RequestPlex.Store/RequestPlex.Store.csproj index a51323bed..e7a782019 100644 --- a/RequestPlex.Store/RequestPlex.Store.csproj +++ b/RequestPlex.Store/RequestPlex.Store.csproj @@ -53,9 +53,12 @@ + + + @@ -83,6 +86,12 @@ + + + {1252336D-42A3-482A-804C-836E60173DFA} + RequestPlex.Helpers + + + + + +
+ + +
+
+
+ +
+
+
+ + +
+
+
+ +
+
+
+
+ + + + + + + + diff --git a/RequestPlex.UI/Views/Search/Index.cshtml b/RequestPlex.UI/Views/Search/Index.cshtml index a9cc68241..a054dde29 100644 --- a/RequestPlex.UI/Views/Search/Index.cshtml +++ b/RequestPlex.UI/Views/Search/Index.cshtml @@ -51,34 +51,37 @@ poster {{/if}} -
+
-

{{overview}}.

+

{{overview}}

-
- Vote Average: {{voteAverage}} - Vote Count: {{voteCount}} +
{{#if_eq type "movie"}} - + {{/if_eq}} {{#if_eq type "tv"}} {{/if_eq}} +
+
+
+ Vote Average: {{voteAverage}} + Vote Count: {{voteCount}}
From ced6d989c900f6dbaca6f0d890cf7239a5f6accf Mon Sep 17 00:00:00 2001 From: tidusjar Date: Tue, 1 Mar 2016 15:18:01 +0000 Subject: [PATCH 6/8] Small updates including assembly version --- RequestPlex.Core/SettingsService.cs | 11 ++--- RequestPlex.Store/RequestedModel.cs | 1 + RequestPlex.Store/SqlTables.sql | 1 + RequestPlex.UI/Content/requests.js | 8 ++-- RequestPlex.UI/Properties/AssemblyInfo.cs | 4 +- RequestPlex.UI/RequestPlex.UI.csproj | 32 ++++++++++++++- RequestPlex.UI/Views/Requests/Index.cshtml | 1 + RequestPlex.UI/app.config | 48 ++++++++++++++-------- 8 files changed, 76 insertions(+), 30 deletions(-) diff --git a/RequestPlex.Core/SettingsService.cs b/RequestPlex.Core/SettingsService.cs index 1362e4125..c0d5c1fe7 100644 --- a/RequestPlex.Core/SettingsService.cs +++ b/RequestPlex.Core/SettingsService.cs @@ -57,13 +57,14 @@ namespace RequestPlex.Core model = new RequestedModel { - Tmdbid = tmdbid, + Tmdbid = movieInfo.Id, Type = type, Overview = movieInfo.Overview, ImdbId = movieInfo.ImdbId, PosterPath = "http://image.tmdb.org/t/p/w150/" + movieInfo.PosterPath, Title = movieInfo.Title, - ReleaseDate = movieInfo.ReleaseDate ?? DateTime.MinValue + ReleaseDate = movieInfo.ReleaseDate ?? DateTime.MinValue, + Status = movieInfo.Status }; } else @@ -72,13 +73,13 @@ namespace RequestPlex.Core model = new RequestedModel { - Tmdbid = tmdbid, + Tmdbid = showInfo.Id, Type = type, Overview = showInfo.Overview, - //ImdbId = showInfo.ImdbId, //TODO where's the IMDBId? PosterPath = "http://image.tmdb.org/t/p/w150/" + showInfo.PosterPath, Title = showInfo.Name, - ReleaseDate = showInfo.FirstAirDate ?? DateTime.MinValue + ReleaseDate = showInfo.FirstAirDate ?? DateTime.MinValue, + Status = showInfo.Status }; } var db = new DbConfiguration(new SqliteFactory()); diff --git a/RequestPlex.Store/RequestedModel.cs b/RequestPlex.Store/RequestedModel.cs index 1b4cfb66e..d62cd9b7c 100644 --- a/RequestPlex.Store/RequestedModel.cs +++ b/RequestPlex.Store/RequestedModel.cs @@ -15,6 +15,7 @@ namespace RequestPlex.Store public string PosterPath { get; set; } public DateTime ReleaseDate { get; set; } public RequestType Type { get; set; } + public string Status { get; set; } } public enum RequestType diff --git a/RequestPlex.Store/SqlTables.sql b/RequestPlex.Store/SqlTables.sql index 16d66320c..b0e9bb2a7 100644 --- a/RequestPlex.Store/SqlTables.sql +++ b/RequestPlex.Store/SqlTables.sql @@ -26,6 +26,7 @@ CREATE TABLE IF NOT EXISTS Requested Title varchar(50) NOT NULL, PosterPath varchar(50) NOT NULL, ReleaseDate varchar(50) NOT NULL + Status varchar(50) NOT NULL ); CREATE TABLE IF NOT EXISTS GlobalSettings diff --git a/RequestPlex.UI/Content/requests.js b/RequestPlex.UI/Content/requests.js index 15295a169..bf68b194b 100644 --- a/RequestPlex.UI/Content/requests.js +++ b/RequestPlex.UI/Content/requests.js @@ -48,7 +48,8 @@ function buildMovieRequestContext(result) { title: result.title, overview: result.overview, year: year, - type: "movie" + type: "movie", + status: result.status }; return context; @@ -62,10 +63,9 @@ function buildTvShowRequestContext(result) { id: result.tmdbid, title: result.name, overview: result.overview, - voteCount: result.voteCount, - voteAverage: result.voteAverage, year: year, - type: "tv" + type: "tv", + status: result.status }; return context; } diff --git a/RequestPlex.UI/Properties/AssemblyInfo.cs b/RequestPlex.UI/Properties/AssemblyInfo.cs index 76144376a..b8d2fa452 100644 --- a/RequestPlex.UI/Properties/AssemblyInfo.cs +++ b/RequestPlex.UI/Properties/AssemblyInfo.cs @@ -10,7 +10,7 @@ using System.Runtime.InteropServices; [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("RequestPlex.UI")] -[assembly: AssemblyCopyright("Copyright © 2013")] +[assembly: AssemblyCopyright("Copyright © 2016")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -31,5 +31,5 @@ using System.Runtime.InteropServices; // // You can specify all the values or you can default the Revision and Build Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/RequestPlex.UI/RequestPlex.UI.csproj b/RequestPlex.UI/RequestPlex.UI.csproj index 305d9cb2f..48a5d21a8 100644 --- a/RequestPlex.UI/RequestPlex.UI.csproj +++ b/RequestPlex.UI/RequestPlex.UI.csproj @@ -8,11 +8,26 @@ Exe Properties RequestPlex.UI - RequestPlex.UI + RequestPlex v4.5.2 512 ..\..\ true + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true AnyCPU @@ -23,6 +38,7 @@ DEBUG;TRACE prompt 4 + false AnyCPU @@ -84,9 +100,11 @@ True + + True ..\packages\Microsoft.AspNet.Razor.2.0.30506.0\lib\net40\System.Web.Razor.dll @@ -228,6 +246,18 @@ PreserveNewest + + + False + Microsoft .NET Framework 4.5.2 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 + false + + diff --git a/RequestPlex.UI/Views/Requests/Index.cshtml b/RequestPlex.UI/Views/Requests/Index.cshtml index 817615243..87fc33bbd 100644 --- a/RequestPlex.UI/Views/Requests/Index.cshtml +++ b/RequestPlex.UI/Views/Requests/Index.cshtml @@ -48,6 +48,7 @@

{{overview}}

+ {{status}}
diff --git a/RequestPlex.UI/app.config b/RequestPlex.UI/app.config index d33a25db3..825a85f28 100644 --- a/RequestPlex.UI/app.config +++ b/RequestPlex.UI/app.config @@ -1,19 +1,31 @@ - - - - -
- - - - - - - - - - - - - + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 1509350ede0ffaef7e3513d01301ecbe9c207f6b Mon Sep 17 00:00:00 2001 From: tidusjar Date: Tue, 1 Mar 2016 15:36:56 +0000 Subject: [PATCH 7/8] Fixed release build. --- RequestPlex.UI/Modules/AdminModule.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RequestPlex.UI/Modules/AdminModule.cs b/RequestPlex.UI/Modules/AdminModule.cs index 8b5bfa836..32ffe8ca9 100644 --- a/RequestPlex.UI/Modules/AdminModule.cs +++ b/RequestPlex.UI/Modules/AdminModule.cs @@ -29,11 +29,11 @@ using System.Dynamic; using Nancy; using Nancy.Extensions; using Nancy.ModelBinding; +using Nancy.Security; using RequestPlex.Api; using RequestPlex.Core; using RequestPlex.Core.SettingModels; -using RequestPlex.Store; using RequestPlex.UI.Models; namespace RequestPlex.UI.Modules From b71a6b8101c9fa885d5f81d92a41cfe36bf83d11 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Tue, 1 Mar 2016 15:49:14 +0000 Subject: [PATCH 8/8] Sql syntax issue fixed --- RequestPlex.Store/SqlTables.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RequestPlex.Store/SqlTables.sql b/RequestPlex.Store/SqlTables.sql index b0e9bb2a7..820a090f7 100644 --- a/RequestPlex.Store/SqlTables.sql +++ b/RequestPlex.Store/SqlTables.sql @@ -25,7 +25,7 @@ CREATE TABLE IF NOT EXISTS Requested Overview varchar(50) NOT NULL, Title varchar(50) NOT NULL, PosterPath varchar(50) NOT NULL, - ReleaseDate varchar(50) NOT NULL + ReleaseDate varchar(50) NOT NULL, Status varchar(50) NOT NULL );