Exemplo n.º 1
0
        /// <summary>
        /// Create and format the DCat request uri based on the provided endpoint, id, id type and locale.
        /// </summary>
        /// <param name="endpoint"></param>
        /// <param name="ID"></param>
        /// <param name="IDType"></param>
        /// <param name="locale"></param>
        /// <returns></returns>
        public static Uri CreateAlternateDCatUri(DCatEndpoint endpoint, string ID, IdentiferType IDType, Services.Locale locale)
        {
            switch (IDType)
            {
            case IdentiferType.ContentID:
                return(new Uri($"{TypeHelpers.EnumToUri(endpoint)}lookup?alternateId=CONTENTID&Value={ID}&{locale.DCatTrail}&fieldsTemplate=Details"));

            case IdentiferType.LegacyWindowsPhoneProductID:
                return(new Uri($"{TypeHelpers.EnumToUri(endpoint)}lookup?alternateId=LegacyWindowsPhoneProductID&Value={ID}&{locale.DCatTrail}&fieldsTemplate=Details"));

            case IdentiferType.LegacyWindowsStoreProductID:
                return(new Uri($"{TypeHelpers.EnumToUri(endpoint)}lookup?alternateId=LegacyWindowsStoreProductID&Value={ID}&{locale.DCatTrail}&fieldsTemplate=Details"));

            case IdentiferType.LegacyXboxProductID:
                return(new Uri($"{TypeHelpers.EnumToUri(endpoint)}lookup?alternateId=LegacyXboxProductID&Value={ID}&{locale.DCatTrail}&fieldsTemplate=Details"));

            case IdentiferType.PackageFamilyName:
                return(new Uri($"{TypeHelpers.EnumToUri(endpoint)}lookup?alternateId=PackageFamilyName&Value={ID}&{locale.DCatTrail}&fieldsTemplate=Details"));

            case IdentiferType.XboxTitleID:
                return(new Uri($"{TypeHelpers.EnumToUri(endpoint)}lookup?alternateId=XboxTitleID&Value={ID}&{locale.DCatTrail}&fieldsTemplate=Details"));

            case IdentiferType.ProductID:
                return(new Uri($"{TypeHelpers.EnumToUri(endpoint)}{ID}?{locale.DCatTrail}"));

            default:
                throw new Exception("CreateAlternateDCatUri: Unknown IdentifierType was passed, an update is likely required, please report this issue.");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Queries DisplayCatalog for the provided ID. The resulting possibly found product is reflected in DisplayCatalogHandlerInstance.ProductListing. If the product isn't found, that variable will be null, check IsFound and Result.
        /// The provided Auth Token is also sent allowing for flighted or sandboxed listings. The resulting possibly found product is reflected in DisplayCatalogHandlerInstance.ProductListing. If the product isn't found, that variable will be null, check IsFound and Res
        /// </summary>
        /// <param name="ID">The ID, type specified in DCatHandler Instance.</param>
        /// <param name="IDType">Type of ID being passed.</param>
        /// <param name="AuthenticationToken"></param>
        /// <returns></returns>
        public async Task QueryDCATAsync(string ID, IdentiferType IDType = IdentiferType.ProductID, string AuthenticationToken = null) //Optional Authentication Token used for Sandbox and Flighting Queries.
        {
            this.ID             = ID;
            this.ConstructedUri = Utilities.UriHelpers.CreateAlternateDCatUri(SelectedEndpoint, ID, IDType, SelectedLocale);
            Result = new DisplayCatalogResult(); //We need to clear the result incase someone queries a product, then queries a not found one, the wrong product will be returned.
            HttpResponseMessage httpResponse = new HttpResponseMessage();
            HttpRequestMessage  httpRequestMessage;

            //We need to build the request URL based on the requested EndPoint;
            httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, ConstructedUri);

            if (!String.IsNullOrEmpty(AuthenticationToken))
            {
                httpRequestMessage.Headers.TryAddWithoutValidation("Authentication", AuthenticationToken);
            }

            try
            {
                httpResponse = await _httpClient.SendAsync(httpRequestMessage, new System.Threading.CancellationToken());
            }
            catch (TaskCanceledException)
            {
                Result = DisplayCatalogResult.TimedOut;
            }
            if (httpResponse.IsSuccessStatusCode)
            {
                string content = await httpResponse.Content.ReadAsStringAsync();

                Result         = DisplayCatalogResult.Found;
                IsFound        = true;
                ProductListing = DisplayCatalogModel.FromJson(content);
            }
            else if (httpResponse.StatusCode == System.Net.HttpStatusCode.NotFound)
            {
                Result = DisplayCatalogResult.NotFound;
            }
            else
            {
                throw new Exception($"Failed to query DisplayCatalog Endpoint: {SelectedEndpoint.ToString()} Status Code: {httpResponse.StatusCode} Returned Data: {await httpResponse.Content.ReadAsStringAsync()}");
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Get package download URLs
        /// </summary>
        /// <param name="dcatHandler">Instance of DisplayCatalogHandler</param>
        /// <param name="productId">Product Id (e.g. 9wzdncrfj3tj)</param>
        /// <returns></returns>
        public static async Task PackagesAsync(DisplayCatalogHandler dcatHandler, string id, IdentiferType type)
        {
            if (String.IsNullOrEmpty(Token))
            {
                await dcatHandler.QueryDCATAsync(id, type);
            }
            else
            {
                await dcatHandler.QueryDCATAsync(id, type, Token);
            }

            if (!dcatHandler.IsFound)
            {
                Console.WriteLine("Product not found!");
                return;
            }

            if (dcatHandler.ProductListing.Product != null) //One day ill fix the mess that is the StoreLib JSON, one day.
            {
                dcatHandler.ProductListing.Products = new List <Product>();
                dcatHandler.ProductListing.Products.Add(dcatHandler.ProductListing.Product);
            }

            var product = dcatHandler.ProductListing.Products[0];
            var props   = product.DisplaySkuAvailabilities[0].Sku.Properties;
            var header  = $"{product.LocalizedProperties[0].ProductTitle} - {product.LocalizedProperties[0].PublisherName}";


            Console.WriteLine($"Processing {header}");

            if (props.FulfillmentData == null)
            {
                Console.WriteLine("FullfilmentData empty");
                return;
            }

            var packages = await dcatHandler.GetPackagesForProductAsync();

            //iterate through all packages
            foreach (PackageInstance package in packages)
            {
                var line = await GetPrintablePackageLink(package.PackageUri, package.PackageMoniker);

                Console.WriteLine(line);
            }

            if (props.Packages.Count == 0 ||
                props.Packages[0].PackageDownloadUris == null)
            {
                Console.WriteLine("Packages.Count == 0");
            }

            foreach (var Package in props.Packages[0].PackageDownloadUris)
            {
                var line = await GetPrintablePackageLink(new Uri(Package.Uri));

                Console.WriteLine(line);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Convert the provided id to other formats
        /// </summary>
        /// <param name="id"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static async Task ConvertId(DisplayCatalogHandler dcatHandler, string id, IdentiferType type)
        {
            if (String.IsNullOrEmpty(Token))
            {
                await dcatHandler.QueryDCATAsync(id, type);
            }
            else
            {
                await dcatHandler.QueryDCATAsync(id, type, Token);
            }

            if (!dcatHandler.IsFound)
            {
                Console.WriteLine("No Product found!");
                return;
            }

            if (dcatHandler.ProductListing.Product != null) //One day ill fix the mess that is the StoreLib JSON, one day. Yeah mate just like how one day i'll learn how to fly
            {
                dcatHandler.ProductListing.Products = new List <Product>();
                dcatHandler.ProductListing.Products.Add(dcatHandler.ProductListing.Product);
            }

            var product = dcatHandler.ProductListing.Products[0];

            Console.WriteLine("App info:");
            Console.WriteLine($"{product.LocalizedProperties[0].ProductTitle} - {product.LocalizedProperties[0].PublisherName}");

            //Dynamicly add any other ID(s) that might be present rather than doing a ton of null checks.
            foreach (AlternateId PID in product.AlternateIds)
            {
                Console.WriteLine($"{PID.IdType}: {PID.Value}");
            }

            //Add the product ID
            Console.WriteLine($"ProductID: {product.ProductId}");

            try
            {
                //Add the package family name
                Console.WriteLine($"PackageFamilyName: {product.Properties.PackageFamilyName}");
            }
            catch (Exception ex) {
                Console.WriteLine($"Failed to add PFN: {ex}");
            };
        }
Exemplo n.º 5
0
        /// <summary>
        /// Query for detailed product information
        /// </summary>
        /// <param name="dcatHandler"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public static async Task AdvancedQueryAsync(DisplayCatalogHandler dcatHandler, string id, IdentiferType type)
        {
            if (String.IsNullOrEmpty(Token))
            {
                await dcatHandler.QueryDCATAsync(id, type);
            }
            else
            {
                await dcatHandler.QueryDCATAsync(id, type, Token);
            }

            if (!dcatHandler.IsFound)
            {
                Console.WriteLine("Product not found");
                return;
            }

            if (dcatHandler.ProductListing.Product != null) //One day ill fix the mess that is the StoreLib JSON, one day.
            {
                dcatHandler.ProductListing.Products = new List <Product>();
                dcatHandler.ProductListing.Products.Add(dcatHandler.ProductListing.Product);
            }

            var product = dcatHandler.ProductListing.Product;

            Console.WriteLine("App Info:");
            Console.WriteLine($"{product.LocalizedProperties[0].ProductTitle} - {product.LocalizedProperties[0].PublisherName}");
            Console.WriteLine($"Description: {product.LocalizedProperties[0].ProductDescription}");
            Console.WriteLine($"Rating: {product.MarketProperties[0].UsageData[0].AverageRating} Stars");
            Console.WriteLine($"Last Modified: {product.MarketProperties[0].OriginalReleaseDate.ToString()}");
            Console.WriteLine($"Product Type: {product.ProductType}");
            Console.WriteLine($"Is a Microsoft Listing: {product.IsMicrosoftProduct.ToString()}");
            if (product.ValidationData != null)
            {
                Console.WriteLine($"Validation Info: `{product.ValidationData.RevisionId}`");
            }
            if (product.SandboxID != null)
            {
                Console.WriteLine($"SandBoxID: {product.SandboxID}");
            }

            //Dynamicly add any other ID(s) that might be present rather than doing a ton of null checks.
            foreach (AlternateId PID in product.AlternateIds)
            {
                Console.WriteLine($"{PID.IdType}: {PID.Value}");
            }

            var skuProps = product.DisplaySkuAvailabilities[0].Sku.Properties;

            if (skuProps.FulfillmentData != null)
            {
                if (skuProps.Packages[0].KeyId != null)
                {
                    Console.WriteLine($"EAppx Key ID: {skuProps.Packages[0].KeyId}");
                }
                Console.WriteLine($"WuCategoryID: {skuProps.FulfillmentData.WuCategoryId}");
            }
        }