public object Add(SecureSetting model) { SecureSettingsService.Instance.Add(model); return "Added..."; }
public object Remove(SecureSetting model) { SecureSettingsService.Instance.Remove(model.Id); return "Removed..."; }
internal static void AddKey(PetaPocoUnitOfWork unitOfWork, SecureSetting model) { if (!string.IsNullOrEmpty(model.Key) && !string.IsNullOrEmpty(model.Value) && model.CategoryId > 0) { var setting = GetSetting(unitOfWork, model.Key); if (setting == null) { LogHelper.Info<SecureSetting>("Adding new key..."); try { unitOfWork.Database.Save(new SecureSetting() { Key = model.Key, Value = SecurityHelper.Encrypt(model.Value, SecurityHelper.GetKey()), CategoryId = model.CategoryId, UpdatedOn = DateTime.UtcNow }); SecureSettingsService.Clear(); } catch (Exception ex) { Console.WriteLine(ex.Message); LogHelper.Error<Exception>(ex.Message, ex); } } else { LogHelper.Info<SecureSetting>("Key exists already=>" + model.Key); } } }
public object Save(SecureSetting model) { SecureSettingsService.Instance.SaveKey(model.Key, model.Value); return "Saved..."; }
public void Init() { Console.Write("Starting..."); PetaPocoUnitOfWork.ConnectionString = "testDb"; SecurityHelper.CipherKey = "zebUD6w2kvMf2AMRaQkwe4PjUOvQ2n60AlzFjbe3BRY="; /* var externalKey = ""; using (var client = new HttpClient()) { client.DefaultRequestHeaders .Accept .Add(new MediaTypeWithQualityHeaderValue("text/plain")); var responseString = client.GetStringAsync("http://somedomain.local/umbraco/api/testapi/getcipherkey").Result; Console.WriteLine(responseString); externalKey = responseString.Replace(@"""", ""); Console.WriteLine(externalKey); SecurityHelper.CipherKey = externalKey; } */ SecureSettingsService.Instance.AddCategory("General"); var foo = new SecureSetting() { CategoryId = 1, Key = "foo", Value = "bar" }; SecureSettingsService.Instance.Add(foo); SecureSettingsService.Instance.SaveKey(foo.Key, foo.Value); SecureSettingsService.Instance.Add(new SecureSetting() { CategoryId = 1, Key = "int", Value = "1" }); SecureSettingsService.Instance.Add(new SecureSetting() { CategoryId = 1, Key = "float", Value = "1.0" }); SecureSettingsService.Instance.Add(new SecureSetting() { CategoryId = 1, Key = "boolTrue", Value = "True" }); SecureSettingsService.Instance.Add(new SecureSetting() { CategoryId = 1, Key = "boolFalse", Value = "False" }); SecureSettingsService.Instance.Add(new SecureSetting() { CategoryId = 1, Key = "bool1", Value = "1" }); SecureSettingsService.Instance.Add(new SecureSetting() { CategoryId = 1, Key = "bool0", Value = "0" }); SecureSettingsService.Instance.Add(new SecureSetting() { CategoryId = 1, Key = "double", Value = "2.0" }); Console.WriteLine("Items in cache=>" + SecureSettingsService.Instance.GetRawSettings().Count()); }