public void ClientConfiguration_Edit_RaisesEvents()
        {
            // Arrange
            var configuration = CreateConfiguration();

            configuration.Add("test", new NullClient {
                Settings = new ClientSettings {
                    Name = "test", Server = "server", Port = ClientSettings.DefaultPort
                }
            });
            ClientConfigurationChangedEventArgs changedEventArgs = null;

            configuration.ClientConfigurationChanged += (sender, e) => { changedEventArgs = e; };
            // Act
            configuration.Edit("test", new ClientSettings {
                Name = "test2", Server = "server1", Port = 36331
            });
            // Assert
            Assert.AreEqual(1, configuration.Count);
            Assert.IsTrue(configuration.ContainsKey("test2"));
            Assert.AreEqual(ClientConfigurationChangedAction.Edit, changedEventArgs.Action);
            Assert.AreEqual("test2", changedEventArgs.Client.Settings.Name);
            Assert.AreEqual("server1", changedEventArgs.Client.Settings.Server);
            Assert.AreEqual(36331, changedEventArgs.Client.Settings.Port);
        }
        public void ClientConfiguration_Clear_DoesNotRaiseConfigurationChangedWhenConfigurationIsEmpty()
        {
            // Arrange
            var configuration = CreateConfiguration();
            ClientConfigurationChangedEventArgs eventArgs = null;

            configuration.ClientConfigurationChanged += (sender, e) => { eventArgs = e; };
            // Act
            configuration.Clear();
            // Assert
            Assert.IsNull(eventArgs);
        }
        public void ClientConfiguration_Clear_RaisesConfigurationChangedEvent()
        {
            // Arrange
            var configuration = CreateConfiguration();

            configuration.Add("test", new NullClient());
            ClientConfigurationChangedEventArgs eventArgs = null;

            configuration.ClientConfigurationChanged += (sender, e) => { eventArgs = e; };
            // Act
            configuration.Clear();
            // Assert
            Assert.AreEqual(ClientConfigurationChangedAction.Clear, eventArgs.Action);
            Assert.IsNull(eventArgs.Client);
        }
        public void ClientConfiguration_Load_RaisesConfigurationChangedEvent()
        {
            // Arrange
            var configuration = CreateConfiguration();
            var settings      = new[] { new ClientSettings {
                                            Name = "test", Server = "foo"
                                        } };
            ClientConfigurationChangedEventArgs eventArgs = null;

            configuration.ClientConfigurationChanged += (sender, e) => { eventArgs = e; };
            // Act
            configuration.Load(settings);
            // Assert
            Assert.AreEqual(ClientConfigurationChangedAction.Add, eventArgs.Action);
            Assert.IsNull(eventArgs.Client);
        }
        public void ClientConfiguration_Remove_RaisesConfigurationChangedEvent()
        {
            // Arrange
            var configuration = CreateConfiguration();
            ClientConfigurationChangedEventArgs eventArgs = null;

            configuration.ClientConfigurationChanged += (sender, e) => { eventArgs = e; };
            configuration.Add("test", new NullClient());
            // Act
            bool result = configuration.Remove("test");

            // Assert
            Assert.IsTrue(result);
            Assert.AreEqual(ClientConfigurationChangedAction.Remove, eventArgs.Action);
            Assert.IsNotNull(eventArgs.Client);
        }
Пример #6
0
        protected virtual void OnClientConfigurationChanged(object sender, ClientConfigurationChangedEventArgs e)
        {
            if (e.Action == ClientConfigurationChangedAction.Remove ||
                e.Action == ClientConfigurationChangedAction.Clear)
            {
                // Disable timers if no hosts
                if ((_clientRetrievalTask.Enabled || _webGenerationTask.Enabled) && ClientConfiguration.Count == 0)
                {
                    Logger.Info("No clients... stopping all scheduled tasks");
                    _clientRetrievalTask.Cancel();
                    _webGenerationTask.Cancel();
                }
            }
            else if (e.Action == ClientConfigurationChangedAction.Add)
            {
                var clientTaskEnabled = Preferences.Get <bool>(Preference.ClientRetrievalTaskEnabled);
                if (e.Client == null)
                {
                    // no client specified - retrieve all
                    _clientRetrievalTask.Interval = ClientInterval;
                    _clientRetrievalTask.Run(clientTaskEnabled);
                }
                else
                {
                    Task.Run(() => e.Client.Retrieve());
                    if (clientTaskEnabled)
                    {
                        _clientRetrievalTask.Interval = ClientInterval;
                        _clientRetrievalTask.Start();
                    }
                }

                if (Preferences.Get <bool>(Preference.WebGenerationTaskEnabled) &&
                    Preferences.Get <bool>(Preference.WebGenerationTaskAfterClientRetrieval) == false)
                {
                    _webGenerationTask.Interval = WebInterval;
                    _webGenerationTask.Start();
                }
            }
            else if (e.Action == ClientConfigurationChangedAction.Edit)
            {
                Task.Run(() => e.Client.Retrieve());
            }
        }
Пример #7
0
 protected virtual void OnClientConfigurationChanged(ClientConfigurationChangedEventArgs e)
 {
     ClientConfigurationChanged?.Invoke(this, e);
 }
 protected override void OnClientConfigurationChanged(object sender, ClientConfigurationChangedEventArgs e)
 {
 }