public static void LoadListings(string[] productIds) { Deployment.Current.Dispatcher.BeginInvoke(() => { Dictionary<string, ProductListing> resultListings = new Dictionary<string, ProductListing>(); try { IAsyncOperation<ListingInformation> asyncOp = CurrentApp.LoadListingInformationByProductIdsAsync(productIds); asyncOp.Completed = (op, status) => { var listings = op.GetResults(); foreach (var l in listings.ProductListings) { var listing = l.Value; var resultListing = new ProductListing( listing.ProductId, listing.Name, listing.Description, listing.FormattedPrice); resultListings[l.Key] = resultListing; } if (LoadListingsSucceeded != null) LoadListingsSucceeded(resultListings); }; } catch (Exception e) { if (LoadListingsFailed != null) LoadListingsFailed(e.Message); } }); }
public string SaveReceipt(ProductListing productListing, bool returnReceipt) { if (productListing.ProductType == ProductType.Unknown) return string.Empty; // nothing to do with this one. string mockReceipt = string.Format(ReceiptTemplate, productListing.FormattedPrice, DateTime.Now.ToLongTimeString(), Guid.NewGuid().ToString(), productListing.ProductId, productListing.ProductType.ToString()); IsolatedStorageFile userStore = IsolatedStorageFile.GetUserStoreForApplication(); string targetFileName = Path.Combine(ReceiptStore, productListing.ProductId + ".xml"); if (!userStore.FileExists(targetFileName)) { IsolatedStorageFileStream stream = userStore.CreateFile(targetFileName); var sw = new StreamWriter(stream); sw.WriteLine(mockReceipt); sw.Close(); } return mockReceipt; }
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { GroupId = NavigationContext.QueryString["ID"]; productInfo = App.IAPListingInformation.ProductListings[GroupId]; #if DEBUG if (null != productInfo.ImageUri) { //Tweak image URI string s = productInfo.ImageUri.OriginalString; s = s.Replace("ms-appdata://", ""); productInfo.ImageUri = new Uri(s, UriKind.Relative); } #endif this.DataContext = productInfo; base.OnNavigatedTo(e); }
internal static ProductListing Create(Windows.ApplicationModel.Store.ProductListing productListing) { var p = new ProductListing { Description = productListing.Description, FormattedPrice = productListing.FormattedPrice, ImageUri = productListing.ImageUri }; var keywords = productListing.Keywords.ToList(); p.Keywords = keywords; p.Name = productListing.Name; p.ProductId = productListing.ProductId; p.ProductType = productListing.ProductType; p.Tag = productListing.Tag; return p; }
/// <summary> /// Populates the Mock Library with IAP items defined in XML /// </summary> /// <param name="Xml">XML to parse</param> public static void PopulateIAPItemsFromXml(string Xml) { CheckIfInitialized(); XElement xmlDoc = XElement.Parse(Xml); foreach (XElement element in xmlDoc.Elements()) { var pl = new ProductListing(); pl.Name = element.Element("Name").Value; pl.ProductId = element.Element("ProductId").Value; pl.Description = element.Element("Description").Value; pl.FormattedPrice = element.Element("FormattedPrice").Value; string uri = element.Element("ImageUri").Value; pl.ImageUri = string.IsNullOrEmpty(uri) ? null : new Uri(uri); pl.ProductType = (ProductType) Enum.Parse(typeof (ProductType), element.Element("ProductType").Value); string keywords = element.Element("Keywords").Value; pl.Keywords = string.IsNullOrEmpty(keywords) ? null : keywords.Split(';'); pl.Tag = element.Element("Tag").Value; if (pl.Tag.Length > 3000) throw new Exception("Data stored in the 'Tag' can not exceed 3000 characters!"); AddProductListing(element.Attribute("Key").Value, pl); bool purchased = bool.Parse(element.Attribute("Purchased").Value); bool fulfilled = bool.Parse(element.Attribute("Fulfilled").Value); if (!purchased && fulfilled) throw new InvalidOperationException("Error in your XML definition: An item can't be marked as fulfilled but not purchased! Item: " + pl.Name); if (purchased) { var store = new MockReceiptStore(); store.SaveReceipt(pl, false); StateInformation.SetState(pl.ProductId, fulfilled); _appLicenseInformation.ProductLicenses[pl.ProductId].IsActive = true; } } }
public static void AddProductListing(string key, ProductListing productListing) { CheckIfInitialized(); if (_appListingInformation == null) throw new Exception("A call to SetListingInformation is required before calling this method"); if (allProducts == null) allProducts = new Dictionary<string, ProductListing>(); allProducts.Add(key, productListing); var store = new MockReceiptStore(); Dictionary<string, string> receipts = store.EnumerateReceipts(); // add a license for this item as well. var license = new ProductLicense { ExpirationDate = DateTimeOffset.Now, IsActive = receipts.ContainsKey(productListing.ProductId), IsConsumable = productListing.ProductType == ProductType.Consumable, ProductId = productListing.ProductId }; _appLicenseInformation.ProductLicenses.Add(productListing.ProductId, license); }
private static async void LoadListing(Action<ListingInformation, Exception> onComplete) { try { #if DEBUG var task = CurrentApp.LoadListingInformationAsync(); #else var task = CurrentApp.LoadListingInformationAsync().AsTask(); #endif await task; var information = task.Result; if (information != null) { var listing = new ListingInformation(); listing.AgeRating = information.AgeRating; listing.CurrentMarket = information.CurrentMarket; listing.Description = information.Description; listing.FormattedPrice = information.FormattedPrice; listing.Name = information.Name; listing.ProductListings = new Dictionary<string, ProductListing>(); var productListings = information.ProductListings; foreach (var productListing in productListings) { var value = productListing.Value; var product = new ProductListing(); product.ProductId = value.ProductId; product.ProductType = (ProductType)value.ProductType; product.FormattedPrice = value.FormattedPrice; product.Name = value.Name; listing.ProductListings.Add(productListing.Key, product); } if (onComplete != null) { EtceteraWindows.RunOnUnityThread(() => onComplete(listing, null)); } } else { if (onComplete != null) { EtceteraWindows.RunOnUnityThread(() => onComplete(null, new Exception("ListingInformation is null"))); } } } catch (Exception ex) { if (onComplete != null) { EtceteraWindows.RunOnUnityThread(() => onComplete(null, ex)); } } }
public static void LoadListings(string[] productIds) { Deployment.Current.Dispatcher.BeginInvoke(() => { Dictionary<string, ProductListing> resultListings = new Dictionary<string, ProductListing>(); IAsyncOperation<ListingInformation> asyncOp; try { asyncOp = CurrentApp.LoadListingInformationByProductIdsAsync(productIds); } catch(Exception e) { if (LoadListingsFailed != null) LoadListingsFailed(GetErrorDescription(e)); return; } asyncOp.Completed = (op, status) => { if (op.Status == AsyncStatus.Error) { if (LoadListingsFailed != null) LoadListingsFailed(GetErrorDescription(op.ErrorCode)); return; } if (op.Status == AsyncStatus.Canceled) { if (LoadListingsFailed != null) LoadListingsFailed("QueryInventory was cancelled"); return; } var listings = op.GetResults(); foreach (var l in listings.ProductListings) { var listing = l.Value; var resultListing = new ProductListing( listing.ProductId, listing.Name, listing.Description, listing.FormattedPrice); resultListings[l.Key] = resultListing; } if (LoadListingsSucceeded != null) LoadListingsSucceeded(resultListings); }; }); }
public static bool ProductIsActive(ProductListing product) { return(CurrentApp.LicenseInformation.ProductLicenses[product.ProductId].IsActive); }