public async override Task RefreshAppProducts() { AppProducts.Clear(); var listingInfo = await GetListingInformationAsync(); foreach (var product in listingInfo.ProductListings) { var license = GetLicense(product.Value.ProductId); AppProduct appProduct = new AppProduct(license.ProductId, license.ProductId, false); appProduct.Name = product.Value.Name; appProduct.Description = product.Value.Description; appProduct.CurrentFormattedPrice = product.Value.FormattedPrice; appProduct.BaseFormattedPrice = product.Value.FormattedBasePrice; appProduct.ExpiryDate = license.ExpirationDate.DateTime; appProduct.Purchased = license.IsActive; if (license.IsConsumable) { appProduct.ProductType = ProductKind.Consumable; } else { appProduct.ProductType = ProductKind.Durable; } AppProducts.Add(appProduct); } // Invoke the event InvokeAppProductsChanged(); }
public async override Task RefreshAppProducts() { var kinds = GetProductKinds(); var appLicense = await Context.GetAppLicenseAsync(); var result = await Context.GetAssociatedStoreProductsAsync(kinds.Select(x => x.ToString())); AppProducts.Clear(); foreach (var item in result.Products) { Debug.WriteLine($"Key: {item.Key} | StoreID: {item.Value.StoreId} | ProductID: {item.Value.InAppOfferToken}"); // Cache the value var storeProduct = item.Value; // Create the App Product AppProduct appProduct = new AppProduct(storeProduct.InAppOfferToken, storeProduct.StoreId); appProduct.Name = storeProduct.Title; appProduct.Description = storeProduct.Description; appProduct.CurrentFormattedPrice = storeProduct.Price.FormattedPrice; appProduct.BaseFormattedPrice = storeProduct.Price.FormattedBasePrice; // Parse the Product Type if (Enum.TryParse <ProductKind>(storeProduct.ProductKind, out ProductKind parsedProductKind)) { appProduct.ProductType = parsedProductKind; } else { appProduct.ProductType = ProductKind.Unknown; } // Add License Info appProduct.Purchased = storeProduct.IsInUserCollection; foreach (var license in appLicense.AddOnLicenses) { Debug.WriteLine($"Licence Key: {license.Key} == Product Key: {item.Key}"); if (license.Key.Contains(item.Key)) { appProduct.Purchased = license.Value.IsActive; appProduct.ExpiryDate = license.Value.ExpirationDate.DateTime; Debug.WriteLine($"Licence Found - Purchased: {appProduct.Purchased} | Expiry Date: {appProduct.ExpiryDate}"); break; } } // Finally, add to the main list Debug.WriteLine(appProduct); AppProducts.Add(appProduct); } InvokeAppProductsChanged(); }