public AppElementViewModel(IAppStoreItem appItem, bool usePhoneFeed) { if (appItem == null) throw new ArgumentNullException("appItem"); _usePhoneFeed = usePhoneFeed; AppStoreId = ExtractAppId(appItem.Id); PackageFamilyName = appItem.PackageFamilyName; ThumbnailUrl = GetThumbnailUrl(appItem); AppName = appItem.Name; //Price value from feed comes in en-US culture format so we need to make sure it works when OS is set to a different culture. CultureInfo culture = CultureInfo.InvariantCulture; NumberStyles style = NumberStyles.AllowDecimalPoint; double price; Double.TryParse(appItem.Price, style, culture, out price); if (usePhoneFeed) { Rating = appItem.Rating / 2; // Converting rating score to [0 to 5 stars] range. Price = price; } else { Rating = appItem.Rating; //Rating range is [0 to 5] stars if (string.IsNullOrEmpty(appItem.Price)) { //Discounted price is missing so use full price Price = appItem.FullPrice; } else { Price = price; } } NumRatings = appItem.NumOfReviews; _currencySymbol = appItem.CurrencySymbol; Category = GetCatogoryName(appItem); if (usePhoneFeed) { //Remove leading characters from app Id AppStoreLink = string.Format(_baseStoreUrlPhone, AppStoreId); } else { AppStoreLink = string.Format(_baseStoreUrl, appItem.PackageFamilyName); } }
private string GetThumbnailUrl(IAppStoreItem appItem) { if (null != appItem && null != appItem.Assets && appItem.Assets.Count > 0) { var asset = appItem.Assets.FirstOrDefault(); if (null != asset && null != asset.Images && asset.Images.Count > 0) { foreach (var image in asset.Images) { // Check image size to see if it's the square tile if (image.Size == 1) { if (image.Url == string.Empty) { return "Assets/LightGray.png"; // Renturn place holder image } if (_usePhoneFeed) { return _storeImagesUrlPhone + ExtractAppId(image.Url); } else { return _storeImagesUrl + ExtractAppId(image.Url); } } } } } return string.Empty; }
private string GetCatogoryName(IAppStoreItem appItem) { if (null != appItem && null != appItem.Category && null != appItem.Category.Name) { return appItem.Category.Name; } else { return _resloader.GetString("NoCategory"); } }