From d1c1aff7d9490f06001f8860f4e5161d9b07722f Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 8 Apr 2019 20:54:59 -0400 Subject: [PATCH] mobile storage service --- src/Core/Services/MobileStorageService.cs | 52 +++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/Core/Services/MobileStorageService.cs diff --git a/src/Core/Services/MobileStorageService.cs b/src/Core/Services/MobileStorageService.cs new file mode 100644 index 000000000..3bf1b77e0 --- /dev/null +++ b/src/Core/Services/MobileStorageService.cs @@ -0,0 +1,52 @@ +using Bit.Core.Abstractions; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Bit.Core.Services +{ + public class MobileStorageService : IStorageService + { + private readonly IStorageService _preferencesStorageService; + private readonly IStorageService _liteDbStorageService; + + private readonly HashSet _preferenceStorageKeys = new HashSet + { + Constants.LockOptionKey + }; + + public MobileStorageService( + IStorageService preferenceStorageService, + IStorageService liteDbStorageService) + { + _preferencesStorageService = preferenceStorageService; + _liteDbStorageService = liteDbStorageService; + } + + public Task GetAsync(string key) + { + if(_preferenceStorageKeys.Contains(key)) + { + return _preferencesStorageService.GetAsync(key); + } + return _liteDbStorageService.GetAsync(key); + } + + public Task SaveAsync(string key, T obj) + { + if(_preferenceStorageKeys.Contains(key)) + { + return _preferencesStorageService.SaveAsync(key, obj); + } + return _liteDbStorageService.SaveAsync(key, obj); + } + + public Task RemoveAsync(string key) + { + if(_preferenceStorageKeys.Contains(key)) + { + return _preferencesStorageService.RemoveAsync(key); + } + return _liteDbStorageService.RemoveAsync(key); + } + } +}