// example of linq usage //public Stats Minus2(Stats other) //{ // var added = FiletypeStat.Keys.Except(other.FiletypeStat.Keys) // .Select(x => new { x, res = FiletypeStat[x] }) // .ToDictionary(x => x.x, x => x.res); // var removed = other.FiletypeStat.Keys.Except(FiletypeStat.Keys) // .Select(x => new { x, res = other.FiletypeStat[x] }) // .ToDictionary(x => x.x, x => x.res); // var calc = FiletypeStat.Keys.Intersect(other.FiletypeStat.Keys) // .Select(x => new { x, res = FiletypeStat[x] - other.FiletypeStat[x] }) // .ToDictionary(x => x.x, x => x.res); // var result = added.Union(removed).Union(calc).ToDictionary(x => x.Key, x => x.Value); // return new Stats(result); //} public string Print() { var formatter = new WebFormatter(); var lines = FiletypeStat .OrderBy(x => x.Key) //.Select(x => $"{x.Key,15}:, {formatter.PrintOnlyCode(x.Value)}"); .Select(x => $"{x.Key,15}:, {formatter.ToString(x.Value)}"); return(string.Join("\n", lines)); }
/// <summary> /// Looks for magic marker <!--start-->....<!--end--> and replace the body of that with the shield content /// </summary> public void ReplaceWebshieldsInFile(string codeFolderPath, string pathOfFileToMutate) { var stats = new LineCounting().CountFolder(codeFolderPath); var shieldsRegEx = new Regex("<!--start-->.*<!--end-->", RegexOptions.Singleline); var githubShields = new WebFormatter().CreateGithubShields(stats.Total); var oldReadme = File.ReadAllText(pathOfFileToMutate); var newReadMe = shieldsRegEx.Replace(oldReadme, $"<!--start-->\r\n{githubShields}\r\n<!--end-->"); if (oldReadme != newReadMe) { File.WriteAllText(pathOfFileToMutate, newReadMe); } }