From 86f1874379a09a081244fc142043f4b4e0f50b2e Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 28 Mar 2019 13:57:45 -0400 Subject: [PATCH] playground app and json settings for litedb --- bitwarden-mobile.sln | 37 +++++++++++++++++++++++ src/Core/Services/LiteDbStorageService.cs | 11 +++++-- test/Playground/Playground.csproj | 14 +++++++++ test/Playground/Program.cs | 23 ++++++++++++++ 4 files changed, 82 insertions(+), 3 deletions(-) create mode 100644 test/Playground/Playground.csproj create mode 100644 test/Playground/Program.cs diff --git a/bitwarden-mobile.sln b/bitwarden-mobile.sln index f97d6f4e8..a2c3b52a2 100644 --- a/bitwarden-mobile.sln +++ b/bitwarden-mobile.sln @@ -11,6 +11,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "App", "src\App\App.csproj", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core", "src\Core\Core.csproj", "{4B8A8C41-9820-4341-974C-41E65B7F4366}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Playground", "test\Playground\Playground.csproj", "{9C8DA5A8-904D-466F-B9B0-1A4AB5A9AFC3}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{D10CA4A9-F866-40E1-B658-F69051236C71}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{8904C536-C67D-420F-9971-51B26574C3AA}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Ad-Hoc|Any CPU = Ad-Hoc|Any CPU @@ -159,10 +165,41 @@ Global {4B8A8C41-9820-4341-974C-41E65B7F4366}.Release|iPhone.Build.0 = Release|Any CPU {4B8A8C41-9820-4341-974C-41E65B7F4366}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU {4B8A8C41-9820-4341-974C-41E65B7F4366}.Release|iPhoneSimulator.Build.0 = Release|Any CPU + {9C8DA5A8-904D-466F-B9B0-1A4AB5A9AFC3}.Ad-Hoc|Any CPU.ActiveCfg = Debug|Any CPU + {9C8DA5A8-904D-466F-B9B0-1A4AB5A9AFC3}.Ad-Hoc|Any CPU.Build.0 = Debug|Any CPU + {9C8DA5A8-904D-466F-B9B0-1A4AB5A9AFC3}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU + {9C8DA5A8-904D-466F-B9B0-1A4AB5A9AFC3}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU + {9C8DA5A8-904D-466F-B9B0-1A4AB5A9AFC3}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {9C8DA5A8-904D-466F-B9B0-1A4AB5A9AFC3}.Ad-Hoc|iPhoneSimulator.Build.0 = Debug|Any CPU + {9C8DA5A8-904D-466F-B9B0-1A4AB5A9AFC3}.AppStore|Any CPU.ActiveCfg = Debug|Any CPU + {9C8DA5A8-904D-466F-B9B0-1A4AB5A9AFC3}.AppStore|Any CPU.Build.0 = Debug|Any CPU + {9C8DA5A8-904D-466F-B9B0-1A4AB5A9AFC3}.AppStore|iPhone.ActiveCfg = Debug|Any CPU + {9C8DA5A8-904D-466F-B9B0-1A4AB5A9AFC3}.AppStore|iPhone.Build.0 = Debug|Any CPU + {9C8DA5A8-904D-466F-B9B0-1A4AB5A9AFC3}.AppStore|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {9C8DA5A8-904D-466F-B9B0-1A4AB5A9AFC3}.AppStore|iPhoneSimulator.Build.0 = Debug|Any CPU + {9C8DA5A8-904D-466F-B9B0-1A4AB5A9AFC3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9C8DA5A8-904D-466F-B9B0-1A4AB5A9AFC3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9C8DA5A8-904D-466F-B9B0-1A4AB5A9AFC3}.Debug|iPhone.ActiveCfg = Debug|Any CPU + {9C8DA5A8-904D-466F-B9B0-1A4AB5A9AFC3}.Debug|iPhone.Build.0 = Debug|Any CPU + {9C8DA5A8-904D-466F-B9B0-1A4AB5A9AFC3}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {9C8DA5A8-904D-466F-B9B0-1A4AB5A9AFC3}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU + {9C8DA5A8-904D-466F-B9B0-1A4AB5A9AFC3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9C8DA5A8-904D-466F-B9B0-1A4AB5A9AFC3}.Release|Any CPU.Build.0 = Release|Any CPU + {9C8DA5A8-904D-466F-B9B0-1A4AB5A9AFC3}.Release|iPhone.ActiveCfg = Release|Any CPU + {9C8DA5A8-904D-466F-B9B0-1A4AB5A9AFC3}.Release|iPhone.Build.0 = Release|Any CPU + {9C8DA5A8-904D-466F-B9B0-1A4AB5A9AFC3}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU + {9C8DA5A8-904D-466F-B9B0-1A4AB5A9AFC3}.Release|iPhoneSimulator.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {304400AF-F0ED-40FA-B102-EA3C3EC43E4F} = {D10CA4A9-F866-40E1-B658-F69051236C71} + {599E0201-420A-4C3E-A7BA-5349F72E0B15} = {D10CA4A9-F866-40E1-B658-F69051236C71} + {EE44C6A1-2A85-45FE-8D9B-BF1D5F88809C} = {D10CA4A9-F866-40E1-B658-F69051236C71} + {4B8A8C41-9820-4341-974C-41E65B7F4366} = {D10CA4A9-F866-40E1-B658-F69051236C71} + {9C8DA5A8-904D-466F-B9B0-1A4AB5A9AFC3} = {8904C536-C67D-420F-9971-51B26574C3AA} + EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {7D436EA3-8B7E-45D2-8D14-0730BD2E0410} EndGlobalSection diff --git a/src/Core/Services/LiteDbStorageService.cs b/src/Core/Services/LiteDbStorageService.cs index eef1c2ccc..39fe228fa 100644 --- a/src/Core/Services/LiteDbStorageService.cs +++ b/src/Core/Services/LiteDbStorageService.cs @@ -1,6 +1,7 @@ using Bit.Core.Abstractions; using LiteDB; using Newtonsoft.Json; +using Newtonsoft.Json.Serialization; using System.Linq; using System.Threading.Tasks; @@ -8,7 +9,11 @@ namespace Bit.Core.Services { public class LiteDbStorageService : IStorageService { - private LiteCollection _collection; + private readonly LiteCollection _collection; + private readonly JsonSerializerSettings _jsonSettings = new JsonSerializerSettings + { + ContractResolver = new CamelCasePropertyNamesContractResolver() + }; public LiteDbStorageService(string dbPath) { @@ -23,12 +28,12 @@ namespace Bit.Core.Services { return Task.FromResult(default(T)); } - return Task.FromResult(JsonConvert.DeserializeObject(item.Value)); + return Task.FromResult(JsonConvert.DeserializeObject(item.Value, _jsonSettings)); } public Task SaveAsync(string key, T obj) { - var data = JsonConvert.SerializeObject(obj); + var data = JsonConvert.SerializeObject(obj, _jsonSettings); _collection.Upsert(new JsonItem(key, data)); return Task.FromResult(0); } diff --git a/test/Playground/Playground.csproj b/test/Playground/Playground.csproj new file mode 100644 index 000000000..710ddc02d --- /dev/null +++ b/test/Playground/Playground.csproj @@ -0,0 +1,14 @@ + + + + Exe + netcoreapp2.0 + BitwardenPlayground + Bit.Playground + + + + + + + diff --git a/test/Playground/Program.cs b/test/Playground/Program.cs new file mode 100644 index 000000000..ca57eb5d2 --- /dev/null +++ b/test/Playground/Program.cs @@ -0,0 +1,23 @@ +using Bit.Core.Services; +using System; +using System.Threading.Tasks; + +namespace Bit.Playground +{ + public class Program + { + public static void Main(string[] args) + { + MainAsync(args).Wait(); + Console.ReadLine(); + } + + public static async Task MainAsync(string[] args) + { + var db = new LiteDbStorageService("test.db"); + await db.SaveAsync("testkey", new { val = 1 }); + Console.WriteLine(await db.GetAsync("testkey")); + Console.ReadLine(); + } + } +}