public async void multiSet(string[][] keyValueArray, ICallback callback)
        {
            if (keyValueArray == null || keyValueArray.Length == 0)
            {
                callback.Invoke(AsyncStorageErrorHelpers.GetInvalidKeyError(null));
                return;
            }

            var error = default(JObject);

            await _mutex.WaitAsync().ConfigureAwait(false);

            try
            {
                foreach (var pair in keyValueArray)
                {
                    if (pair.Length != 2)
                    {
                        error = AsyncStorageErrorHelpers.GetInvalidValueError(null);
                        break;
                    }

                    if (pair[0] == null)
                    {
                        error = AsyncStorageErrorHelpers.GetInvalidKeyError(null);
                        break;
                    }

                    if (pair[1] == null)
                    {
                        error = AsyncStorageErrorHelpers.GetInvalidValueError(pair[0]);
                        break;
                    }

                    error = await SetAsync(pair[0], pair[1]).ConfigureAwait(false);

                    if (error != null)
                    {
                        break;
                    }
                }
            }
            finally
            {
                _mutex.Release();
            }

            if (error != null)
            {
                callback.Invoke(error);
            }
            else
            {
                callback.Invoke();
            }
        }
Exemplo n.º 2
0
        public async void multiSet(string[][] keyValueArray, ICallback callback)
        {
            if (keyValueArray == null || keyValueArray.Length == 0)
            {
                callback.Invoke(AsyncStorageErrorHelpers.GetInvalidKeyError(null));
                return;
            }

            var error = default(JObject);

            await Task.Run(() =>
            {
                lock (_gate)
                {
                    foreach (var pair in keyValueArray)
                    {
                        if (pair.Length != 2)
                        {
                            error = AsyncStorageErrorHelpers.GetInvalidValueError(null);
                            break;
                        }

                        if (pair[0] == null)
                        {
                            error = AsyncStorageErrorHelpers.GetInvalidKeyError(null);
                            break;
                        }

                        if (pair[1] == null)
                        {
                            error = AsyncStorageErrorHelpers.GetInvalidValueError(pair[0]);
                            break;
                        }

                        error = Set(pair[0], pair[1]);
                        if (error != null)
                        {
                            break;
                        }
                    }
                }
            });

            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(AsyncStorageErrorHelpers.GetInvalidKeyError(null));
                return;
            }

            var error = default(JObject);

            await _mutex.WaitAsync().ConfigureAwait(false);

            try
            {
                foreach (var key in keys)
                {
                    if (key == null)
                    {
                        error = AsyncStorageErrorHelpers.GetInvalidKeyError(null);
                        break;
                    }

                    error = await RemoveAsync(key).ConfigureAwait(false);

                    if (error != null)
                    {
                        break;
                    }
                }
            }
            finally
            {
                _mutex.Release();
            }

            if (error != null)
            {
                callback.Invoke(error);
            }
            else
            {
                callback.Invoke();
            }
        }
        public async void multiGet(string[] keys, ICallback callback)
        {
            if (keys == null)
            {
                callback.Invoke(AsyncStorageErrorHelpers.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 = AsyncStorageErrorHelpers.GetInvalidKeyError(null);
                        break;
                    }

                    var value = await GetAsync(key).ConfigureAwait(false);

                    data.Add(new JArray(key, value));
                }
            }
            finally
            {
                _mutex.Release();
            }

            if (error != null)
            {
                callback.Invoke(error);
            }
            else
            {
                callback.Invoke(null, data);
            }
        }
Exemplo n.º 5
0
        public async void multiRemove(string[] keys, ICallback callback)
        {
            if (keys == null || keys.Length == 0)
            {
                callback.Invoke(AsyncStorageErrorHelpers.GetInvalidKeyError(null));
                return;
            }

            var error = default(JObject);

            await Task.Run(() =>
            {
                lock (_gate)
                {
                    foreach (var key in keys)
                    {
                        if (key == null)
                        {
                            error = AsyncStorageErrorHelpers.GetInvalidKeyError(null);
                            break;
                        }

                        error = Remove(key);
                        if (error != null)
                        {
                            break;
                        }
                    }
                }
            });

            if (error != null)
            {
                callback.Invoke(error);
            }
            else
            {
                callback.Invoke();
            }
        }
Exemplo n.º 6
0
        public async void multiGet(string[] keys, ICallback callback)
        {
            if (keys == null)
            {
                callback.Invoke(AsyncStorageErrorHelpers.GetInvalidKeyError(null), null);
                return;
            }

            var error = default(JObject);
            var data  = new JArray();

            await Task.Run(() =>
            {
                lock (_gate)
                {
                    foreach (var key in keys)
                    {
                        if (key == null)
                        {
                            error = AsyncStorageErrorHelpers.GetInvalidKeyError(null);
                            break;
                        }

                        var value = Get(key);
                        data.Add(new JArray(key, value));
                    }
                }
            });

            if (error != null)
            {
                callback.Invoke(error);
            }
            else
            {
                callback.Invoke(null, data);
            }
        }