private void FiltersComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Filter = FilterProvider.CreateNewFilterFromDescription((string)FiltersComboBox.SelectedItem);

            var textFilter = Filter as ITextFilter;

            if (textFilter != null)
            {
                FlagColumnDef.Width = new GridLength(0);
                FilterText.Text     = textFilter.Text;
                return;
            }

            var textFilterWithFlag = Filter as ITextFilterWithFlag;

            if (textFilterWithFlag != null)
            {
                FlagColumnDef.Width = new GridLength(180);
                FilterFlag.Content  = textFilterWithFlag.FlagDescription;
                FilterText.Text     = textFilterWithFlag.Text;
                return;
            }

            throw new NotSupportedException($"Unexpected filter type: {Filter.GetType().FullName}");
        }
Example #2
0
        public void FiltersChanged_Should_Notify_Correct_Filter_Factories_When_Add()
        {
            // Act
            var rebuilded = false;
            var options   = new MariCommandsOptions();

            options.Filters.Add(typeof(TestResultFilter));

            var filterFactoryMock = new Mock <IFilterFactory>();

            filterFactoryMock.Setup(a => a.CanInvoke(typeof(TestResultFilter))).Returns(true);

            filterFactoryMock.Setup(a => a.FiltersDefinitionWasChanged(options.Filters)).Callback <IEnumerable <ICommandFilter> >(filters =>
            {
                rebuilded = filters.Equals(options.Filters);
            });

            var filterFactory = filterFactoryMock.Object;

            var filtersFactories = new List <IFilterFactory>
            {
                filterFactory,
            };

            var filterProvider = new FilterProvider(filtersFactories, options);

            // Arrange
            options.Filters.Add(typeof(TestResultFilter));

            // Assert
            Assert.True(rebuilded);
        }
        private CompilableProvider InsertCalculateFilter(CompilableProvider source,
                                                         CalculateProvider calculateProvider)
        {
            var result = source;

            if (State.CalculateFilters.ContainsKey(calculateProvider))
            {
                Expression <Func <Tuple, bool> > concatenatedPredicate = null;
                foreach (var filterPair in State.CalculateFilters[calculateProvider])
                {
                    var currentPredicate = (Expression <Func <Tuple, bool> >)calculateExpressionRewriter
                                           .Rewrite(filterPair.First, filterPair.First.Parameters[0],
                                                    filterPair.Second, result.Header.Columns);
                    if (concatenatedPredicate == null)
                    {
                        concatenatedPredicate = currentPredicate;
                    }
                    else
                    {
                        concatenatedPredicate = collectorHelper
                                                .CreatePredicatesConjunction(currentPredicate, concatenatedPredicate);
                    }
                }
                result = new FilterProvider(result, concatenatedPredicate);
                State.CalculateFilters.Remove(calculateProvider);
            }
            return(result);
        }
        public void Setup()
        {
            var autoSubstitute = AutoSubstituteContainer.Create();

            _context        = autoSubstitute.Resolve <ControllerContext>();
            _filterProvider = new FilterProvider();
            DependencyResolver.SetResolver(new AutofacDependencyResolver(autoSubstitute.Container));
            _httpSimulator = new HttpSimulator().SimulateRequest();
        }
Example #5
0
        public bool TryAddFilter(FilterProvider filter)
        {
            var tupleAccesses = tupleGatherer.Gather(filter.Predicate);

            if (tupleAccesses.Count == 0)
            {
                return(false);
            }
            return(TryAddCalculateFilter(filter, tupleAccesses));
        }
Example #6
0
 public void Init()
 {
     _activator    = new StubFilterActivator(Activator.CreateInstance);
     _descProvider = new StubDescriptorProvider();
     _filterProviderWithNoDescProvider = new FilterProvider(new Lazy <FilterDescriptorProvider, IComponentOrder> [0]);
     _filterProviderWith1DescProvider  = new FilterProvider(new[]
     {
         new Lazy <FilterDescriptorProvider, IComponentOrder>(() => _descProvider, new ComponentOrder(1))
     });
 }
Example #7
0
        public void ReplaceShouldReturnCorrectResult(string filter, Dictionary <string, string> replacements, string expected)
        {
            // Arrange
            IFilterProvider filterProvider = new FilterProvider();

            // Act
            var result = filterProvider.Replace(filter, replacements);

            // Assert
            result.Should().Be(expected);
        }
Example #8
0
        public FilteredBindingList <C> FilteredList(T list, Dictionary <string, object> filter,
                                                    FilterProvider FilterProvider)
        {
            var filteredList = new FilteredBindingList <C>(list);

            if (list.Count == 0)
            {
                return(filteredList);
            }

            return(FilteredList(filteredList, filter, FilterProvider));
        }
Example #9
0
        protected override Provider VisitFilter(FilterProvider provider)
        {
            mappings[provider.Source] = Merge(mappings[provider], mappingsGatherer.Gather(provider.Predicate));
            var newSourceProvider = VisitCompilable(provider.Source);

            mappings[provider] = mappings[provider.Source];

            var predicate = TranslateLambda(provider, provider.Predicate);

            return(newSourceProvider == provider.Source && predicate == provider.Predicate
        ? provider
        : new FilterProvider(newSourceProvider, (Expression <Func <Tuple, bool> >)predicate));
        }
        public bool TryAdd(FilterProvider filter)
        {
            var applyParameter = parameterSearcher.Find(filter.Predicate);

            if (applyParameter != null)
            {
                if (!owner.State.SelfConvertibleApplyProviders[applyParameter])
                {
                    SaveApplyPredicate(filter, applyParameter);
                    return(true);
                }
            }
            return(false);
        }
        /// <inheritdoc/>
        protected override SqlProvider VisitFilter(FilterProvider provider)
        {
            var source = Compile(provider.Source);

            var query = ExtractSqlSelect(provider, source);

            var sourceColumns = ExtractColumnExpressions(query);
            var result        = ProcessExpression(provider.Predicate, sourceColumns);
            var predicate     = result.First;
            var bindings      = result.Second;

            query.Where &= predicate;

            return(CreateProvider(query, bindings, provider, source));
        }
Example #12
0
        public Pair <Expression <Func <Tuple, bool> >, ColumnCollection> ConcatenateWithExistingPredicate(
            FilterProvider provider, Pair <Expression <Func <Tuple, bool> >, ColumnCollection> existingPredicatePair)
        {
            var newPredicate = CreatePredicatesConjunction(provider.Predicate,
                                                           existingPredicatePair.First);
            var currentColumns = existingPredicatePair.Second;

            foreach (var column in provider.Header.Columns)
            {
                if (!currentColumns.Any(c => c.Name == column.Name))
                {
                    currentColumns.Add(column);
                }
            }
            return(new Pair <Expression <Func <Tuple, bool> >, ColumnCollection>(newPredicate, currentColumns));
        }
 private void SaveApplyPredicate(FilterProvider filter, ApplyParameter applyParameter)
 {
     if (owner.State.Predicates.ContainsKey(applyParameter))
     {
         owner.State.Predicates[applyParameter]
         .Add(new Pair <Expression <Func <Tuple, bool> >, ColumnCollection>(filter.Predicate,
                                                                            filter.Header.Columns));
     }
     else
     {
         var newPair = new Pair <Expression <Func <Tuple, bool> >, ColumnCollection>(filter.Predicate,
                                                                                     filter.Header.Columns);
         owner.State.Predicates.Add(applyParameter,
                                    new List <Pair <Expression <Func <Tuple, bool> >, ColumnCollection> > {
             newPair
         });
     }
 }
Example #14
0
        private void PrepareDataSourceForCql(IProvider provider, string cqlFilterString)
        {
            // for layerNames with a filterprovider
            FilterProvider filterProvider = provider as FilterProvider;

            if (filterProvider != null)
            {
                filterProvider.FilterDelegate = row => CqlFilter(row, cqlFilterString);
                return;
            }
            // for layerNames with a SQL datasource with a DefinitionQuery property
            PropertyInfo piDefinitionQuery = provider.GetType().GetProperty("DefinitionQuery", BindingFlags.Public | BindingFlags.Instance);

            if (piDefinitionQuery != null)
            {
                piDefinitionQuery.SetValue(provider, cqlFilterString, null);
            }
        }
        protected override Provider VisitFilter(FilterProvider provider)
        {
            var source = VisitCompilable(provider.Source);

            if (calculateProviderCollector.TryAddFilter(provider))
            {
                return(source);
            }

            var newProvider = source != provider.Source
        ? new FilterProvider(source, provider.Predicate) : provider;

            if (predicateCollector.TryAdd(newProvider))
            {
                return(source);
            }
            return(newProvider);
        }
Example #16
0
        private void AddCalculateFilter(CalculateProvider calculateProvider, FilterProvider filterProvider)
        {
            var newPair =
                new Pair <Expression <Func <Tuple, bool> >, ColumnCollection>(filterProvider.Predicate,
                                                                              filterProvider.Header.Columns);

            if (owner.State.CalculateFilters.ContainsKey(calculateProvider))
            {
                owner.State.CalculateFilters[calculateProvider].Add(newPair);
            }
            else
            {
                owner.State.CalculateFilters.Add(calculateProvider,
                                                 new List <Pair <Expression <Func <Tuple, bool> >, ColumnCollection> > {
                    newPair
                });
            }
        }
Example #17
0
        private bool TryAddCalculateFilter(FilterProvider filterProvider, List <int> tupleAccesses)
        {
            var result = false;

            foreach (var key in owner.State.Predicates.Keys)
            {
                if (!owner.State.CalculateProviders.ContainsKey(key))
                {
                    continue;
                }
                foreach (var providerPair in owner.State.CalculateProviders[key])
                {
                    if (ContainsAccessToTupleField(tupleAccesses, providerPair.First, filterProvider))
                    {
                        result = true;
                        AddCalculateFilter(providerPair.First, filterProvider);
                    }
                }
            }
            return(result);
        }
Example #18
0
        public void FiltersChanged_Should_Notify_Correct_Filter_Factories_When_Replace()
        {
            // Act
            var callCount         = 0;
            var expectedCallCount = 2;
            var options           = new MariCommandsOptions();

            options.Filters.Add(typeof(TestResultFilter));

            var filterFactoryMock = new Mock <IFilterFactory>();

            filterFactoryMock.Setup(a => a.CanInvoke(typeof(TestResultFilter))).Returns(true);

            filterFactoryMock.Setup(a => a.FiltersDefinitionWasChanged(options.Filters)).Callback <IEnumerable <ICommandFilter> >(filters =>
            {
                if (filters.Equals(options.Filters))
                {
                    callCount++;
                }
            });

            var filterFactory = filterFactoryMock.Object;

            var filtersFactories = new List <IFilterFactory>
            {
                filterFactory,
            };

            var filterProvider = new FilterProvider(filtersFactories, options);

            // Arrange
            options.Filters[0] = new ServiceCommandFilterFactory(typeof(TestResultFilter));

            // Assert
            Assert.Equal(expectedCallCount, callCount);
        }
Example #19
0
        /// <summary>
        /// Opens the media by initializing the DirectShow graph
        //
        //                                          +----------------+          +----------------+       +-----------------------+
        //     +---------------------+              | LavVideo       |          | VobSub         |       | EVR+CustomPresenter   |
        //     | LavSplitterSource   |              |----------------|          |----------------|       |-----------------------|
        //     +---------------------+              |                |          |                |       |                       |
        //     |                     |              |                |          |                |       |    VIDEO              |
        //     |             video  +|->+---------+<-+ IN       OUT +->+------+<-+ VID_IN   OUT +-> +-+ <-+   RENDERER           |
        //     |                     |              +----------------+          |                |       |                       |
        //     |             audio  +|->+------+                                |                |       +-----------------------+
        //     |                     |         |    +----------------+      +-+<-+ TXT_IN        |
        //     |          subtitle  +|->+--+   |    | LavAudio       |      |   |                |
        //     +---------------------+    |   |    |----------------|      |   +----------------+       +-----------------------+
        //                                 |   |    |                |      |                            | DShow output device   |
        //                                 |   |    |                |     xxx                           |-----------------------|
        //                                 |   +--+<-+ IN       OUT +->+--x | x-----------------------+  |                       |
        //                                 |        +----------------+      |                            |    AUDIO              |
        //                                 |                                |                           <-+   RENDERER           |
        //                                 |                                |                            |                       |
        //                                 +--------------------------------+                            +-----------------------+
        //
        /// </summary>
//        protected virtual void OpenSource()
//        {
//            /* Make sure we clean up any remaining mess */
//            //if (m_graph != null) RemoveAllFilters(m_graph);
//            FreeResources();

//            if (m_sourceUri == null)
//                return;

//            string fileSource = m_sourceUri.OriginalString;

//            if (string.IsNullOrEmpty(fileSource))
//                return;

//            try
//            {
//                if (m_graph != null) Marshal.ReleaseComObject(m_graph);

//                /* Creates the GraphBuilder COM object */
//                m_graph = new FilterGraphNoThread() as IGraphBuilder;

//                if (m_graph == null)
//                    throw new Exception("Could not create a graph");

//                /* Add our prefered audio renderer */
//                var audioRenderer = InsertAudioRenderer(AudioRenderer);
//                if (_audioRenderer != null) Marshal.ReleaseComObject(_audioRenderer);
//                _audioRenderer = audioRenderer;

//                if ((System.Environment.OSVersion.Platform == PlatformID.Win32NT &&
//                (System.Environment.OSVersion.Version.Major == 5)))
//                    VideoRenderer = VideoRendererType.VideoMixingRenderer9;

//                IBaseFilter renderer = CreateVideoRenderer(VideoRenderer, m_graph, 2);
//                if (_renderer != null) Marshal.ReleaseComObject(_renderer);
//                _renderer = renderer;
//                //if (_renderer != null)
//                //    m_graph.AddFilter((IBaseFilter)_renderer, "Renderer");

//                var filterGraph = m_graph as IFilterGraph2;

//                if (filterGraph == null)
//                    throw new Exception("Could not QueryInterface for the IFilterGraph2");

//                ILAVAudioSettings lavAudioSettings;
//                ILAVAudioStatus lavStatus;
//                IBaseFilter audioDecoder = FilterProvider.GetAudioFilter(out lavAudioSettings, out lavStatus);
//                if (audioDecoder != null)
//                {
//                    if (_audio != null) Marshal.ReleaseComObject(_audio);
//                    _audio = audioDecoder;
//                    lavAudioSettings.SetRuntimeConfig(true);
//                    m_graph.AddFilter((IBaseFilter)_audio, "LavAudio");
//                }

//                ILAVSplitterSettings splitterSettings;
//                IFileSourceFilter splitter = FilterProvider.GetSplitterSource(out splitterSettings);
//                //IBaseFilter splitter = FilterProvider.GetSplitter(out splitterSettings);

//                if (splitter != null)
//                {
//                    splitter.Load(fileSource, null);
//                    if (_splitter != null) Marshal.ReleaseComObject(_splitter);
//                    _splitter = splitter;
//                    splitterSettings.SetRuntimeConfig(true);
//                    m_graph.AddFilter((IBaseFilter)splitter, "LavSplitter");
//                }

//                int hr = 0;


//                /* We will want to enum all the pins on the source filter */
//                IEnumPins pinEnum;

//                hr = ((IBaseFilter)splitter).EnumPins(out pinEnum);
//                DsError.ThrowExceptionForHR(hr);

//                IntPtr fetched = IntPtr.Zero;
//                IPin[] pins = { null };

//                /* Counter for how many pins successfully rendered */


//                if (VideoRenderer == VideoRendererType.VideoMixingRenderer9)
//                {
//                    var mixer = renderer as IVMRMixerControl9;

//                    if (mixer != null)
//                    {
//                        VMR9MixerPrefs dwPrefs;
//                        mixer.GetMixingPrefs(out dwPrefs);
//                        dwPrefs &= ~VMR9MixerPrefs.RenderTargetMask;
//                        dwPrefs |= VMR9MixerPrefs.RenderTargetRGB;
//                        //mixer.SetMixingPrefs(dwPrefs);
//                    }
//                }

//                // Test using FFDShow Video Decoder Filter
//                ILAVVideoSettings lavVideoSettings;
//                IBaseFilter lavVideo = FilterProvider.GetVideoFilter(out lavVideoSettings);
//                if (_video != null) Marshal.ReleaseComObject(_video);
//                _video = lavVideo;

//                IBaseFilter vobSub = FilterProvider.GetVobSubFilter();

//                if (vobSub != null)
//                {
//                    m_graph.AddFilter(vobSub, "VobSub");
//                    IDirectVobSub vss = vobSub as IDirectVobSub;
//                    if (_vobsub != null) Marshal.ReleaseComObject(_vobsub);
//                    _vobsub = vss;
//                    InitSubSettings();
//                }

//                if (lavVideo != null)
//                {
//                    lavVideoSettings.SetRuntimeConfig(true);
//                    m_graph.AddFilter(lavVideo, "LavVideo");
//                }

//                int ret;

//                IBaseFilter dcDsp = FilterProvider.GetDCDSPFilter();
//                if (dcDsp != null)
//                {
//                    _dspFilter = (IDCDSPFilterInterface)dcDsp;

//                    //hr = i.set_PCMDataBeforeMainDSP(true);
//                    hr = m_graph.AddFilter((IBaseFilter)dcDsp, "VobSub");

//                    ret = m_graph.Connect(DsFindPin.ByName((IBaseFilter)splitter, "Audio"), DsFindPin.ByDirection(audioDecoder, PinDirection.Input, 0));
//                    ret = m_graph.Connect(DsFindPin.ByDirection((IBaseFilter)audioDecoder, PinDirection.Output, 0), DsFindPin.ByDirection(_dspFilter, PinDirection.Input, 0));
//                    ret = m_graph.Connect(DsFindPin.ByDirection((IBaseFilter)_dspFilter, PinDirection.Output, 0), DsFindPin.ByDirection(audioRenderer, PinDirection.Input, 0));

//                    //bool d = false;
//                    //int delay = 0;
//                    //hr = i.get_EnableDelay(ref d);
//                    int cnt = 0;
//                    object intf = null;
//                    //hr = i.set_EnableDelay(true);
//                    //hr = i.set_Delay(0);
//                    hr = _dspFilter.set_AddFilter(0, TDCFilterType.ftEqualizer);
//                    hr = _dspFilter.get_FilterCount(ref cnt);
//                    hr = _dspFilter.get_FilterInterface(0, out intf);
//                    _equalizer = (IDCEqualizer)intf;
//                    hr = _dspFilter.set_AddFilter(0, TDCFilterType.ftDownMix);
//                    hr = _dspFilter.get_FilterInterface(0, out intf);
//                    _downmix = (IDCDownMix)intf;
//                    hr = _dspFilter.set_AddFilter(0, TDCFilterType.ftAmplify);
//                    hr = _dspFilter.get_FilterInterface(0, out intf);
//                    _amplify = (IDCAmplify)intf;

//                    _equalizer.set_Seperate(false);
//                }

//                bool subconnected = false;
//                ret = m_graph.Connect(DsFindPin.ByName((IBaseFilter)splitter, "Video"), DsFindPin.ByDirection(lavVideo, PinDirection.Input, 0));
//                ret = m_graph.Connect(DsFindPin.ByDirection((IBaseFilter)lavVideo, PinDirection.Output, 0), DsFindPin.ByDirection(vobSub, PinDirection.Input, 0));
//                if (ret == 0)
//                {
//                    int lc;
//                    ((IDirectVobSub)vobSub).get_LanguageCount(out lc);
//                    subconnected = (lc != 0);
//                    IPin pn = DsFindPin.ByName((IBaseFilter)splitter, "Subtitle");
//                    if (pn != null)
//                    {
//                        ret = m_graph.Connect(pn, DsFindPin.ByDirection(vobSub, PinDirection.Input, 1));
//                        ((IDirectVobSub)vobSub).get_LanguageCount(out lc);
//                        subconnected = (lc != 0);
//                    }
//                    ret = m_graph.Connect(DsFindPin.ByDirection(vobSub, PinDirection.Output, 0),
//                                          DsFindPin.ByDirection(renderer, PinDirection.Input, 0));
//                }
//                else
//                {
//                    ret = m_graph.Connect(DsFindPin.ByDirection(lavVideo, PinDirection.Output, 0),
//                                      DsFindPin.ByDirection(renderer, PinDirection.Input, 0));
//                }

//                /* Loop over each pin of the source filter */
//                while (pinEnum.Next(pins.Length, pins, fetched) == 0)
//                {
//                    IPin cTo;
//                    pins[0].ConnectedTo(out cTo);
//                    if (cTo == null)
//                    {
//                        // this should not happen if the filtegraph is manually connected in a good manner
//                        ret = filterGraph.RenderEx(pins[0], AMRenderExFlags.RenderToExistingRenderers, IntPtr.Zero);
//                    }
//                    else
//                    {
//                        Marshal.ReleaseComObject(cTo);
//                    }
//                    Marshal.ReleaseComObject(pins[0]);
//                }

//                if (lavVideoSettings != null)
//                {
//                    if (lavVideoSettings.CheckHWAccelSupport(LAVHWAccel.HWAccel_CUDA) != 0)
//                    {
//                        ret = lavVideoSettings.SetHWAccel(LAVHWAccel.HWAccel_CUDA);
//                    }
//                    else if (lavVideoSettings.CheckHWAccelSupport(LAVHWAccel.HWAccel_QuickSync) != 0)
//                    {
//                        ret = lavVideoSettings.SetHWAccel(LAVHWAccel.HWAccel_QuickSync);
//                    }
//                    else if (lavVideoSettings.CheckHWAccelSupport(LAVHWAccel.HWAccel_DXVA2Native) != 0)
//                    {
//                        ret = lavVideoSettings.SetHWAccel(LAVHWAccel.HWAccel_DXVA2Native);
//                    }
//                    else if (lavVideoSettings.CheckHWAccelSupport(LAVHWAccel.HWAccel_DXVA2) != 0)
//                    {
//                        ret = lavVideoSettings.SetHWAccel(LAVHWAccel.HWAccel_DXVA2);
//                    }
//                    else if (lavVideoSettings.CheckHWAccelSupport(LAVHWAccel.HWAccel_DXVA2CopyBack) != 0)
//                    {
//                        ret = lavVideoSettings.SetHWAccel(LAVHWAccel.HWAccel_DXVA2CopyBack);
//                    }
//                }

//                //hr = m_graph.RenderFile(fileSource, null);

//                Marshal.ReleaseComObject(pinEnum);

//                IAMStreamSelect selector = splitter as IAMStreamSelect;
//                int numstreams;
//                selector.Count(out numstreams);
//                AMMediaType mt;
//                AMStreamSelectInfoFlags fl;
//                SubtitleStreams.Clear();
//                VideoStreams.Clear();
//                AudioStreams.Clear();
//                for (int i = 0; i < numstreams; i++)
//                {
//                    int lcid;
//                    int group;
//                    string name;
//                    object o, o2;
//                    selector.Info(i, out mt, out fl, out lcid, out group, out name, out o, out o2);
//                    switch (group)
//                    {
//                        case 0:
//                            VideoStreams.Add(name);
//                            break;
//                        case 1:
//                            AudioStreams.Add(name);
//                            break;
//                        case 2:
//                            SubtitleStreams.Add(name);
//                            break;
//                    }

//                    if (o != null) Marshal.ReleaseComObject(o);
//                    if (o2 != null) Marshal.ReleaseComObject(o2);
//                }

//                OnPropertyChanged("SubtitleStreams");
//                OnPropertyChanged("VideoStreams");
//                OnPropertyChanged("AudioStreams");

//                //Marshal.ReleaseComObject(splitter);


//                /* Configure the graph in the base class */
//                SetupFilterGraph(m_graph);

//#if DEBUG
//                /* Adds the GB to the ROT so we can view
//* it in graphedit */
//                m_dsRotEntry = new DsROTEntry(m_graph);
//#endif

//                //if (_splitterSettings != null)
//                //{
//                // Marshal.ReleaseComObject(_splitterSettings);
//                // _splitterSettings = null;
//                //}
//                if (_splitterSettings != null) Marshal.ReleaseComObject(_splitterSettings);
//                _splitterSettings = (ILAVSplitterSettings)splitter;
//                //ret = _splitterSettings.SetRuntimeConfig(true);
//                //if (ret != 0)
//                // throw new Exception("Could not set SetRuntimeConfig to true");

//                //string sss = "*:*";

//                //LAVSubtitleMode mode = LAVSubtitleMode.LAVSubtitleMode_NoSubs;
//                //mode = _splitterSettings.GetSubtitleMode();
//                //if (mode != LAVSubtitleMode.LAVSubtitleMode_Default)
//                // throw new Exception("Could not set GetAdvancedSubtitleConfige");

//                //ret = _splitterSettings.SetSubtitleMode(LAVSubtitleMode.LAVSubtitleMode_Advanced);
//                //if (ret != 1)
//                // throw new Exception("Could not set SetAdvancedSubtitleConfige");

//                //ret = _splitterSettings.SetAdvancedSubtitleConfig(sss);
//                //if (ret != 1)
//                // throw new Exception("Could not set SetAdvancedSubtitleConfige");

//                //sss = "";
//                //ret = _splitterSettings.GetAdvancedSubtitleConfig(out sss);
//                //if (ret != 0)
//                // throw new Exception("Could not set GetAdvancedSubtitleConfige");

//                //IPin sub = DsFindPin.ByDirection((IBaseFilter)splitter, PinDirection.Output, 2);
//                //PinInfo pi;
//                //sub.QueryPinInfo(out pi);
//                SIZE a, b;
//                if ((_displayControl).GetNativeVideoSize(out a, out b) == 0)
//                {
//                    if (a.cx > 0 && a.cy > 0)
//                    {
//                        HasVideo = true;
//                        SetNativePixelSizes(a);
//                    }
//                }

//                if (!subconnected)
//                {
//                    InvokeNoSubtitleLoaded(new EventArgs());
//                }
//                else
//                {
//                    InitSubSettings();
//                }
//                /* Sets the NaturalVideoWidth/Height */
//                //SetNativePixelSizes(renderer);

//                //InvokeMediaFailed(new MediaFailedEventArgs(sss, null));
//            }
//            catch (Exception ex)
//            {
//                /* This exection will happen usually if the media does
//                * not exist or could not open due to not having the
//                * proper filters installed */
//                FreeResources();

//                /* Fire our failed event */
//                InvokeMediaFailed(new MediaFailedEventArgs(ex.Message, ex));
//            }
//            finally
//            {
//                string filters = string.Join(Environment.NewLine, EnumAllFilters(m_graph).ToArray());
//                System.Diagnostics.Debug.WriteLine(filters);
//            }
//            InvokeMediaOpened();
//        }
        protected virtual void OpenSource()
        {
            _eqEnabled = false;
            //if (m_graph != null)
            //{
            //    //RemoveAllFilters(m_graph);
            //    Marshal.ReleaseComObject(m_graph);
            //}

            /* Make sure we clean up any remaining mess */
            FreeResources();

            if (m_sourceUri == null)
            {
                return;
            }

            string fileSource = m_sourceUri.OriginalString;

            if (string.IsNullOrEmpty(fileSource))
            {
                return;
            }

            try
            {
                int hr = 0;

                /* Creates the GraphBuilder COM object */
                m_graph = new FilterGraphNoThread() as IGraphBuilder;

                if (_displayControl != null)
                {
                    Marshal.ReleaseComObject(_displayControl);
                    _displayControl = null;
                }

                if (_displayControlVMR != null)
                {
                    Marshal.ReleaseComObject(_displayControlVMR);
                    _displayControlVMR = null;
                }

                if (m_graph == null)
                {
                    throw new Exception("Could not create a graph");
                }

                var filterGraph = m_graph as IFilterGraph2;

                var flt = EnumAllFilters(m_graph).ToList();

                if (filterGraph == null)
                {
                    throw new Exception("Could not QueryInterface for the IFilterGraph2");
                }

                /* Add our prefered audio renderer */
                var audioRenderer = InsertAudioRenderer(AudioRenderer);
                if (audioRenderer != null)
                {
                    if (_audioRenderer != null)
                    {
                        Marshal.ReleaseComObject(_audioRenderer);
                    }
                    _audioRenderer = audioRenderer;
                }

                if ((System.Environment.OSVersion.Platform == PlatformID.Win32NT &&
                     (System.Environment.OSVersion.Version.Major == 5)))
                {
                    VideoRenderer = VideoRendererType.VideoMixingRenderer9;
                }

                if (_presenterSettings != null)
                {
                    Marshal.ReleaseComObject(_presenterSettings);
                }
                if (_renderer != null)
                {
                    Marshal.ReleaseComObject(_renderer);
                }

                IBaseFilter renderer = InsertVideoRenderer(VideoRenderer, m_graph, 1);
                _renderer = renderer;

                ILAVAudioSettings lavAudioSettings;
                ILAVAudioStatus   lavStatus;
                IBaseFilter       audioDecoder = FilterProvider.GetAudioFilter(out lavAudioSettings, out lavStatus);
                if (audioDecoder != null)
                {
                    if (_audio != null)
                    {
                        Marshal.ReleaseComObject(_audio);
                    }
                    _audio         = audioDecoder;
                    _audioStatus   = lavStatus;
                    _audioSettings = lavAudioSettings;

                    hr = (int)lavAudioSettings.SetRuntimeConfig(true);
                    hr = m_graph.AddFilter((IBaseFilter)audioDecoder, "LavAudio");
                    DsError.ThrowExceptionForHR(hr);
#if DEBUG
                    hr = (int)lavAudioSettings.SetTrayIcon(true);
#endif
                }

                ILAVSplitterSettings splitterSettings;
                IFileSourceFilter    splitter = FilterProvider.GetSplitterSource(out splitterSettings);

                if (splitter != null)
                {
                    if (_splitter != null)
                    {
                        Marshal.ReleaseComObject(_splitter);
                    }
                    _splitter = splitter;

                    _splitterSettings = (ILAVSplitterSettings)splitterSettings;

                    hr = splitterSettings.SetRuntimeConfig(true);
                    hr = splitter.Load(fileSource, null);
                    if (hr != 0)
                    {
                        throw new Exception("Playback of this file is not supported!");
                    }
                    hr = m_graph.AddFilter((IBaseFilter)splitter, "LavSplitter");
                    DsError.ThrowExceptionForHR(hr);
                }

                IEnumPins pinEnum;
                hr = ((IBaseFilter)splitter).EnumPins(out pinEnum);
                DsError.ThrowExceptionForHR(hr);

                IntPtr fetched = IntPtr.Zero;
                IPin[] pins    = { null };

                if (VideoRenderer == VideoRendererType.VideoMixingRenderer9)
                {
                    var mixer = _renderer as IVMRMixerControl9;

                    if (mixer != null)
                    {
                        VMR9MixerPrefs dwPrefs;
                        mixer.GetMixingPrefs(out dwPrefs);
                        dwPrefs &= ~VMR9MixerPrefs.RenderTargetMask;
                        dwPrefs |= VMR9MixerPrefs.RenderTargetRGB;
                        mixer.SetMixingPrefs(dwPrefs);
                    }
                }

                ILAVVideoSettings lavVideoSettings;
                IBaseFilter       lavVideo = FilterProvider.GetVideoFilter(out lavVideoSettings);

                if (lavVideo != null)
                {
                    if (_video != null)
                    {
                        Marshal.ReleaseComObject(_video);
                    }
                    _video = lavVideo;

                    if (lavVideoSettings != null)
                    {
                        _videoSettings = lavVideoSettings;

                        lavVideoSettings.SetRuntimeConfig(true);
                        hr = lavVideoSettings.SetHWAccel(LAVHWAccel.HWAccel_None);

                        // check for best acceleration available
                        //if (lavVideoSettings.CheckHWAccelSupport(LAVHWAccel.HWAccel_CUDA) != 0)
                        //{
                        //    hr = lavVideoSettings.SetHWAccel(LAVHWAccel.HWAccel_CUDA);
                        //    hr = lavVideoSettings.SetHWAccelResolutionFlags(LAVHWResFlag.SD | LAVHWResFlag.HD | LAVHWResFlag.UHD);
                        //}
                        //else if (lavVideoSettings.CheckHWAccelSupport(LAVHWAccel.HWAccel_QuickSync) != 0)
                        //{
                        //    hr = lavVideoSettings.SetHWAccel(LAVHWAccel.HWAccel_QuickSync);
                        //    hr = lavVideoSettings.SetHWAccelResolutionFlags(LAVHWResFlag.SD | LAVHWResFlag.HD | LAVHWResFlag.UHD);
                        //}
                        //else
                        if (lavVideoSettings.CheckHWAccelSupport(LAVHWAccel.HWAccel_DXVA2Native) != 0)
                        {
                            hr = lavVideoSettings.SetHWAccel(LAVHWAccel.HWAccel_DXVA2Native);
                            hr = lavVideoSettings.SetHWAccelResolutionFlags(LAVHWResFlag.SD | LAVHWResFlag.HD | LAVHWResFlag.UHD);
                        }
                        //else
                        //if (lavVideoSettings.CheckHWAccelSupport(LAVHWAccel.HWAccel_DXVA2CopyBack) != 0)
                        //{
                        //    hr = lavVideoSettings.SetHWAccel(LAVHWAccel.HWAccel_DXVA2CopyBack);
                        //    hr = lavVideoSettings.SetHWAccelResolutionFlags(LAVHWResFlag.SD | LAVHWResFlag.HD | LAVHWResFlag.UHD);
                        //}

#if DEBUG
                        hr = lavVideoSettings.SetTrayIcon(true);
#endif
                    }

                    hr = m_graph.AddFilter(_video, "LavVideo");
                    DsError.ThrowExceptionForHR(hr);
                }

                IBaseFilter vobSub = FilterProvider.GetVobSubFilter();

                if (vobSub != null)
                {
                    try
                    {
                        hr = m_graph.AddFilter(vobSub, "VobSub");
                        DsError.ThrowExceptionForHR(hr);
                        IDirectVobSub vss = vobSub as IDirectVobSub;
                        if (_vobsub != null)
                        {
                            Marshal.ReleaseComObject(_vobsub);
                        }
                        _vobsub = vss;
                        InitSubSettings();
                    }
                    catch { }
                }

                hr = m_graph.Connect(DsFindPin.ByName((IBaseFilter)splitter, "Audio"), DsFindPin.ByDirection(_audio, PinDirection.Input, 0));
                if (hr == 0)
                {
                    HasAudio = true;
                }
                else
                {
                    HasAudio = false;
                }


                IBaseFilter dcDsp = FilterProvider.GetDCDSPFilter();
                if (dcDsp != null)
                {
                    if (_dspFilter != null)
                    {
                        Marshal.ReleaseComObject(_dspFilter);
                    }
                    _dspFilter = (IDCDSPFilterInterface)dcDsp;

                    if (HasAudio)
                    {
                        hr = m_graph.AddFilter((IBaseFilter)_dspFilter, "AudioProcessor");
                        hr = _dspFilter.set_EnableBitrateConversionBeforeDSP(true);
                        hr = ((IDCDSPFilterVisualInterface)_dspFilter).set_VISafterDSP(true);
                        hr = m_graph.Connect(DsFindPin.ByDirection((IBaseFilter)_audio, PinDirection.Output, 0), DsFindPin.ByDirection(_dspFilter, PinDirection.Input, 0));
                        DsError.ThrowExceptionForHR(hr);
                        hr = m_graph.Connect(DsFindPin.ByDirection((IBaseFilter)_dspFilter, PinDirection.Output, 0), DsFindPin.ByDirection(_audioRenderer, PinDirection.Input, 0));

                        var cb = new AudioCallback(this);
                        hr = _dspFilter.set_CallBackPCM(cb);

                        object intf = null;
                        hr         = _dspFilter.set_AddFilter(0, TDCFilterType.ftEqualizer);
                        hr         = _dspFilter.get_FilterInterface(0, out intf);
                        _equalizer = (IDCEqualizer)intf;
                        _equalizer.set_Seperate(false);
                    }
                }
                else
                {
                    if (HasAudio)
                    {
                        hr = m_graph.Connect(DsFindPin.ByDirection((IBaseFilter)_audio, PinDirection.Output, 0), DsFindPin.ByDirection(_audioRenderer, PinDirection.Input, 0));
                    }
                }

                bool subconnected = false;

                hr = m_graph.Connect(DsFindPin.ByName((IBaseFilter)_splitter, "Video"), DsFindPin.ByDirection(_video, PinDirection.Input, 0));
                if (hr == 0)
                {
                    HasVideo = true;
                }
                else
                {
                    HasVideo = false;
                }

                if (HasVideo)
                {
                    hr = m_graph.Connect(DsFindPin.ByDirection((IBaseFilter)_video, PinDirection.Output, 0), DsFindPin.ByDirection(vobSub, PinDirection.Input, 0));
                    DsError.ThrowExceptionForHR(hr);
                    if (hr == 0)
                    {
                        int lc;
                        ((IDirectVobSub)vobSub).get_LanguageCount(out lc);
                        subconnected = (lc != 0);
                        IPin pn = DsFindPin.ByName((IBaseFilter)splitter, "Subtitle");
                        if (pn != null)
                        {
                            hr = m_graph.Connect(pn, DsFindPin.ByDirection(vobSub, PinDirection.Input, 1));
                            ((IDirectVobSub)vobSub).get_LanguageCount(out lc);
                            subconnected = (lc != 0);
                        }
                        hr = m_graph.Connect(DsFindPin.ByDirection(vobSub, PinDirection.Output, 0),
                                             DsFindPin.ByDirection(_renderer, PinDirection.Input, 0));
                    }
                    else
                    {
                        if (_vobsub != null)
                        {
                            Marshal.ReleaseComObject(_vobsub);
                        }
                        _vobsub = null;
                        hr      = m_graph.Connect(DsFindPin.ByDirection(_video, PinDirection.Output, 0),
                                                  DsFindPin.ByDirection(_renderer, PinDirection.Input, 0));
                    }
                }

                /* Loop over each pin of the source filter */
                while (pinEnum.Next(pins.Length, pins, fetched) == 0)
                {
                    IPin cTo;
                    pins[0].ConnectedTo(out cTo);
                    if (cTo == null)
                    {
                        // this should not happen if the filtegraph is manually connected in a good manner
                        hr = filterGraph.RenderEx(pins[0], AMRenderExFlags.RenderToExistingRenderers, IntPtr.Zero);
                    }
                    else
                    {
                        Marshal.ReleaseComObject(cTo);
                    }
                    Marshal.ReleaseComObject(pins[0]);
                }

                Marshal.ReleaseComObject(pinEnum);

                var selector = splitter as IAMStreamSelect;
                int numstreams;
                selector.Count(out numstreams);
                AMMediaType             mt;
                AMStreamSelectInfoFlags fl;
                SubtitleStreams.Clear();
                VideoStreams.Clear();
                AudioStreams.Clear();
                for (int i = 0; i < numstreams; i++)
                {
                    int    lcid;
                    int    group;
                    string name;
                    object o, o2;
                    selector.Info(i, out mt, out fl, out lcid, out group, out name, out o, out o2);
                    switch (group)
                    {
                    case 0:
                        VideoStreams.Add(name);
                        break;

                    case 1:
                        AudioStreams.Add(name);
                        break;

                    case 2:
                        SubtitleStreams.Add(name);
                        break;
                    }

                    if (o != null)
                    {
                        Marshal.ReleaseComObject(o);
                    }
                    if (o2 != null)
                    {
                        Marshal.ReleaseComObject(o2);
                    }
                }

                OnPropertyChanged("SubtitleStreams");
                OnPropertyChanged("VideoStreams");
                OnPropertyChanged("AudioStreams");

                /* Configure the graph in the base class */
                SetupFilterGraph(m_graph);

#if DEBUG
                /* Adds the GB to the ROT so we can view
                 * it in graphedit */
                m_dsRotEntry = new DsROTEntry(m_graph);
#endif

                SIZE a, b;
                if (HasVideo && _displayControl != null && (_displayControl).GetNativeVideoSize(out a, out b) == 0)
                {
                    var sz = MediaPlayerBase.GetVideoSize(_renderer, PinDirection.Input, 0);
                    if (a.cx > 0 && a.cy > 0)
                    {
                        SetNativePixelSizes(a);
                    }
                }

                if (!subconnected)
                {
                    InvokeNoSubtitleLoaded(new EventArgs());
                }
                else
                {
                    InitSubSettings();
                }
            }
            catch (Exception ex)
            {
                /* This exection will happen usually if the media does
                 * not exist or could not open due to not having the
                 * proper filters installed */
                FreeResources();

                /* Fire our failed event */
                InvokeMediaFailed(new MediaFailedEventArgs(ex.Message, ex));
            }

            InvokeMediaOpened();
        }
Example #20
0
 public FilterProviderTests()
 {
     provider = new FilterProvider(filterRegistryMock.Object);
 }
Example #21
0
        public FilteredBindingList <C> FilteredList(FilteredBindingList <C> filteredList,
                                                    Dictionary <string, object> filter, FilterProvider FilterProvider)
        {
            FilteredBindingList <C> filteredListDummy;

            if (filteredList.Count == 0)
            {
                return(filteredList);
            }

            int counter = 0;

            foreach (KeyValuePair <string, object> filterElement in filter)
            {
                if (filteredList.Count == 0)
                {
                    break;
                }

                C            item     = filteredList[0];
                PropertyInfo property = PropertyReflectionHelper.GetPropertyInfo(item, filterElement.Key);
                if (property == null)
                {
                    throw new FilterPropertyException(String.Format("{0} Property existiert nicht in {1}",
                                                                    filterElement.Key, filteredList[0]));
                }
                if (FilterProvider != null)
                {
                    filteredList.FilterProvider = FilterProvider;
                }
                filteredList.ApplyFilter(filterElement.Key, filterElement.Value);

                counter++;
                if (counter < filter.Count)
                {
                    filteredListDummy = new FilteredBindingList <C>(filteredList);
                    filteredList      = filteredListDummy;
                }
            }
            return(filteredList);
        }
 protected override Provider VisitFilter(FilterProvider provider)
 {
     return(checker.Check(provider.Predicate.Body)
 ? provider.Source
 : base.VisitFilter(provider));
 }
Example #23
0
        public FiltersController(IConfiguration config)
        {
            var db = new DatabaseConnection(config, "TankBuddy");

            _filters = new FilterProvider(db);
        }
Example #24
0
        static void Main(string[] args)
        {
            PictureProvider p   = new PictureProvider();
            IPicture        pic = p.GetPicture("../faceImage.jpg");

            IFilter filterGreyscale          = new FilterGreyscale();
            IFilter filterNegative           = new FilterNegative();
            IFilter filterProvider           = new FilterProvider();
            IFilter filterTwiter             = new FilterTwitter();
            IFilter filterConditional        = new FilterConditional();
            IFilter filterBlurConvolution    = new FilterBlurConvolution();
            IFilter filterSharpenConvolution = new FilterSharpenConvolution();

            //EJERCICIO 1

            IPipe pipeNull_ej1    = new PipeNull();
            IPipe pipeSerial2_ej1 = new PipeSerial(filterNegative, pipeNull_ej1);
            IPipe pipeSerial1_ej1 = new PipeSerial(filterGreyscale, pipeSerial2_ej1);

            pipeSerial1_ej1.Send(pic);

            //EJERCICIO 2

            IPipe pipeNull_ej2      = new PipeNull();
            IPipe pipeProvider2_ej2 = new PipeSerial(filterProvider, pipeNull_ej2);
            IPipe pipeSerial2_ej2   = new PipeSerial(filterNegative, pipeProvider2_ej2);
            IPipe pipeProvider1_ej2 = new PipeSerial(filterProvider, pipeSerial2_ej2);
            IPipe pipeSerial1_ej2   = new PipeSerial(filterGreyscale, pipeProvider1_ej2);

            pipeSerial1_ej2.Send(pic);


            //EJERCICIO 3

            IPipe pipeNull_ej3      = new PipeNull();
            IPipe pipeTwiter2_ej3   = new PipeSerial(filterTwiter, pipeNull_ej3);
            IPipe pipeProvider2_ej3 = new PipeSerial(filterProvider, pipeTwiter2_ej3);
            IPipe pipeSerial2_ej3   = new PipeSerial(filterNegative, pipeProvider2_ej3);
            IPipe pipeTwiter1_ej3   = new PipeSerial(filterTwiter, pipeSerial2_ej3);
            IPipe pipeProvider1_ej3 = new PipeSerial(filterProvider, pipeTwiter1_ej3);
            IPipe pipeSerial1_ej3   = new PipeSerial(filterGreyscale, pipeProvider1_ej3);

            pipeSerial1_ej3.Send(pic);


            //EJERCICIO 4

            IPipe pipeNull_ej4             = new PipeNull();
            IPipe pipeProvider2_ej4        = new PipeSerial(filterProvider, pipeNull_ej4);
            IPipe pipeSerial2_ej4          = new PipeSerial(filterNegative, pipeProvider2_ej4);
            IPipe pipeTwiter1_ej4          = new PipeSerial(filterTwiter, pipeNull_ej4);
            IPipe pipeConditionalFork1_ej4 = new PipeConditionalFork(filterConditional, pipeTwiter1_ej4, pipeSerial2_ej4);
            IPipe pipeProvider1_ej4        = new PipeSerial(filterProvider, pipeConditionalFork1_ej4);
            IPipe pipeSerial1_ej4          = new PipeSerial(filterGreyscale, pipeProvider1_ej4);

            pipeSerial1_ej4.Send(pic);


            //EJERCICIO BONUS

            IPipe pipeNull_ejB      = new PipeNull();
            IPipe pipeProvider2_ejB = new PipeSerial(filterProvider, pipeNull_ejB);
            IPipe pipeSerial2_ejB   = new PipeSerial(filterSharpenConvolution, pipeProvider2_ejB);
            IPipe pipeProvider1_ejB = new PipeSerial(filterProvider, pipeSerial2_ejB);
            IPipe pipeSerial1_ejB   = new PipeSerial(filterBlurConvolution, pipeProvider1_ejB);

            pipeSerial1_ejB.Send(pic);
        }
Example #25
0
 /// <summary>
 /// Creates a new view based on the provided IList object.
 /// </summary>
 /// <param name="list">The IList (collection) containing the data.</param>
 /// <param name="filterProvider">
 /// Delegate pointer to a method that implements the filter behavior.
 /// </param>
 public FilteredBindingList(IList <T> list, FilterProvider filterProvider) : this(list)
 {
     _provider = filterProvider;
 }
Example #26
0
 /// <summary>
 /// Compiles <see cref="FilterProvider"/>.
 /// </summary>
 /// <param name="provider">Filter provider.</param>
 protected abstract TResult VisitFilter(FilterProvider provider);
Example #27
0
 private IEnumerable <TFilter> GetFilters <TFilter>(FilterProvider from) where TFilter : class
 {
     return(from.Provide <TFilter>(
                _activator,
                new ActionExecutionContext(new FakeActionDescriptor("index"), new ControllerPrototype(new object()), new StubHttpContext(), null)));
 }
Example #28
0
 public FilterProviderTests()
 {
     provider = new FilterProvider(filterRegistryMock.Object);
 }
Example #29
0
 private static bool ContainsAccessToTupleField(IEnumerable <int> tupleAccesses,
                                                CalculateProvider calculateProvider, FilterProvider provider)
 {
     return(tupleAccesses.Any(i => calculateProvider.Header.Columns.Contains(provider.Header.Columns[i])));
 }