Exemple #1
0
        /// <summary>
        /// Updates a file in the target project folder, using the given <paramref name="updateContents"/> function.
        /// </summary>
        /// <param name="fileName">The target file name to change it's contents.</param>
        /// <param name="updateContents">The function that changes the contents of the file.</param>
        public void UpdateFileInProject(string fileName, Func <string, string> updateContents)
        {
            Guard.NotNullOrWhitespace(fileName, nameof(fileName), "Requires a non-blank file name (no file path) to update the contents");
            Guard.NotNull(updateContents, nameof(updateContents), "Requires a function to update the project file contents");

            string destPath = Path.Combine(ProjectDirectory.FullName, fileName);

            if (!File.Exists(destPath))
            {
                string files = String.Join(", ", ProjectDirectory.GetFiles().Select(f => f.FullName));
                throw new FileNotFoundException($"No project file with the file name: '{fileName}' was found in the target project folder");
            }

            string content = File.ReadAllText(destPath);

            content = updateContents(content);
            File.WriteAllText(destPath, content);
        }
Exemple #2
0
    public void IndexDirectory(ProjectDirectory dir, TreeNode node)
    {
        if (node.Tag == null)
        {
            node.Tag = dir;
        }
        node.Nodes.Clear();

        //get sub directory and files
        ProjectDirectory[] dirs  = dir.GetDirectories();
        ProjectFile[]      files = dir.GetFiles();

        //recursively invoke this function for every sub-directory
        for (int c = 0; c < dirs.Length; c++)
        {
            //add the tree node for the sub directory
            TreeNode n = node.Nodes.Add(dirs[c].Name);
            n.ImageKey         = "folder";
            n.SelectedImageKey = "folder";

            //index the child directory
            IndexDirectory(dirs[c], n);
        }

        for (int c = 0; c < files.Length; c++)
        {
            //get the type for the image key to apply
            //to this file.
            string type = files[c].FileType.ToString();

            //add the node
            TreeNode n = node.Nodes.Add(files[c].Name);
            n.ImageKey         = type;
            n.SelectedImageKey = type;
            n.Tag = files[c];
        }
    }
    public void IndexDirectory(ProjectDirectory dir, TreeNode node)
    {
        if (node.Tag == null) {
            node.Tag = dir;
        }
        node.Nodes.Clear();

        //get sub directory and files
        ProjectDirectory[] dirs = dir.GetDirectories();
        ProjectFile[] files = dir.GetFiles();

        //recursively invoke this function for every sub-directory
        for (int c = 0; c < dirs.Length; c++) {
            //add the tree node for the sub directory
            TreeNode n = node.Nodes.Add(dirs[c].Name);
            n.ImageKey = "folder";
            n.SelectedImageKey = "folder";

            //index the child directory
            IndexDirectory(dirs[c], n);
        }

        for (int c = 0; c < files.Length; c++) {
            //get the type for the image key to apply
            //to this file.
            string type = files[c].FileType.ToString();

            //add the node
            TreeNode n = node.Nodes.Add(files[c].Name);
            n.ImageKey = type;
            n.SelectedImageKey = type;
            n.Tag = files[c];
        }
    }