Пример #1
0
        private void GlobalToLocal()
        {
            // Convert a rule from global to local:
            var item = listView1.SelectedItems[0];
            var rule = item.Tag as BestPracticeRule;

            analyzer.GlobalRules.Remove(rule);
            analyzer.LocalRules.Add(rule);
            item.Group = lvgLocal;

            analyzer.SaveLocalRulesToModel();

            // Save global rules (less the newly demoted rule):
            var bpc             = new BestPracticeCollection();
            var globalRulesFile = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\TabularEditor\BPARules.json";

            bpc.AddFromJsonFile(globalRulesFile);
            var deleteRule = bpc.FirstOrDefault(r => r.ID.Equals(rule.ID, StringComparison.InvariantCultureIgnoreCase));

            if (deleteRule != null)
            {
                bpc.Remove(deleteRule);
                bpc.SaveToFile(globalRulesFile);
            }
        }
Пример #2
0
        private void btnEdit_Click(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count == 1)
            {
                var rule = listView1.SelectedItems[0].Tag as BestPracticeRule;
                editor.PopulateCategories(analyzer.AllRules);
                var oldRuleId = rule.ID;
                if (editor.EditRule(rule))
                {
                    if (analyzer.LocalRules.Contains(rule))
                    {
                        analyzer.SaveLocalRulesToModel();
                    }
                    else if (analyzer.GlobalRules.Contains(rule))
                    {
                        var bpc = new BestPracticeCollection();
                        bpc.Add(rule);

                        var globalRulesFile = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\TabularEditor\BPARules.json";

                        bpc.AddFromJsonFile(globalRulesFile);
                        if (oldRuleId != rule.ID)
                        {
                            // ID changed - let's delete the rule with the old ID:
                            var oldRule = bpc.FirstOrDefault(r => r.ID == oldRuleId);
                            if (oldRule != null)
                            {
                                bpc.Remove(oldRule);
                            }
                        }
                        bpc.SaveToFile(globalRulesFile);
                    }

                    PopulateListView();
                }
            }
        }