Пример #1
0
 private static void ProcessNodeForString(StringBuilder sb, ParameterDirectoryNode node, string indent)
 {
     sb.AppendFormat("{0}{1}{2}\n", indent, "Dir:    ", node.Info.FullName);
     sb.AppendFormat("{0}{1}\n", indent, "Files:");
     foreach (var fi in node.Files)
     {
         sb.AppendFormat("{0}\t{1}\n", indent, fi.Name);
         var dict = ParseForParameters(fi);
         if (dict == null || dict.Count == 0)
         {
             continue;
         }
         sb.AppendFormat("{0}\t{1}{2}\n", indent, "Properties: ", dict.Keys.Count);
         foreach (var p in dict)
         {
             sb.AppendFormat("{0}\t\t[ {1} = {2} ]\n", indent, p.Key, p.Value);
         }
     }
     sb.AppendLine();
     // now indent for the next level in the branch
     indent += "\t";
     foreach (var di in node.Children)
     {
         ProcessNodeForString(sb, (ParameterDirectoryNode)di, indent);
     }
 }
Пример #2
0
        private static void ProcessNodeForXml(XElement xml, ParameterDirectoryNode node)
        {
            var files = new XElement("files", new XAttribute("count", node.Files.Count));

            xml.Add(files);
            foreach (var fi in node.Files)
            {
                var dict = ParseForParameters(fi);
                if (dict == null || dict.Count == 0)
                {
                    continue;
                }
                var file = new XElement("file", new XAttribute("name", fi.Name), new XAttribute("propertyCount", dict.Count));
                files.Add(file);
                foreach (var p in dict)
                {
                    file.Add(new XElement("property", new XAttribute("key", p.Key), new XAttribute("value", p.Value)));
                }
            }
            foreach (ParameterDirectoryNode di in node.Children)
            {
                var dir = new XElement("directory", new XAttribute("name", di.Info.Name));
                xml.Add(dir);
                ProcessNodeForXml(dir, di);
            }
        }
Пример #3
0
        /// <summary>
        /// This override for the Build(...) method is for the case in which
        /// the parameter file extension has been changed.
        /// Instead of searching for "*.params", the client can search
        /// for whatever extension it might require.
        /// </summary>
        /// <param name="rootDir">The top-level directory where the tree will be "rooted".</param>
        /// <param name="fileSearchPattern"></param>
        public void Build(string rootDir, string fileSearchPattern)
        {
            if (String.IsNullOrEmpty(rootDir) || !Directory.Exists(rootDir) || Path.GetDirectoryName(rootDir).StartsWith("."))
            {
                throw new DirectoryNotFoundException(String.Format("A valid directory must be specified: {0}", rootDir));
            }

            Root = new ParameterDirectoryNode(new DirectoryInfo(rootDir), fileSearchPattern);
        }