/// <summary> /// Get a single item from a specific category in the catalog index. This is a specific IndexItem returned from the GetCategoryItems() function. /// </summary> /// <param name="catalogIndexId">Id of the Catalog Index (that is, <seealso cref="IndexCatalog.CatalogID"/>)</param> /// <param name="catalogSectionName">Name of the section within that catalog (that is, <seealso cref="IndexCatalogCategory.GroupId"/>)</param> /// <param name="idOrNameOrOfferId">The Id or Name or Offer Id of the item</param> /// <param name="language">2-letter ISO language code (eg: "en")</param> /// <param name="locale">4 letter ISO locale code (eg: "en-us")</param> /// <returns>Single item in that catalog index under the provided section or NULL</returns> public static async Task <IndexItem?> GetCategoryItem(string catalogIndexId, string catalogSectionName, string idOrNameOrOfferId, string language = "en", string locale = "en-us") { IList <IndexCatalogCategory> categories = await GetCategories(catalogIndexId, language, locale, false); if (categories.Count == 0) { return(null); } IndexCatalogCategory section = categories.FirstOrDefault(d => d.GroupId.Equals(catalogSectionName)); if (section == default) { return(null); } foreach (IndexItem item in section.Items) { if (item.Id.Equals(idOrNameOrOfferId, StringComparison.InvariantCultureIgnoreCase) || item.OfferId.Equals(idOrNameOrOfferId, StringComparison.InvariantCultureIgnoreCase) || ((item.LegacyOfferId != null) && item.LegacyOfferId.Equals(idOrNameOrOfferId, StringComparison.InvariantCultureIgnoreCase)) || ((item.BigId != null) && item.BigId.Equals(idOrNameOrOfferId, StringComparison.InvariantCultureIgnoreCase)) || item.DisplayName.Equals(idOrNameOrOfferId, StringComparison.InvariantCultureIgnoreCase) ) { return(item); } } return(null); }
/// <summary> /// Get the items under a specific category in the catalog index. These are items in a catalog's category /// (Examples: the types of VMs that could be created in the "Compute" catalog). /// </summary> /// <param name="catalogIndexId">Id of the Catalog Index (that is, <seealso cref="IndexCatalog.CatalogID"/>)</param> /// <param name="catalogSectionName">Name of the section within that catalog (that is, <seealso cref="IndexCatalogCategory.GroupId"/>)</param> /// <param name="language">2-letter ISO language code (eg: "en")</param> /// <param name="locale">4 letter ISO locale code (eg: "en-us")</param> /// <returns>List of items in that catalog index under the provided section</returns> public static async Task <List <IndexItem> > GetCategoryItems(string catalogIndexId, string catalogSectionName, string language = "en", string locale = "en-us") { IList <IndexCatalogCategory> categories = await GetCategories(catalogIndexId, language, locale); if (categories.Count == 0) { return(new List <IndexItem>()); } IndexCatalogCategory section = categories.FirstOrDefault(d => d.GroupId.Equals(catalogSectionName)); if (section == default) { return(new List <IndexItem>()); } return(section.Items); }