public static ICollection <Changelog> ParseChangelogsCache(this string filePath) { ChangelogParser? parser = ChangelogParserProvider.GetParser(Path.GetExtension(filePath)); ICollection <Changelog> cache; if (parser == null) { throw new InvalidOperationException($"{filePath} is not convertible!"); } try { Console.PrintInfo($"{ChangelogGeneratorResources.PARSING_CACHE_FILE} {filePath}"); cache = parser.ParseCache(File.ReadAllText(filePath)); } catch (Exception e) { Console.PrintError($"{ChangelogGeneratorResources.PARSING_ERROR} {e.InnerException?.Message}"); Console.PrintException(e); throw; } return(cache); }
public static void SaveCache(this string filePath, ICollection <Changelog> cache) { ChangelogParser?parser = ChangelogParserProvider.GetParser(Path.GetExtension(filePath)); if (parser == null) { throw new InvalidOperationException($"{filePath} is not convertible!"); } Console.PrintInfo($"{ChangelogGeneratorResources.SAVING_CACHE}"); string result = parser.SerializeCache(cache); File.WriteAllText(filePath, result); }
private static IDictionary <string, Changelog> ParseChangelogsInternal( IEnumerable <string> files, StatusContext context) { var changelogs = new Dictionary <string, Changelog>(); foreach (var file in files) { string extension = Path.GetExtension(file); ChangelogParser?parser = ChangelogParserProvider.GetParser(extension); if (parser == null) { continue; } Changelog changelog; try { context.Status($"{ChangelogGeneratorResources.PARSING_FILE} {file}"); changelog = parser.Parse(File.ReadAllText(file)); Console.PrintInfo($"{ChangelogGeneratorResources.FILE_PARSED} {file}"); } catch (Exception e) { Console.PrintError($"{ChangelogGeneratorResources.PARSING_ERROR} {e.InnerException?.Message}"); Console.PrintException(e); continue; } changelogs.Add(file, changelog); } return(changelogs); }