private void OnConfigurationChanged(object sender, SectionChangedEventArgs <LoggingSettings> args) { ILoggingUpdateHandler[] executingHandlers = null; lock (handlers) { executingHandlers = handlers.ToArray(); } var contextList = new Dictionary <ILoggingUpdateHandler, object>(); try { Array.ForEach(executingHandlers, h => contextList.Add(h, h.PrepareForUpdate(args.Container))); } catch (ActivationException e) { instrumentationProvider.FireConfigurationFailureEvent(e); return; } catch (Exception e) { instrumentationProvider.FireReconfigurationErrorEvent(e); return; } ExecuteWriteOperation(() => Array.ForEach(executingHandlers, h => h.CommitUpdate(contextList[h]))); }
public void OnSectionChanged <T>(SectionChangedEventArgs <T> sectionChangedEventArgs) where T : ConfigurationSection { Delegate handler = this.handlers[typeof(T)]; var directHandler = (EventHandler <SectionChangedEventArgs <T> >)handler; directHandler(this, sectionChangedEventArgs); }
// Helper method - looks up the appropriate event handler by type, builds the appropriate event // args, and invokes the handlers. // ReSharper disable UnusedMember.Local - this member is found and invoked via reflection private void OnSectionChanged <TSection>(TSection section, IServiceLocator container) where TSection : ConfigurationSection // ReSharper restore UnusedMember.Local { var handler = (EventHandler <SectionChangedEventArgs <TSection> >)sectionChangeHandlers[typeof(TSection)]; if (handler != null) { var eventArgs = new SectionChangedEventArgs <TSection>(section, container); handler(this, eventArgs); } }
public void Given() { eventSource = new ConfigurationChangeEventSourceImpl(); configurationSource = new DictionaryConfigurationSource(); configurationSource.Add(testsSectionName, new TestsConfigurationSection()); mockLocator = new Mock <IServiceLocator>().Object; eventSource.SourceChanged += (sender, e) => { sourceChangedEventArgs = e; }; eventSource.GetSection <TestsConfigurationSection>().SectionChanged += (sender, e) => { sectionChangedEventArgs = e; }; eventSource.GetSection <AppSettingsSection>().SectionChanged += (sender, e) => { appSettingsChangedEventArgs = e; }; eventSource.ConfigurationSourceChanged(configurationSource, mockLocator, testsSectionName); }
private void OnConfigurationChanged(object sender, SectionChangedEventArgs<MessagingSettings> args) { ILoggingUpdateHandler[] executingHandlers = null; lock (handlers) { executingHandlers = handlers.ToArray(); } var contextList = new Dictionary<ILoggingUpdateHandler, object>(); try { Array.ForEach(executingHandlers, h => contextList.Add(h, h.PrepareForUpdate(args.Container))); } catch (ActivationException e) { instrumentationProvider.FireConfigurationFailureEvent(e); return; } catch (Exception e) { instrumentationProvider.FireReconfigurationErrorEvent(e); return; } ExecuteWriteOperation(() => Array.ForEach(executingHandlers, h => h.CommitUpdate(contextList[h]))); }
public void Given() { eventSource = new ConfigurationChangeEventSourceImpl(); configurationSource = new DictionaryConfigurationSource(); configurationSource.Add(testsSectionName, new TestsConfigurationSection()); mockLocator = new Mock<IServiceLocator>().Object; eventSource.SourceChanged += (sender, e) => { sourceChangedEventArgs = e; }; eventSource.GetSection<TestsConfigurationSection>().SectionChanged += (sender, e) => { sectionChangedEventArgs = e; }; eventSource.GetSection<AppSettingsSection>().SectionChanged += (sender, e) => { appSettingsChangedEventArgs = e; }; eventSource.ConfigurationSourceChanged(configurationSource, mockLocator, testsSectionName); }