Example #1
0
        public void ClientConfiguration_Edit_RaisesEvents()
        {
            // Arrange
            _clientConfiguration.Add("test", new FahClient {
                Settings = new ClientSettings {
                    Name = "test", Server = "server", Port = ClientSettings.DefaultPort
                }
            });
            ConfigurationChangedEventArgs changedEventArgs = null;

            _clientConfiguration.ConfigurationChanged += (sender, e) => { changedEventArgs = e; };
            ClientEditedEventArgs editedEventArgs = null;

            _clientConfiguration.ClientEdited += (sender, e) => editedEventArgs = e;
            // Act
            _clientConfiguration.Edit("test", new ClientSettings {
                Name = "test2", Server = "server1", Port = 36331
            });
            // Assert
            Assert.AreEqual(1, _clientConfiguration.Count);
            Assert.IsTrue(_clientConfiguration.ContainsKey("test2"));
            Assert.AreEqual(ConfigurationChangedType.Edit, changedEventArgs.ChangedType);
            Assert.AreEqual("test2", changedEventArgs.Client.Settings.Name);
            Assert.AreEqual("server1-36331", changedEventArgs.Client.Settings.DataPath());
            Assert.AreEqual("test", editedEventArgs.PreviousName);
            Assert.AreEqual("server-36330", editedEventArgs.PreviousPath);
            Assert.AreEqual("test2", editedEventArgs.NewName);
            Assert.AreEqual("server1-36331", editedEventArgs.NewPath);
        }
Example #2
0
        public void Edit(string key, ClientSettings settings)
        {
            if (key == null)
            {
                throw new ArgumentNullException(nameof(key));
            }
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            // Edit is only called after a client setup dialog
            // has returned.  At this point the client name
            // has already been validated.  Just make sure we
            // have a value here.
            Debug.Assert(!String.IsNullOrEmpty(settings.Name));

            IClient client;
            ClientEditedEventArgs e;

            _syncLock.EnterWriteLock();
            try
            {
                bool keyChanged = key != settings.Name;
                if (keyChanged && _clientDictionary.ContainsKey(settings.Name))
                {
                    // would like to eventually use the exact same
                    // exception message that would be used by
                    // the inner dictionary object.
                    throw new ArgumentException("An element with the same key already exists.");
                }

                client = _clientDictionary[key];
                string existingName = client.Settings.Name;
                string existingPath = client.Settings.DataPath();

                client.SlotsChanged      -= OnInvalidate;
                client.RetrievalFinished -= OnInvalidate;
                // update the settings
                client.Settings = settings;
                // if the key changed the client object needs removed and re-added with the correct key
                if (keyChanged)
                {
                    _clientDictionary.Remove(key);
                    _clientDictionary.Add(settings.Name, client);
                }
                client.SlotsChanged      += OnInvalidate;
                client.RetrievalFinished += OnInvalidate;

                e = new ClientEditedEventArgs(existingName, settings.Name, existingPath, settings.DataPath());
            }
            finally
            {
                _syncLock.ExitWriteLock();
            }

            IsDirty = true;
            OnClientEdited(e);
            OnDictionaryChanged(new ConfigurationChangedEventArgs(ConfigurationChangedType.Edit, client));
        }
Example #3
0
        private void OnClientEdited(ClientEditedEventArgs e)
        {
            var handler = ClientEdited;

            if (handler != null)
            {
                handler(this, e);
            }
        }
 private static void UpdateBenchmarkData(IProteinBenchmarkService benchmarkService, ClientEditedEventArgs e)
 {
     // the name changed
     if (e.PreviousName != e.NewName)
     {
         // update the Names in the benchmark collection
         benchmarkService.UpdateOwnerName(e.PreviousName, e.PreviousPath, e.NewName);
     }
     // the path changed
     if (!FileSystemPath.Equal(e.PreviousPath, e.NewPath))
     {
         // update the Paths in the benchmark collection
         benchmarkService.UpdateOwnerPath(e.NewName, e.PreviousPath, e.NewPath);
     }
 }