Beispiel #1
0
        public ControlSet Execute(DependencyObject sourceControl)
        {
            Common.AddToLog("executing selector: " + this.Query);

            SourceControl = sourceControl;
            ControlSet superSet        = XamlQuery.All(sourceControl);
            ControlSet matchedControls = new ControlSet();

            if (SimpleSelectors.Count == 1) //if only one simple-selector, then execute it and return the result
            {
                return(SimpleSelectors[0].Execute(superSet));
            }
            else if (SimpleSelectors.Count > 1) //if more than one simple-selectors, then apply combinators while executing
            {
                //apply each combinator to result of simple-selector that precedes it
                ControlSet currentSet = new ControlSet();
                currentSet.AddRange(superSet);
                for (int index = 0; index < SimpleSelectors.Count; index++)
                {
                    if (index > 0)
                    {
                        Common.AddToLog("**Executing Combinator: " + Combinators[index - 1].Token.Content);
                        currentSet = Combinators[index - 1].Execute(currentSet);
                        Common.AddToLog("**Combinator-Result: " + currentSet.Count + " controls");
                        if (Combinators[index - 1].Type == CombinatorType.Adjacent)
                        {
                            //for adjacent combinator
                            //   get first-set by executing simple-selector before + with result of combinator
                            //   get second-set by executing simple-selector after + with result of combinator
                            //   combine first and second sets as result of combinator and its simple-selectors
                            ControlSet firstSet  = SimpleSelectors[index - 1].Execute(currentSet);
                            ControlSet secondSet = SimpleSelectors[index].Execute(currentSet);
                            currentSet.Clear();
                            currentSet.AddRange(firstSet);
                            currentSet.AddRange(secondSet);
                            Common.AddToLog("**First-Set-Result: " + firstSet.Count + " controls. " + string.Join(",", (from c in firstSet select c.GetType().ToString()).ToArray()));
                            Common.AddToLog("**Second-Set-Result: " + secondSet.Count + " controls. " + string.Join(",", (from c in secondSet select c.GetType().ToString()).ToArray()));
                            Common.AddToLog("**Simple-Selector-Result: " + currentSet.Count + " controls");
                            continue;
                        }
                    }
                    Common.AddToLog("**Executing Simple-Selector: " + SimpleSelectors[index].Query);
                    currentSet = SimpleSelectors[index].Execute(currentSet);
                    Common.AddToLog("**Simple-Selector-Result: " + currentSet.Count + " controls");
                }
                matchedControls.AddRange(currentSet);
            }

            return(matchedControls);
        }
Beispiel #2
0
        public ControlSet Execute(DependencyObject sourceControl)
        {
            Common.AddToLog("executing selector: " + this.Query);

            SourceControl = sourceControl;
            ControlSet superSet = XamlQuery.All(sourceControl);
            ControlSet matchedControls = new ControlSet();

            if (SimpleSelectors.Count == 1) //if only one simple-selector, then execute it and return the result
            {
                return (SimpleSelectors[0].Execute(superSet));
            }
            else if (SimpleSelectors.Count > 1) //if more than one simple-selectors, then apply combinators while executing
            {
                //apply each combinator to result of simple-selector that precedes it
                ControlSet currentSet = new ControlSet();
                currentSet.AddRange(superSet);
                for (int index = 0; index < SimpleSelectors.Count; index++)
                {
                    if (index > 0)
                    {
                        Common.AddToLog("**Executing Combinator: " + Combinators[index - 1].Token.Content);
                        currentSet = Combinators[index - 1].Execute(currentSet);
                        Common.AddToLog("**Combinator-Result: " + currentSet.Count + " controls");
                        if (Combinators[index - 1].Type == CombinatorType.Adjacent)
                        {
                            //for adjacent combinator
                            //   get first-set by executing simple-selector before + with result of combinator
                            //   get second-set by executing simple-selector after + with result of combinator
                            //   combine first and second sets as result of combinator and its simple-selectors
                            ControlSet firstSet = SimpleSelectors[index - 1].Execute(currentSet);
                            ControlSet secondSet = SimpleSelectors[index].Execute(currentSet);
                            currentSet.Clear();
                            currentSet.AddRange(firstSet);
                            currentSet.AddRange(secondSet);
                            Common.AddToLog("**First-Set-Result: " + firstSet.Count + " controls. " + string.Join(",", (from c in firstSet select c.GetType().ToString()).ToArray()));
                            Common.AddToLog("**Second-Set-Result: " + secondSet.Count + " controls. " + string.Join(",", (from c in secondSet select c.GetType().ToString()).ToArray()));
                            Common.AddToLog("**Simple-Selector-Result: " + currentSet.Count + " controls");
                            continue;
                        }
                    }
                    Common.AddToLog("**Executing Simple-Selector: " + SimpleSelectors[index].Query);
                    currentSet = SimpleSelectors[index].Execute(currentSet);
                    Common.AddToLog("**Simple-Selector-Result: " + currentSet.Count + " controls");
                }
                matchedControls.AddRange(currentSet);
            }

            return (matchedControls);
        }