public async Task <IList <ProductItem> > LoadProductsAsync(IEnumerable <string> supportedProductIds, string localizedPurchasedText = null)
        {
            var productItems = new List <ProductItem>();

            // fallback purchased text
            if (string.IsNullOrEmpty(localizedPurchasedText))
            {
                localizedPurchasedText = "purchased";
            }

            try
            {
                // load supported products
#if DEBUG
                ListingInformation lisitingInfo = await CurrentAppSimulator.LoadListingInformationByProductIdsAsync(supportedProductIds);
#else
                ListingInformation lisitingInfo = await CurrentApp.LoadListingInformationByProductIdsAsync(supportedProductIds);
#endif

                foreach (var id in lisitingInfo.ProductListings.Keys)
                {
                    ProductListing product         = lisitingInfo.ProductListings[id];
                    var            isProductActive = IsProductActive(id);
                    var            status          = isProductActive ? localizedPurchasedText : product.FormattedPrice;
                    var            imageLink       = string.Empty;
                    productItems.Add(
                        new ProductItem
                    {
                        ImageUri    = product.ImageUri,
                        Name        = product.Name,
                        Description = product.Description,
                        Status      = status,
                        Id          = id,
                        IsActive    = isProductActive
                    }
                        );
                }
            }
            catch (Exception e)
            {
                Logger.WriteLine(e, "Loading of products failed");
                return(null);
            }

            return(productItems);
        }
        /// <summary>
        /// Returns the list of all purchaseable items
        /// </summary>
        /// <returns></returns>
        public async Task <List <PurchaseableItem> > PurchaseableItems()
        {
            // First, retrieve the list of some products by their IDs.
        #if DEBUG
            ListingInformation listings = await CurrentAppSimulator.LoadListingInformationByProductIdsAsync(new string[] { "pebble_notifications" });
        #else
            ListingInformation listings = await CurrentApp.LoadListingInformationByProductIdsAsync(new string[] { "pebble_notifications" });
        #endif

            List <PurchaseableItem> Items = new List <PurchaseableItem>();

            foreach (var item in listings.ProductListings.Values)
            {
                Items.Add(new PurchaseableItem {
                    ID = item.ProductId, Name = item.Name, Description = item.Description, Price = item.FormattedPrice
                });
            }

            return(Items);
        }
 LoadListingInformationByProductIdsAsync(IEnumerable <string> productIds)
 {
     return(IsMockEnabled
         ? CurrentAppSimulator.LoadListingInformationByProductIdsAsync(productIds)
         : CurrentApp.LoadListingInformationByProductIdsAsync(productIds));
 }
示例#4
0
        //public static async Task<ListingInformation> LoadListingInformationAsync(bool isTestingMode)
        //{
        //   return isTestingMode ? await CurrentAppSimulator.LoadListingInformationAsync() : await CurrentApp.LoadListingInformationAsync();
        //}

        public static async Task <ListingInformation> LoadListingInformationByProductIdsAsync(bool isTestingMode, IEnumerable <string> productIds)
        {
            // This won't work until the app is public
            return(isTestingMode ? await CurrentAppSimulator.LoadListingInformationByProductIdsAsync(productIds) : await CurrentApp.LoadListingInformationByProductIdsAsync(productIds));
        }