private List <ActiveRule> createActiveRules() { /* * <Rules AnalyzerId=""SonarLint.CSharp"" RuleNamespace=""SonarLint.CSharp""> * <Rule Id=""S1116"" Action=""Warning""/> * <Rule Id=""S1125"" Action=""Warning""/> * </Rules> * <Rules AnalyzerId=""Wintellect.Analyzers"" RuleNamespace=""Wintellect.Analyzers""> * <Rule Id=""Wintellect003"" Action=""Warning""/> * </Rules> */ var rules = new List <ActiveRule>(); var ruleWithParameter = new ActiveRule("csharpsquid", "S1116"); var p = new Dictionary <string, string> { { "key", "value" } }; ruleWithParameter.Parameters = p; rules.Add(ruleWithParameter); rules.Add(new ActiveRule("csharpsquid", "S1125")); rules.Add(new ActiveRule("roslyn.wintellect", "Wintellect003")); return(rules); }
/// <summary> /// Retrieves active rules from the quality profile with the given ID, including their parameters and template keys. /// /// </summary> /// <param name="qprofile">Quality profile id.</param> /// <returns>List of active rules</returns> public IList <ActiveRule> GetActiveRules(string qprofile) { var fetched = 0; var page = 1; var total = 0; var activeRuleList = new List <ActiveRule>(); do { var ws = GetUrl("/api/rules/search?f=repo,name,severity,lang,internalKey,templateKey,params,actives&ps=500&activation=true&qprofile={0}&p={1}", qprofile, page.ToString()); logger.LogDebug(Resources.MSG_FetchingActiveRules, qprofile, ws); activeRuleList.AddRange(DoLogExceptions(() => { var contents = downloader.Download(ws); var json = JObject.Parse(contents); total = json["total"].ToObject <int>(); fetched += json["ps"].ToObject <int>(); page++; var rules = json["rules"].Children <JObject>(); var actives = json["actives"]; return(rules.Select(r => { var activeRulesForRuleKey = actives.Value <JArray>(r["key"].ToString()); if (activeRulesForRuleKey == null || activeRulesForRuleKey.Count != 1) { // Because of the parameters we use we expect to have only actives rules. So rules and actives // should both contain the same number of elements (i.e. the same rules). throw new JsonException($"Malformed json response, \"actives\" field should contain rule '{r["key"].ToString()}'"); } var activeRule = new ActiveRule(r["repo"].ToString(), ParseRuleKey(r["key"].ToString())); if (r["internalKey"] != null) { activeRule.InternalKey = r["internalKey"].ToString(); } if (r["templateKey"] != null) { activeRule.TemplateKey = r["templateKey"].ToString(); } var activeRuleParams = activeRulesForRuleKey[0]["params"].Children <JObject>(); activeRule.Parameters = activeRuleParams.ToDictionary(pair => pair["key"].ToString(), pair => pair["value"].ToString()); if (activeRule.Parameters.ContainsKey("CheckId")) { activeRule.RuleKey = activeRule.Parameters["CheckId"]; } return activeRule; })); }, ws)); } while (fetched < total); return(activeRuleList); }
/// <summary> /// Retrieves active rules from the quality profile with the given ID, including their parameters and template keys. /// /// </summary> /// <param name="qprofile">Quality profile id.</param> /// <returns>List of active rules</returns> public IList <ActiveRule> GetActiveRules(string qprofile) { var fetched = 0; var page = 1; var total = 0; var activeRuleList = new List <ActiveRule>(); do { var ws = GetUrl("/api/rules/search?f=repo,name,severity,lang,internalKey,templateKey,params,actives&ps=500&activation=true&qprofile={0}&p={1}", qprofile, page.ToString()); logger.LogDebug(Resources.MSG_FetchingActiveRules, qprofile, ws); activeRuleList.AddRange(DoLogExceptions(() => { var contents = downloader.Download(ws); var json = JObject.Parse(contents); total = Convert.ToInt32(json["total"]); fetched += Convert.ToInt32(json["ps"]); page++; var rules = json["rules"].Children <JObject>(); var actives = json["actives"]; return(rules.Select(r => { var activeRule = new ActiveRule(r["repo"].ToString(), ParseRuleKey(r["key"].ToString())); if (r["internalKey"] != null) { activeRule.InternalKey = r["internalKey"].ToString(); } if (r["templateKey"] != null) { activeRule.TemplateKey = r["templateKey"].ToString(); } var active = actives[r["key"].ToString()]; var listParams = active.Single()["params"].Children <JObject>(); activeRule.Parameters = listParams.ToDictionary(pair => pair["key"].ToString(), pair => pair["value"].ToString()); if (activeRule.Parameters.ContainsKey("CheckId")) { activeRule.RuleKey = activeRule.Parameters["CheckId"]; } return activeRule; })); }, ws)); } while (fetched < total); return(activeRuleList); }
public QualityProfile AddRule(ActiveRule rule) { this.activeRules.Add(rule); return(this); }
public void AddActiveRuleToProfile(string qProfile, ActiveRule rule) { var profile = FindProfile(qProfile); profile.ActiveRules.Add(rule); }
public void AddActiveRuleToProfile(string qProfile, ActiveRule rule) { QualityProfile profile = this.FindProfile(qProfile); profile.ActiveRules.Add(rule); }
private static void InitMainEngine() { IBinder binderObject = null; if (binder) { if (csharpBinder) { String code; using (StreamReader sr = File.OpenText(RuleBaseFile + ".ccb")) code = sr.ReadToEnd(); binderObject = CSharpBinderFactory.LoadFromString("NxBRE.StressTests." + ActiveRule.ToUpper() + "_Binder", code); } else { binderObject = new FlowEngineBinder(RuleBaseFile + ".xbre", BindingTypes.BeforeAfter); } } MAIN_IE.LoadRuleBase(new RuleML09NafDatalogAdapter(RuleBaseFile, System.IO.FileAccess.Read), binderObject); }