public void AddFilter_AddingAFilterWhenFilterIsAlreadyAdded_FilterManagerHasOneFilter()
        {
            // Arrange
            FilterManager target = new FilterManager();
            var           filter = Mock.Create <IFilter>();

            // Act
            target.AddFilter(filter);
            target.AddFilter(filter);
            // Assert
            Assert.IsTrue(target.CurrentFilters.Length == 1);
        }
        public void RemoveFilter_RemovingAFilterWhenOtherFilterExist_FilterManagerShouldContainThatFilters()
        {
            // Arrange
            FilterManager target  = new FilterManager();
            var           filter  = Mock.Create <IFilter>();
            var           filter2 = Mock.Create <IFilter>();

            target.AddFilter(filter);
            target.AddFilter(filter2);

            // Act

            target.RemoveFilter(filter);
            // Assert
            Assert.IsTrue(target.CurrentFilters.Contains(filter2));
            Assert.IsFalse(target.CurrentFilters.Contains(filter));
        }
        public void AddFilter_AddingAFilterForEmptyManager_FilterManagerHasOneFilter()
        {
            // Arrange
            FilterManager target = new FilterManager();
            var           filter = Mock.Create <IFilter>();

            // Act
            target.AddFilter(filter);
            // Assert
            Assert.IsTrue(target.CurrentFilters.Contains(filter));
        }
        public void Process_CommandIsPendingWitWithOnePassingFilter_CommandNotFiltered()
        {
            var command = new TestCommand(CommandState.Pending);

            FilterManager filterManager = new FilterManager();
            var           filter        = new GenericFilter(c => true);

            filterManager.AddFilter(filter);
            var result = filterManager.Process(command);

            Assert.IsTrue(result);
        }
        public void Process_NonPassingFilterAddedDuringCommandProcessing_CommandIsFiltered()
        {
            var command = new TestCommand(CommandState.Pending);

            FilterManager        filterManager = new FilterManager();
            ManualResetEventSlim evt           = new ManualResetEventSlim(false);
            var filter = new GenericFilter(c =>
            {
                evt.Wait();
                return(true);
            });

            filterManager.AddFilter(filter);

            Task <bool> result = Task.Factory.StartNew(() => filterManager.Process(command));

            filterManager.AddFilter(new GenericFilter(c => false));
            evt.Set();

            Assert.IsFalse(result.Result);
        }
        public void AddFilter_WithEmptyFilter_ItemIsAdded()
        {
            bool wasAdded = false;
            var filter = new EmptyFilter();

            FilterManager filterManager = new FilterManager();
            filterManager.ItemsAdded.Subscribe(Observer.Create<IFilter>(_ => wasAdded = true));

            filterManager.AddFilter(filter);

            Assert.IsTrue(wasAdded);
        }
        public void AddFilter_WithEmptyFilter_AddedItemIsTheSame()
        {
            bool areSame = false;
            var filter = new EmptyFilter();

            FilterManager filterManager = new FilterManager();
            filterManager.ItemsAdded.Subscribe(Observer.Create<IFilter>(f => areSame = filter == f));

            filterManager.AddFilter(filter);

            Assert.IsTrue(areSame);
        }
        public void AddFilter_WithEmptyFilter_AddedItemIsTheSame()
        {
            bool areSame = false;
            var  filter  = new EmptyFilter();

            FilterManager filterManager = new FilterManager();

            filterManager.ItemsAdded.Subscribe(Observer.Create <IFilter>(f => areSame = filter == f));

            filterManager.AddFilter(filter);

            Assert.IsTrue(areSame);
        }
        public void AddFilter_WithEmptyFilter_ItemIsAdded()
        {
            bool wasAdded = false;
            var  filter   = new EmptyFilter();

            FilterManager filterManager = new FilterManager();

            filterManager.ItemsAdded.Subscribe(Observer.Create <IFilter>(_ => wasAdded = true));

            filterManager.AddFilter(filter);

            Assert.IsTrue(wasAdded);
        }
        public void ItemsChanged_WithEmptyFilter_ChangedItemsIsCalledForAddAndRemove()
        {
            int timesCalled = 0;
            var filter = new EmptyFilter();

            FilterManager filterManager = new FilterManager();
            filterManager.ItemsChanged.Subscribe(Observer.Create<IFilter>(_ => ++timesCalled));

            filterManager.AddFilter(filter);
            filterManager.RemoveFilter(filter);

            Assert.AreEqual(2, timesCalled);
        }
        public void ItemsChanged_WithEmptyFilter_ChangedItemsIsCalledForAddAndRemove()
        {
            int timesCalled = 0;
            var filter      = new EmptyFilter();

            FilterManager filterManager = new FilterManager();

            filterManager.ItemsChanged.Subscribe(Observer.Create <IFilter>(_ => ++ timesCalled));

            filterManager.AddFilter(filter);
            filterManager.RemoveFilter(filter);

            Assert.AreEqual(2, timesCalled);
        }
        public void RemoveFilter_RemovingAFilterWhenFilterExist_FilterManagerRemainEmptyFilters()
        {
            // Arrange
            FilterManager target = new FilterManager();
            var           filter = Mock.Create <IFilter>();

            target.AddFilter(filter);

            // Act

            target.RemoveFilter(filter);
            // Assert
            Assert.IsTrue(target.CurrentFilters.Length == 0);
        }
Beispiel #13
0
 // A lot of methods to initalize filters and UI elements, some very similar code, not gonna comment them all.
 private void MakeOutcomeFilter(float xOffset, float yOffset)
 {
     // If the filter has not yet been created, do so and add it to the filter manager
     if (outcomeFilter == null)
     {
         outcomeFilter = new RunDataFilterOutcome();
         filterManager.AddFilter(outcomeFilter);
     }
     // UI stuff
     CustomUIManager.AddLabelToComponent(content, "Run Outcome:", xOffset, yOffset, 240, 50);
     outcomeFilterDropdown = CustomUIManager.AddDropdownToComponent(content, "OutcomeDropdown", outcomeFilter.options, xOffset + columnWidth, yOffset);
     outcomeFilterDropdown.optionChosenSignal.AddListener(HandleOutcome);
     // Manually set the dropdown menu to the current option chosen. There might be a less ugly way to do this.
     outcomeFilterDropdown.SetValue(outcomeFilter.options[outcomeFilter.Outcome]);
     dropdowns.Add(outcomeFilterDropdown);
 }
Beispiel #14
0
        static void Main(string[] args)
        {
            Console.WriteLine("1. Вылет до текущего момента времени");
            Console.WriteLine("2. Сегмент с датой прилёта раньше даты вылета");
            Console.WriteLine("3. Общее время, проведённое на земле превышает два часа");
            Console.WriteLine("-------------------------------------------------------");

            while (true)
            {
                FilterManager filterManager = new FilterManager();

                Console.WriteLine("Добавить номер фильтров через пробел или 0 для выбора всех фильтров");

                var commands = Console.ReadLine()?.Split(' ');

                foreach (var command in commands)
                {
                    switch (command)
                    {
                    case "1":
                        filterManager.AddFilter(new FilterNowTime(DateTime.Now));
                        break;

                    case "2":
                        filterManager.AddFilter(new FilterDepartsBeforeArrives());
                        break;

                    case "3":
                        filterManager.AddFilter(new FilterOverHoursOnGround(2));
                        break;

                    case "0":
                        filterManager.AddFilter(new FilterNowTime(DateTime.Now));
                        filterManager.AddFilter(new FilterDepartsBeforeArrives());
                        filterManager.AddFilter(new FilterOverHoursOnGround(2));
                        break;
                    }
                }

                FlightBuilder flightBuilder = new FlightBuilder();
                var           flights       = flightBuilder.GetFlights();

                filterManager.Process(flights);
                Console.WriteLine("******************************************************\r\n");
            }
        }
        private void btnAddFilter_Click(object sender, RoutedEventArgs e)
        {
            Filter f = new Filter();

            f.Name = txtFilterName.Text.Trim();
            int tmp = -1;

            if (int.TryParse(txtFilterPriority.Text.Trim(), out tmp))
            {
                f.Priority = tmp;
            }

            f.SearchTokens   = txtFilterSearchTokens.Text.Trim();
            f.HighlightColor = txtFilterHighlightColor.Text.Trim();
            try
            {
                System.Drawing.Color myColor = ColorTranslator.FromHtml(f.HighlightColor);
            }
            catch (Exception ex)
            {
                MessageBox.Show("You must supply a valie html color. " + ex.Message);
                return;
            }

            if (!_filterManager.AddFilter(f))
            {
                return;
            }

            LoadFilters();

            TreeViewItem node = new TreeViewItem();

            node.Header = f.Name;
            node.Tag    = f.Name; //note: this could be used to hold the object.
            tvwSearchResults.Items.Add(node);
        }
Beispiel #16
0
    //AA: Load the filters according to GUI selections
    void LoadFilters()
    {
        fm.Clear();

        m_previousAbsPixelPosition = m_absPixelPosition = Vector2.zero;

        if (m_bUseSimpleAverage == true)
        {
            Filter f = new Filter();
            f.name       = Filter.FILTER_NAME.SIMPLE_AVG;
            f.numHistory = 10;                          // Number of values to consider in mean
            fm.AddFilter(f);
        }

        if (m_bUseMovingAverage == true)
        {
            Filter f = new Filter();
            f.name       = Filter.FILTER_NAME.MOVING_AVG;
            f.numHistory = 10;                          // Number of values to consider in moving average
            fm.AddFilter(f);
        }

        if (m_bUseSimpleAverage5 == true)
        {
            Filter f = new Filter();
            f.name       = Filter.FILTER_NAME.SIMPLE_AVG;
            f.numHistory = 5;                           // Number of values to consider in mean
            fm.AddFilter(f);
        }

        if (m_bDblMovingAverage == true)
        {
            Filter f = new Filter();
            f.name       = Filter.FILTER_NAME.DOUBLE_MOVING_AVG;
            f.numHistory = 5;                           // Amount of history to keep
            fm.AddFilter(f);
        }

        if (m_bUseExpSmoothing == true)
        {
            Filter f = new Filter();
            f.name       = Filter.FILTER_NAME.EXP_SMOOTHING;
            f.numHistory = 5;                           // Amount of history to keep
            fm.AddFilter(f);
        }

        if (m_bUseDblExpSmoothing == true)
        {
            Filter f = new Filter();
            f.name       = Filter.FILTER_NAME.DOUBLE_EXP_SMOOTHING;
            f.numHistory = 10;
            fm.AddFilter(f);
        }

        if (m_bUseAdaptive == true)
        {
            Filter f = new Filter();
            f.name = Filter.FILTER_NAME.ADAPTIVE_DOUBLE_EXP_SMOOTHING;
            fm.AddFilter(f);
        }

        if (m_bUseMedian == true)
        {
            Filter f = new Filter();
            f.name       = Filter.FILTER_NAME.MEDIAN;
            f.numHistory = 10;                          // Amount of history to keep
            fm.AddFilter(f);
        }

        if (m_bUseCombination1 == true)
        {
            Filter f = new Filter();
            f.name = Filter.FILTER_NAME.COMBINATION1;
            fm.AddFilter(f);
        }

        if (m_bUseCombination2 == true)
        {
            Filter f = new Filter();
            f.name = Filter.FILTER_NAME.COMBINATION2;
            fm.AddFilter(f);
        }

        if (m_bUseNone == true)
        {
            Filter f = new Filter();
            f.name = Filter.FILTER_NAME.NONE;
            fm.AddFilter(f);
        }
    }
        public void Process_CommandIsPendingWitWithOnePassingFilter_CommandNotFiltered()
        {
            var command = new TestCommand(CommandState.Pending);

            FilterManager filterManager = new FilterManager();
            var filter = new GenericFilter(c => true);
            filterManager.AddFilter(filter);
            var result = filterManager.Process(command);
            Assert.IsTrue(result);
        }
Beispiel #18
0
        public MainViewModel()
        {
            Filters           = new ObservableCollection <IFilter>();
            SendSignalCommand = new DelegateCommand <string>(s =>
            {
                if (string.IsNullOrEmpty(SignalValue))
                {
                    callMe.OnNext(new DeviceResult {
                        CommandId = s
                    });
                }
                else
                {
                    callMe.OnNext(new DeviceResult <string>
                    {
                        CommandId = s,
                        Input     = SignalValue
                    });
                }
            }
                                                             );

            _types = Assembly.GetExecutingAssembly().GetTypes();
            _additionals[typeof(ConnectCommand)] =
                c =>
            {
                CommandBase <bool> command = c as CommandBase <bool>;
                command.CompleteAction = com =>
                {
                    CommandBase <bool> cast = com as CommandBase <bool>;
                    if (cast.ReturnValue)
                    {
                        FilterManager.RemoveFilter(_notConnectedFilter);
                    }
                };
                currentConnectCommand = command;
            };
            _additionals[typeof(AlertsCommand)] =
                c =>
            {
                CommandBase <String> com = c as CommandBase <string>;
                com.Subscribe(
                    Observer.Create <ICommandResponse <string> >(
                        x => AddMessage(x.Sender.ToString() + " Got result " + x.Value.ToString()),
                        ex => AddMessage(ex.Source + " Got Error: " + ex.Message),
                        () => { }));
                currentAlertCommand = c;
            };

            _CanExecutes["AlertsCommand"] = new Func <string, bool>(s => CanConnect);

            CreateCommandCommand = new DelegateCommand <string>(CreateACommand, s =>
            {
                if (_CanExecutes.ContainsKey(s))
                {
                    return(_CanExecutes[s](s));
                }
                return(true);
            });

            ThrowAlertCommand =
                new DelegateCommand <string>(
                    s => callMe.OnNext(new DeviceResult <string> {
                Input = s, CommandId = currentAlertCommand.CommandId
            }));

            Commands = new ObservableCollection <IProcessedCommand>();
            Messages = new ObservableCollection <Message>();

            FilterManager = new FilterManager();
            FilterManager.ItemsAdded.Subscribe(f => Filters.Add(f));
            FilterManager.ItemsRemoved.Subscribe(f => Filters.Remove(f));
            FilterManager.AddFilter(_notConnectedFilter);
            commandFactory = new CommandFactory(FilterManager);
            commandFactory.OnCreateCommand = new Action <CommandBase>(c => Commands.Add(c));

            CommandProcessor = new CommandProcessor(callMe, FilterManager);
            CommandProcessor.RegisterForCompletedCommands(
                Observer.Create <CommandBase>(c => AddMessage(c.ToString() + "  is Completed")));

            SendConnectCommand = new DelegateCommand <bool?>(b =>
                                                             callMe.OnNext(new DeviceResult <bool>
            {
                Input     = b.Value,
                CommandId =
                    currentConnectCommand.CommandId
            }));


            callMe.OnNext(new ProcessorInput());

            ReleaseBlockedCommand = new DelegateCommand <string>(s => CommandProcessor.RerunBlockedCommand((CommandBase)
                                                                                                           Commands.First(c => c.CommandId == s)));
            CancelCommandCommand = new DelegateCommand <string>(s => CommandProcessor.CancelCommand((CommandBase)
                                                                                                    Commands.First(c => c.CommandId == s)));

            CreateSequnceCommand = new DelegateCommand(() =>
            {
                SequenceCommand c1 = new SequenceCommand(this, "AAA");
                SequenceCommand c2 = new SequenceCommand(this, "BBB");
                SequenceCommand c3 = new SequenceCommand(this, "CCC");
                SequenceCommand c4 = new SequenceCommand(this, "DDD");
                Commands.Add(c1);
                Commands.Add(c2);
                Commands.Add(c3);
                Commands.Add(c4);
                subscriptions.AddRange(
                    CommandProcessor.PublishOrderedCommands(
                        new[] { c1, c2, c3, c4 },
                        new[] { MyObserver, MyObserver, MyObserver, MyObserver }));
            });
        }
        public void Process_NonPassingFilterAddedDuringCommandProcessing_CommandIsFiltered()
        {
            var command = new TestCommand(CommandState.Pending);

            FilterManager filterManager = new FilterManager();
            ManualResetEventSlim evt = new ManualResetEventSlim(false);
            var filter = new GenericFilter(c =>
                {
                    evt.Wait();
                    return true;
                });

            filterManager.AddFilter(filter);

            Task<bool> result = Task.Factory.StartNew(() => filterManager.Process(command));

            filterManager.AddFilter(new GenericFilter(c => false));
            evt.Set();

            Assert.IsFalse(result.Result);
        }