public JObject ReportRule()

in Source/Reports/PerEndpointJsonReport.cs [97:173]


        public JObject ReportRule(RuleResult rule)
        {
            JObject jsonRule = new JObject();

            if (rule == null)
                return null;

            if (!s_supportedRules.Contains(rule.RuleName))
            {
                return null;
            }

            JObject jsonResult = new JObject();

            jsonRule["Name"] = rule.RuleName;
            jsonRule["Description"] = rule.RuleDescription;

            foreach (var data in rule.Results)
            {
                jsonResult[data.Key] = data.Value.ToString();
            }

            jsonRule["ResultData"] = jsonResult;

            foreach (ViolationLevel level in System.Enum.GetValues(typeof(ViolationLevel)))
            {
                jsonRule[System.Enum.GetName(typeof(ViolationLevel), level)] = rule.Violations.Count(v => v.m_level == level);
            }

            if (jsonRule[System.Enum.GetName(typeof(ViolationLevel), ViolationLevel.Error)].ToObject<Int32>() > 0)
            {
                jsonRule["Result"] = System.Enum.GetName(typeof(ViolationLevel), ViolationLevel.Error);
            }
            else if (jsonRule[System.Enum.GetName(typeof(ViolationLevel), ViolationLevel.Warning)].ToObject<Int32>() > 0)
            {
                jsonRule["Result"] = System.Enum.GetName(typeof(ViolationLevel), ViolationLevel.Warning);
            }
            else
            {
                jsonRule["Result"] = "Pass";
            }

            JArray jsonViolations = new JArray();

            foreach (var violation in rule.Violations)
            {
                JObject jsonViolation = new JObject();

                jsonViolation["Level"] = System.Enum.GetName(typeof(ViolationLevel), violation.m_level);
                jsonViolation["Summary"] = violation.m_summary;

                JArray calls = new JArray();

                foreach (var call in violation.m_violatingCalls)
                {
                    JObject jsonCall = new JObject();

                    jsonCall["Call Id"] = call.m_id;
                    jsonCall["UriMethod"] = call.m_uri;
                    if (call.m_xsapiMethods != null)
                    {
                        jsonCall["CppMethod"] = call.m_xsapiMethods.Item1;
                        jsonCall["WinRTMethod"] = call.m_xsapiMethods.Item2;
                    }

                    calls.Add(jsonCall);
                }

                jsonViolation["Calls"] = calls;

                jsonViolations.Add(jsonViolation);
            }

            jsonRule["Violations"] = jsonViolations;

            return jsonRule;
        }