Example #1
0
 /// <summary>
 /// Abstract method to be implemented to enable searching.
 /// </summary>
 /// <param name="path">List of tokenized path elements.</param>
 /// <param name="index">Current Index in the List</param>
 /// <returns>Configuration Node</returns>
 public override AbstractConfigNode Find(List<string> path, int index)
 {
     AbstractConfigNode psn = CheckParentSearch(path, index);
     if (psn != null)
     {
         return psn;
     }
     string name = path[index];
     if (name.Length == 1 && name[0] == ConfigurationSettings.NODE_SEARCH_WILDCARD)
     {
         if (GetValues().Count > 0)
         {
             List<AbstractConfigNode> nodes = new List<AbstractConfigNode>();
             foreach (ConfigValueNode value in GetValues())
             {
                 AbstractConfigNode sn = value.Find(path, index + 1);
                 if (sn != null)
                 {
                     nodes.Add(sn);
                 }
             }
             if (nodes.Count == 1)
             {
                 return nodes[0];
             }
             else if (nodes.Count > 1)
             {
                 ConfigSearchResult result = new ConfigSearchResult();
                 result.Configuration = Configuration;
                 result.AddAll(nodes);
                 return result;
             }
         }
         return null;
     }
     ResolvedName resolved = ConfigUtils.ResolveName(name, Name, Configuration.Settings);
     if (resolved == null)
     {
         if (name == Name && index == (path.Count - 1))
         {
             return this;
         }
     }
     else
     {
         if (resolved.AbbrReplacement == NODE_NAME)
         {
             if (resolved.Name == Name && index == (path.Count - 1))
             {
                 int indx = Int32.Parse(resolved.ChildName);
                 return GetValue(indx);
             }
         }
     }
     return null;
 }
Example #2
0
        /// <summary>
        /// Find a child node that matches the search.
        /// </summary>
        /// <param name="path">List of tokenized path elements.</param>
        /// <param name="index">Current Index</param>
        /// <returns>Config node if found</returns>
        private AbstractConfigNode FindChild(List <string> path, int index)
        {
            string name = path[index + 1];

            if (name == ConfigurationSettings.NODE_SEARCH_PARENT)
            {
                if (Parent != null)
                {
                    path[index + 1] = Parent.Name;
                    return(Parent.Find(path, index + 1));
                }
            }
            if (name.Length == 1 && name[0] == ConfigurationSettings.NODE_SEARCH_WILDCARD)
            {
                if (index == (path.Count - 2))
                {
                    if (children.Count > 0)
                    {
                        List <AbstractConfigNode> nodes = new List <AbstractConfigNode>();
                        foreach (string key in children.Keys)
                        {
                            nodes.Add(children[key]);
                        }
                        if (nodes.Count == 1)
                        {
                            return(nodes[0]);
                        }
                        else if (nodes.Count > 1)
                        {
                            ConfigSearchResult result = new ConfigSearchResult();
                            result.Configuration = Configuration;
                            result.AddAll(nodes);
                            return(result);
                        }
                    }
                    return(null);
                }
                if (children.Count > 0)
                {
                    List <AbstractConfigNode> nodes = new List <AbstractConfigNode>();
                    foreach (string key in children.Keys)
                    {
                        AbstractConfigNode sn = children[key].Find(path, index + 1);
                        if (sn != null)
                        {
                            nodes.Add(sn);
                        }
                    }
                    if (nodes.Count == 1)
                    {
                        return(nodes[0]);
                    }
                    else if (nodes.Count > 1)
                    {
                        ConfigSearchResult result = new ConfigSearchResult();
                        result.Configuration = Configuration;
                        result.AddAll(nodes);
                        return(result);
                    }
                }
                return(null);
            }
            ResolvedName resolved = ConfigUtils.ResolveName(name, Name, Configuration.Settings);

            if (resolved == null)
            {
                List <AbstractConfigNode> nodes = new List <AbstractConfigNode>();
                if (children.ContainsKey(name))
                {
                    return(children[name].Find(path, index + 1));
                }
                else if (name == ConfigurationSettings.NODE_SEARCH_RECURSIVE_WILDCARD)
                {
                    foreach (string key in children.Keys)
                    {
                        AbstractConfigNode cnode = children[key].Find(path, index + 1);
                        if (cnode != null)
                        {
                            nodes.Add(cnode);
                        }
                    }
                }
                if (nodes.Count == 1)
                {
                    return(nodes[0]);
                }
                else if (nodes.Count > 1)
                {
                    ConfigSearchResult result = new ConfigSearchResult();
                    result.Configuration = Configuration;
                    result.AddAll(nodes);
                    return(result);
                }
            }
            else
            {
                name = resolved.Name;
                if (name == Name)
                {
                    if (!String.IsNullOrWhiteSpace(resolved.AbbrReplacement))
                    {
                        if (children.ContainsKey(resolved.AbbrReplacement))
                        {
                            return(children[resolved.AbbrReplacement].Find(path, index + 1));
                        }
                    }
                }
                else if (children.ContainsKey(name))
                {
                    return(children[name].Find(path, index + 1));
                }
            }
            return(null);
        }
Example #3
0
        /// <summary>
        /// Abstract method to be implemented to enable searching.
        /// </summary>
        /// <param name="path">List of tokenized path elements.</param>
        /// <param name="index">Current Index in the List</param>
        /// <returns>Configuration Node</returns>
        public override AbstractConfigNode Find(List <string> path, int index)
        {
            AbstractConfigNode sn = CheckParentSearch(path, index);

            if (sn != null)
            {
                return(sn);
            }
            string name = path[index];

            if (name == ConfigurationSettings.NODE_SEARCH_RECURSIVE_WILDCARD)
            {
                string cname = path[index + 1];
                if (children.Count > 0)
                {
                    List <AbstractConfigNode> nodes = new List <AbstractConfigNode>();
                    if (children.ContainsKey(cname))
                    {
                        AbstractConfigNode node = children[cname].Find(path, index + 1);
                        nodes.Add(node);
                    }

                    foreach (string key in children.Keys)
                    {
                        AbstractConfigNode cnode = children[key].Find(path, index);
                        if (cnode != null)
                        {
                            nodes.Add(cnode);
                        }
                    }

                    if (nodes.Count == 1)
                    {
                        return(nodes[0]);
                    }
                    else if (nodes.Count > 1)
                    {
                        ConfigSearchResult result = new ConfigSearchResult();
                        result.Configuration = Configuration;
                        result.AddAll(nodes);
                        return(result);
                    }
                }
            }
            ResolvedName resolved = ConfigUtils.ResolveName(name, Name, Configuration.Settings);

            if (resolved == null)
            {
                if (name == Name)
                {
                    if (index == (path.Count - 1))
                    {
                        return(this);
                    }
                    else
                    {
                        return(FindChild(path, index));
                    }
                }
                else if (index == 0)
                {
                    return(FindChild(path, index - 1));
                }
            }
            else
            {
                if (resolved.Name == Name)
                {
                    if (!String.IsNullOrWhiteSpace(resolved.AbbrReplacement))
                    {
                        if (children.ContainsKey(resolved.AbbrReplacement))
                        {
                            AbstractConfigNode child = children[resolved.AbbrReplacement];
                            if (typeof(ConfigKeyValueNode).IsAssignableFrom(child.GetType()))
                            {
                                ConfigKeyValueNode kv = (ConfigKeyValueNode)child;
                                if (index == (path.Count - 1))
                                {
                                    if (String.IsNullOrWhiteSpace(resolved.ChildName))
                                    {
                                        return(kv);
                                    }
                                    else
                                    {
                                        return(kv.GetValue(resolved.ChildName));
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        return(FindChild(path, index));
                    }
                }
            }
            return(null);
        }