Bitwarden-app-android-iphon.../src/Core/Services/StateService.cs

45 lines
1.0 KiB
C#
Raw Normal View History

2019-04-09 23:01:55 +02:00
using Bit.Core.Abstractions;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Bit.Core.Services
{
public class StateService : IStateService
{
private readonly Dictionary<string, object> _state = new Dictionary<string, object>();
public Task<T> GetAsync<T>(string key)
{
return Task.FromResult(_state.ContainsKey(key) ? (T)_state[key] : (T)(object)null);
}
public Task SaveAsync<T>(string key, T obj)
{
if (_state.ContainsKey(key))
2019-04-09 23:01:55 +02:00
{
_state[key] = obj;
}
else
{
_state.Add(key, obj);
}
return Task.FromResult(0);
}
public Task RemoveAsync(string key)
{
if (_state.ContainsKey(key))
2019-04-09 23:01:55 +02:00
{
_state.Remove(key);
}
return Task.FromResult(0);
}
2019-05-15 21:47:50 +02:00
public Task PurgeAsync()
{
_state.Clear();
return Task.FromResult(0);
}
2019-04-09 23:01:55 +02:00
}
}