private TitleIDs ParseproductInstance(XDocument node) { //<productInstance> is Similiar to <Entry> var retIds = new TitleIDs(); var firstOrDefault = node.Descendants(Constants.NetworkConnectivity.Namespaces.Market + "hexTitleId").FirstOrDefault(); if (firstOrDefault != null) { retIds.HextitleId = firstOrDefault.Value; } firstOrDefault = node.Descendants(Constants.NetworkConnectivity.Namespaces.Market + "productInstanceId").FirstOrDefault(); if (firstOrDefault != null) { retIds.ProductInstanceId = firstOrDefault.Value; } firstOrDefault = node.Descendants(Constants.NetworkConnectivity.Namespaces.Market + "titleId").FirstOrDefault(); if (firstOrDefault != null) { retIds.Alttitleid = firstOrDefault.Value; } //todo:Change contentId to array and retrieve all Content for product XElement previousContentId; previousContentId = null; foreach (XElement offers in node.Descendants(Constants.NetworkConnectivity.Namespaces.Market + "offerInstance")) { var contentIdElement = offers.Descendants(Constants.NetworkConnectivity.Namespaces.Market + "contentId").FirstOrDefault(); if (contentIdElement != null) { if (previousContentId?.Value != contentIdElement.Value) { var tierElement = offers.Descendants(Constants.NetworkConnectivity.Namespaces.Market + "tier").FirstOrDefault(); var priceElement = offers.Descendants(Constants.NetworkConnectivity.Namespaces.Market + "price").FirstOrDefault(); var acquirableElement = offers.Descendants(Constants.NetworkConnectivity.Namespaces.Market + "isAcquirable").FirstOrDefault(); //var priceElement = offers.Descendants(Namespaces.Market + "price").FirstOrDefault(); retIds.Offers.Add(new OfferEntry { Tier = tierElement?.Value, Price = priceElement?.Value, IsAcquirable = acquirableElement != null && (Convert.ToInt32(acquirableElement.Value) > 0), ContentId = contentIdElement.Value }); } } previousContentId = contentIdElement; } if (retIds.Offers.Count <= 0) { retIds.Offers = new List <OfferEntry> { new OfferEntry() { Reason = "NoContentID", Urlchecked = true } }; } return(retIds); }
public void InitializeUrl(bool force = false) { if (!force) { try { Download.FileCache.Load(); } catch (Exception e) { Console.WriteLine(e.ToString()); throw; } } if (!Download.FileCache.DataLoaded || !Download.FileCache.Urlchecked || force) { TitleIDs tempIDs = ParseproductInstance(DownloadCatalogueXDoc()); Download.HexTitleId = tempIDs.HextitleId; Download.AltTitleId = tempIDs.Alttitleid; Download.ProductInstanceId = tempIDs.ProductInstanceId; Download.Offers = tempIDs.Offers; } }