예제 #1
0
        void PopulateDocument(string name, FeatureTarget target, XmlDocument doc, XmlNode parent,
                              IDefaultContainer[] defaults, List <Section> children)
        {
            if (defaults == null || defaults.Length == 0)
            {
                return;
            }

            XmlNode     node;
            XmlDocument tmp;

            foreach (Section s in children)
            {
                tmp = Helpers.FindDefault(defaults, s.DefaultBlockName, target);
                if (tmp == null)
                {
                    continue;
                }

                node = doc.ImportNode(tmp.DocumentElement.FirstChild, true);
                try {
                    PopulateDocument(name, target, doc, node, defaults, s.Children);
                } catch (Exception ex) {
                    throw new ApplicationException(
                              String.Format("Error building default config file '{0}'", name),
                              ex);
                }

                parent.AppendChild(node);
            }
        }
        XmlNode FindNodeOrAddDefault(XmlDocument doc, string nodeName, string nodePath, IDefaultContainer[] defaults)
        {
            XmlNode ret = doc.SelectSingleNode(nodePath);

            if (ret != null)
            {
                return(ret);
            }

            XmlDocument defDoc = Helpers.FindDefault(defaults, nodeName, FeatureTarget.Any);

            if (defDoc == null)
            {
                throw new ApplicationException(
                          String.Format("Document doesn't contain node '{0}' and no default can be found",
                                        nodePath));
            }

            return(doc.ImportNode(defDoc.DocumentElement.FirstChild, true));
        }