示例#1
0
        public void Load(IEnumerable <ClientSettings> settingsCollection)
        {
            if (settingsCollection == null)
            {
                throw new ArgumentNullException("settingsCollection");
            }

            Clear();

            int added = 0;

            // don't enter write lock before Clear(), would result in deadlock
            _syncLock.EnterWriteLock();
            try
            {
                // add each instance to the collection
                foreach (var client in _factory.CreateCollection(settingsCollection))
                {
                    if (client != null)
                    {
                        client.SlotsChanged      += OnInvalidate;
                        client.RetrievalFinished += OnInvalidate;
                        _clientDictionary.Add(client.Settings.Name, client);
                        added++;
                    }
                }
            }
            finally
            {
                _syncLock.ExitWriteLock();
            }

            if (added != 0)
            {
                OnDictionaryChanged(new ConfigurationChangedEventArgs(ConfigurationChangedType.Add, null));
            }
        }