示例#1
0
        /// <summary>
        /// Loads listing information and fires completingHandler with the data once loading completes
        /// 
        /// </summary>
        /// <param name="completionHandler"/>
        public static async void LoadListingInformation(Action<ListingInformation, Exception> onComplete)
        {
            try
            {
                await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
                {
                    try
                    {
                        var task = CurrentApp.LoadListingInformationAsync().AsTask();
                    
                        await task;

                        if (onComplete != null)
                        {
                            ListingInformation listing = null;
                            var information = task.Result;
                            if (information != null)
                            {
                                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>();
                                foreach (var productListing in information.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);
                                }
                            }

                            onComplete(listing, null);
                        }
                    }
                    catch (Exception ex)
                    {
                        if (onComplete != null)
                        {
                            onComplete(null, ex);
                        }
                    }
                });
            }
            catch (Exception ex)
            {
                if (onComplete != null)
                {
                    onComplete(null, ex);
                }
            }
        }