Example #1
0
 internal ChildSelector With(Int32 step, Int32 offset, ISelector kind)
 {
     _step = step;
     _offset = offset;
     _kind = kind;
     return this;
 }
Example #2
0
 protected override void ReplaceWith(ICssRule rule)
 {
     var newRule = (CssStyleRule)rule;
     _selector = newRule._selector;
     _style.Clear();
     _style.SetDeclarations(newRule._style.Declarations);
 }
Example #3
0
    /// <summary>
    /// 创建现有 CSS 选择器的自动缓存包装
    /// </summary>
    /// <param name="selector">已有的 CSS 选择器</param>
    /// <returns>对已有选择器的自动缓存的包装</returns>
    public static ISelector CreateCacheableWrapper( ISelector selector )
    {
      var cacheable = selector as CacheableSelector;
      if ( cacheable == null )
        cacheable = new CacheableCssSelectorWrapper( selector );

      return cacheable;
    }
Example #4
0
    protected override bool IsEligible( ISelector leftSelector, IHtmlElement element )
    {
      var restrict = leftSelector as ContainerRestrict;
      if ( restrict != null )
        return restrict.RestrictContainer.Nodes().Contains( element );

      return leftSelector.IsEligibleBuffered( element.Parent() );
    }
        /// <summary>
        /// Initializes a new instance of the <see cref="PropertyReflectionStrategy"/> class.
        /// </summary>
        /// <param name="selector">The selector component.</param>
        /// <param name="injectorFactory">The injector factory component.</param>
        public PropertyReflectionStrategy(ISelector selector, IInjectorFactory injectorFactory)
        {
            Ensure.ArgumentNotNull(selector, "selector");
            Ensure.ArgumentNotNull(injectorFactory, "injectorFactory");

            Selector = selector;
            InjectorFactory = injectorFactory;
        }
Example #6
0
 public string SelectDocument(ISelector selector)
 {
     IElementSelector elementSelector = selector as IElementSelector;
     if (elementSelector != null)
     {
         return elementSelector.Select(Document);
     }
     return selector?.Select(GetFirstSourceText());
 }
Example #7
0
 public IList<string> SelectDocumentForList(ISelector selector)
 {
     var elementSelector = selector as IElementSelector;
     if (elementSelector != null)
     {
         return elementSelector.SelectList(Document);
     }
     return selector?.SelectList(GetFirstSourceText());
 }
Example #8
0
 public MultiSelector(
     IRangeSelector rangeSelector,
     ISelector inverseSelector,
     ISelector nullSelector)
 {
     _nullSelector = nullSelector;
     _inverseSelector = inverseSelector;
     _rangeSelector = rangeSelector;
 }
Example #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="StandardProvider"/> class.
        /// </summary>
        /// <param name="type">The type (or prototype) of instances the provider creates.</param>
        /// <param name="planner">The planner component.</param>
        /// <param name="selector">The selector component.</param>
        public StandardProvider(Type type, IPlanner planner, ISelector selector)
        {
            Ensure.ArgumentNotNull(type, "type");
            Ensure.ArgumentNotNull(planner, "planner");
            Ensure.ArgumentNotNull(selector, "selector");

            Type = type;
            Planner = planner;
            Selector = selector;
        }
Example #10
0
        /// <summary>
        /// 使用选择器从元素集中筛选出符合选择器要求的元素
        /// </summary>
        /// <param name="source">源元素集</param>
        /// <param name="selector">选择器</param>
        /// <returns>筛选结果</returns>
        public static IEnumerable<IHtmlElement> FilterBy( this IEnumerable<IHtmlElement> source, ISelector selector )
        {
            if ( source == null )
            return null;

              if ( selector == null )
            return source;

              return source.Where( selector.IsEligible );
        }
        /// <summary>
        /// 创建 CSS 层叠选择器对象
        /// </summary>
        /// <param name="relativeSelector">关系选择器</param>
        /// <param name="lastSelector">附加的最后一个选择器</param>
        public CssCasecadingSelector( CssRelativeSelector relativeSelector, ISelector lastSelector )
        {
            if ( relativeSelector == null )
            throw new ArgumentNullException( "relativeSelector" );

              if ( lastSelector == null )
            throw new ArgumentNullException( "lastSelector" );

              RelativeSelector = relativeSelector;
              LastSelector = lastSelector;
        }
Example #12
0
 public void ConcludeSelector(ISelector selector)
 {
     if (!IsReady)
     {
         _selectors.Add(new CombinatorSelector
         {
             Selector = selector,
             Transform = null,
             Delimiter = null
         });
         IsReady = true;
     }
 }
Example #13
0
        /// <summary>
        /// 派生类重写此方法确定指定元素是否需要重写渲染规则
        /// </summary>
        /// <param name="element">要检测的元素</param>
        /// <returns>是否需要使用自定义渲染规则</returns>
        protected virtual bool IsEligible( IHtmlElement element )
        {
            if ( CssSelector == null )
            return false;

              if ( _selectorExpression == CssSelector )
            return _selectorCache.IsEligible( element );

              _selectorExpression = CssSelector;
              _selectorCache = CssParser.ParseSelector( CssSelector );

              return _selectorCache.IsEligible( element );
        }
        public GeneticAlgorithm(IRandom rand, Population candidates, Func<IOrganism, double> fitnessFunction, ISelector selector, IMutator mutator, ICrossover crossLinker, double elitismProportion, int maximumGenerations)
        {
            this.rand = rand;
            this.candidates = candidates;
            this.fitnessFunction = fitnessFunction;
            this.selector = selector;
            this.mutator = mutator;
            this.crossLinker = crossLinker;
            this.elitismProportion = elitismProportion;
            this._generationCount = 0;
            this.generationInformation = new Dictionary<int, double>();
            this.initialCount = candidates.Count;
            this.maximumGenerations = maximumGenerations;

            this.candidates.CalculateFitnesses(this.fitnessFunction);
        }
Example #15
0
    /// <summary>
    /// 创建层叠选择器实例
    /// </summary>
    /// <param name="leftSelector">左选择器</param>
    /// <param name="combinator">结合符</param>
    /// <param name="rightSelector">右选择器</param>
    public static CssCasecadingSelector Create( ISelector leftSelector, char combinator, ISelector rightSelector )
    {
      if ( leftSelector == null )
        throw new ArgumentNullException( "leftSelector" );

      if ( rightSelector == null )
        throw new ArgumentNullException( "rightSelector" );


      var relativeSelctor = CreateRelativeSelector( leftSelector, combinator );
      var casecadingSelector = rightSelector as CssCasecadingSelector;

      if ( casecadingSelector != null )
        return Combine( relativeSelctor, casecadingSelector );

      return new CssCasecadingSelector( relativeSelctor, rightSelector );
    }
 private void RunProcessing()
 {
     try
     {
         int delay = config.HostRequestDelayMilliseconds();
         selector = CallSelectorFactory.createISelector(config);
         selector.setIErrorHandler(errorHandler);
         threadStarted.Set();
         while (!stopThread.WaitOne(delay))
         {
             if (false == selector.Run())
                 break;
         }
         lock (lockLog)
         {
             serviceEventLog.WriteEntry("Processing finished.");
         }
     }
     catch (ThreadAbortException) {/*ignore*/}
 }
Example #17
0
 public void Deselect(ISelector selector)
 {
     if (selectors.ContainsKey(selector))
     {
         Border b = selectors[selector] as Border;
         if (Content == b)
         {
             object c = b.Child;
             Content = null;
             b.Child = null;
             Content = c;
         }
         else if (b.Parent is Border)
         {
             UIElement uie = b.Child;
             b.Child = null;
             Border parent = b.Parent as Border;
             parent.Child = null;
             parent.Child = uie;
         }
         selectors.Remove(selector);
     }
 }
 /// <summary>
 /// Registers a new selector for the specified name.
 /// Throws an exception if another selector for the given
 /// name is already added.
 /// </summary>
 /// <param name="name">The name of the CSS pseudo element.</param>
 /// <param name="selector">The selector to register.</param>
 public void Register(String name, ISelector selector)
 {
     _selectors.Add(name, selector);
 }
        public static Task <IList <T> > ResolveAsync <T>(this IManagedConnection runner, NpgsqlCommand cmd, ISelector <T> selector, IIdentityMap map, QueryStatistics stats, CancellationToken token)
        {
            var selectMap = map.ForQuery();

            return(runner.ExecuteAsync(cmd, async(c, tkn) =>
            {
                var list = new List <T>();
                using (var reader = await cmd.ExecuteReaderAsync(tkn).ConfigureAwait(false))
                {
                    while (await reader.ReadAsync(tkn).ConfigureAwait(false))
                    {
                        list.Add(selector.Resolve(reader, selectMap, stats));
                    }
                }

                return list.As <IList <T> >();
            }, token));
        }
Example #20
0
        private static IEnumerable <IElement> GetMany(this IEnumerable <IElement> elements, Func <IElement, IEnumerable <IElement> > getter, ISelector selector)
        {
            if (selector == null)
            {
                selector = AllSelector.Instance;
            }

            foreach (var element in elements)
            {
                var children = getter(element);

                foreach (var child in children)
                {
                    if (selector.Match(child))
                    {
                        yield return(child);
                    }
                }
            }
        }
Example #21
0
 /// <summary>
 /// Gets the children of the provided elements. Optionally uses a CSS
 /// selector to filter the results.
 /// </summary>
 /// <param name="elements">The elements owning the children.</param>
 /// <param name="selector">The CSS selector to use, if any.</param>
 /// <returns>A filtered list containing the children.</returns>
 public static IEnumerable <IElement> Children(this IEnumerable <IElement> elements, ISelector selector = null)
 {
     return(elements.GetMany(m => m.Children, selector));
 }
Example #22
0
        private static IEnumerable <IElement> Get(this IEnumerable <IElement> elements, Func <IElement, IElement> getter, ISelector selector)
        {
            if (selector == null)
            {
                selector = AllSelector.Instance;
            }

            foreach (var element in elements)
            {
                var child = getter(element);

                while (child != null)
                {
                    if (selector.Match(child))
                    {
                        yield return(child);

                        break;
                    }

                    child = getter(child);
                }
            }
        }
Example #23
0
 public IGroupEnumerator <T2, K2> Agrupa(IEnumerable <T2> coleccion, ISelector <T2, K2> selector)
 {
     return(new GrupoEnumerador <T2, K2>(coleccion, selector));
 }
        /// <summary>
        /// Gets all style rules that have the same selector text.
        /// </summary>
        /// <param name="sheets">The list of stylesheets to consider.</param>
        /// <param name="selector">The selector to compare to.</param>
        /// <returns>The list of style rules.</returns>
        public static IEnumerable <ICssStyleRule> StylesWith(this IEnumerable <IStyleSheet> sheets, ISelector selector)
        {
            if (selector == null)
            {
                throw new ArgumentNullException("selector");
            }

            var selectorText = selector.Text;

            return(sheets.RulesOf <ICssStyleRule>().Where(m => m.SelectorText == selectorText));
        }
Example #25
0
        public NSGA2()
        {
            Parameters.Add(new ValueParameter <IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
            Parameters.Add(new ValueParameter <BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
            Parameters.Add(new ValueParameter <IntValue>("PopulationSize", "The size of the population of solutions.", new IntValue(100)));
            Parameters.Add(new ConstrainedValueParameter <ISelector>("Selector", "The operator used to select solutions for reproduction."));
            Parameters.Add(new ValueParameter <PercentValue>("CrossoverProbability", "The probability that the crossover operator is applied on two parents.", new PercentValue(0.9)));
            Parameters.Add(new ConstrainedValueParameter <ICrossover>("Crossover", "The operator used to cross solutions."));
            Parameters.Add(new ValueParameter <PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new PercentValue(0.05)));
            Parameters.Add(new ConstrainedValueParameter <IManipulator>("Mutator", "The operator used to mutate solutions."));
            Parameters.Add(new ValueParameter <MultiAnalyzer>("Analyzer", "The operator used to analyze each generation.", new MultiAnalyzer()));
            Parameters.Add(new ValueParameter <IntValue>("MaximumGenerations", "The maximum number of generations which should be processed.", new IntValue(1000)));
            Parameters.Add(new ValueParameter <IntValue>("SelectedParents", "Each two parents form a new child, typically this value should be twice the population size, but because the NSGA-II is maximally elitist it can be any multiple of 2 greater than 0.", new IntValue(200)));
            Parameters.Add(new FixedValueParameter <BoolValue>("DominateOnEqualQualities", "Flag which determines wether solutions with equal quality values should be treated as dominated.", new BoolValue(false)));

            RandomCreator         randomCreator         = new RandomCreator();
            SolutionsCreator      solutionsCreator      = new SolutionsCreator();
            SubScopesCounter      subScopesCounter      = new SubScopesCounter();
            RankAndCrowdingSorter rankAndCrowdingSorter = new RankAndCrowdingSorter();
            ResultsCollector      resultsCollector      = new ResultsCollector();
            NSGA2MainLoop         mainLoop = new NSGA2MainLoop();

            OperatorGraph.InitialOperator = randomCreator;

            randomCreator.RandomParameter.ActualName          = "Random";
            randomCreator.SeedParameter.ActualName            = SeedParameter.Name;
            randomCreator.SeedParameter.Value                 = null;
            randomCreator.SetSeedRandomlyParameter.ActualName = SetSeedRandomlyParameter.Name;
            randomCreator.SetSeedRandomlyParameter.Value      = null;
            randomCreator.Successor = solutionsCreator;

            solutionsCreator.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name;
            solutionsCreator.Successor = subScopesCounter;

            subScopesCounter.Name = "Initialize EvaluatedSolutions";
            subScopesCounter.ValueParameter.ActualName = "EvaluatedSolutions";
            subScopesCounter.Successor = rankAndCrowdingSorter;

            rankAndCrowdingSorter.DominateOnEqualQualitiesParameter.ActualName = DominateOnEqualQualitiesParameter.Name;
            rankAndCrowdingSorter.CrowdingDistanceParameter.ActualName         = "CrowdingDistance";
            rankAndCrowdingSorter.RankParameter.ActualName = "Rank";
            rankAndCrowdingSorter.Successor = resultsCollector;

            resultsCollector.CollectedValues.Add(new LookupParameter <IntValue>("Evaluated Solutions", null, "EvaluatedSolutions"));
            resultsCollector.ResultsParameter.ActualName = "Results";
            resultsCollector.Successor = mainLoop;

            mainLoop.PopulationSizeParameter.ActualName       = PopulationSizeParameter.Name;
            mainLoop.SelectorParameter.ActualName             = SelectorParameter.Name;
            mainLoop.CrossoverParameter.ActualName            = CrossoverParameter.Name;
            mainLoop.CrossoverProbabilityParameter.ActualName = CrossoverProbabilityParameter.Name;
            mainLoop.MaximumGenerationsParameter.ActualName   = MaximumGenerationsParameter.Name;
            mainLoop.MutatorParameter.ActualName             = MutatorParameter.Name;
            mainLoop.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
            mainLoop.RandomParameter.ActualName             = RandomCreator.RandomParameter.ActualName;
            mainLoop.AnalyzerParameter.ActualName           = AnalyzerParameter.Name;
            mainLoop.ResultsParameter.ActualName            = "Results";
            mainLoop.EvaluatedSolutionsParameter.ActualName = "EvaluatedSolutions";

            foreach (ISelector selector in ApplicationManager.Manager.GetInstances <ISelector>().Where(x => !(x is ISingleObjectiveSelector)).OrderBy(x => x.Name))
            {
                SelectorParameter.ValidValues.Add(selector);
            }
            ISelector tournamentSelector = SelectorParameter.ValidValues.FirstOrDefault(x => x.GetType().Name.Equals("CrowdedTournamentSelector"));

            if (tournamentSelector != null)
            {
                SelectorParameter.Value = tournamentSelector;
            }

            ParameterizeSelectors();

            paretoFrontAnalyzer = new RankBasedParetoFrontAnalyzer();
            paretoFrontAnalyzer.RankParameter.ActualName    = "Rank";
            paretoFrontAnalyzer.RankParameter.Depth         = 1;
            paretoFrontAnalyzer.ResultsParameter.ActualName = "Results";
            ParameterizeAnalyzers();
            UpdateAnalyzers();

            RegisterEventhandlers();
        }
 public WriterSceneInfoSelector(ISelector <EncounterSelectedEventArgs> encounterSelector)
 => EncounterSelector = encounterSelector;
Example #27
0
 protected CompoundControl(ISearchContainer container, ISelector selector)
     : base(container, selector)
 {
     ExecuteInitAction();
 }
        public GeneticAlgorithm()
            : base()
        {
            Parameters.Add(new ValueParameter <IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
            Parameters.Add(new ValueParameter <BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
            Parameters.Add(new ValueParameter <IntValue>("PopulationSize", "The size of the population of solutions.", new IntValue(100)));
            Parameters.Add(new ConstrainedValueParameter <ISelector>("Selector", "The operator used to select solutions for reproduction."));
            Parameters.Add(new ConstrainedValueParameter <ICrossover>("Crossover", "The operator used to cross solutions."));
            Parameters.Add(new ValueParameter <PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new PercentValue(0.05)));
            Parameters.Add(new OptionalConstrainedValueParameter <IManipulator>("Mutator", "The operator used to mutate solutions."));
            Parameters.Add(new ValueParameter <IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1)));
            Parameters.Add(new FixedValueParameter <BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)", new BoolValue(false))
            {
                Hidden = true
            });
            Parameters.Add(new ValueParameter <MultiAnalyzer>("Analyzer", "The operator used to analyze each generation.", new MultiAnalyzer()));
            Parameters.Add(new ValueParameter <IntValue>("MaximumGenerations", "The maximum number of generations which should be processed.", new IntValue(1000)));

            RandomCreator            randomCreator    = new RandomCreator();
            SolutionsCreator         solutionsCreator = new SolutionsCreator();
            SubScopesCounter         subScopesCounter = new SubScopesCounter();
            ResultsCollector         resultsCollector = new ResultsCollector();
            GeneticAlgorithmMainLoop mainLoop         = new GeneticAlgorithmMainLoop();

            OperatorGraph.InitialOperator = randomCreator;

            randomCreator.RandomParameter.ActualName          = "Random";
            randomCreator.SeedParameter.ActualName            = SeedParameter.Name;
            randomCreator.SeedParameter.Value                 = null;
            randomCreator.SetSeedRandomlyParameter.ActualName = SetSeedRandomlyParameter.Name;
            randomCreator.SetSeedRandomlyParameter.Value      = null;
            randomCreator.Successor = solutionsCreator;

            solutionsCreator.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name;
            solutionsCreator.Successor = subScopesCounter;

            subScopesCounter.Name = "Initialize EvaluatedSolutions";
            subScopesCounter.ValueParameter.ActualName = "EvaluatedSolutions";
            subScopesCounter.Successor = resultsCollector;

            resultsCollector.CollectedValues.Add(new LookupParameter <IntValue>("Evaluated Solutions", null, "EvaluatedSolutions"));
            resultsCollector.ResultsParameter.ActualName = "Results";
            resultsCollector.Successor = mainLoop;

            mainLoop.SelectorParameter.ActualName            = SelectorParameter.Name;
            mainLoop.CrossoverParameter.ActualName           = CrossoverParameter.Name;
            mainLoop.ElitesParameter.ActualName              = ElitesParameter.Name;
            mainLoop.ReevaluateElitesParameter.ActualName    = ReevaluateElitesParameter.Name;
            mainLoop.MaximumGenerationsParameter.ActualName  = MaximumGenerationsParameter.Name;
            mainLoop.MutatorParameter.ActualName             = MutatorParameter.Name;
            mainLoop.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
            mainLoop.RandomParameter.ActualName              = RandomCreator.RandomParameter.ActualName;
            mainLoop.AnalyzerParameter.ActualName            = AnalyzerParameter.Name;
            mainLoop.EvaluatedSolutionsParameter.ActualName  = "EvaluatedSolutions";
            mainLoop.PopulationSizeParameter.ActualName      = PopulationSizeParameter.Name;
            mainLoop.ResultsParameter.ActualName             = "Results";

            foreach (ISelector selector in ApplicationManager.Manager.GetInstances <ISelector>().Where(x => !(x is IMultiObjectiveSelector)).OrderBy(x => x.Name))
            {
                SelectorParameter.ValidValues.Add(selector);
            }
            ISelector proportionalSelector = SelectorParameter.ValidValues.FirstOrDefault(x => x.GetType().Name.Equals("ProportionalSelector"));

            if (proportionalSelector != null)
            {
                SelectorParameter.Value = proportionalSelector;
            }
            ParameterizeSelectors();

            qualityAnalyzer = new BestAverageWorstQualityAnalyzer();
            ParameterizeAnalyzers();
            UpdateAnalyzers();

            Initialize();
        }
Example #29
0
 public void RegisterSelector(ISelector filter)
 {
 }
Example #30
0
 public Button(ISearchContainer container, ISelector selector)
     : base(container, selector)
 {
 }
Example #31
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ConstructorReflectionStrategy"/> class.
 /// </summary>
 /// <param name="selector">The selector component.</param>
 /// <param name="injectorFactory">The injector factory component.</param>
 public ConstructorReflectionStrategy(ISelector selector, IInjectorFactory injectorFactory)
 {
     this.Selector        = selector;
     this.InjectorFactory = injectorFactory;
 }
Example #32
0
 /// <summary>
 /// Creates a new CSS style rule.
 /// </summary>
 internal CssStyleRule(CssParser parser)
     : base(CssRuleType.Style, parser)
 {
     _style = new CssStyleDeclaration(this);
     _selector = SimpleSelector.All;
 }
Example #33
0
 /// <summary>
 /// Gets the preceding siblings of the provided elements. Optionally
 /// uses a CSS selector to filter the results.
 /// </summary>
 /// <param name="elements">The elements with siblings.</param>
 /// <param name="selector">The CSS selector to use, if any.</param>
 /// <returns>A filtered list containing the previous siblings.</returns>
 public static IEnumerable <IElement> Previous(this IEnumerable <IElement> elements, ISelector selector = null)
 {
     return(elements.Get(m => m.PreviousElementSibling, selector));
 }
Example #34
0
        private dynamic ExtractField(ISelectable item, Page page, DataToken field, int index)
        {
            ISelector selector = SelectorUtil.Parse(field.Selector);

            if (selector == null)
            {
                return(null);
            }

            var f = field as Field;

            bool isEntity = field is Entity;

            if (!isEntity)
            {
                string tmpValue;
                if (selector is EnviromentSelector)
                {
                    var enviromentSelector = selector as EnviromentSelector;
                    tmpValue = GetEnviromentValue(enviromentSelector.Field, page, index);
                    if (f != null)
                    {
                        foreach (var formatter in f.Formatters)
                        {
                            tmpValue = formatter.Formate(tmpValue);
                        }
                    }
                    return(tmpValue);
                }
                else
                {
                    bool needPlainText = ((Field)field).Option == PropertyDefine.Options.PlainText;
                    if (field.Multi)
                    {
                        var propertyValues = item.SelectList(selector).Nodes();

                        List <string> results = new List <string>();
                        foreach (var propertyValue in propertyValues)
                        {
                            results.Add(propertyValue.GetValue(needPlainText));
                        }
                        if (f != null)
                        {
                            foreach (var formatter in f.Formatters)
                            {
                                results = formatter.Formate(results);
                            }
                        }
                        return(new JArray(results));
                    }
                    else
                    {
                        bool needCount = (((Field)field).Option == PropertyDefine.Options.Count);
                        if (needCount)
                        {
                            var    propertyValues = item.SelectList(selector).Nodes();
                            string count          = propertyValues?.Count.ToString();
                            count = string.IsNullOrEmpty(count) ? "-1" : count;
                            return(count);
                        }
                        else
                        {
                            tmpValue = item.Select(selector)?.GetValue(needPlainText);
                            if (f != null)
                            {
                                foreach (var formatter in f.Formatters)
                                {
                                    tmpValue = formatter.Formate(tmpValue);
                                }
                            }
                            return(tmpValue);
                        }
                    }
                }
            }
            else
            {
                if (field.Multi)
                {
                    JArray objs        = new JArray();
                    var    selectables = item.SelectList(selector).Nodes();
                    foreach (var selectable in selectables)
                    {
                        JObject obj = new JObject();

                        foreach (var child in ((Entity)field).Fields)
                        {
                            obj.Add(child.Name, ExtractField(selectable, page, child, 0));
                        }
                        objs.Add(obj);
                    }
                    return(objs);
                }
                else
                {
                    JObject obj        = new JObject();
                    var     selectable = item.Select(selector);
                    foreach (var child in ((Entity)field).Fields)
                    {
                        obj.Add(child.Name, ExtractField(selectable, page, field, 0));
                    }
                    return(obj);
                }
            }
        }
Example #35
0
 public async Task <ApiResponse> Set(ISelector selector, SentState state)
 {
     return(await this.Execute(state, selector.GetSelectorText()));
 }
Example #36
0
 /// <summary>
 /// 通过查询器查找结果
 /// </summary>
 /// <param name="selector">查询器</param>
 /// <returns>查询接口</returns>
 public abstract IEnumerable <ISelectable> SelectList(ISelector selector);
Example #37
0
 public ControlsWithoutRootTid(ISearchContainer container, ISelector selector)
     : base(container, selector)
 {
 }
Example #38
0
 public abstract IEnumerable<INode> GetNodes(ISelector<INode> selector);
Example #39
0
 /// <summary>
 /// Gets the siblings of the provided elements. Optionally uses a CSS
 /// selector to filter the results.
 /// </summary>
 /// <param name="elements">The elements with siblings.</param>
 /// <param name="selector">The CSS selector to use, if any.</param>
 /// <returns>A filtered list containing the siblings.</returns>
 public static IEnumerable <IElement> Siblings(this IEnumerable <IElement> elements, ISelector selector = null)
 {
     return(elements.GetMany(m => m.Parent.ChildNodes.OfType <IElement>().Except(m), selector));
 }
Example #40
0
 public abstract IEnumerable<Triple> GetTriples(ISelector<Triple> selector);
Example #41
0
 public abstract IEnumerable<Triple> GetTriplesWithSubject(ISelector<INode> selector);
Example #42
0
 public ListQueryHandler(Statement statement, ISelector <T> selector)
 {
     _statement = statement;
     Selector   = selector;
 }
Example #43
0
 public async Task <ApiResponse> Set(ISelector selector, Transition transition)
 {
     return(await this.Execute(transition, selector.GetSelectorText()));
 }
        public static IList <T> Resolve <T>(this IManagedConnection runner, NpgsqlCommand cmd, ISelector <T> selector, IIdentityMap map, QueryStatistics stats)
        {
            var selectMap = map.ForQuery();

            return(runner.Execute(cmd, c =>
            {
                var list = new List <T>();

                using (var reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        list.Add(selector.Resolve(reader, selectMap, stats));
                    }
                }

                return list;
            }));
        }
Example #45
0
 public abstract IEnumerable<Triple> GetTriples(ISelector<Triple> firstSelector, List<IDependentSelector<Triple>> selectorChain);
Example #46
0
 public void RegisterSelector(ISelector filter) {
    _filters.Add(filter);
 }
Example #47
0
 public abstract IEnumerable<Triple> GetTriplesWithPredicate(ISelector<INode> selector);
Example #48
0
 /// <summary>
 /// Gets the parents of the provided elements. Optionally uses a CSS
 /// selector to filter the results.
 /// </summary>
 /// <param name="elements">The elements with parents.</param>
 /// <param name="selector">The CSS selector to use, if any.</param>
 /// <returns>A filtered list containing the parents.</returns>
 public static IEnumerable <IElement> Parent(this IEnumerable <IElement> elements, ISelector selector = null)
 {
     return(elements.Get(m => m.ParentElement, selector));
 }
Example #49
0
 public abstract bool TriplesExist(ISelector<Triple> selector);
        internal static async Task <T> LoadOneAsync <T>(this IManagedConnection connection, NpgsqlCommand command, ISelector <T> selector, CancellationToken token)
        {
            using (var reader = await connection.ExecuteReaderAsync(command, token))
            {
                if (!(await reader.ReadAsync(token)))
                {
                    return(default(T));
                }

                return(await selector.ResolveAsync(reader, token));
            }
        }
Example #51
0
 public void AppendSelector(ISelector selector, CssCombinator combinator)
 {
     if (!IsReady)
     {
         _selectors.Add(new CombinatorSelector
         {
             Selector = combinator.Change(selector),
             Transform = combinator.Transform,
             Delimiter = combinator.Delimiter
         });
     }
 }
Example #52
0
 /// <summary>
 /// 通过查询器查找结果
 /// </summary>
 /// <param name="selector">查询器</param>
 /// <returns>查询接口</returns>
 public abstract ISelectable SelectList(ISelector selector);
 /// <summary>
 /// 
 /// </summary>
 /// <param name="selector"></param>
 /// <param name="injectorFactory"></param>
 public EventReflectionStrategy( ISelector selector, IInjectorFactory injectorFactory )
 {
     Selector = selector;
     InjectorFactory = injectorFactory;
 }
Example #54
0
 public async Task <IEnumerable <Light> > Get(ISelector selector)
 {
     return(await this.Execute(selector.GetSelectorText()));
 }
Example #55
0
        private dynamic ExtractField(ISelectable item, Page page, Column field, int index)
        {
            if (field == null)
            {
                return(null);
            }
            ISelector selector = SelectorUtils.Parse(field.Selector);

            if (selector == null)
            {
                return(null);
            }

            if (selector is EnviromentSelector)
            {
                var enviromentSelector = selector as EnviromentSelector;
                var tmpValue           = SelectorUtils.GetEnviromentValue(enviromentSelector.Field, page, index);
                foreach (var formatter in field.Formatters)
                {
#if DEBUG
                    try
                    {
#endif
                    tmpValue = formatter.Formate(tmpValue);
#if DEBUG
                }
                catch (Exception e)
                {
                }
#endif
                }
                return(tmpValue == null ? null : Convert.ChangeType(tmpValue, field.DataType));
            }
            else
            {
                bool needPlainText = field.Option == PropertyDefine.Options.PlainText;
                if (field.Multi)
                {
                    var propertyValues = item.SelectList(selector).Nodes();

                    List <dynamic> results = new List <dynamic>();
                    foreach (var propertyValue in propertyValues)
                    {
                        results.Add(Convert.ChangeType(propertyValue.GetValue(needPlainText), field.DataType));
                    }
                    foreach (var formatter in field.Formatters)
                    {
#if DEBUG
                        try
                        {
#endif
                        results = formatter.Formate(results);
#if DEBUG
                    }
                    catch (Exception e)
                    {
                    }
#endif
                    }
                    return(results);
                }
                else
                {
                    bool needCount = field.Option == PropertyDefine.Options.Count;
                    if (needCount)
                    {
                        var values = item.SelectList(selector).Nodes();
                        return(values.Count);
                    }
                    else
                    {
                        var     value    = item.Select(selector)?.GetValue(needPlainText);
                        dynamic tmpValue = value;
                        foreach (var formatter in field.Formatters)
                        {
#if DEBUG
                            try
                            {
#endif
                            tmpValue = formatter.Formate(tmpValue);
#if DEBUG
                        }
                        catch (Exception e)
                        {
                        }
#endif
                        }

                        return(tmpValue == null ? null : Convert.ChangeType(tmpValue, field.DataType));
                    }
                }
            }
        }
Example #56
0
 /// <summary>
 /// Gets the following siblings of the provided elements. Optionally
 /// uses a CSS selector to filter the results.
 /// </summary>
 /// <param name="elements">The elements with siblings.</param>
 /// <param name="selector">The CSS selector to use, if any.</param>
 /// <returns>A filtered list containing the next siblings.</returns>
 public static IEnumerable <IElement> Next(this IEnumerable <IElement> elements, ISelector selector = null)
 {
     return(elements.Get(m => m.NextElementSibling, selector));
 }
Example #57
0
 public static Stage Process(this PipeLine pipeline, ISelector filter)
 {
     Stage stage = filter.ToStage();
     return Processor.Process(pipeline, stage);
 }
Example #58
0
 public AccordionRow(ISearchContainer container, ISelector selector)
     : base(container, selector)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="PerRequestProvider"/> class.
 /// </summary>
 /// <param name="type">The type (or prototype) of instances the provider creates.</param>
 /// <param name="planner">The <see cref="IPlanner"/> component.</param>
 /// <param name="selector">The <see cref="ISelector"/> component</param>
 public PerRequestProvider(Type type, IPlanner planner, ISelector selector)
     : base(type, planner, selector)
 {
 }
        internal static T LoadOne <T>(this IManagedConnection connection, NpgsqlCommand command, ISelector <T> selector)
        {
            using (var reader = connection.ExecuteReader(command))
            {
                if (!reader.Read())
                {
                    return(default(T));
                }

                return(selector.Resolve(reader));
            }
        }