Ejemplo n.º 1
0
 public void Constructor_SetsDefaultValues()
 {
    FilterCombinator<Boolean> combinator = new FilterCombinator<Boolean>();
    Assert.IsNotNull(combinator.Filters, "Initial Filters value");
    Assert.AreEqual(0, combinator.Filters.Count, "Initial Filters count");
    Assert.AreEqual(Functor.Or, combinator.Predicate, "Initial Predicate.");
 }
Ejemplo n.º 2
0
        public override bool TryCombineOperations(
            QueryableFilterContext context,
            Queue <Expression> operations,
            FilterCombinator combinator,
            [NotNullWhen(true)] out Expression combined)
        {
            if (operations.Count < 1)
            {
                throw new InvalidOperationException();
            }

            combined = operations.Dequeue();

            while (operations.Count > 0)
            {
                combined = combinator switch
                {
                    FilterCombinator.And => Expression.AndAlso(combined, operations.Dequeue()),
                    FilterCombinator.Or => Expression.OrElse(combined, operations.Dequeue()),
                    _ => throw new InvalidOperationException(),
                };
            }

            return(true);
        }
Ejemplo n.º 3
0
    public override bool TryCombineOperations(
        QueryableFilterContext context,
        Queue <Expression> operations,
        FilterCombinator combinator,
        [NotNullWhen(true)] out Expression combined)
    {
        if (operations.Count < 1)
        {
            throw ThrowHelper.Filtering_QueryableCombinator_QueueEmpty(this);
        }

        combined = operations.Dequeue();

        while (operations.Count > 0)
        {
            combined = combinator switch
            {
                FilterCombinator.And => Expression.AndAlso(combined, operations.Dequeue()),
                FilterCombinator.Or => Expression.OrElse(combined, operations.Dequeue()),
                _ => throw ThrowHelper
                      .Filtering_QueryableCombinator_InvalidCombinator(this, combinator)
            };
        }

        return(true);
    }
}
Ejemplo n.º 4
0
 public override bool TryCombineOperations(
     FilterVisitorContext <string> context,
     Queue <string> operations,
     FilterCombinator combinator,
     out string combined)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 5
0
   public void Predicate_SetNewValue_RaisesFilterChangedEvent()
   {
      Boolean filterChangedRaised = false;
      FilterCombinator<Boolean> combinator = new FilterCombinator<Boolean>();
      combinator.FilterChanged += (sender, args) => filterChangedRaised = true;

      combinator.Predicate = Functor.And;

      Assert.IsTrue(filterChangedRaised);
   }
Ejemplo n.º 6
0
   public void AddFilter_RaisesFilterChangedEvent()
   {
      Boolean filterChangedEventRaised = false;
      FilterCombinator<Boolean> combinator = new FilterCombinator<bool>();
      combinator.FilterChanged += (sender, args) => filterChangedEventRaised = true;

      combinator.Filters.Add(new Mock<Filter<Boolean>>().Object);

      Assert.IsTrue(filterChangedEventRaised);
   }
Ejemplo n.º 7
0
   public void Predicate_SetNewValue_ChangesPredicateValue()
   {
      FilterCombinator<Boolean> combinator = new FilterCombinator<Boolean>();

      combinator.Predicate = Functor.And;

      Assert.AreEqual(Functor.And, combinator.Predicate);

      combinator.Predicate = Functor.Or;

      Assert.AreEqual(Functor.Or, combinator.Predicate);
   }
Ejemplo n.º 8
0
   public void RaiseChildFilterChanged_RaisesFilterChangedEvent()
   {
      Boolean filterChangedEventRaised = false;
      FilterCombinator<Boolean> combinator = new FilterCombinator<bool>();
      Mock<Filter<Boolean>> filter = new Mock<Filter<Boolean>>();
      combinator.Filters.Add(filter.Object);
      combinator.FilterChanged += (sender, args) => filterChangedEventRaised = true;

      filter.Raise(f => f.FilterChanged += null, EventArgs.Empty);

      Assert.IsTrue(filterChangedEventRaised);
   }
        public override bool TryCombineOperations <TVisitorContext, TOperation>(
            TVisitorContext context,
            Queue <TOperation> operations,
            FilterCombinator combinator,
            [NotNullWhen(true)] out TOperation combined)
        {
            if (operations is Queue <T> operationsOfT &&
                context is TContext contextOfT &&
                TryCombineOperations(
                    contextOfT,
                    operationsOfT,
                    combinator,
                    out T combinedOfT) &&
                combinedOfT is TOperation combinedOperation)
            {
                combined = combinedOperation;
                return(true);
            }

            combined = default !;
Ejemplo n.º 10
0
        /// <inheritdoc />
        public override bool TryCombineOperations(
            Neo4JFilterVisitorContext context,
            Queue <Condition> operations,
            FilterCombinator combinator,
            [NotNullWhen(true)] out Condition combined)
        {
            if (operations.Count < 1)
            {
                throw new InvalidOperationException();
            }

            combined = combinator switch
            {
                FilterCombinator.And => CombineWithAnd(operations),
                FilterCombinator.Or => CombineWithOr(operations),
                _ => throw new InvalidOperationException()
            };

            return(true);
        }
Ejemplo n.º 11
0
   /// <summary>
   /// Initializes a new instance of the TreeMode class.
   /// </summary>
   /// <param name="tree">The TreeView control which this TreeMode operates on.</param>
   protected TreeMode(TreeView tree)
   {
      Throw.IfNull(tree, "tree");

      proc_PausePreSystemEvent = new GlobalDelegates.Delegate5(this.PausePreSystemEvent);
      proc_ResumePostSystemEvent = new GlobalDelegates.Delegate5(this.ResumePostSystemEvent);
      proc_SelectionsetChanged = new GlobalDelegates.Delegate5(this.SelectionSetChanged);
      proc_NodeRenamed = new GlobalDelegates.Delegate5(this.NodeRenamed);
      proc_LayerHiddenChanged = new GlobalDelegates.Delegate5(this.LayerHiddenChanged);
      proc_LayerFrozenChanged = new GlobalDelegates.Delegate5(this.LayerFrozenChanged);
      proc_LayerPropChanged = new GlobalDelegates.Delegate5(this.LayerPropChanged);

      this.Tree = tree;
      this.treeNodes = new Dictionary<Object, ICollection<TreeNode>>();

      this.filters = new FilterCombinator<IMaxNode>(Functor.And);
      this.filters.Filters.Add(new InvisibleNodeFilter());
      this.filters.Filters.Add(new MaxNodeFilterCombinator() { Enabled = false });
      this.filters.FilterChanged += filters_FilterChanged;

      this.Started = false;
   }
Ejemplo n.º 12
0
        protected override ISyntaxVisitorAction Leave(
            ListValueNode node,
            TContext context)
        {
            FilterCombinator combinator =
                context.Operations.Peek() is OrField
                    ? FilterCombinator.Or
                    : FilterCombinator.And;

            Queue <T> operations = context.PopLevel();

            if (TryCombineOperations(
                    context,
                    operations,
                    combinator,
                    out T combined))
            {
                context.GetLevel().Enqueue(combined);
            }

            return(Continue);
        }
 public FilterCombinatorDragDropHandler(FilterCombinator<IMaxNode> filter)
 {
    this.filter = filter;
 }
 public abstract bool TryCombineOperations(
     TContext context,
     Queue <T> operations,
     FilterCombinator combinator,
     [NotNullWhen(true)] out T combined);
 /// <summary>
 /// Tries to combine all operations provided by <paramref name="operations"/> with the kind
 /// of combinator specified bu <paramref name="combinator"/>.
 /// </summary>
 /// <param name="context">The context of the visitor</param>
 /// <param name="operations">The operations to combine</param>
 /// <param name="combinator">The kind of combinator that should be applied</param>
 /// <param name="combined">
 /// The combined operations as a new instance of <typeparamref name="T"/>
 /// </param>
 /// <typeparam name="TContext">The type of the context</typeparam>
 /// <typeparam name="T">The type of the combined object</typeparam>
 /// <returns>True if the combination was successful</returns>
 public abstract bool TryCombineOperations <TContext, T>(
     TContext context,
     Queue <T> operations,
     FilterCombinator combinator,
     [NotNullWhen(true)] out T combined)
     where TContext : FilterVisitorContext <T>;
Ejemplo n.º 16
0
   public void ShowNode_EmptyFilterSet_AlwaysReturnsTrue()
   {
      FilterCombinator<Boolean> combinator = new FilterCombinator<Boolean>();
      Assert.AreEqual(0, combinator.Filters.Count, "Initial Filters count");

      Assert.IsTrue(combinator.ShowNode(true), "Empty combinator should return true for ShowNode(true).");
      Assert.IsTrue(combinator.ShowNode(false), "Empty combinator should return true for ShowNode(false).");
   }
Ejemplo n.º 17
0
   public void ShowNode_AndPredicate_ANDsFilterResults()
   {
      FilterCombinator<Boolean> combinator = new FilterCombinator<Boolean>();
      combinator.Predicate = Functor.And;

      Mock<Filter<Boolean>> filterA = new Mock<Filter<Boolean>>();
      filterA.Setup(f => f.ShowNode(It.IsAny<Boolean>())).Returns(true);
      combinator.Filters.Add(filterA.Object);

      Mock<Filter<Boolean>> filterB = new Mock<Filter<Boolean>>();
      filterB.Setup(f => f.ShowNode(It.IsAny<Boolean>())).Returns(false);
      combinator.Filters.Add(filterB.Object);

      Assert.IsFalse(combinator.ShowNode(true));
      Assert.IsFalse(combinator.ShowNode(false));
      filterA.Verify(f => f.ShowNode(It.IsAny<Boolean>()), Times.AtLeastOnce);
      filterB.Verify(f => f.ShowNode(It.IsAny<Boolean>()), Times.AtLeastOnce);
   }
Ejemplo n.º 18
0
   private void addFilterButton_Click(object sender, EventArgs e)
   {
      OutlinerPluginData selPlugin = this.filtersComboBox.SelectedItem as OutlinerPluginData;

      FilterCombinator<IMaxNode> combinator = null;
      Tree.TreeNode selCombinatorTn = this.filtersTree.SelectedNodes.FirstOrDefault();
      while (selCombinatorTn != null && combinator == null)
      {
         combinator = selCombinatorTn.Tag as FilterCombinator<IMaxNode>;
         selCombinatorTn = selCombinatorTn.Parent;
      }

      if (selPlugin != null)
      {
         Filter<IMaxNode> filter = Activator.CreateInstance(selPlugin.Type, null) as Filter<IMaxNode>;
         filter.FilterChanged += filterChanged;
         if (combinator != null)
            combinator.Filters.Add(filter);
         else if (this.rootFilter == null)
         {
            this.RootFilter = filter;
            if (this.filterConfiguration != null)
               this.filterConfiguration.Filter = filter;
         }
         else
         {
            Filter<IMaxNode> oldRoot = this.RootFilter;
            combinator = new FilterCombinator<IMaxNode>();
            combinator.Filters.Add(oldRoot);
            combinator.Filters.Add(filter);
            this.RootFilter = combinator;
            if (this.filterConfiguration != null)
               this.filterConfiguration.Filter = combinator;
         }
      }
   }
Ejemplo n.º 19
0
 protected override bool TryCombineOperations(
     TContext context,
     Queue <T> operations,
     FilterCombinator combinator,
     [NotNullWhen(true)] out T combined) =>
 _combinator.TryCombineOperations(context, operations, combinator, out combined);