public static IEnumerable <Common.Types.RuleGroup> ToKernalRuleGroups(RuleGroup[] ruleGroups)
        {
            List <Common.Types.RuleGroup> groups = new List <Common.Types.RuleGroup>();

            foreach (var g in ruleGroups)
            {
                if (g.Rules.Length == 0)
                {
                    continue;
                }

                var rg = new Common.Types.RuleGroup()
                {
                    DisplayName = g.DisplayName,
                    Name        = g.Name,
                };

                var drList = new List <Common.Types.Rule>();
                AddKernalRules(g.Rules, drList);
                rg.Rules = drList.ToArray();

                groups.Add(rg);
            }

            return(groups.ToArray());
        }
        /// <summary>
        /// Apply the test case selection rules detected by the plug-in.
        /// </summary>
        /// <param name="ruleGroupsBySelectedRules">The rule groups by selected rules.</param>
        /// <param name="targetFilterIndex">Target filter index</param>
        /// <param name="mappingFilterIndex">Mapping filter index</param>
        public void ApplyDetectedRules(out IEnumerable <Common.Types.RuleGroup> ruleGroupsBySelectedRules, int targetFilterIndex, int mappingFilterIndex)
        {
            // Get the filter.
            var filter = TestSuite.GetTestCaseFilter();

            // create mapping table for the filter.
            CreateMappingTableForTestCaseFilter(filter, targetFilterIndex, mappingFilterIndex);
            // Update selected rules for the filter.
            foreach (var rule in ValueDetector.GetSelectedRules())
            {
                Kernel.Rule r = filter.FindRuleByName(rule.Name);
                if (r == null)
                {
                    throw new Exception(string.Format("Cannot find rule by name {0}.", rule.Name));
                }
                switch (rule.Status)
                {
                case Microsoft.Protocols.TestManager.Detector.RuleStatus.Selected:
                    r.SelectStatus = Kernel.RuleSelectStatus.Selected;
                    r.Status       = RuleSupportStatus.Selected;
                    break;

                case Microsoft.Protocols.TestManager.Detector.RuleStatus.NotSupported:
                    r.SelectStatus = Kernel.RuleSelectStatus.UnSelected;
                    r.Status       = RuleSupportStatus.NotSupported;
                    break;

                case Microsoft.Protocols.TestManager.Detector.RuleStatus.Unknown:
                    r.SelectStatus = Kernel.RuleSelectStatus.UnSelected;
                    r.Status       = RuleSupportStatus.Unknown;
                    break;

                default:
                    r.SelectStatus = Kernel.RuleSelectStatus.UnSelected;
                    r.Status       = RuleSupportStatus.Default;
                    break;
                }
            }
            // Update filter to ruleGroups
            var ruleGroups = new List <Common.Types.RuleGroup>();

            foreach (var group in filter)
            {
                Common.Types.RuleGroup ruleGroup = new Common.Types.RuleGroup()
                {
                    Name        = group.Name,
                    DisplayName = group.Name,
                    Rules       = new List <Common.Types.Rule>()
                };
                AddItems(ruleGroup.Rules, group);
                ruleGroups.Add(ruleGroup);
            }
            // Update the selected rule groups.
            ruleGroupsBySelectedRules = ruleGroups;
        }