/// <summary> /// Returns the word definitions with the specified name. /// </summary> /// <param name="name">The name of the script words to return.</param> /// <param name="parentDefinition">The parent definition.</param> /// <returns>The script words with the specified name.</returns> public Dictionary <string, IBdoScriptwordDefinition> GetDefinitionsWithExactName( string name, IBdoScriptwordDefinition parentDefinition = null) { var matchingDefinitions = new Dictionary <string, IBdoScriptwordDefinition>(); if (name != null) { Dictionary <string, IBdoScriptwordDefinition> poolScriptwordDefinitions = null; if (parentDefinition == null) { poolScriptwordDefinitions = Definitions; } else if (parentDefinition.Children != null) { poolScriptwordDefinitions = parentDefinition.Children; } matchingDefinitions = new Dictionary <string, IBdoScriptwordDefinition>(); if (poolScriptwordDefinitions != null) { foreach (var def in poolScriptwordDefinitions.Where(p => p.Value?.Dto?.Name.KeyEquals(name) == true).Select(p => p.Value)) { matchingDefinitions.Add(def.UniqueId, def); } } } return(matchingDefinitions); }
/// <summary> /// Gets the word definitions approximatively with the specified name. /// </summary> /// <param name="name">The name of the script words to return.</param> /// <param name="parentDefinition">The parent definition.</param> /// <returns>The script words with the specified name.</returns> public Dictionary <string, IBdoScriptwordDefinition> GetDefinitionsWithApproximativeName( string name, IBdoScriptwordDefinition parentDefinition = null) { var matchingDefinitions = new Dictionary <string, IBdoScriptwordDefinition>(); if (name == null) { return(matchingDefinitions); } Dictionary <string, IBdoScriptwordDefinition> poolScriptwordDefinitions = null; if (parentDefinition == null) { poolScriptwordDefinitions = Definitions; } else if (parentDefinition.Children != null) { poolScriptwordDefinitions = new Dictionary <string, IBdoScriptwordDefinition>(parentDefinition.Children); } matchingDefinitions = new Dictionary <string, IBdoScriptwordDefinition>(); if (poolScriptwordDefinitions != null) { foreach (var def in poolScriptwordDefinitions.Where(p => p.Value?.Dto?.Name.IndexOf(name, StringComparison.OrdinalIgnoreCase) > 0).Select(p => p.Value)) { matchingDefinitions.Add(def.UniqueId, def); } } return(matchingDefinitions); }
private void BuildScriptwordTree( IBdoScriptwordDictionaryDto dictionaryDto, List <BdoScriptwordDefinition> allDefinitions, IBdoLog log = null, IBdoScriptwordDefinition parentDefinition = null) { if (dictionaryDto == null) { return; } List <BdoScriptwordDefinitionDto> scriptWordDefinitionDtos = parentDefinition == null ? dictionaryDto.Definitions : parentDefinition?.Dto.Children; // we recursively retrieve the sub script words foreach (IBdoScriptwordDefinitionDto definitionDto in scriptWordDefinitionDtos) { // if the current script word is a reference then if (!string.IsNullOrEmpty(definitionDto.ReferenceUniqueName)) { // we retrieve the reference script word IBdoScriptwordDefinition referenceScriptwordDefinition = allDefinitions.Find(p => p.KeyEquals(definitionDto.ReferenceUniqueName) == true); if (referenceScriptwordDefinition == null) { log?.AddError( title: "Child reference '" + definitionDto.ReferenceUniqueName + "' not found in index for script word '" + definitionDto.Key() + "'"); } else { parentDefinition?.Children?.Add(referenceScriptwordDefinition.UniqueId?.ToUpper(), referenceScriptwordDefinition); } } else { IBdoScriptwordDefinition definition = allDefinitions.Find(p => p.Dto?.KeyEquals(definitionDto) == true); if (definition == null) { log?.AddError(title: "Script word '" + definitionDto.Key() + "' not found in code"); } else { if (parentDefinition != null) { parentDefinition.Children.Add(definition.UniqueId?.ToUpper(), definition); definition.Parent = parentDefinition; } else { _store.Add <IBdoScriptwordDefinition>(definition); } BuildScriptwordTree(dictionaryDto, allDefinitions, log, definition); } } } }