/// <summary> /// Reads the category configuration. /// </summary> /// <returns></returns> private IList<PreferenceCategory> ReadCategoryConfig() { var categories = new List<PreferenceCategory>(); var configFileName = "Configuration.xml"; var config = XmlHelper.ReadXmlFile(configFileName); if (config == null) { return null; } try { // Read the list of categories from the xml var foundCategories = config.Descendants("category"); // For each category, store the values in a new PreferenceCategory object. foreach (var foundCategory in foundCategories) { var category = new PreferenceCategory(); category.FriendlyName = XElementHelper.ReadStringValue(foundCategory, "friendlyName"); categories.Add(category); // Read the list of Preference tags var foundPreferences = XElementHelper.ReadEnumerable(foundCategory, "preference"); // For each preference Tag, store the values into a new Preference object foreach (var foundPreference in foundPreferences) { IPreference preference = new Preference(); preference.Name = XElementHelper.ReadStringValue(foundPreference, "name"); preference.FriendlyName = XElementHelper.ReadStringValue(foundPreference, "friendlyName"); preference.Description = XElementHelper.ReadStringValue(foundPreference, "description", false); preference.MinValue = XElementHelper.ReadDoubleValue(foundPreference, "minValue", false); preference.MaxValue = XElementHelper.ReadDoubleValue(foundPreference, "maxValue", false); preference.Value = XElementHelper.ReadStringValue(foundPreference, "value", false); preference.HasDirectlyEditableValue = XElementHelper.ReadBoolValue(foundPreference, "hasDirectlyEditableValue", false); category.Preferences.Add(preference); // Read the list of entryOption tags var foundEntries = XElementHelper.ReadEnumerable(foundPreference, "entryOption", false); // For each tag, read the values into a new PreferenceEntry object foreach (var entry in foundEntries) { preference.Entries.Add(this.BuildPreferenceEntry(preference, entry)); } } } } ////catch (MissingRequiredXMLPropertyException ex) ////{ ////} ////catch (MalformedXMLException ex) ////{ ////} ////catch (UnParsableDataValueException ex) ////{ ////} catch (XMLParseExceptionBase ex) { this.ShowMalformedOrMissingXMLElementError(configFileName, ex); } catch (Exception ex) { this.options.Logger.AddLogEntry(new LogEntry(ex.Message + " - " + ex.InnerException, LogEntrySeverity.Error, LogEntrySource.UI)); } return categories; }
/// <summary> /// Initializes a new instance of the <see cref="PreferencesViewModel"/> class. /// </summary> /// <param name="options">The options.</param> /// <param name="view">The view.</param> /// <param name="category">The category.</param> public PreferencesViewModel(ConverterOptions options, IView view, PreferenceCategory category) : base(view, category.FriendlyName, options) { this.Category = category; }