Example #1
0
        private static void SaveSnippets(List <Snippet> snippets)
        {
            var settings = new SaveSettings()
            {
                Comment = XmlComment,
            };

            foreach (Snippet snippet in snippets
                     .Select(f => SnippetChecker.GetChangedSnippetOrDefault(f))
                     .Where(f => f != null))
            {
                Console.WriteLine();
                Console.WriteLine($"saving snippet \"{snippet.Title}\"");

                try
                {
                    snippet.Save(snippet.FilePath + ".modified", settings);

                    Console.WriteLine("saved");
                }
                catch (IOException ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
Example #2
0
        private static void SaveSnippets2(List <Snippet> snippets)
        {
            var settings = new SaveSettings()
            {
                Comment = XmlComment,
                OmitCodeSnippetsElement = true,
                IndentChars             = "  ",
                OmitXmlDeclaration      = true
            };

            foreach (Snippet snippet in snippets
                     .Select(f => SnippetChecker.CloneAndSortCollections(f)))
            {
                Console.WriteLine();
                Console.WriteLine($"saving snippet \"{snippet.Title}\"");

                try
                {
                    using (var fs = new FileStream(snippet.FilePath, FileMode.Create))
                        snippet.Save(fs, settings);

                    Console.WriteLine("saved");
                }
                catch (IOException ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
Example #3
0
        static void Main(string[] args)
        {
            var dirPaths = new List <string>();

            if (args?.Length > 0)
            {
                dirPaths.AddRange(args);
            }
            else
            {
                dirPaths.Add(Environment.CurrentDirectory);
            }

            Console.WriteLine();
            Console.WriteLine("directories:");

            for (int i = 0; i < dirPaths.Count; i++)
            {
                Console.WriteLine($"  {dirPaths[i]}");

                if (!Assert(Directory.Exists(dirPaths[i]), "directory not found"))
                {
                    return;
                }
            }

            var snippets = new List <Snippet>(SnippetSerializer.DeserializeFiles(dirPaths[0], SearchOption.AllDirectories).SelectMany(f => f.Snippets));

            Console.WriteLine();
            Console.WriteLine($"number of snippets: {snippets.Count}");

            foreach (SnippetValidationResult result in SnippetChecker.Validate(snippets))
            {
                Console.WriteLine();
                Console.WriteLine($"{result.Importance}: \"{result.Description}\" in \"{result.Snippet.FilePath}\"");
            }

            foreach (IGrouping <string, Snippet> snippet in snippets
                     .Where(f => f.Keywords.Contains(NonUniqueShortcutKeyword))
                     .GroupBy(f => f.Shortcut)
                     .Where(f => f.Count() == 1))
            {
                Console.WriteLine();
                Console.WriteLine($"unused {NonUniqueShortcutKeyword} in \"{snippet.First().FilePath}\"");
            }

            foreach (ShortcutInfo shortcutInfo in SnippetChecker.FindDuplicateShortcuts(dirPaths, NonUniqueShortcutKeyword))
            {
                Console.WriteLine();
                Console.WriteLine($"shortcut duplicate: {shortcutInfo.Shortcut}");

                foreach (Snippet item in shortcutInfo.Snippets)
                {
                    Console.WriteLine($"  {item.FilePath}");
                }
            }
            ;

            SaveSnippets(snippets);

            Assert(false);
        }