public async void multiSet(string[][] keyValueArray, ICallback callback) { if (keyValueArray == null || keyValueArray.Length == 0) { callback.Invoke(AsyncStorageHelpers.GetInvalidKeyError(null)); return; } var error = default(JObject); await _mutex.WaitAsync().ConfigureAwait(false); try { foreach (var pair in keyValueArray) { if (pair.Length != 2) { error = AsyncStorageHelpers.GetInvalidValueError(null); break; } if (pair[0] == null) { error = AsyncStorageHelpers.GetInvalidKeyError(null); break; } if (pair[1] == null) { error = AsyncStorageHelpers.GetInvalidValueError(pair[0]); break; } error = await SetAsync(pair[0], pair[1]).ConfigureAwait(false); if (error != null) { break; } } } catch (Exception ex) { error = AsyncStorageHelpers.GetError(ex); } finally { _mutex.Release(); } if (error != null) { callback.Invoke(error); } else { callback.Invoke(); } }
public async void clear(ICallback callback) { var error = default(JObject); await _mutex.WaitAsync().ConfigureAwait(false); try { var storageFolder = await GetAsyncStorageFolder(false).ConfigureAwait(false); if (storageFolder != null) { await storageFolder.DeleteAsync().ConfigureAwait(false); } } catch (Exception ex) { error = AsyncStorageHelpers.GetError(ex); } finally { _mutex.Release(); } if (error != null) { callback.Invoke(error); } else { callback.Invoke(); } }
public async void multiRemove(string[] keys, ICallback callback) { if (keys == null || keys.Length == 0) { callback.Invoke(AsyncStorageHelpers.GetInvalidKeyError(null)); return; } var error = default(JObject); await _mutex.WaitAsync().ConfigureAwait(false); try { foreach (var key in keys) { if (key == null) { error = AsyncStorageHelpers.GetInvalidKeyError(null); break; } error = await RemoveAsync(key).ConfigureAwait(false); if (error != null) { break; } } } catch (Exception ex) { error = AsyncStorageHelpers.GetError(ex); } finally { _mutex.Release(); } if (error != null) { RnLog.Warn(ReactConstants.RNW, $"Error in AsyncStorageModule.multiRemove: {error}"); callback.Invoke(error); } else { callback.Invoke(); } }
public async void multiGet(string[] keys, ICallback callback) { if (keys == null) { callback.Invoke(AsyncStorageHelpers.GetInvalidKeyError(null), null); return; } var error = default(JObject); var data = new JArray(); await _mutex.WaitAsync().ConfigureAwait(false); try { foreach (var key in keys) { if (key == null) { error = AsyncStorageHelpers.GetInvalidKeyError(null); break; } var value = await GetAsync(key).ConfigureAwait(false); data.Add(new JArray(key, value)); } } catch (Exception ex) { error = AsyncStorageHelpers.GetError(ex); } finally { _mutex.Release(); } if (error != null) { RnLog.Warn(ReactConstants.RNW, $"Error in AsyncStorageModule.multiGet: {error}"); callback.Invoke(error); } else { callback.Invoke(null, data); } }
public async void getAllKeys(ICallback callback) { var error = default(JObject); var keys = new JArray(); var error = default(JObject); await _mutex.WaitAsync().ConfigureAwait(false); try { var storageFolder = await GetAsyncStorageFolder(false).ConfigureAwait(false); if (storageFolder != null) { var items = await storageFolder.GetFilesAsync().ConfigureAwait(false); foreach (var item in items) { var itemName = item.Name; if (itemName.EndsWith(AsyncStorageHelpers.FileExtension)) { keys.Add(AsyncStorageHelpers.GetKeyName(itemName)); } } } } catch (Exception ex) { error = AsyncStorageHelpers.GetError(ex); } finally { _mutex.Release(); } if (error != null) { callback.Invoke(error); } else { callback.Invoke(null, keys); } }
public async void clear(ICallback callback) { var error = default(JObject); await _mutex.WaitAsync().ConfigureAwait(false); try { var storageFolder = await GetAsyncStorageFolder(false).ConfigureAwait(false); if (storageFolder != null) { await storageFolder.DeleteAsync().AsTask().ConfigureAwait(false); _cachedFolder = null; } } catch (Exception ex) { error = AsyncStorageHelpers.GetError(ex); } finally { _mutex.Release(); } if (error != null) { RnLog.Warn(ReactConstants.RNW, $"Error in AsyncStorageModule.clear: {error}"); callback.Invoke(error); } else { callback.Invoke(); } }