/// <summary> /// Loads configuration for the specified directory and its subdirectories and file using the specified configuration node as parent node /// </summary> internal void LoadConfiguration(IConfigurationNode parentNode, IDirectory directory) { m_Logger.Info($"Loading configuration for directory '{directory.FullPath}'"); // determine configuration node for directory IConfigurationNode configNode; // config file present in directory => create new node if (directory.FileExists(s_DirectoryConfigName)) { configNode = new HierarchicalConfigurationNode(parentNode, LoadConfigurationFile(directory.GetFile(s_DirectoryConfigName))); } // no config file found => use parent node else { configNode = parentNode; } m_Mapper.AddMapping(configNode, directory); // load configuration for files in the directory foreach (var file in directory.Files) { LoadConfiguration(configNode, file); } // load configuration for subdirectories foreach (var dir in directory.Directories) { LoadConfiguration(configNode, dir); } }
protected static void DisposeNodeAction(IConfigurationNode node) { if (node is IDisposable) { ((IDisposable)node).Dispose(); } }
/// <summary> /// Adds all supported settings in the specified <paramref name="sectionOrGroupNode"/> to the specified /// <paramref name="settingsList"/>. For each setting, a <see cref="ListItem"/> will be created /// with the setting text as name and a command which triggers the method <see cref="ShowConfigItem"/> /// with the according setting location. /// </summary> /// <param name="sectionOrGroupNode">Section or group node, whose contained settings should be added.</param> /// <param name="settingsList">List where the extracted settings will be added to.</param> protected void AddConfigSettings(IConfigurationNode sectionOrGroupNode, ItemsList settingsList) { foreach (IConfigurationNode childNode in sectionOrGroupNode.ChildNodes) { if (childNode.ConfigObj is ConfigSetting) { ConfigSetting setting = (ConfigSetting)childNode.ConfigObj; if (!setting.Visible || !IsSettingSupported(setting)) { continue; } string location = childNode.Location; ListItem item = new ListItem(KEY_NAME, setting.SettingMetadata.Text) { Command = new MethodDelegateCommand(() => ShowConfigItem(location)) }; item.SetLabel(KEY_HELPTEXT, setting.SettingMetadata.HelpText); item.Enabled = setting.Enabled; TrackItemVisibleEnabledProperty(setting.VisibleProperty); TrackItemVisibleEnabledProperty(setting.EnabledProperty); settingsList.Add(item); } if (childNode.ConfigObj is ConfigGroup) { AddConfigSettings(childNode, settingsList); } } }
void SerializeSetting(string name, IConfigurationNode configurationNode, JObject json) { // name has sub-key if (name.Contains(":")) { var prefix = name.Split(':').First(); // get or create the inner json object for the sub-keys var innerJson = json[prefix] as JObject; if (innerJson == null) { innerJson = new JObject(); json[prefix] = innerJson; } // serialize setting (remove prefix from name) var newName = name.Remove(0, prefix.Length + 1); SerializeSetting(newName, new PrefixConfigurationNode(configurationNode, prefix), innerJson); } // no subkeys => write setting to current json object else { var value = configurationNode.GetValue(name); json[name] = value; } }
/// <summary> /// Searches for a configuration node which best matches the specified <paramref name="searchMatcher"/> /// in the given <paramref name="startNode"/> and subnodes. /// </summary> /// <param name="startNode">Node to search through.</param> /// <param name="searchMatcher">Pattern which does the matching.</param> /// <param name="bestMatch">Location of the best matching configuration node for the /// search value.</param> /// <param name="bestScore">Score of the best match.</param> /// <returns>Enumeration of matching configuration nodes.</returns> protected static ICollection<IConfigurationNode> Search(IConfigurationNode startNode, ConfigObjectSearchMatcher searchMatcher, out IConfigurationNode bestMatch, out float bestScore) { bestMatch = null; List<IConfigurationNode> result = new List<IConfigurationNode>(); // Check current node (the node may have no config object assigned if it is the root node or // if we have a section in use which was not defined) bestScore = startNode.ConfigObj == null ? 0 : searchMatcher.CalculateMatchQuality(startNode.ConfigObj); if (bestScore > 0) { bestMatch = startNode; result.Add(startNode); } // Check children foreach (ConfigurationNode childNode in startNode.ChildNodes) { IConfigurationNode match; float score; result.AddRange(Search(childNode, searchMatcher, out match, out score)); if (score > bestScore) { bestMatch = match; bestScore = score; } } return result; }
/// <summary> /// Searches for a configuration node which best matches the specified <paramref name="searchMatcher"/> /// in the given <paramref name="startNode"/> and subnodes. /// </summary> /// <param name="startNode">Node to search through.</param> /// <param name="searchMatcher">Pattern which does the matching.</param> /// <param name="bestMatch">Location of the best matching configuration node for the /// search value.</param> /// <param name="bestScore">Score of the best match.</param> /// <returns>Enumeration of matching configuration nodes.</returns> protected static ICollection <IConfigurationNode> Search(IConfigurationNode startNode, ConfigObjectSearchMatcher searchMatcher, out IConfigurationNode bestMatch, out float bestScore) { bestMatch = null; List <IConfigurationNode> result = new List <IConfigurationNode>(); // Check current node (the node may have no config object assigned if it is the root node or // if we have a section in use which was not defined) bestScore = startNode.ConfigObj == null ? 0 : searchMatcher.CalculateMatchQuality(startNode.ConfigObj); if (bestScore > 0) { bestMatch = startNode; result.Add(startNode); } // Check children foreach (ConfigurationNode childNode in startNode.ChildNodes) { IConfigurationNode match; float score; result.AddRange(Search(childNode, searchMatcher, out match, out score)); if (score > bestScore) { bestMatch = match; bestScore = score; } } return(result); }
/// <summary> /// Gets a node with the specified name that is a child of the current node. /// </summary> /// <param name="name"> /// A string specifying the name of the node. The name is case-insensitive. /// </param> /// <returns> /// A child node with the specified name or <c>null</c> if the node is not /// found. /// </returns> protected internal virtual IConfigurationNode this[string name] { get { IConfigurationNode node = null; child_nodes_.TryGetValue(name, out node); return(node); } set { child_nodes_[name] = value; } }
/// <summary> /// Returns if the specified location can be found in the tree. /// If found, it <paramref name="node"/> will be returned. /// </summary> /// <param name="location">Location to search for. Has to be absolute (starting with "/" character).</param> /// <param name="node">Node to be returned. If this method returns <c>false</c>, this parameter /// is undefined.</param> /// <returns><c>true</c>, if the node at the specified <paramref name="location"/> exists, /// else <c>false</c>.</returns> public bool FindNode(string location, out IConfigurationNode node) { if (!RegistryHelper.IsAbsolutePath(location)) { throw new ArgumentException(string.Format("ConfigurationTree: Node location has to be absolute (argument was: '{0}')", location)); } return(_root.FindNode(RegistryHelper.RemoveRootFromAbsolutePath(location), out node)); }
protected static void SaveNodeAction(IConfigurationNode node) { ConfigSetting cs = node.ConfigObj as ConfigSetting; if (cs != null) { cs.Save(); } }
public ConfigurationLoader(IConfigurationMapper mapper, IDefaultConfigurationNode defaultConfiguration) { if (mapper == null) { throw new ArgumentNullException(nameof(mapper)); } m_Mapper = mapper; m_DefaultConfiguration = defaultConfiguration; }
public HierarchicalConfigurationNode(IConfigurationNode parentNode, IConfiguration configuration) { if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } m_ParentNode = parentNode; m_Configuration = configuration; }
protected IConfigurationNode GetRootNode() { IConfigurationNode current = this; while (current.Parent != null) { current = current.Parent; } return(current); }
public ConfigurationLoader(IConfigurationMapper mapper, IDefaultConfigurationNode defaultConfiguration) { if(mapper == null) { throw new ArgumentNullException(nameof(mapper)); } m_Mapper = mapper; m_DefaultConfiguration = defaultConfiguration; }
public void WriteConfiguration(IConfigurationNode configuration, string outputPath) { // create root config json object var json = new JObject(); //serialize all settings of the node foreach (var name in configuration.Names) { SerializeSetting(name, configuration, json); } // write json to file File.WriteAllText(outputPath, json.ToString(Formatting.Indented)); }
protected void UpdateConfigSettingsAndHeader() { _configSettingsList.Clear(); IConfigurationManager configurationManager = ServiceRegistration.Get <IConfigurationManager>(); IConfigurationNode currentNode = configurationManager.GetNode(_currentLocation); if (currentNode == null) { // This is an error case, should not happen return; } AddConfigSettings(currentNode, _configSettingsList); _configSettingsList.FireChange(); ConfigBase configObj = currentNode.ConfigObj; HeaderText = configObj == null ? RES_CONFIGURATION_NAME : configObj.Metadata.Text; }
public MusicFileCop(IFileSystemLoader fileSystemLoader, IConfigurationLoader configurationLoader, IMetadataLoader metadataLoader, IConsistencyChecker consistencyChecker, IDefaultConfigurationNode defaultConfiguration, IConfigurationWriter configWriter, ITextOutputWriter outputWriter, IRuleSet ruleSet) { if (fileSystemLoader == null) { throw new ArgumentNullException(nameof(fileSystemLoader)); } if (configurationLoader == null) { throw new ArgumentNullException(nameof(configurationLoader)); } if (metadataLoader == null) { throw new ArgumentNullException(nameof(metadataLoader)); } if (consistencyChecker == null) { throw new ArgumentNullException(nameof(consistencyChecker)); } if (defaultConfiguration == null) { throw new ArgumentNullException(nameof(defaultConfiguration)); } if (configWriter == null) { throw new ArgumentNullException(nameof(configWriter)); } if (outputWriter == null) { throw new ArgumentNullException(nameof(outputWriter)); } if (ruleSet == null) { throw new ArgumentNullException(nameof(ruleSet)); } this.m_FileSystemLoader = fileSystemLoader; this.m_ConfigLoader = configurationLoader; this.m_MetadataLoader = metadataLoader; this.m_ConsistencyChecker = consistencyChecker; this.m_DefaultConfiguration = defaultConfiguration; m_ConfigWriter = configWriter; m_OutputWriter = outputWriter; m_RuleSet = ruleSet; }
/// <summary> /// Initializes the model state variables for the GUI to be used in the screen for the configuration /// item of the specified <paramref name="configLocation"/> and shows the screen. /// </summary> /// <param name="configLocation">The configuration location to be shown.</param> public void ShowConfigItem(string configLocation) { _currentLocation = configLocation; IConfigurationManager configurationManager = ServiceRegistration.Get <IConfigurationManager>(); IConfigurationNode currentNode = configurationManager.GetNode(configLocation); ConfigSetting configSetting = currentNode == null ? null : currentNode.ConfigObj as ConfigSetting; _currentConfigController = FindConfigurationController(configSetting); if (_currentConfigController == null) { // Error case: We don't have a configuration controller for the setting to be shown ServiceRegistration.Get <ILogger>().Warn( "ConfigurationModel: Cannot show configuration for setting '{0}', no configuration controller available", configSetting); return; } _currentConfigController.Initialize(configSetting); _currentConfigController.ExecuteConfiguration(); }
public void UpdateMenuActions(NavigationContext context, IDictionary <Guid, WorkflowAction> actions) { IConfigurationManager configurationManager = ServiceRegistration.Get <IConfigurationManager>(); string configLocation = GetConfigLocation(context); WorkflowState mainState; ServiceRegistration.Get <IWorkflowManager>().States.TryGetValue(new Guid(CONFIGURATION_MAIN_STATE_ID_STR), out mainState); IConfigurationNode currentNode = configurationManager.GetNode(configLocation); foreach (IConfigurationNode childNode in currentNode.ChildNodes) { if (childNode.ConfigObj is ConfigSection) { bool supportedSettings = NumSettingsSupported(childNode) > 0; // Hint (Albert): Instead of skipping, we could disable the transition in case there are no supported // settings contained in it if (!supportedSettings) { continue; } ConfigSection section = (ConfigSection)childNode.ConfigObj; // Create transient state for new config section WorkflowState newState = WorkflowState.CreateTransientState( string.Format("Config: '{0}'", childNode.Location), section.SectionMetadata.Text, false, CONFIGURATION_SECTION_SCREEN, false, WorkflowType.Workflow, context.WorkflowState.HideGroups); // Add action for menu IResourceString res = LocalizationHelper.CreateResourceString(section.Metadata.Text); WorkflowAction wa = new PushTransientStateNavigationTransition( Guid.NewGuid(), context.WorkflowState.Name + "->" + childNode.Location, null, new Guid[] { context.WorkflowState.StateId }, newState, res) { DisplayCategory = ACTIONS_WORKFLOW_CATEGORY, SortOrder = childNode.Sort ?? res.Evaluate(), WorkflowNavigationContextVariables = new Dictionary <string, object> { { CONFIG_LOCATION_KEY, childNode.Location } } }; actions.Add(wa.ActionId, wa); } } }
/// <summary> /// Returns the information if the specified location can be found in the tree. /// If found, the <paramref name="node"/> will be returned. /// </summary> /// <param name="location">Location to search for. May be absolute or relative.</param> /// <param name="node">Node to be returned. If this method returns <c>false</c>, this parameter /// is undefined.</param> /// <returns><c>true</c>, if the node at the specified <paramref name="location"/> exists, /// else <c>false</c>.</returns> public bool FindNode(string location, out IConfigurationNode node) { node = RegistryHelper.IsAbsolutePath(location) ? GetRootNode() : this; string[] locEntries = location.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); foreach (string locEntry in locEntries) { if (locEntry == ".") { continue; } node = locEntry == ".." ? node.Parent : node.GetSubNodeById(locEntry); if (node == null) { return(false); } } return(true); }
private static IList <ConfigSection> GetSections(IConfigurationManager manager, string parentLocation) { List <ConfigSection> result = new List <ConfigSection>(); // Get the collection containing the nodes IConfigurationNode parentNode = manager.GetNode(parentLocation); if (parentNode == null) { return(null); } // Section found, get subsections foreach (IConfigurationNode node in parentNode.ChildNodes) { if (node.ConfigObj is ConfigSection) { result.Add((ConfigSection)node.ConfigObj); } } return(result); }
/// <summary> /// Returns the number of supported settings in or under the specified <paramref name="sectionOrGroupNode"/>. /// </summary> /// <param name="sectionOrGroupNode">Section or group node to check.</param> /// <returns>Number of supported settings in the specified node.</returns> protected int NumSettingsSupported(IConfigurationNode sectionOrGroupNode) { int result = 0; foreach (IConfigurationNode childNode in sectionOrGroupNode.ChildNodes) { if (childNode.ConfigObj is ConfigSetting) { if (IsSettingSupported((ConfigSetting)childNode.ConfigObj)) { result++; } } else if (childNode.ConfigObj is ConfigGroup || childNode.ConfigObj is ConfigSection) { result += NumSettingsSupported(childNode); } } return(result); }
public PrefixConfigurationNode(IConfigurationNode wrappedConfigurationNode, string prefix) { if (wrappedConfigurationNode == null) { throw new ArgumentNullException(nameof(wrappedConfigurationNode)); } if (prefix == null) { throw new ArgumentNullException(nameof(prefix)); } if (string.IsNullOrEmpty(prefix)) { throw new ArgumentException("Prefix must not be empty", nameof(prefix)); } m_WrappedConfigurationNode = wrappedConfigurationNode; m_Prefix = prefix; }
/// <summary> /// Returns the number of supported settings in or under the specified <paramref name="sectionOrGroupNode"/>. /// </summary> /// <param name="sectionOrGroupNode">Section or group node to check.</param> /// <returns>Number of supported settings in the specified node.</returns> protected bool AnySettingsSupported(IConfigurationNode sectionOrGroupNode) { foreach (IConfigurationNode childNode in sectionOrGroupNode.ChildNodes) { if (childNode.ConfigObj is ConfigSetting) { if (IsSettingSupported((ConfigSetting)childNode.ConfigObj)) { return(true); } } else if (childNode.ConfigObj is ConfigGroup || childNode.ConfigObj is ConfigSection) { if (AnySettingsSupported(childNode)) { return(true); } } } return(false); }
/// <summary> /// Loads configuration for the specified file using the specified configuration node as parent node /// </summary> internal void LoadConfiguration(IConfigurationNode parentNode, IFile file) { m_Logger.Info($"Loading configuration for file '{file.FullPath}'"); // determine the configuration node to associate with the file IConfigurationNode configNode; var configFileName = String.Format(s_FileConfigName, file.NameWithExtension); // there is a file-specific configuration file => create new config node if (file.Directory.FileExists(configFileName)) { configNode = new HierarchicalConfigurationNode(parentNode, LoadConfigurationFile(file.Directory.GetFile(configFileName))); } // no config file found => use parent node else { configNode = parentNode; } // associate configuration node with file m_Mapper.AddMapping(configNode, file); }
/// <summary> /// Returns the information if the specified location can be found in the tree. /// If found, the <paramref name="node"/> will be returned. /// </summary> /// <param name="location">Location to search for. May be absolute or relative.</param> /// <param name="node">Node to be returned. If this method returns <c>false</c>, this parameter /// is undefined.</param> /// <returns><c>true</c>, if the node at the specified <paramref name="location"/> exists, /// else <c>false</c>.</returns> public bool FindNode(string location, out IConfigurationNode node) { node = RegistryHelper.IsAbsolutePath(location) ? GetRootNode() : this; string[] locEntries = location.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); foreach (string locEntry in locEntries) { if (locEntry == ".") continue; node = locEntry == ".." ? node.Parent : node.GetSubNodeById(locEntry); if (node == null) return false; } return true; }
/// <summary> /// Initializes a new instance of SearchResult /// based on the given <paramref name="matches"/> and the specified <paramref name="bestMatch"/>. /// </summary> /// <param name="matches">All matching instances of <see cref="IConfigurationNode"/>.</param> /// <param name="bestMatch">The best matching instance of <see cref="IConfigurationNode"/>.</param> public SearchResult(IEnumerable<IConfigurationNode> matches, IConfigurationNode bestMatch) { _matches = matches; _bestMatch = bestMatch; }
public DefaultConfigurationNode(IConfigurationNode wrappedConfigurationNode) { m_WrappedConfigurationNode = wrappedConfigurationNode; }
/// <summary> /// Initializes a new instance of SearchResult /// based on the given <paramref name="matches"/> and the specified <paramref name="bestMatch"/>. /// </summary> /// <param name="matches">All matching instances of <see cref="IConfigurationNode"/>.</param> /// <param name="bestMatch">The best matching instance of <see cref="IConfigurationNode"/>.</param> public SearchResult(IEnumerable <IConfigurationNode> matches, IConfigurationNode bestMatch) { _matches = matches; _bestMatch = bestMatch; }
public void AddMapping(IConfigurationNode configurationNode, IFile file) => m_InnerMapper.AddMapping(configurationNode, file);
/// <summary> /// Returns if the specified location can be found in the tree. /// If found, it <paramref name="node"/> will be returned. /// </summary> /// <param name="location">Location to search for. Has to be absolute (starting with "/" character).</param> /// <param name="node">Node to be returned. If this method returns <c>false</c>, this parameter /// is undefined.</param> /// <returns><c>true</c>, if the node at the specified <paramref name="location"/> exists, /// else <c>false</c>.</returns> public bool FindNode(string location, out IConfigurationNode node) { if (!RegistryHelper.IsAbsolutePath(location)) throw new ArgumentException(string.Format("ConfigurationTree: Node location has to be absolute (argument was: '{0}')", location)); return _root.FindNode(RegistryHelper.RemoveRootFromAbsolutePath(location), out node); }
/// <summary> /// Adds the specified node to the internal collection of /// <see cref="AbstractHierarchicalConfigurationNode"/>. /// </summary> /// <param name="node"> /// An <see cref="IConfigurationNode"/> to be added to /// the child nodes collection. /// </param> /// <param name="node_key"> /// An string that uniquelly identifies the given configuration node. /// </param> protected virtual void AddChildNode(string node_key, IConfigurationNode node) { child_nodes_.Add(node_key, node); }
/// <summary> /// Builds the specified node to a Panel. /// </summary> /// <param name="node">Node to build to the Panel.</param> /// <param name="position">Defines the positioning parameters.</param> /// <returns></returns> private Panel BuildToPanel(IConfigurationNode node, Position position) { Panel panel = new Panel(); panel.Tag = node == null ? null : node.ConfigObj; panel.AutoSize = false; panel.Height = 0; panel.Width = position.FullWidth; panel.Padding = new Padding(0, 0, 0, 0); panel.Margin = new Padding(0, 0, 0, 0); if (node == null || node.ConfigObj == null) return panel; // Return empty panel panel.Name = string.Format("{0}_{1}", node.Location, node.ConfigObj); // Add heading if (node.ConfigObj is ConfigGroup) { panel.Controls.Add(CreateHeading(position, node.ConfigObj.Text.Evaluate())); position.LinePosition += position.LineHeight; } // Add subcontrols foreach (IConfigurationNode subNode in node.ChildNodes) { if (subNode.ConfigObj.Hidden) continue; if (subNode.ConfigObj is ConfigGroup) { Position pos = (Position) position.Clone(); pos.StartColumnOne += pos.Indent; // indent the first column pos.WidthColumnOne -= pos.Indent; // shorten the width, so it doesn't overlap with column two pos.LinePosition = 0; // reset linePosition, this is relative to the new control // Make a recursive call to process the group to a Panel Panel subPanel = BuildToPanel(subNode, pos); subPanel.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; subPanel.Location = new Point(0, position.LinePosition); subPanel.Enabled = !subNode.ConfigObj.Disabled; panel.Controls.Add(subPanel); position.LinePosition += pos.LinePosition; } else if (subNode.ConfigObj is ConfigSetting) { ConfigSetting setting = (ConfigSetting) subNode.ConfigObj; setting.OnChangeEvent += _configChangedHandler; if (setting is Entry) { panel.Controls.Add(CreateLabel(position, setting.Text.Evaluate())); TextBox txt = CreateTextBox(position, setting.Columns); txt.Text = ((Entry) setting).Value; txt.Tag = setting; SetHelp(txt, setting.Help.Evaluate()); txt.Enabled = !setting.Disabled; panel.Controls.Add(txt); position.LinePosition += position.LineHeight + position.Margin; } else if (setting is LimitedNumberSelect) { int height; panel.Controls.Add(CreateLabel(position, setting.Text.Evaluate(), position.Width, out height)); panel.Controls.Add(CreateLimitedNumberSelect(position, (LimitedNumberSelect) setting)); position.LinePosition += height + position.Margin; } else if (setting is MultipleEntryList) { panel.Controls.Add(CreateLabel(position, setting.Text.Evaluate())); position.LinePosition += position.LineHeight; TextBox txt = CreateMultiLineTextBox(position, setting.Rows); txt.Tag = setting; MultipleEntryList entryList = (MultipleEntryList) setting; txt.Lines = new string[entryList.Lines.Count]; for (int i = 0; i < txt.Lines.Length; i++) txt.Lines[i] = entryList.Lines[i]; SetHelp(txt, setting.Help.Evaluate()); txt.Enabled = !setting.Disabled; panel.Controls.Add(txt); position.LinePosition += txt.Height + position.Margin; } else if (setting is MultipleSelectionList) { int lblHeight; panel.Controls.Add(CreateLabel(position, setting.Text.Evaluate(), position.WidthColumnOne, out lblHeight)); position.LinePosition += lblHeight + position.Margin; CheckedListBox chk = CreateCheckedListBox(position); MultipleSelectionList list = ((MultipleSelectionList) setting); for (int i = 0; i < list.Items.Count; i++) chk.Items.Add(list.Items[i], list.SelectedIndices.Contains(i)); chk.Enabled = !setting.Disabled; panel.Controls.Add(chk); position.LinePosition += chk.Height + position.Margin; } else if (setting is NumberSelect) { int height; panel.Controls.Add(CreateLabel(position, setting.Text.Evaluate(), position.Width, out height)); panel.Controls.Add(CreateNumberSelect(position, (NumberSelect) setting)); position.LinePosition += height + position.Margin; } else if (setting is Path) { int height; panel.Controls.Add(CreateLabel(position, setting.Text.Evaluate(), position.Width, out height)); position.LinePosition += height + position.Margin; Panel browse = CreateBrowseEntry(position, (Path) setting); panel.Controls.Add(browse); position.LinePosition += browse.Height + position.Margin; } else if (setting is PreferenceList) { int height; panel.Controls.Add(CreateLabel(position, setting.Text.Evaluate(), position.Width, out height)); position.LinePosition += height + position.Margin; Panel list = CreatePreferenceList(position, (PreferenceList) setting); panel.Controls.Add(list); position.LinePosition += list.Height + position.Margin; } else if (setting is SingleSelectionList) { int lblHeight; panel.Controls.Add(CreateLabel(position, setting.Text.Evaluate(), position.WidthColumnOne, out lblHeight)); lblHeight += position.Margin; if (((SingleSelectionList) setting).Items.Count > 3) // ComboBox { ComboBox cmb = CreateComboBox(position); foreach (IResourceString item in ((SingleSelectionList)setting).Items) cmb.Items.Add(item.Evaluate()); cmb.SelectedIndex = ((SingleSelectionList) setting).Selected; cmb.Tag = setting; SetHelp(cmb, setting.Help.Evaluate()); cmb.Enabled = !setting.Disabled; panel.Controls.Add(cmb); if (lblHeight > position.LineHeight) position.LinePosition += (position.ItemHeight*(lblHeight/(position.ItemHeight*2))); position.LinePosition += position.LineHeight; } else // 3 or less items: Radiobuttons { Panel radioPanel = CreateRadioPanel(position, (SingleSelectionList) setting); panel.Enabled = !setting.Disabled; panel.Controls.Add(radioPanel); position.LinePosition += radioPanel.Height + position.Margin; } } else if (setting is YesNo) { int lblHeight; panel.Controls.Add(CreateLabel(position, setting.Text.Evaluate(), position.WidthColumnOne, out lblHeight)); lblHeight += position.Margin; CheckBox chk = CreateCheckBox(position); chk.Checked = ((YesNo) setting).Yes; chk.Tag = setting; SetHelp(chk, setting.Help.Evaluate()); chk.Enabled = !setting.Disabled; panel.Controls.Add(chk); if (lblHeight > position.LineHeight) position.LinePosition += (position.ItemHeight*(lblHeight/(position.ItemHeight*2))); position.LinePosition += position.LineHeight; } } } panel.Height = position.LinePosition; return panel; }
/// <summary> /// Adds all supported settings in the specified <paramref name="sectionOrGroupNode"/> to the specified /// <paramref name="settingsList"/>. For each setting, a <see cref="ListItem"/> will be created /// with the setting text as name and a command which triggers the method <see cref="ShowConfigItem"/> /// with the according setting location. /// </summary> /// <param name="sectionOrGroupNode">Section or group node, whose contained settings should be added.</param> /// <param name="settingsList">List where the extracted settings will be added to.</param> protected void AddConfigSettings(IConfigurationNode sectionOrGroupNode, ItemsList settingsList) { foreach (IConfigurationNode childNode in sectionOrGroupNode.ChildNodes) { if (childNode.ConfigObj is ConfigSetting) { ConfigSetting setting = (ConfigSetting) childNode.ConfigObj; if (!setting.Visible || !IsSettingSupported(setting)) continue; string location = childNode.Location; ListItem item = new ListItem(KEY_NAME, setting.SettingMetadata.Text) { Command = new MethodDelegateCommand(() => ShowConfigItem(location)) }; item.SetLabel(KEY_HELPTEXT, setting.SettingMetadata.HelpText); item.Enabled = setting.Enabled; TrackItemVisibleEnabledProperty(setting.VisibleProperty); TrackItemVisibleEnabledProperty(setting.EnabledProperty); settingsList.Add(item); } if (childNode.ConfigObj is ConfigGroup) AddConfigSettings(childNode, settingsList); } }
public void AddMapping(IConfigurationNode configurationNode, IFile file) => m_FileToConfigMapping.Add(file, configurationNode);
protected static void DisposeNodeAction(IConfigurationNode node) { if (node is IDisposable) ((IDisposable) node).Dispose(); }
protected static void SaveNodeAction(IConfigurationNode node) { ConfigSetting cs = node.ConfigObj as ConfigSetting; if (cs != null) cs.Save(); }
/// <summary> /// Builds the specified node to a Panel. /// </summary> /// <param name="node">Node to build to the Panel.</param> /// <param name="position">Defines the positioning parameters.</param> /// <returns></returns> private Panel BuildToPanel(IConfigurationNode node, Position position) { Panel panel = new Panel(); panel.Tag = node == null ? null : node.ConfigObj; panel.AutoSize = false; panel.Height = 0; panel.Width = position.FullWidth; panel.Padding = new Padding(0, 0, 0, 0); panel.Margin = new Padding(0, 0, 0, 0); if (node == null || node.ConfigObj == null) { return(panel); // Return empty panel } panel.Name = string.Format("{0}_{1}", node.Location, node.ConfigObj); // Add heading if (node.ConfigObj is ConfigGroup) { panel.Controls.Add(CreateHeading(position, node.ConfigObj.Text.Evaluate())); position.LinePosition += position.LineHeight; } // Add subcontrols foreach (IConfigurationNode subNode in node.ChildNodes) { if (subNode.ConfigObj.Hidden) { continue; } if (subNode.ConfigObj is ConfigGroup) { Position pos = (Position)position.Clone(); pos.StartColumnOne += pos.Indent; // indent the first column pos.WidthColumnOne -= pos.Indent; // shorten the width, so it doesn't overlap with column two pos.LinePosition = 0; // reset linePosition, this is relative to the new control // Make a recursive call to process the group to a Panel Panel subPanel = BuildToPanel(subNode, pos); subPanel.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; subPanel.Location = new Point(0, position.LinePosition); subPanel.Enabled = !subNode.ConfigObj.Disabled; panel.Controls.Add(subPanel); position.LinePosition += pos.LinePosition; } else if (subNode.ConfigObj is ConfigSetting) { ConfigSetting setting = (ConfigSetting)subNode.ConfigObj; setting.OnChangeEvent += _configChangedHandler; if (setting is Entry) { panel.Controls.Add(CreateLabel(position, setting.Text.Evaluate())); TextBox txt = CreateTextBox(position, setting.Columns); txt.Text = ((Entry)setting).Value; txt.Tag = setting; SetHelp(txt, setting.Help.Evaluate()); txt.Enabled = !setting.Disabled; panel.Controls.Add(txt); position.LinePosition += position.LineHeight + position.Margin; } else if (setting is LimitedNumberSelect) { int height; panel.Controls.Add(CreateLabel(position, setting.Text.Evaluate(), position.Width, out height)); panel.Controls.Add(CreateLimitedNumberSelect(position, (LimitedNumberSelect)setting)); position.LinePosition += height + position.Margin; } else if (setting is MultipleEntryList) { panel.Controls.Add(CreateLabel(position, setting.Text.Evaluate())); position.LinePosition += position.LineHeight; TextBox txt = CreateMultiLineTextBox(position, setting.Rows); txt.Tag = setting; MultipleEntryList entryList = (MultipleEntryList)setting; txt.Lines = new string[entryList.Lines.Count]; for (int i = 0; i < txt.Lines.Length; i++) { txt.Lines[i] = entryList.Lines[i]; } SetHelp(txt, setting.Help.Evaluate()); txt.Enabled = !setting.Disabled; panel.Controls.Add(txt); position.LinePosition += txt.Height + position.Margin; } else if (setting is MultipleSelectionList) { int lblHeight; panel.Controls.Add(CreateLabel(position, setting.Text.Evaluate(), position.WidthColumnOne, out lblHeight)); position.LinePosition += lblHeight + position.Margin; CheckedListBox chk = CreateCheckedListBox(position); MultipleSelectionList list = ((MultipleSelectionList)setting); for (int i = 0; i < list.Items.Count; i++) { chk.Items.Add(list.Items[i], list.SelectedIndices.Contains(i)); } chk.Enabled = !setting.Disabled; panel.Controls.Add(chk); position.LinePosition += chk.Height + position.Margin; } else if (setting is NumberSelect) { int height; panel.Controls.Add(CreateLabel(position, setting.Text.Evaluate(), position.Width, out height)); panel.Controls.Add(CreateNumberSelect(position, (NumberSelect)setting)); position.LinePosition += height + position.Margin; } else if (setting is Path) { int height; panel.Controls.Add(CreateLabel(position, setting.Text.Evaluate(), position.Width, out height)); position.LinePosition += height + position.Margin; Panel browse = CreateBrowseEntry(position, (Path)setting); panel.Controls.Add(browse); position.LinePosition += browse.Height + position.Margin; } else if (setting is PreferenceList) { int height; panel.Controls.Add(CreateLabel(position, setting.Text.Evaluate(), position.Width, out height)); position.LinePosition += height + position.Margin; Panel list = CreatePreferenceList(position, (PreferenceList)setting); panel.Controls.Add(list); position.LinePosition += list.Height + position.Margin; } else if (setting is SingleSelectionList) { int lblHeight; panel.Controls.Add(CreateLabel(position, setting.Text.Evaluate(), position.WidthColumnOne, out lblHeight)); lblHeight += position.Margin; if (((SingleSelectionList)setting).Items.Count > 3) // ComboBox { ComboBox cmb = CreateComboBox(position); foreach (IResourceString item in ((SingleSelectionList)setting).Items) { cmb.Items.Add(item.Evaluate()); } cmb.SelectedIndex = ((SingleSelectionList)setting).Selected; cmb.Tag = setting; SetHelp(cmb, setting.Help.Evaluate()); cmb.Enabled = !setting.Disabled; panel.Controls.Add(cmb); if (lblHeight > position.LineHeight) { position.LinePosition += (position.ItemHeight * (lblHeight / (position.ItemHeight * 2))); } position.LinePosition += position.LineHeight; } else // 3 or less items: Radiobuttons { Panel radioPanel = CreateRadioPanel(position, (SingleSelectionList)setting); panel.Enabled = !setting.Disabled; panel.Controls.Add(radioPanel); position.LinePosition += radioPanel.Height + position.Margin; } } else if (setting is YesNo) { int lblHeight; panel.Controls.Add(CreateLabel(position, setting.Text.Evaluate(), position.WidthColumnOne, out lblHeight)); lblHeight += position.Margin; CheckBox chk = CreateCheckBox(position); chk.Checked = ((YesNo)setting).Yes; chk.Tag = setting; SetHelp(chk, setting.Help.Evaluate()); chk.Enabled = !setting.Disabled; panel.Controls.Add(chk); if (lblHeight > position.LineHeight) { position.LinePosition += (position.ItemHeight * (lblHeight / (position.ItemHeight * 2))); } position.LinePosition += position.LineHeight; } } } panel.Height = position.LinePosition; return(panel); }
/// <summary> /// Returns the number of supported settings in or under the specified <paramref name="sectionOrGroupNode"/>. /// </summary> /// <param name="sectionOrGroupNode">Section or group node to check.</param> /// <returns>Number of supported settings in the specified node.</returns> protected int NumSettingsSupported(IConfigurationNode sectionOrGroupNode) { int result = 0; foreach (IConfigurationNode childNode in sectionOrGroupNode.ChildNodes) { if (childNode.ConfigObj is ConfigSetting) { if (IsSettingSupported((ConfigSetting) childNode.ConfigObj)) result++; } else if (childNode.ConfigObj is ConfigGroup || childNode.ConfigObj is ConfigSection) result += NumSettingsSupported(childNode); } return result; }
public void AddMapping(IConfigurationNode configurationNode, IDirectory directory) => m_InnerMapper.AddMapping(configurationNode, directory);
public void AddMapping(IConfigurationNode configurationNode, IDirectory directory) => m_DirectoryToConfigMapping.Add(directory, configurationNode);