Пример #1
0
        /// <summary>
        /// Recursively replace defined variables with properties in the configuration nodes.
        ///
        /// </summary>
        /// <param name="node">Configuration Node.</param>
        /// <param name="inProps">Scoped properties map</param>
        /// <param name="replace">Replace variables?</param>
        private void NodePostLoad(AbstractConfigNode node, Dictionary <string, ConfigValueNode> inProps, bool replace)
        {
            Dictionary <string, ConfigValueNode> properties = General.Clone <string, ConfigValueNode>(inProps);

            if (node.GetType() == typeof(ConfigPathNode))
            {
                ConfigPathNode       pnode = (ConfigPathNode)node;
                ConfigPropertiesNode props = pnode.GetProperties();
                if (props != null && !props.IsEmpty())
                {
                    Dictionary <string, ConfigValueNode> pd = props.GetValues();
                    foreach (string key in pd.Keys)
                    {
                        if (!properties.ContainsKey(key))
                        {
                            properties.Add(key, pd[key]);
                        }
                        else
                        {
                            properties[key] = pd[key];
                        }
                    }
                }
                if (!pnode.IsEmpty())
                {
                    foreach (string key in pnode.GetChildren().Keys)
                    {
                        NodePostLoad(pnode.GetChildren()[key], properties, replace);
                    }
                }
            }
            else
            {
                if (node.GetType() == typeof(ConfigParametersNode))
                {
                    ConfigParametersNode pnode = (ConfigParametersNode)node;
                    if (!pnode.IsEmpty() && replace)
                    {
                        foreach (string key in pnode.GetValues().Keys)
                        {
                            ConfigValueNode vn    = pnode.GetValue(key);
                            string          value = vn.GetValue();
                            if (!String.IsNullOrWhiteSpace(value))
                            {
                                string nv = ReplaceVariable(value, properties);
                                vn.SetValue(nv);
                            }
                        }
                    }
                }
                else if (node.GetType() == typeof(ConfigAttributesNode))
                {
                    ConfigAttributesNode pnode = (ConfigAttributesNode)node;
                    if (!pnode.IsEmpty() && replace)
                    {
                        foreach (string key in pnode.GetValues().Keys)
                        {
                            ConfigValueNode vn    = pnode.GetValue(key);
                            string          value = vn.GetValue();
                            if (!String.IsNullOrWhiteSpace(value))
                            {
                                string nv = ReplaceVariable(value, properties);
                                vn.SetValue(nv);
                            }
                        }
                    }
                }
                else if (node.GetType() == typeof(ConfigListValueNode))
                {
                    ConfigListValueNode pnode = (ConfigListValueNode)node;
                    if (!pnode.IsEmpty() && replace)
                    {
                        foreach (ConfigValueNode vn in pnode.GetValues())
                        {
                            string value = vn.GetValue();
                            if (!String.IsNullOrWhiteSpace(value))
                            {
                                string nv = ReplaceVariable(value, properties);
                                vn.SetValue(nv);
                            }
                        }
                    }
                }
                else if (node.GetType() == typeof(ConfigElementListNode))
                {
                    ConfigElementListNode pnode = (ConfigElementListNode)node;
                    if (!pnode.IsEmpty())
                    {
                        foreach (ConfigElementNode vn in pnode.GetValues())
                        {
                            NodePostLoad(vn, properties, replace);
                        }
                    }
                }
                else if (node.GetType() == typeof(ConfigValueNode))
                {
                    if (replace)
                    {
                        ConfigValueNode vn    = (ConfigValueNode)node;
                        string          value = vn.GetValue();
                        if (!String.IsNullOrWhiteSpace(value))
                        {
                            string nv = ReplaceVariable(value, properties);
                            vn.SetValue(nv);
                        }
                    }
                }
            }
        }