Task <T> IDataStore.GetAsync <T>(string key) => Observable.Using(_objectSpaceFactory, objectSpace => { key = FileDataStore.GenerateStoredKey(key, typeof(T)); var cloudAuthentication = objectSpace.GetObjectByKey <GoogleAuthentication>(_userId); return((cloudAuthentication != null && cloudAuthentication.OAuthToken.ContainsKey(key) ? cloudAuthentication.OAuthToken[key] : null).ReturnObservable()); }) .Select(s => NewtonsoftJsonSerializer.Instance.Deserialize <T>(s)) .ToTask();
Task IDataStore.StoreAsync <T>(string key, T value) => Observable.Using(_objectSpaceFactory, objectSpace => { key = FileDataStore.GenerateStoredKey(key, typeof(T)); var cloudAuthentication = objectSpace.GetObjectByKey <GoogleAuthentication>(_userId) ?? objectSpace.CreateObject <GoogleAuthentication>(); cloudAuthentication.Oid = _userId; var serialize = NewtonsoftJsonSerializer.Instance.Serialize(value); if (!cloudAuthentication.OAuthToken.ContainsKey(key)) { cloudAuthentication.OAuthToken.Add(key, serialize); } else { cloudAuthentication.OAuthToken[key] = serialize; } cloudAuthentication.Save(); objectSpace.CommitChanges(); return(default(T).ReturnObservable()); }).ToTask();