private static async Task Main()
        {
            var client = new HttpClient();
            HttpResponseMessage ruleSetResponse = await client.GetAsync(IpMaturityMatrixRuleset.RuleSetDefinitionsUrl).ConfigureAwait(false);

            ruleSetResponse.EnsureSuccessStatusCode();
            string yamlRuleText = await ruleSetResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

            var yamlRules       = IpMaturityMatrixRuleset.FromYaml(yamlRuleText);
            var immProjectScore = IpMaturityMatrix.FromYaml(File.ReadAllText("imm-default.yaml"));

            var evaluationEngine = new EvaluationEngine(new RuleDefinitionRepository(yamlRules));

            var col1 = new StringBuilder();
            var col2 = new StringBuilder();

            ImmEvaluation evalutionResult = evaluationEngine.Evaluate(immProjectScore);

            foreach (var result in evalutionResult.RuleEvaluations)
            {
                Console.WriteLine($"{result.RuleAssertion.Name} {result.Percentage}% Score: {result.Score}");

#pragma warning disable RCS1197 // Optimize StringBuilder.Append/AppendLine call.
                col1.AppendLine($"<tspan x='30' dy='1.5em'>{WebUtility.HtmlEncode(result.RuleAssertion.Name)}</tspan>");
                col2.AppendLine($"<tspan x='310' dy='1.5em'>{result.Percentage}%</tspan>");
#pragma warning restore RCS1197 // Optimize StringBuilder.Append/AppendLine call.

                File.WriteAllText($"imm-{result.RuleAssertion.Id}.svg", BadgePainter.DrawSVG(WebUtility.HtmlEncode(result.RuleAssertion.Name !), $"{result.Percentage}%", ColorScheme.Red, Style.FlatSquare));
            }

            Console.WriteLine($"{evalutionResult.TotalScore} / {evalutionResult.MaximumPossibleTotalScore}");

            File.WriteAllText("imm.svg", BadgePainter.DrawSVG("IMM", $"{evalutionResult.TotalScore} / {evalutionResult.MaximumPossibleTotalScore}", ColorScheme.Red, Style.Flat));
            File.WriteAllText("imm-table.svg", string.Format(Resources.Table, col1.ToString(), col2.ToString()));
        }
Esempio n. 2
0
        /// <summary>
        ///     Creates the output badges.
        /// </summary>
        private void CreateOutputBadges()
        {
            var bp = new BadgePainter();

            // Determine if provided path is a file
            if (_options.BadgePerProject)
            {
                Directory.CreateDirectory(_options.BadgePath);
                // Create a badge for each project
                foreach (var codeProject in CodeProjects)
                {
                    var filename = Path.Combine(_options.BadgePath, "Dependencies_" + codeProject.Name + ".svg");
                    if (codeProject.PackageStatuses.Any(p => p.NotFound))
                    {
                        File.WriteAllText(filename, bp.DrawSVG("Dependencies: " + codeProject.Name, "Some not found", ColorScheme.Red, _options.BadgeStyle));
                        continue;
                    }

                    if (codeProject.PackageStatuses.Any(p => p.NoLocalVersion))
                    {
                        File.WriteAllText(filename, bp.DrawSVG("Dependencies: " + codeProject.Name, "Local version not set", ColorScheme.Red, _options.BadgeStyle));
                        continue;
                    }

                    if (codeProject.PackageStatuses.Any(p => p.Outdated))
                    {
                        File.WriteAllText(filename, bp.DrawSVG("Dependencies: " + codeProject.Name, "Outdated", ColorScheme.Yellow, _options.BadgeStyle));
                        continue;
                    }

                    File.WriteAllText(filename, bp.DrawSVG("Dependencies: " + codeProject.Name, "Up to date", ColorScheme.Green, _options.BadgeStyle));
                }
            }
            else
            {
                // Create only one badge
                var fi = new FileInfo(_options.BadgePath);
                Directory.CreateDirectory(fi.DirectoryName); // Create directory tree
                if (CodeProjects.Any(c => c.PackageStatuses.Any(p => p.NotFound)))
                {
                    File.WriteAllText(_options.BadgePath, bp.DrawSVG("Dependencies", "Some not found", ColorScheme.Red, _options.BadgeStyle));
                    return;
                }

                if (CodeProjects.Any(c => c.PackageStatuses.Any(p => p.NoLocalVersion)))
                {
                    File.WriteAllText(_options.BadgePath, bp.DrawSVG("Dependencies", "Local version not set", ColorScheme.Red, _options.BadgeStyle));
                    return;
                }

                if (CodeProjects.Any(c => c.PackageStatuses.Any(p => p.Outdated)))
                {
                    File.WriteAllText(_options.BadgePath, bp.DrawSVG("Dependencies", "Outdated", ColorScheme.Yellow, _options.BadgeStyle));
                    return;
                }

                File.WriteAllText(_options.BadgePath, bp.DrawSVG("Dependencies", "Up to date", ColorScheme.Green, _options.BadgeStyle));
            }
        }
Esempio n. 3
0
        public async Task <HttpResponseMessage> GitHubImmTotalScore(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "imm/github/{org}/{project}/total")] HttpRequest request,
            string org,
            string project)
        {
            (string rulesObjectName, string projectObjectName) = this.GetGitHubBranchOrObjectNames(request);
            (IRuleDefinitionRepository ruleSet, IpMaturityMatrix ruleAssertions) =
                await this.GetImmRulesFromGitHubAsync(org, project, rulesObjectName, projectObjectName).ConfigureAwait(false);

            var evaluationEngine = new EvaluationEngine(ruleSet);

            ImmEvaluation evaluationResult = evaluationEngine.Evaluate(ruleAssertions);

            string svg = BadgePainter.DrawSVG(
                "IMM",
                $"{evaluationResult.TotalScore} / {evaluationResult.MaximumPossibleTotalScore}",
                GetColourSchemeForPercentage(100M * evaluationResult.TotalScore / evaluationResult.MaximumPossibleTotalScore),
                Style.Flat);

            return(this.CreateUncacheResponse(
                       new ByteArrayContent(Encoding.ASCII.GetBytes(svg)),
                       "image/svg+xml"));
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            var    bp           = new BadgePainter();
            bool   showHelp     = false;
            string subject      = String.Empty;
            string status       = String.Empty;
            string color        = String.Empty;
            string path         = "badge.svg";
            Style  style        = Style.Flat;
            string errorMessage = String.Empty;

            var optionSet = new OptionSet()
            {
                "Usage: DotBadge [OPTIONS]",
                "The output image's content would be like Subject|Status",
                "",
                "Options:",
                {
                    "sb|subject=", "the name of Subject", sb => subject = sb
                },
                {
                    "st|status=", "the value of Status", st => status = st
                },
                {
                    "c|color=", "background color of Status. You can input hexadecimal color value (#ffffff or #fff) or built-in ones (Case sensitive) : " +
                    "Yellow, YellowGreen, Green, BrightGreen, Orange, Red, Blue.", c => {
                        var r = new Regex("^#(?:[0-9a-fA-F]{3}){1,2}$", RegexOptions.IgnoreCase);
                        if (r.Match(c).Success)
                        {
                            color = c;
                        }
                        else
                        {
                            color = bp.ParseColor(c);
                            if (String.IsNullOrEmpty(color))
                            {
                                throw new OptionException("Please input correct Color. " +
                                                          "You can use hexadecimal color value (#ffffff or #fff) or built-in ones (Case sensitive) : " +
                                                          "Yellow, YellowGreen, Green, BrightGreen, Orange, Red or Blue", "-c");
                            }
                        }
                    }
                },
                {
                    "sl|style=", "style of the output image. 0 for Flat, 1 for FlatSquare, 2 for Plastic.",
                    (int sl) => {
                        if (sl > 2 || sl < 0)
                        {
                            throw new OptionException("Please input correct Style: 0 for Flat, 1 for FlatSquare, 2 for Plastic.", "-sl");
                        }
                        else
                        {
                            style = (Style)sl;
                        }
                    }
                },
                {
                    "p|path=", "the value of Path", p => path = p
                },
                {
                    "h|help", "show this message and exit", v => showHelp = v != null
                },
                "Samples:",
                "DotBadge.exe -sb \"Downloads\" -st \"1000\" -c \"Green\" -sl 0",
                "DotBadge.exe -sb \"Build\" -st \"fail\" -c \"Red\" -sl 0",
                "DotBadge.exe -sb \"Star\" -st \"234\" -c \"#ddf\" -sl 1"
            };

            if (args.Length == 0)
            {
                Console.WriteLine("Try `DotBadge --help` for more information");
                return;
            }

            try
            {
                optionSet.Parse(args);
            }
            catch (OptionException e)
            {
                Console.Write("Argument parsing error: ");
                Console.WriteLine(e.Message);
                Console.WriteLine("Try `DotBadge --help` for more information");
                return;
            }

            if (showHelp)
            {
                optionSet.WriteOptionDescriptions(Console.Out);
                return;
            }
            Console.WriteLine($"Path : {path}");
            Console.WriteLine($"Subject : {subject}");
            Console.WriteLine($"Status : {status}");
            Console.WriteLine($"Color : {color}");
            Console.WriteLine($"Style : {style}");
            File.WriteAllText(path, bp.DrawSVG(subject, status, color, style));
            Console.WriteLine("OK");
        }