Пример #1
0
        private void CreateSolutionTemplate(Solution solution)
        {
            string fullPath = solution.FullName;
            string dir      = Path.GetDirectoryName(fullPath);
            string name     = Path.GetFileNameWithoutExtension(fullPath);

            InfoCollectorDialog win = new InfoCollectorDialog(name);

            win.CenterInVs();
            if (win.ShowDialog().GetValueOrDefault())
            {
                const string solutionTemplate = @"{
    ""author"": """",
    ""classifications"": """",
    ""displayName"": """",
    ""name"": """",
    ""defaultName"": """",
    ""groupIdentity"": """",
    ""tags"": { },
    ""shortName"": """",
    ""sourceName"": """",
    ""guids"": [ ]
}";

                JObject o = JObject.Parse(solutionTemplate);
                o["author"]      = win.AuthorTextBox.Text;
                o["displayName"] = win.FriendlyNameTextBox.Text;
                o["name"]        = win.FriendlyNameTextBox.Text;
                o["defaultName"] = win.DefaultNameTextBox.Text;
                o["sourceName"]  = Path.GetFileNameWithoutExtension(solution.FullName);
                o["shortName"]   = win.ShortNameTextBox.Text;
                JArray guids = (JArray)o["guids"];

                Regex          rx            = new Regex(@"\{?[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}\}?", RegexOptions.IgnoreCase);
                string         contents      = File.ReadAllText(solution.FullName);
                HashSet <Guid> distinctGuids = new HashSet <Guid>();

                foreach (Match match in rx.Matches(contents))
                {
                    distinctGuids.Add(Guid.Parse(match.Value));
                }

                rx = new Regex(@"(?<=\("")\{?[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}\}?(?=""\))", RegexOptions.IgnoreCase);

                foreach (Match match in rx.Matches(contents))
                {
                    distinctGuids.Remove(Guid.Parse(match.Value));
                }

                foreach (Guid g in distinctGuids)
                {
                    guids.Add(g);
                }

                File.WriteAllText(Path.Combine(dir, ".netnew.json"), o.ToString());
            }
        }
Пример #2
0
        private void CreateProjectTemplate(Project proj)
        {
            string fullPath = proj.FullName;
            string dir      = Path.GetDirectoryName(fullPath);
            string name     = Path.GetFileNameWithoutExtension(fullPath);

            InfoCollectorDialog win = new InfoCollectorDialog(name);

            win.CenterInVs();
            if (win.ShowDialog().GetValueOrDefault())
            {
                const string solutionTemplate = @"{
    ""author"": """",
    ""classifications"": """",
    ""displayName"": """",
    ""name"": """",
    ""defaultName"": """",
    ""groupIdentity"": """",
    ""tags"": { },
    ""shortName"": """",
    ""sourceName"": """",
    ""guids"": [ ]
}";

                JObject o = JObject.Parse(solutionTemplate);
                o["author"]      = win.AuthorTextBox.Text;
                o["displayName"] = win.FriendlyNameTextBox.Text;
                o["name"]        = win.FriendlyNameTextBox.Text;
                o["defaultName"] = win.DefaultNameTextBox.Text;
                o["sourceName"]  = Path.GetFileNameWithoutExtension(proj.FullName);
                o["shortName"]   = win.ShortNameTextBox.Text;
                JArray guids = (JArray)o["guids"];
                guids.Add(ExtractProjectGuid(fullPath));

                File.WriteAllText(Path.Combine(dir, ".netnew.json"), o.ToString());
            }
        }