Esempio n. 1
0
        public HomeViewModel()
        {
            ComicEngine    = AppEngine.GetRequiredService <ComicEngine>();
            SearchEngine   = AppEngine.GetRequiredService <SearchEngine>();
            ProposalEngine = AppEngine.GetRequiredService <ProposalEngine>();

            SearchCommand       = new AsyncRelayCommand(SearchAsync);
            GoSourceCommand     = new RelayCommand(GoSource);
            SetAndSearchCommand = new AsyncRelayCommand <string>(SetAndSearchAsync);
            ResetCommand        = new RelayCommand(Reset);
            SetCurrentCommand   = new RelayCommand <ComicSnapshotInfo <TSourceInfo> >(SetCurrent);
            CopyCommand         = new RelayCommand <string>(Copy);
            scope = AppEngine.CreateScope();

            observableCollectionFactory = AppEngine.GetRequiredService <IObservableCollectionFactory>();
            SearchProviders             = observableCollectionFactory.Create <ISearchProvider>();
            foreach (var item in SearchEngine)
            {
                var sp = (ISearchProvider)scope.ServiceProvider.GetRequiredService(item);
                SearchProviders.Add(sp);
            }
            CurrentSearchProvider = SearchProviders.FirstOrDefault();

            Snapshots         = observableCollectionFactory.Create <ComicSnapshotInfo <TSourceInfo> >();
            ProposalSnapshots = observableCollectionFactory.Create <ComicSnapshotInfo <TSourceInfo> >();
            EngineIcons       = observableCollectionFactory.Create <EngineInfo <TImage> >();
        }
Esempio n. 2
0
        // Executes a search on each place search provider
        private void doPlaceSearch(object parameter)
        {
            if (!canDoPlaceSearch(parameter))
            {
                throw new Exception(Strings.CommandNotExecutable);
            }

            var placeSearchProviders = SearchProviders.OfType <ArcGISLocatorPlaceSearchProvider>();

            foreach (ArcGISLocatorPlaceSearchProvider placeSearchProvider in placeSearchProviders)
            {
                placeSearchProvider.Search.Execute(parameter);
            }
        }
Esempio n. 3
0
        // Checks whether a search can be executed.  Requires that the current search input is
        // valid for each search provider.
        private bool canDoPlaceSearch(object parameter)
        {
            if (SearchProviders == null)
            {
                return(false);
            }

            var placeSearchProviders = SearchProviders.OfType <ArcGISLocatorPlaceSearchProvider>();

            foreach (ArcGISLocatorPlaceSearchProvider placeSearchProvider in placeSearchProviders)
            {
                if (placeSearchProvider.Search.CanExecute(parameter)) // Only need one to be executable
                {
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 4
0
        private void SearchCallback(IAsyncResult ar)
        {
            try
            {
                SearchEndTime = DateTime.Now;
                SearchResults SearchResults = ContactManager.EndSearch(ar);
                object[]      state         = (object[])ar.AsyncState;

                string          searchKeyword  = (string)state[0];
                SearchProviders searchProvider = (SearchProviders)state[1];

                Dispatcher.Invoke(
                    System.Windows.Threading.DispatcherPriority.Normal,
                    new Action(
                        () =>
                {
                    SearchResultListBox.Items.Clear();
                    foreach (Contact contact in SearchResults.Contacts)
                    {
                        SearchResultListBox.Items.Add("Contact: " + contact.Uri);
                    }
                    foreach (Group group in SearchResults.Groups)
                    {
                        SearchResultListBox.Items.Add("Distribution Group: " + group.Name);
                    }
                    SearchStatisticsTextBox.Text +=
                        "\n\nSearch Results:" + SearchEndTime +
                        "\nSearch keyword => " + SearchKeywordTextBox.Text +
                        "\nSearch provider => " + searchProvider.ToString() +
                        "\nNumber of Contacts => " + SearchResults.Contacts.Count +
                        "\nNumber of Groups => " + SearchResults.Groups.Count +
                        "\nSearch duration => " + (SearchEndTime - SearchStartTime).ToString();
                }));
            }
            catch (Exception ex)
            {
                SearchStatisticsTextBox.Text = "Exception: " + ex.Message;
            }
        }
Esempio n. 5
0
        // Raised when a search provider is added or removed
        private void SearchProviders_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.NewItems != null)
            {
                object input = null;
                // Get existing input so new providers' inputs can be synced
                if (SearchProviders.Count > e.NewItems.Count)
                {
                    ISearchProvider preExistingProvider = SearchProviders.FirstOrDefault(p => !e.NewItems.Contains(p));
                    if (preExistingProvider != null)
                    {
                        input = preExistingProvider.Input;
                    }
                }

                foreach (ISearchProvider provider in e.NewItems)
                {
                    // Listen for property changes on any new search providers
                    provider.PropertyChanged += SearchProvider_PropertyChanged;

                    // Initialize input
                    provider.Input = input;
                }
            }

            if (e.OldItems != null)
            {
                // Unhook from property changes on any removed search providers
                foreach (ISearchProvider provider in e.OldItems)
                {
                    provider.PropertyChanged -= SearchProvider_PropertyChanged;
                }
            }

            raiseCanExecuteChanged();
        }
Esempio n. 6
0
 public SearchArgs(SearchProviders.IQuery query)
 {
     Query = query;
 }
Esempio n. 7
0
 public SearchController(IOptions <ApplicationConfiguration> options, SearchProviders searchProviders)
 {
     this._searchProviders = searchProviders;
 }