Exemple #1
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);
            }
        }
Exemple #2
0
        public async Task GetPackageInstancesForNetflix()
        {
            DisplayCatalogHandler handler = DisplayCatalogHandler.ProductionConfig();
            await handler.QueryDCATAsync("9wzdncrfj3tj");

            Debug.WriteLine("Running GetPackageInstancesForNetflix");
            string WUID             = "d8d75bb2-c5cd-44f2-8c26-c1d1ae5b13fa";
            var    packageinstances = await handler.GetPackagesForProductAsync();

            foreach (var item in packageinstances)
            {
                Debug.WriteLine($"{item.PackageMoniker} : {item.PackageType} : {item.PackageUri}");
            }
        }
        private async void Download_Click(object sender, RoutedEventArgs e)
        {
            InstallButton.IsEnabled = false;
            var    culture   = CultureInfo.CurrentUICulture;
            string productId = ViewModel.Product.ProductId;

            var dialog = new ProgressDialog()
            {
                Title = ViewModel.Product.Title,
                Body  = "Fetching packages..."
            };

            dialog.ShowAsync();

            DisplayCatalogHandler dcathandler = new DisplayCatalogHandler(DCatEndpoint.Production, new Locale(culture, true));
            await dcathandler.QueryDCATAsync(productId);

            var packs = await dcathandler.GetPackagesForProductAsync();

            string packageFamilyName = dcathandler.ProductListing.Product.Properties.PackageFamilyName;

            dialog.Hide();
            if (packs != null)// && packs.Count > 0)
            {
                var package = PackageHelper.GetLatestDesktopPackage(packs.ToList(), packageFamilyName, ViewModel.Product);
                if (package == null)
                {
                    var noPackagesDialog = new ContentDialog()
                    {
                        Title             = ViewModel.Product.Title,
                        Content           = "No available packages for this product.",
                        PrimaryButtonText = "Ok"
                    };
                    await noPackagesDialog.ShowAsync();

                    return;
                }
                else
                {
                    var file = (await PackageHelper.DownloadPackage(package, ViewModel.Product)).Item1;

                    var toast = PackageHelper.GenerateDownloadSuccessToast(package, ViewModel.Product, file);
                    Windows.UI.Notifications.ToastNotificationManager.GetDefault().CreateToastNotifier().Show(toast);
                }
            }

            InstallButton.IsEnabled = true;
        }
        private async void InstallUsingAppInstaller_Click(object sender, RoutedEventArgs e)
        {
            InstallButton.IsEnabled = false;
            var    culture   = CultureInfo.CurrentUICulture;
            string productId = ViewModel.Product.ProductId;

            var dialog = new ProgressDialog()
            {
                Title = ViewModel.Product.Title,
                Body  = "Fetching packages..."
            };

            dialog.ShowAsync();

            DisplayCatalogHandler dcathandler = new DisplayCatalogHandler(DCatEndpoint.Production, new Locale(Market.US, Lang.en, true));
            await dcathandler.QueryDCATAsync(productId);

            var packs = await dcathandler.GetPackagesForProductAsync();

            string packageFamilyName = dcathandler.ProductListing.Product.Properties.PackageFamilyName;

            dialog.Hide();
            if (packs != null)// && packs.Count > 0)
            {
                var package = PackageHelper.GetLatestDesktopPackage(packs.ToList(), packageFamilyName, ViewModel.Product);
                if (package == null)
                {
                    var noPackagesDialog = new ContentDialog()
                    {
                        Title             = ViewModel.Product.Title,
                        Content           = "No available packages for this product.",
                        PrimaryButtonText = "Ok"
                    };
                    await noPackagesDialog.ShowAsync();

                    return;
                }
                else
                {
                    await PackageHelper.InstallPackage(package, ViewModel.Product, true);
                }
            }

            InstallButton.IsEnabled = true;
        }
        public async Task <string> GetPackages(
            /*Mandatory get parameter*/ string Id,
            string Idtype      = "url",
            string Environment = "Production",
            string Market      = "US",
            string Lang        = "en",
            string Msatoken    = null)
        {
            Packages packagerequest = new Packages()
            {
                id          = Id,
                environment = (DCatEndpoint)Enum.Parse(typeof(DCatEndpoint), Environment),
                lang        = (Lang)Enum.Parse(typeof(Lang), Lang),
                market      = (Market)Enum.Parse(typeof(Market), Market),
                msatoken    = Msatoken
            };

            switch (Idtype)
            {
            case "url":
                packagerequest.id   = new Regex(@"[a-zA-Z0-9]{12}").Matches(packagerequest.id)[0].Value;
                packagerequest.type = IdentiferType.ProductID;
                break;

            case "productid":
                packagerequest.type = IdentiferType.ProductID;
                break;

            case "pfn":
                packagerequest.type = IdentiferType.PackageFamilyName;
                break;

            case "cid":
                packagerequest.type = IdentiferType.ContentID;
                break;

            case "xti":
                packagerequest.type = IdentiferType.XboxTitleID;
                break;

            case "lxpi":
                packagerequest.type = IdentiferType.LegacyXboxProductID;
                break;

            case "lwspi":
                packagerequest.type = IdentiferType.LegacyWindowsStoreProductID;
                break;

            case "lwppi":
                packagerequest.type = IdentiferType.LegacyWindowsPhoneProductID;
                break;

            default:
                packagerequest.type = (IdentiferType)Enum.Parse(typeof(IdentiferType), Idtype);
                break;
            }
            DisplayCatalogHandler dcat = new DisplayCatalogHandler(packagerequest.environment, new Locale(packagerequest.market, packagerequest.lang, true));

            if (!string.IsNullOrWhiteSpace(packagerequest.msatoken))
            {
                await dcat.QueryDCATAsync(packagerequest.id, packagerequest.type, packagerequest.msatoken);
            }
            else
            {
                await dcat.QueryDCATAsync(packagerequest.id, packagerequest.type);
            }
            List <PackageInfo> packages = new List <PackageInfo>();
            var productpackages         = await dcat.GetPackagesForProductAsync();

            //iterate through all packages
            foreach (PackageInstance package in productpackages)
            {
                var temppackageinfo = new PackageInfo()
                {
                    packagedownloadurl = package.PackageUri.ToString(),
                    packagemoniker     = package.PackageMoniker
                };
                HttpRequestMessage httpRequest = new HttpRequestMessage();
                httpRequest.RequestUri = package.PackageUri;
                //httpRequest.Method = HttpMethod.Get;
                httpRequest.Method = HttpMethod.Head;
                httpRequest.Headers.Add("Connection", "Keep-Alive");
                httpRequest.Headers.Add("Accept", "*/*");
                //httpRequest.Headers.Add("Range", "bytes=0-1");
                httpRequest.Headers.Add("User-Agent", "Microsoft-Delivery-Optimization/10.0");
                HttpResponseMessage httpResponse = await _httpClient.SendAsync(httpRequest, new System.Threading.CancellationToken());

                HttpHeaders          headers = httpResponse.Content.Headers;
                IEnumerable <string> values;
                if (headers.TryGetValues("Content-Disposition", out values))
                {
                    ContentDisposition contentDisposition = new ContentDisposition(values.First());
                    temppackageinfo.packagefilename = contentDisposition.FileName;
                }
                if (headers.TryGetValues("Content-Length", out values))
                {
                    temppackageinfo.packagefilesize = Convert.ToInt64(values.FirstOrDefault());
                }
                packages.Add(temppackageinfo);
            }
            if (!object.ReferenceEquals(dcat.ProductListing.Product.DisplaySkuAvailabilities[0].Sku.Properties.Packages[0].PackageDownloadUris, null))
            {
                foreach (var Package in dcat.ProductListing.Product.DisplaySkuAvailabilities[0].Sku.Properties.Packages[0].PackageDownloadUris)
                {
                    Uri         PackageURL      = new Uri(Package.Uri);
                    PackageInfo temppackageinfo = new PackageInfo()
                    {
                        packagedownloadurl = Package.Uri,
                        packagemoniker     = PackageURL.Segments[PackageURL.Segments.Length - 1],
                        packagefilename    = PackageURL.Segments[PackageURL.Segments.Length - 1]
                    };
                    HttpRequestMessage httpRequest = new HttpRequestMessage();
                    httpRequest.RequestUri = PackageURL;
                    //httpRequest.Method = HttpMethod.Get;
                    httpRequest.Method = HttpMethod.Head;
                    httpRequest.Headers.Add("Connection", "Keep-Alive");
                    httpRequest.Headers.Add("Accept", "*/*");
                    //httpRequest.Headers.Add("Range", "bytes=0-1");
                    httpRequest.Headers.Add("User-Agent", "Microsoft-Delivery-Optimization/10.0");
                    HttpResponseMessage httpResponse = await _httpClient.SendAsync(httpRequest, new System.Threading.CancellationToken());

                    HttpHeaders          headers = httpResponse.Content.Headers;
                    IEnumerable <string> values;
                    if (headers.TryGetValues("Content-Length", out values))
                    {
                        System.Diagnostics.Debug.WriteLine(values.FirstOrDefault());
                        temppackageinfo.packagefilesize = Convert.ToInt64(values.FirstOrDefault());
                    }
                    packages.Add(temppackageinfo);
                }
            }
            return(JsonConvert.SerializeObject(packages));
        }
Exemple #6
0
        private static async Task BuildReply(DisplayCatalogModel displayCatalogModel, SocketMessage message)
        {
            StringBuilder MoreDetailsHelper = new StringBuilder();
            await Utilities.Log($"{message.Content.Substring(1, 12)} - {displayCatalogModel.Product.LocalizedProperties[0].ProductTitle} was queried by {message.Author.Username}#{message.Author.Id} at {message.Channel.Name}");

            MoreDetailsHelper.AppendLine($"`{displayCatalogModel.Product.LocalizedProperties[0].ProductTitle} - {displayCatalogModel.Product.LocalizedProperties[0].PublisherName}");
            MoreDetailsHelper.AppendLine($"Rating: {displayCatalogModel.Product.MarketProperties[0].UsageData[0].AverageRating} Stars");
            MoreDetailsHelper.AppendLine($"Last Modified: {displayCatalogModel.Product.LastModifiedDate}");
            MoreDetailsHelper.AppendLine($"Original Release: {displayCatalogModel.Product.MarketProperties[0].OriginalReleaseDate}");
            MoreDetailsHelper.AppendLine($"Product Type: {displayCatalogModel.Product.ProductType}");
            MoreDetailsHelper.AppendLine($"Is a Microsoft Listing: {displayCatalogModel.Product.IsMicrosoftProduct}");
            if (displayCatalogModel.Product.ValidationData != null)
            {
                MoreDetailsHelper.AppendLine($"Validation Info: {displayCatalogModel.Product.ValidationData.RevisionId}");
            }
            if (displayCatalogModel.Product.SandboxID != null)
            {
                MoreDetailsHelper.AppendLine($"SandBoxID: {displayCatalogModel.Product.SandboxID}");
            }

            foreach (AlternateId ID in displayCatalogModel.Product.AlternateIds) //Dynamicly add any other ID(s) that might be present rather than doing a ton of null checks.
            {
                MoreDetailsHelper.AppendLine($"{ID.IdType}: {ID.Value}");
            }
            if (displayCatalogModel.Product.DisplaySkuAvailabilities[0].Sku.Properties.FulfillmentData != null)
            {
                MoreDetailsHelper.AppendLine($"WuCategoryID: {displayCatalogModel.Product.DisplaySkuAvailabilities[0].Sku.Properties.FulfillmentData.WuCategoryId}");
                MoreDetailsHelper.AppendLine($"EAppx Key ID: {displayCatalogModel.Product.DisplaySkuAvailabilities[0].Sku.Properties.Packages[0].KeyId}");
            }
            MoreDetailsHelper.AppendLine("`");
            IList <PackageInstance> packageInstances = await dcat.GetPackagesForProductAsync();

#if DEBUG
            await message.Channel.SendMessageAsync($"Found {packageInstances.Count} packages.");
#endif
            MoreDetailsHelper.AppendLine($"Packages: (1/3)\n");
            await message.Channel.SendMessageAsync(MoreDetailsHelper.ToString());

            StringBuilder packages    = new StringBuilder();
            List <string> packagelist = new List <string>(Regex.Split(packages.ToString(), @"(?<=\G.{1999})", RegexOptions.Singleline));

            /*
             * if (displayCatalogModel.Product.DisplaySkuAvailabilities[0].Sku.Properties.Packages.Count > 0)
             * {
             *  Debug.WriteLine(displayCatalogModel.Product.DisplaySkuAvailabilities[0].Sku.Properties.Packages.Count);
             *  try
             *  {
             *      foreach (var Package in displayCatalogModel.Product.DisplaySkuAvailabilities[0].Sku.Properties.Packages[0].PackageDownloadUris)
             *      {
             *          packages.AppendLine($"Xbox Live Package: {Package.Uri}");
             *      }
             *  }
             *  catch { }
             * }
             */
            /*
             *
             */
            packages.AppendLine($"(2/3)");
            await message.Channel.SendMessageAsync(packages.ToString());

            foreach (PackageInstance package in packageInstances)
            {
                try
                {
                    await message.Channel.SendMessageAsync($"{package.PackageMoniker} : {package.PackageType} : {package.PackageUri}");
                }
                catch { }
            }

            await message.Channel.SendMessageAsync("(3/3)");
        }
Exemple #7
0
        public static async Task <string> QueryProduct(string ProductID, DCatEndpoint DCatEndpoint)
        {
            DisplayCatalogHandler dcat = new DisplayCatalogHandler(DCatEndpoint, new Locale(Market.US, Lang.en, true));
            await dcat.QueryDCATAsync(ProductID);

            if (!dcat.IsFound)
            {
                return("");
            }
            StringBuilder MoreDetailsHelper = new StringBuilder();

            MoreDetailsHelper.AppendLine($"`{dcat.ProductListing.Product.LocalizedProperties[0].ProductTitle} - {dcat.ProductListing.Product.LocalizedProperties[0].PublisherName}");
            MoreDetailsHelper.AppendLine($"Rating: {dcat.ProductListing.Product.MarketProperties[0].UsageData[0].AverageRating} Stars");
            MoreDetailsHelper.AppendLine($"Last Modified: {dcat.ProductListing.Product.LastModifiedDate}");
            MoreDetailsHelper.AppendLine($"Original Release: {dcat.ProductListing.Product.MarketProperties[0].OriginalReleaseDate}");
            MoreDetailsHelper.AppendLine($"Product Type: {dcat.ProductListing.Product.ProductType}");
            MoreDetailsHelper.AppendLine($"Is a Microsoft Listing: {dcat.ProductListing.Product.IsMicrosoftProduct}");
            if (dcat.ProductListing.Product.ValidationData != null)
            {
                MoreDetailsHelper.AppendLine($"Validation Info: {dcat.ProductListing.Product.ValidationData.RevisionId}");
            }
            if (dcat.ProductListing.Product.SandboxID != null)
            {
                MoreDetailsHelper.AppendLine($"SandboxID: {dcat.ProductListing.Product.SandboxID}");
            }

            foreach (AlternateId ID in dcat.ProductListing.Product.AlternateIds) //Dynamically add any other ID(s) that might be present rather than doing a ton of null checks.
            {
                MoreDetailsHelper.AppendLine($"{ID.IdType}: {ID.Value}");
            }
            if (dcat.ProductListing.Product.DisplaySkuAvailabilities[0].Sku.Properties.FulfillmentData != null)
            {
                MoreDetailsHelper.AppendLine($"WuCategoryID: {dcat.ProductListing.Product.DisplaySkuAvailabilities[0].Sku.Properties.FulfillmentData.WuCategoryId}");
                MoreDetailsHelper.AppendLine($"EAppx Key ID: {dcat.ProductListing.Product.DisplaySkuAvailabilities[0].Sku.Properties.Packages[0].KeyId}");
            }
            MoreDetailsHelper.AppendLine("`");
            IList <PackageInstance> packageInstances = await dcat.GetPackagesForProductAsync();

            StringBuilder packages = new StringBuilder();

            if (dcat.ProductListing.Product.DisplaySkuAvailabilities[0].Sku.Properties.Packages.Count > 0)
            {
                if (dcat.ProductListing.Product.DisplaySkuAvailabilities[0].Sku.Properties.Packages.Count != 0)
                {
                    //For some weird reason, some listings report having packages when really they don't have one hosted. This checks the child to see if the package is really null or not.
                    if (!object.ReferenceEquals(dcat.ProductListing.Product.DisplaySkuAvailabilities[0].Sku.Properties.Packages[0].PackageDownloadUris, null))
                    {
                        foreach (var Package in dcat.ProductListing.Product.DisplaySkuAvailabilities[0].Sku.Properties.Packages[0].PackageDownloadUris)
                        {
                            packages.AppendLine($"Xbox Live Package: {Package.Uri}");
                        }
                    }
                }
            }
            StringBuilder fe3packages = new StringBuilder();

            foreach (PackageInstance package in packageInstances)
            {
                try
                {
                    fe3packages.AppendLine($"{package.PackageMoniker} : {package.PackageType} : {package.PackageUri}");
                }
                catch { }
            }
            return(MoreDetailsHelper.ToString() + "#" + packages.ToString() + "#" + fe3packages.ToString());
        }