Exemple #1
0
        public void Flush()
        {
            lock (_lock)
            {
                if (_newvalues.Count == 0)
                {
                    return;
                }

                IDictionary result = new Hashtable(_values);
                IUpdate     batch  = CreateNewUpdate();

                foreach (DictionaryEntry newvalue in _newvalues)
                {
                    ProfilePath path  = (ProfilePath)newvalue.Key;
                    string      value = (string)newvalue.Value;

                    if (value == null)
                    {
                        if (_values.Contains(path))
                        {
                            batch.DeleteValue(path);
                            result.Remove(path);
                        }
                    }
                    else
                    {
                        if (_values.Contains(path))
                        {
                            batch.SaveValue(path, value);
                            result[path] = value;
                        }
                        else
                        {
                            batch.AddValue(path, value);
                            result.Add(path, value);
                        }
                    }
                }

                try
                {
                    batch.Execute();

                    _values = result;
                    _newvalues.Clear();

                    batch.AcceptChanges();
                }
                catch
#if DEBUG
                (Exception)
#endif
                {
                    batch.DiscardChanges();
                    throw;
                }
            }
        }