private PluginConfigByObject CreatePluginConfigByObject(object o)
        {
            PluginConfigByObject co = new PluginConfigByObject();

            _byObject.Add(o, co);
            return(co);
        }
        public bool Remove(object o, INamedVersionedUniqueId p, string k)
        {
            if (o == null)
            {
                throw new ArgumentNullException("o");
            }
            if (p == null)
            {
                throw new ArgumentNullException("p");
            }
            if (k == null)
            {
                throw new ArgumentNullException("k");
            }

            SharedDictionaryEntry e = new SharedDictionaryEntry(o, p, k);
            SharedDictionaryEntry result;

            if (_values.TryGetValue(e, out result))
            {
                PluginConfigByObject co = _byObject[e.Obj];
                co.Remove(result);
                PluginConfigByPlugin cp = _byPlugin[e.PluginId.UniqueId];
                cp.Remove(result);
                _finalDictionary[e].Count--;
                _values.Remove(result);
                result.Value = null;
                if (Changed != null)
                {
                    Changed(this, new ConfigChangedEventArgs(e, e, ChangeStatus.Delete));
                }
                return(true);
            }
            return(false);
        }
        void DoRemove(INamedVersionedUniqueId p, bool definitive)
        {
            PluginConfigByPlugin cp;

            if (_byPlugin.TryGetValue(p.UniqueId, out cp) && cp.PluginId == p)
            {
                if (cp.Count > 0)
                {
                    HashSet <object> objectsTouched = new HashSet <object>();
                    foreach (SharedDictionaryEntry e in cp)
                    {
                        _values.Remove(e);
                        PluginConfigByObject co = _byObject[e.Obj];
                        co.Remove(e);
                        _finalDictionary.Remove(e);
                        objectsTouched.Add(e.Obj);
                    }
                    cp.Clear();
                    if (Changed != null)
                    {
                        bool allObjectsConcerned = objectsTouched.Count == _byObject.Count;

                        ChangeStatus changeStatus;
                        if (definitive)
                        {
                            changeStatus = ChangeStatus.ContainerDestroy;
                        }
                        else
                        {
                            changeStatus = ChangeStatus.ContainerClear;
                        }

                        Changed(this, new ConfigChangedEventArgs(new ReadOnlyCollectionOnISet <object>(objectsTouched), allObjectsConcerned, p, changeStatus));
                    }
                }
                if (definitive)
                {
                    _byPlugin.Remove(p.UniqueId);
                }
            }
            // Clears fragment in any case (the plugin beeing known or not).
            ClearFragments(p);
        }
        public void Clear(object o, INamedVersionedUniqueId p)
        {
            if (o == null)
            {
                throw new ArgumentNullException("o");
            }
            if (p == null)
            {
                throw new ArgumentNullException("p");
            }

            FinalDictionary d;

            if (!_finalDictionary.TryGetValue(new SharedDictionaryEntry(o, p, null), out d) || d.Count == 0)
            {
                return;
            }
            PluginConfigByObject co = _byObject[o];
            PluginConfigByPlugin cp = _byPlugin[p.UniqueId];

            for (int i = 0; i < co.Count; ++i)
            {
                SharedDictionaryEntry e = co[i];
                if (e.PluginId == p)
                {
                    co.RemoveAt(i);
                    cp.Remove(e);
                    _values.Remove(e);
                }
            }
            d.Count = 0;
            if (Changed != null)
            {
                Changed(this, new ConfigChangedEventArgs(o, p, ChangeStatus.ContainerClear));
            }
        }
 /// <summary>
 /// Used by SharedDictionaryWriter.
 /// </summary>
 internal bool TryGetPluginConfigByObject(object o, out PluginConfigByObject co)
 {
     return(_byObject.TryGetValue(o, out co));
 }