public void UpdateAppScreenshot(AppScreenshot appScreenshot) { AppScreenshot targetAppScreenshot = context.AppScreenshots.Find(appScreenshot.AppScreenshotID); if (targetAppScreenshot != null) { targetAppScreenshot.FullSizeURL = appScreenshot.FullSizeURL; targetAppScreenshot.ProductDetailID = appScreenshot.ProductDetailID; targetAppScreenshot.Screenshot = appScreenshot.Screenshot; targetAppScreenshot.ScreenshotMimeType = appScreenshot.ScreenshotMimeType; targetAppScreenshot.ThumbnailURL = appScreenshot.ThumbnailURL; } }
public void InsertAppScreenshot(AppScreenshot appScreenshot) { context.AppScreenshots.Add(appScreenshot); }
public void AddAppScreenshot(AppScreenshot screenshot) { if (AppScreenshots == null) { AppScreenshots = new HashSet<AppScreenshot>(); } AppScreenshots.Add(screenshot); screenshot.ProductDetail = this; }
public void BuildListingWithAppID(Listing listing, int appId) { Product product = listing.Product ?? new Product(); ProductDetail productDetail = product.ProductDetail ?? new ProductDetail(); string url = String.Format("http://store.steampowered.com/api/appdetails?appids={0}", product.AppID); string result = new System.Net.WebClient().DownloadString(url); JObject jsonResult = JObject.Parse(result); string appID = product.AppID.ToString(); if (!jsonResult[appID].Any() || !jsonResult[appID]["data"].Any()) { return; } JToken appData = jsonResult[appID]["data"]; int baseAppID = 0; //get all the product details from the jtoken productDetail.ProductType = (string)appData["type"]; productDetail.ProductName = (string)appData["name"]; productDetail.AgeRequirement = (int)appData["required_age"]; productDetail.DetailedDescription = (string)appData["detailed_description"]; productDetail.DLCAppIDs = appData["dlc"].Select(d => (int)d).ToArray(); productDetail.AboutTheGame = (string)appData["about_the_game"]; productDetail.BaseProductName = (string)appData["fullgame "]["name"]; baseAppID = (int)appData["fullgame"]["appid"]; productDetail.SupportedLanguages = (string)appData["supported_languages"]; productDetail.HeaderImageURL = (string)appData["header_image"]; productDetail.ProductWebsite = (string)appData["website"]; productDetail.PCMinimumRequirements = (string)appData["pc_requirements"]["minimum"]; productDetail.PCRecommendedRequirements = (string)appData["pc_requirements"]["recommended"]; productDetail.MacMinimumRequirements = (string)appData["mac_requirements"]["minimum"]; productDetail.MacRecommendedRequirements = (string)appData["mac_requirements"]["recommended"]; productDetail.LinuxMinimumRequirements = (string)appData["linux_requirements"]["minimum"]; productDetail.LinuxRecommendedRequirements = (string)appData["linux_requirements"]["recommended"]; productDetail.Developers = appData["developers"].Select(d => (string)d).ToArray(); productDetail.Publishers = appData["publishers"].Select(d => (string)d).ToArray(); productDetail.DemoAppID = (int)appData["demos"]["appid"]; productDetail.DemoRestrictions = (string)appData["demos"]["description"]; productDetail.FinalPrice = (int)appData["price_overview"]["final"]; productDetail.InitialPrice = (int)appData["price_overview"]["initial"]; productDetail.CurrencyType = (string)appData["price_overview"]["currency"]; productDetail.PackageIDs = appData["packages"].Select(d => (int)d).ToArray(); productDetail.AvailableOnPC = (bool)appData["platforms"]["windows"]; productDetail.AvailableOnMac = (bool)appData["platforms"]["mac"]; productDetail.AvailableOnLinux = (bool)appData["platforms"]["linux"]; productDetail.MetacriticScore = (int)appData["metacritic"]["score"]; productDetail.MetacriticURL = (string)appData["metacritic"]["url"]; productDetail.Genres = appData["genres"].Select(d => (string)d["description"]).ToArray(); productDetail.TotalRecommendations = (int)appData["recommendations"]["total"]; productDetail.NumAchievements = (int)appData["achievements"]["total"]; productDetail.ReleaseDate = (string)appData["release_date"]["date"]; JArray movies = (JArray)appData["movies"]; for (int i = 0; i < movies.Count; i++) { AppMovie temp = new AppMovie(); temp.Highlight = (bool)movies[i]["highlight"]; temp.LargeMovieURL = (string)movies[i]["webm"]["max"]; temp.Name = (string)movies[i]["name"]; temp.SmallMovieURL = (string)movies[i]["webm"]["480"]; temp.ThumbnailURL = (string)movies[i]["thumbnail"]; productDetail.AddAppMovie(temp); } JArray screenshots = (JArray)appData["screenshots"]; for (int i = 0; i < screenshots.Count; i++) { AppScreenshot temp = new AppScreenshot(); temp.FullSizeURL = (string)screenshots[i]["path_full"]; temp.ThumbnailURL = (string)screenshots[i]["path_thumbnail"]; productDetail.AddAppScreenshot(temp); } string[] categories = appData["categories"].Select(c => (string)c).ToArray(); if (categories != null) { for (int i = 0; i < categories.Count(); i++) { if (_storeService.GetProductCategoryByName(categories[i]) == null) { ProductCategory category = new ProductCategory(categories[i]); product.AddProductCategory(category); } else { product.AddProductCategory(_storeService.GetProductCategoryByName(categories[i])); } } } product.AddProductDetail(productDetail); if (String.IsNullOrEmpty(product.ProductName)) { product.ProductName = productDetail.ProductName; } }
// using a Steam App ID, queries the storefront API to get information about the product and build the listing object // listings sent to this method should be persisted to prevent looping behavior private void BuildListingWithAppID(Listing listing, int appId) { if (listing.ListingID == 0) { throw new Exception("The listing was not persisted!"); } if (listing.Product == null) { throw new Exception("A valid product object was not added to the listing object!"); } ProductDetail productDetail = listing.Product.ProductDetail ?? new ProductDetail(); if (listing.Product.ProductDetail == null) { listing.Product.AddProductDetail(productDetail); } string url = String.Format("http://store.steampowered.com/api/appdetails?appids={0}", listing.Product.AppID); string result = new System.Net.WebClient().DownloadString(url); JObject jsonResult = JObject.Parse(result); string appID = listing.Product.AppID.ToString(); if (jsonResult == null || jsonResult[appID] == null || jsonResult[appID]["data"] == null) { return; } JToken appData = jsonResult[appID]["data"]; int baseAppID = 0; //get all the product details from the jtoken productDetail.AppID = (appData["steam_appid"].IsNullOrEmpty()) ? 0 : (int)appData["steam_appid"]; productDetail.ProductType = (string)appData["type"] ?? ""; productDetail.ProductName = (string)appData["name"] ?? ""; listing.ListingName = (String.IsNullOrEmpty(productDetail.ProductName) ? listing.ListingName : productDetail.ProductName); productDetail.AgeRequirement = (appData["required_age"].IsNullOrEmpty()) ? 0 : (int)appData["required_age"]; productDetail.DetailedDescription = (string)appData["detailed_description"] ?? ""; if (!appData["dlc"].IsNullOrEmpty()) { productDetail.DLCAppIDs = appData["dlc"].Select(d => (int)d).ToArray(); } productDetail.AboutTheGame = (string)appData["about_the_game"] ?? ""; if (!appData["fullgame"].IsNullOrEmpty()) { productDetail.BaseProductName = (string)appData["fullgame"]["name"] ?? ""; baseAppID = (appData["fullgame"]["appid"].IsNullOrEmpty()) ? 0 : (int)appData["fullgame"]["appid"]; } productDetail.SupportedLanguages = (string)appData["supported_languages"] ?? ""; productDetail.HeaderImageURL = (string)appData["header_image"] ?? ""; productDetail.ProductWebsite = (string)appData["website"] ?? ""; if (!appData["pc_requirements"].IsNullOrEmpty()) { productDetail.PCMinimumRequirements = (string)appData["pc_requirements"]["minimum"] ?? ""; productDetail.PCRecommendedRequirements = (string)appData["pc_requirements"]["recommended"] ?? ""; } if (!appData["mac_requirements"].IsNullOrEmpty()) { productDetail.MacMinimumRequirements = (string)appData["mac_requirements"]["minimum"] ?? ""; productDetail.MacRecommendedRequirements = (string)appData["mac_requirements"]["recommended"] ?? ""; } if (!appData["linux_requirements"].IsNullOrEmpty()) { productDetail.LinuxMinimumRequirements = (string)appData["linux_requirements"]["minimum"] ?? ""; productDetail.LinuxRecommendedRequirements = (string)appData["linux_requirements"]["recommended"] ?? ""; } if (!appData["developers"].IsNullOrEmpty()) { productDetail.Developers = appData["developers"].Select(d => (string)d).ToArray(); } if (!appData["publishers"].IsNullOrEmpty()) { productDetail.Publishers = appData["publishers"].Select(d => (string)d).ToArray(); } if (!appData["demos"].IsNullOrEmpty()) { productDetail.DemoAppID = (appData["demos"][0]["appid"].IsNullOrEmpty()) ? 0 : (int)appData["demos"][0]["appid"]; productDetail.DemoRestrictions = (string)appData["demos"][0]["description"] ?? ""; } if (!appData["price_overview"].IsNullOrEmpty()) { productDetail.FinalPrice = (appData["price_overview"]["final"].IsNullOrEmpty()) ? 0 : (int)appData["price_overview"]["final"]; productDetail.InitialPrice = (appData["price_overview"]["initial"].IsNullOrEmpty()) ? 0 : (int)appData["price_overview"]["initial"]; productDetail.CurrencyType = (string)appData["price_overview"]["currency"] ?? ""; } if (!appData["packages"].IsNullOrEmpty()) { productDetail.PackageIDs = appData["packages"].Select(d => (int)d).ToArray(); } if (!appData["platforms"].IsNullOrEmpty()) { productDetail.AvailableOnPC = (appData["platforms"]["windows"].IsNullOrEmpty()) ? true : (bool)appData["platforms"]["windows"]; productDetail.AvailableOnMac = (appData["platforms"]["mac"].IsNullOrEmpty()) ? false : (bool)appData["platforms"]["mac"]; productDetail.AvailableOnLinux = (appData["platforms"]["linux"].IsNullOrEmpty()) ? false : (bool)appData["platforms"]["linux"]; } if (!appData["metacritic"].IsNullOrEmpty()) { productDetail.MetacriticScore = (appData["metacritic"]["score"].IsNullOrEmpty()) ? 0 : (int)appData["metacritic"]["score"]; productDetail.MetacriticURL = (string)appData["metacritic"]["url"] ?? ""; } if (!appData["genres"].IsNullOrEmpty()) { JArray jGenres = (JArray)appData["genres"]; List<string> genresList = new List<string>(); for (int i = 0; i < jGenres.Count; i++) { genresList.Add((string)jGenres[i]["description"]); } string[] genres = genresList.ToArray(); if (genres != null) { for (int i = 0; i < genres.Count(); i++) { if (GetTagByName(genres[i]) != null) { listing.Product.AddTag(GetTagByName(genres[i])); } else { Tag tag = new Tag(genres[i]); listing.Product.AddTag(tag); } } } productDetail.Genres = genresList.ToArray(); } if (!appData["recommendations"].IsNullOrEmpty()) { productDetail.TotalRecommendations = (appData["recommendations"]["total"].IsNullOrEmpty()) ? 0 : (int)appData["recommendations"]["total"]; } if (!appData["achievements"].IsNullOrEmpty()) { productDetail.NumAchievements = (appData["achievements"]["total"].IsNullOrEmpty()) ? 0 : (int)appData["achievements"]["total"]; } if (!appData["release_date"].IsNullOrEmpty()) { productDetail.ReleaseDate = (string)appData["release_date"]["date"] ?? ""; } // run a sub-routine to build a listing/product for the base game of this demo/DLC if (baseAppID != 0) { Listing baseGameListing = GetListingByAppID(baseAppID, "Steam"); if (baseGameListing == null) { baseGameListing = new Listing(productDetail.BaseProductName); baseGameListing.AddPlatform(GetPlatforms().Where(p => object.Equals(p.PlatformName, "Steam")).SingleOrDefault()); baseGameListing.AddProduct(new Product(baseAppID)); AddListing(baseGameListing); BuildListingWithAppID(baseGameListing, baseAppID); if (productDetail.ProductType.CompareTo("dlc") == 0) { baseGameListing.Product.ProductDetail.AddDLC(productDetail.Product); } else { productDetail.BaseProduct = baseGameListing.Product; } UpdateListing(baseGameListing); } else { if (productDetail.ProductType.CompareTo("dlc") == 0) { baseGameListing.Product.ProductDetail.AddDLC(productDetail.Product); } else { productDetail.BaseProduct = baseGameListing.Product; } } } // run a series of sub-routines to build listings/products for each DLC of this game (if applicable) if (productDetail.DLCAppIDs != null && productDetail.DLCAppIDs.Count() > 0) { for (int i = 0; i < productDetail.DLCAppIDs.Count(); i++) { Listing DLCListing = GetListingByAppID(productDetail.DLCAppIDs[i], "Steam"); if (DLCListing == null) { DLCListing = new Listing(); DLCListing.AddPlatform(GetPlatforms().Where(p => object.Equals(p.PlatformName, "Steam")).SingleOrDefault()); DLCListing.AddProduct(new Product(productDetail.DLCAppIDs[i])); AddListing(DLCListing); BuildListingWithAppID(DLCListing, productDetail.DLCAppIDs[i]); productDetail.AddDLC(DLCListing.Product); UpdateListing(DLCListing); } else { productDetail.AddDLC(DLCListing.Product); } } } if (!appData["movies"].IsNullOrEmpty()) { JArray movies = (JArray)appData["movies"]; for (int i = 0; i < movies.Count; i++) { AppMovie temp = new AppMovie(); temp.Highlight = (!movies[i]["highlight"].IsNullOrEmpty()) ? false : (bool)movies[i]["highlight"]; temp.LargeMovieURL = (string)movies[i]["webm"]["max"] ?? ""; temp.Name = (string)movies[i]["name"] ?? ""; temp.SmallMovieURL = (string)movies[i]["webm"]["480"] ?? ""; temp.ThumbnailURL = (string)movies[i]["thumbnail"] ?? ""; productDetail.AddAppMovie(temp); } } if (!appData["screenshots"].IsNullOrEmpty()) { JArray screenshots = (JArray)appData["screenshots"]; for (int i = 0; i < screenshots.Count; i++) { AppScreenshot temp = new AppScreenshot(); temp.FullSizeURL = (string)screenshots[i]["path_full"] ?? ""; temp.ThumbnailURL = (string)screenshots[i]["path_thumbnail"] ?? ""; productDetail.AddAppScreenshot(temp); } } if (!appData["categories"].IsNullOrEmpty()) { JArray jCategories = (JArray)appData["categories"]; List<string> categoriesList = new List<string>(); for (int i = 0; i < jCategories.Count; i++) { categoriesList.Add((string)jCategories[i]["description"]); } string[] categories = categoriesList.ToArray(); if (categories != null) { for (int i = 0; i < categories.Count(); i++) { if (GetProductCategoryByName(categories[i]) == null) { ProductCategory category = new ProductCategory(categories[i]); listing.Product.AddProductCategory(category); } else { listing.Product.AddProductCategory(GetProductCategoryByName(categories[i])); } } } } listing.Product.AddProductDetail(productDetail); if (String.IsNullOrEmpty(listing.Product.ProductName)) { listing.Product.ProductName = productDetail.ProductName; } if (String.IsNullOrEmpty(listing.ListingName)) { listing.ListingName = productDetail.ProductName; } }