예제 #1
0
        public SearchOptionsViewModel(ICombinedSearchMetadataCollection combinedSearchMetadataCollection,
                                      ISearchProxyCollectionFactory searchProxyCollectionFactory,
                                      ISearchMetadataFactory searchMetadataFactory,
                                      ISchedulerProvider schedulerProvider,
                                      SearchHints searchHints)
        {
            SearchHints = searchHints;

            var global = combinedSearchMetadataCollection.Global;
            var local  = combinedSearchMetadataCollection.Local;

            Action <SearchMetadata> changeScopeAction = meta =>
            {
                if (meta.IsGlobal)
                {
                    //make global
                    global.Remove(meta.SearchText);
                    var newValue = new SearchMetadata(meta, local.NextIndex(), false);
                    local.AddorUpdate(newValue);
                }
                else
                {
                    //make local
                    local.Remove(meta.SearchText);
                    var newValue = new SearchMetadata(meta, global.NextIndex(), true);
                    global.AddorUpdate(newValue);
                }
            };

            Local  = searchProxyCollectionFactory.Create(local, Id, changeScopeAction);
            Global = searchProxyCollectionFactory.Create(global, Id, changeScopeAction);

            //command to add the current search to the tail collection
            var searchInvoker = SearchHints.SearchRequested
                                .ObserveOn(schedulerProvider.Background)
                                .Subscribe(request =>
            {
                var isGlobal  = SelectedIndex == 1;
                var nextIndex = isGlobal ? global.NextIndex() : local.NextIndex();

                var meta = searchMetadataFactory.Create(request.Text,
                                                        request.UseRegEx,
                                                        nextIndex,
                                                        false,
                                                        isGlobal);

                if (isGlobal)
                {
                    global.AddorUpdate(meta);
                }
                else
                {
                    local.AddorUpdate(meta);
                }
            });

            _cleanUp = new CompositeDisposable(searchInvoker,
                                               searchInvoker,
                                               SearchHints,
                                               Global,
                                               Local);
        }
        public SearchOptionsViewModel(ICombinedSearchMetadataCollection combinedSearchMetadataCollection,
            ISearchProxyCollectionFactory searchProxyCollectionFactory,
            ISearchMetadataFactory searchMetadataFactory,
            ISchedulerProvider schedulerProvider,
            SearchHints searchHints)
        {
            SearchHints = searchHints;

            var global = combinedSearchMetadataCollection.Global;
            var local = combinedSearchMetadataCollection.Local;

            Action<SearchMetadata> changeScopeAction = meta =>
            {
                if (meta.IsGlobal)
                {
                    //make global
                    global.Remove(meta.SearchText);
                    var newValue = new SearchMetadata(meta, local.NextIndex(),false);
                    local.AddorUpdate(newValue);
                }
                else
                {
                    //make local
                    local.Remove(meta.SearchText);
                    var newValue = new SearchMetadata(meta, global.NextIndex(), true);
                    global.AddorUpdate(newValue);
                }
            };

            Local = searchProxyCollectionFactory.Create(local, Id, changeScopeAction);
            Global = searchProxyCollectionFactory.Create(global, Id, changeScopeAction);

            //command to add the current search to the tail collection
            var searchInvoker = SearchHints.SearchRequested
                .ObserveOn(schedulerProvider.Background)
                .Subscribe(request =>
                {
                    var isGlobal = SelectedIndex == 1;
                    var nextIndex = isGlobal ? global.NextIndex() : local.NextIndex();

                    var meta = searchMetadataFactory.Create(request.Text,
                        request.UseRegEx,
                        nextIndex,
                        false,
                        isGlobal);

                    if (isGlobal)
                    {
                        global.AddorUpdate(meta);
                    }
                    else
                    {
                        local.AddorUpdate(meta);
                    }
                });

            _cleanUp = new CompositeDisposable(searchInvoker,
                searchInvoker,
                SearchHints,
                Global,
                Local);
        }