Exemple #1
0
        private void PerformSearch(string searchText)
        {
            if (string.IsNullOrWhiteSpace(searchText))
            {
                SelectedSearchResults?.Clear();
                SearchResults    = null;
                HasSearchResults = false;
                return;
            }

            var keywords = searchText.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            var results  = new List <SearchResultItem>();

            foreach (var category in _categories)
            {
                var resultWithKeywords =
                    from counter in category.Counters
                    from instance in category.Instances.DefaultIfEmpty()
                    select new SearchResultItem(keywords, category.Name, counter, instance);

                results.AddRange(resultWithKeywords.Where(result => result.IsMatch));
            }

            SearchResults    = results;
            HasSearchResults = results.Any();
        }
Exemple #2
0
        public CategoriesViewModel()
        {
            _categories = new KeyedCollectionProxy <string, CategoryViewModel>(c => c.Name);
            _categories.CollectionView.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending));

            AddCommand = CreateCommand(PublishAdd,
                                       () => SelectedCategory != null &&
                                       SelectedCounters != null && SelectedCounters.Count > 0 &&
                                       SelectedInstances != null && SelectedInstances.Count > 0);

            AddSearchResultsCommand = CreateCommand(PublishAddSearchResults,
                                                    () => SelectedSearchResults != null && SelectedSearchResults.OfType <SearchResultItem>().Any(t => t.IsValid));

            CloseCommand = CreateCommand(OnClosed);

            Load();
        }