Example #1
0
        public CategoryList List()
        {
            #if DEBUG
            Console.WriteLine("List()");
            #endif

            if (!categories.Any())
            {
                foreach (var category in PerformanceCounterCategory.GetCategories())
                {
                    if (!allowedCategories.Contains(category.CategoryName))
                    {
                        continue;
                    }

                    List <Counter> counters = new List <Counter>();

                    foreach (var counter in category.GetCounters(string.Empty))
                    {
                        counters.Add(new Counter()
                        {
                            Name = counter.CounterName
                        });
                    }

                    categories.Add(new Category()
                    {
                        Name = category.CategoryName, Counters = counters
                    });
                }
            }

            return(categories);
        }
Example #2
0
        /// <summary>
        /// return categories from category list matching category root id
        /// </summary>
        /// <param name="categoryList"></param>
        /// <param name="rootCategoryId"></param>
        /// <returns></returns>
        public static List <string> GetCategories(CategoryList categoryList, int rootCategoryId)
        {
            var categories = new List <string>();

            var categoryRepository = ServiceLocator.Current.GetInstance <CategoryRepository>();

            var rootCategory = categoryRepository.GetRoot();

            if (categoryList.Any())
            {
                foreach (var categoryId in categoryList)
                {
                    var category = FindCategory(rootCategory, categoryId);

                    if (category != null)
                    {
                        var parent = category.Parent;

                        do
                        {
                            if (parent.ID == rootCategoryId)
                            {
                                categories.Add(category.Name);
                                break;
                            }

                            parent = parent.Parent;
                        } while (parent != null);
                    }
                }
            }

            return(categories);
        }
Example #3
0
        /// <summary>
        /// Removes any page not matching any of the specified categories
        /// </summary>
        /// <param name="pages">The page collection to filter</param>
        /// <param name="categories">Categories used for filtering, pages not matching at least one category will be filtered out</param>
        public static void FilterByCategories(this PageDataCollection pages, CategoryList categories)
        {
            if (categories == null || !categories.Any())
            {
                return;
            }

            for (var i = pages.Count - 1; i >= 0; i--)
            {
                var atLeastOneCategoryMatches = categories.Any(c => pages[i].Category.Contains(c));

                if (!atLeastOneCategoryMatches)
                {
                    pages.RemoveAt(i);
                }
            }
        }
        /// <summary>
        /// Removes any page not matching any of the specified categories
        /// </summary>
        /// <param name="pages">The page collection to filter</param>
        /// <param name="categories">Categories used for filtering, pages not matching at least one category will be filtered out</param>
        public static void FilterByCategories(this PageDataCollection pages, CategoryList categories)
        {
            if (categories == null || !categories.Any())
            {
                return;
            }

            for (var i = pages.Count - 1; i >= 0; i--)
            {
                var atLeastOneCategoryMatches = categories.Any(c => pages[i].Category.Contains(c));

                if (!atLeastOneCategoryMatches)
                {
                    pages.RemoveAt(i);
                }
            }
        }
Example #5
0
 public static List <Category> GetCategoryList(this CategoryList list)
 {
     if (list != null && list.Any())
     {
         var catRepo = ServiceLocator.Current.GetInstance <CategoryRepository>();
         return(list.Select(x => catRepo.Get(x)).ToList());
     }
     return(new List <Category>());
 }
        public static Category GetCategory(CategoryList categoryId)
        {
            if (categoryId != null && categoryId.Any())
            {
                return(_categoryRepository.Service.Get(categoryId.FirstOrDefault()));
            }

            return(null);
        }
        public static string GetDisplayName(CategoryList categoryId)
        {
            if (categoryId != null && categoryId.Any())
            {
                var catId = categoryId.FirstOrDefault();
                return(GetDisplayName(catId));
            }

            return(string.Empty);
        }
 public override void OnAppearing()
 {
     base.OnAppearing();
     MainThread.BeginInvokeOnMainThread(async() =>
     {
         if (CategoryList.Any())
         {
             return;
         }
         await GetDataAsync();
     });
 }
Example #9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="categoryList"></param>
        /// <param name="categoryId"></param>
        /// <returns></returns>
        public static bool HasCategory(CategoryList categoryList, long categoryId)
        {
            if (categoryList.Any())
            {
                foreach (var catId in categoryList)
                {
                    if (catId == categoryId)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        public static IEnumerable <string> GetDisplayNamesRespectOrder(CategoryList categoryIds)
        {
            var catList = new List <Category>();

            if (categoryIds != null && categoryIds.Any())
            {
                foreach (var id in categoryIds)
                {
                    var cat = _categoryRepository.Service.Get(id);
                    if (cat != null)
                    {
                        catList.Add(cat);
                    }
                }
            }

            return(catList.Any() ? catList.OrderBy(x => x.SortOrder).Select(x => x.Description) : Enumerable.Empty <string>());
        }
        /// <summary>
        /// Filters out content references to content that does not match current category filters, if any
        /// </summary>
        /// <param name="contentReferences"></param>
        /// <returns></returns>
        private IList <T> FilterByCategory <T>(IEnumerable <T> contentReferences)
        {
            if (_category == null || !_category.Any())
            {
                return(contentReferences.ToList());
            }

            // Filter by category if a category filter has been set
            var filteredChildren = new List <T>();

            foreach (var contentReference in contentReferences)
            {
                ICategorizable content = null;
                if (contentReference is ContentReference)
                {
                    content = (contentReference as ContentReference).Get <IContent>() as ICategorizable;
                }
                else if (typeof(T) == typeof(GetChildrenReferenceResult))
                {
                    content = (contentReference as GetChildrenReferenceResult).ContentLink.Get <IContent>() as ICategorizable;
                }

                if (content != null)
                {
                    var atLeastOneMatchingCategory = content.Category.Any(c => _category.Contains(c));

                    if (atLeastOneMatchingCategory)
                    {
                        filteredChildren.Add(contentReference);
                    }
                }
                else // Non-categorizable content will also be included
                {
                    filteredChildren.Add(contentReference);
                }
            }

            return(filteredChildren);
        }
Example #12
0
        public static List <string> GetCategories(CategoryList categoryList)
        {
            var categories = new List <string>();

            var categoryRepository = ServiceLocator.Current.GetInstance <CategoryRepository>();

            var rootCategory = categoryRepository.GetRoot();

            if (categoryList.Any())
            {
                foreach (var categoryId in categoryList)
                {
                    var category = FindCategory(rootCategory, categoryId);

                    if (category != null)
                    {
                        categories.Add(category.Name);
                    }
                }
            }

            return(categories);
        }
Example #13
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="categoryList"></param>
        /// <returns></returns>
        public static List <string> GetCategoryPaths(CategoryList categoryList)
        {
            var categories = new List <string>();

            var categoryRepository = ServiceLocator.Current.GetInstance <CategoryRepository>();

            var rootCategory = categoryRepository.GetRoot();

            if (categoryList.Any())
            {
                foreach (var categoryId in categoryList)
                {
                    var categoryPaths = CreateCategoryPath(rootCategory, categoryId);

                    //if(categoryPaths.Any())
                    //    categories.AddRange(categoryPaths);

                    var path = string.Empty;

                    foreach (var category in categoryPaths)
                    {
                        if (path == string.Empty)
                        {
                            path = category;
                        }
                        else
                        {
                            path = string.Format("{0}/{1}", path, category);
                        }

                        categories.Add(path);
                    }
                }
            }

            return(categories);
        }