Esempio n. 1
0
        public void IgnoreRule(BestPracticeRule rule, bool ignore = true, IAnnotationObject obj = null)
        {
            if (obj == null)
            {
                obj = _model;
            }

            var ignoreRules = new AnalyzerIgnoreRules(obj ?? _model);

            if (ignore)
            {
                if (!ignoreRules.RuleIDs.Contains(rule.ID))
                {
                    ignoreRules.RuleIDs.Add(rule.ID);
                }
            }
            else
            {
                if (ignoreRules.RuleIDs.Contains(rule.ID))
                {
                    ignoreRules.RuleIDs.Remove(rule.ID);
                }
            }

            ignoreRules.Save(obj);
        }
Esempio n. 2
0
        public static void Show(Analyzer analyzer)
        {
            var model = analyzer.Model;
            var form  = new BPAManager();

            form.lblNoModelWarning.Visible = model == null;
            form.Model    = model;
            form.Analyzer = analyzer;
            form.Init();

            analyzer.UpdateEnabled();

            if (form.ShowDialog(ActiveForm) == DialogResult.OK)
            {
                if (model != null)
                {
                    UIController.Current.Handler.BeginUpdate("BPA rule management");

                    // Persist ignore changes to model:
                    var ignoreHandler = new AnalyzerIgnoreRules(model);
                    var newIgnored    = new HashSet <string>(analyzer.EffectiveRules.Where(r => !r.Enabled).Select(r => r.ID));

                    foreach (var rule in newIgnored.Except(ignoreHandler.RuleIDs).ToList())
                    {
                        ignoreHandler.RuleIDs.Add(rule);
                    }
                    foreach (var rule in ignoreHandler.RuleIDs.Except(newIgnored).ToList())
                    {
                        ignoreHandler.RuleIDs.Remove(rule);
                    }
                    ignoreHandler.Save(model);

                    analyzer.ModelRules.Save();
                }

                analyzer.LocalUserRules.Save();
                analyzer.LocalMachineRules.Save();
                analyzer.SaveExternalRuleCollections();

                foreach (var externalRuleCollection in analyzer.ExternalRuleCollections)
                {
                    externalRuleCollection.Save();
                }

                if (model != null)
                {
                    UIController.Current.Handler.EndUpdate();
                    UIController.Current.InvokeBPABackground(false);
                }
            }
            else
            {
                var addedRules    = form.rulesModel.AddedRules;
                var deletedRules  = form.rulesModel.DeletedRules;
                var modifiedRules = form.rulesModel.ModifiedRules;

                // Remove rules that were added:
                foreach (var ruleKvp in addedRules)
                {
                    ruleKvp.Value.Rules.Remove(ruleKvp.Key);
                }

                // Restore rules that were deleted:
                foreach (var ruleKvp in deletedRules)
                {
                    ruleKvp.Value.Add(ruleKvp.Key);
                }

                // Restore rules that were modified:
                foreach (var ruleKvp in modifiedRules)
                {
                    ruleKvp.Key.AssignFrom(ruleKvp.Value);
                }

                // Restore rule enabled status:
                foreach (var rule in analyzer.EffectiveRules)
                {
                    rule.UpdateEnabled(model);
                }

                // Restore external rule collections:
                analyzer.LoadExternalRuleCollections();
            }
        }