/// <summary> /// Handles the change of a search processor property. /// /// This method stores the configuration of the search processor in the user settings. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event arguments.</param> void SearchProcessorPropertyChanged(object sender, PropertyChangedEventArgs e) { const string SEARCH_OPTIONS_PREFIX = "SearchOptions."; var searchProcessor = sender as SearchProcessor; if (searchProcessor != null) { UserSettings.SearchProcessorSettings searchProcessorSettings = null; if (mUserSettings.SearchProcessors.TryGetValue(searchProcessor.SearchType, out searchProcessorSettings)) { if (e.PropertyName.StartsWith(SEARCH_OPTIONS_PREFIX)) { string searchOption = e.PropertyName.Substring(SEARCH_OPTIONS_PREFIX.Length); searchProcessorSettings.SearchOptions[searchOption] = searchProcessor.SearchOptions.GetOptionValue(searchOption); } else { var processorProperty = searchProcessor.GetType().GetProperty(e.PropertyName, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.SetProperty); var settingsProperty = searchProcessorSettings.GetType().GetProperty(e.PropertyName, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.SetProperty); if (settingsProperty != null && settingsProperty.CanWrite && settingsProperty.GetSetMethod() != null && processorProperty != null) { settingsProperty.SetValue(searchProcessorSettings, processorProperty.GetValue(searchProcessor, null), null); } } } } }
/// <summary> /// Initializes a search processor from user settings. /// </summary> /// <param name="userSettings">User settings, from which the search processor should be initialized.</param> /// <param name="searchProcessor">Search processor, which should be initialized.</param> private static void InitializeSearchProcessorFromUserSettings(UserSettings userSettings, SearchProcessor searchProcessor) { if (userSettings == null) { return; } UserSettings.SearchProcessorSettings searchProcessorSettings = null; if (userSettings.SearchProcessors.TryGetValue(searchProcessor.SearchType, out searchProcessorSettings)) { searchProcessor.ImmediateSearch = searchProcessorSettings.ImmediateSearch; InitializeSearchOptionsFromOptionEntries(searchProcessorSettings.SearchOptions, searchProcessor.SearchOptions); } }