public async Task QueryNetflixUsingPackageFamilyName()
        {
            DisplayCatalogHandler dcathandler = new DisplayCatalogHandler(DCatEndpoint.Production, new Locale(Market.US, Lang.en, true));
            await dcathandler.QueryDCATAsync("Microsoft.SoDTest_8wekyb3d8bbwe", IdentiferType.PackageFamilyName);

            Assert.True(dcathandler.IsFound);
        }
Exemple #2
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);
            }
        }
        public async Task QueryNetflixInt()
        {
            DisplayCatalogHandler dcathandler = new DisplayCatalogHandler(DCatEndpoint.Int, new Locale(Market.US, Lang.en, true));
            await dcathandler.QueryDCATAsync("9wzdncrfj3tj");

            Assert.True(dcathandler.IsFound);
            Assert.Equal("Netflix", dcathandler.ProductListing.Product.LocalizedProperties[0].ProductTitle);
        }
        public async Task SearchXbox()
        {
            DisplayCatalogHandler dcathandler = new DisplayCatalogHandler(DCatEndpoint.Production, new Locale(Market.US, Lang.en, true));
            DCatSearch            search      = await dcathandler.SearchDCATAsync("Halo 5", DeviceFamily.Xbox);

            _output.WriteLine($"Halo 5: Guardians: Result Count: {search.TotalResultCount}");
            Assert.Equal("Halo 5: Guardians", search.Results[0].Products[0].Title);
        }
        public async Task QueryNetflixProdConfig()
        {
            DisplayCatalogHandler dcathandler = DisplayCatalogHandler.ProductionConfig();
            await dcathandler.QueryDCATAsync("9wzdncrfj3tj");

            Assert.True(dcathandler.IsFound);
            Assert.Equal("Netflix", dcathandler.ProductListing.Product.LocalizedProperties[0].ProductTitle);
        }
Exemple #6
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}");
            }
        }
        public async Task GetSuperHeroArtForNetflix()
        {
            DisplayCatalogHandler dcathandler = new DisplayCatalogHandler(DCatEndpoint.Production, new Locale(Market.US, Lang.en, true));
            await dcathandler.QueryDCATAsync("9wzdncrfj3tj");

            Assert.True(dcathandler.IsFound);
            Uri SuperHeroArt = StoreLib.Utilities.ImageHelpers.GetImageUri(ImagePurpose.SuperHeroArt, dcathandler.ProductListing);

            Assert.NotNull(SuperHeroArt);
        }
Exemple #8
0
        private static void Run(Options opts)
        {
            DisplayCatalogHandler dcatHandler = new DisplayCatalogHandler(
                opts.Environment,
                new Locale(opts.Market, opts.Language, true));

            if (!String.IsNullOrEmpty(opts.AuthToken) &&
                !opts.AuthToken.StartsWith("Token") &&
                !opts.AuthToken.StartsWith("Bearer") &&
                !opts.AuthToken.StartsWith("XBL3.0="))
            {
                Console.WriteLine("Invalid token format, ignoring...");
            }
            else if (!String.IsNullOrEmpty(opts.AuthToken))
            {
                Console.WriteLine("Setting token...");
                CommandHandler.Token = opts.AuthToken;
            }

            switch (opts.Command)
            {
            case Commands.Packages:
                Console.WriteLine("* PACKAGES");
                CommandHandler
                .PackagesAsync(dcatHandler, opts.IdOrSearchQuery, opts.IdType)
                .GetAwaiter()
                .GetResult();
                break;

            case Commands.Query:
                Console.WriteLine("* QUERY");
                CommandHandler
                .AdvancedQueryAsync(dcatHandler, opts.IdOrSearchQuery, opts.IdType)
                .GetAwaiter()
                .GetResult();
                break;

            case Commands.Search:
                Console.WriteLine("* SEARCH");
                CommandHandler
                .SearchAsync(dcatHandler, opts.IdOrSearchQuery, opts.DeviceFamily)
                .GetAwaiter()
                .GetResult();
                break;

            case Commands.Convert:
                Console.WriteLine("* CONVERT");
                CommandHandler
                .ConvertId(dcatHandler, opts.IdOrSearchQuery, opts.IdType)
                .GetAwaiter()
                .GetResult();
                break;
            }
        }
        public async Task CacheImage()
        {
            DisplayCatalogHandler dcathandler = new DisplayCatalogHandler(DCatEndpoint.Production, new Locale(Market.US, Lang.en, true));
            await dcathandler.QueryDCATAsync("9wzdncrfj3tj");

            Assert.True(dcathandler.IsFound);
            Uri SuperHeroArt = StoreLib.Utilities.ImageHelpers.GetImageUri(ImagePurpose.SuperHeroArt, dcathandler.ProductListing);

            byte[] imagetest = await Utilities.ImageHelpers.CacheImageAsync(SuperHeroArt, Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), false); //The ExecutingAssembly path is only being used for this unit test, in an actual program, you would want to save to the temp.

            Assert.NotNull(imagetest);
        }
Exemple #10
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}");
            }
        }
        public async Task RandomLocale()
        {
            Array  Markets      = Enum.GetValues(typeof(Market));
            Array  Langs        = Enum.GetValues(typeof(Lang));
            Random ran          = new Random();
            Market RandomMarket = (Market)Markets.GetValue(ran.Next(Markets.Length));
            Lang   RandomLang   = (Lang)Langs.GetValue(ran.Next(Langs.Length));

            _output.WriteLine($"RandomLocale: Testing with {RandomMarket}-{RandomLang}");
            DisplayCatalogHandler dcathandler = new DisplayCatalogHandler(DCatEndpoint.Production, new Locale(RandomMarket, RandomLang, true));
            await dcathandler.QueryDCATAsync("9wzdncrfj3tj");

            Assert.True(dcathandler.IsFound);
            Assert.Equal("Netflix", dcathandler.ProductListing.Product.LocalizedProperties[0].ProductTitle);
        }
        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;
        }
Exemple #13
0
        public async Task GetPackagesAndNamesForNetflix()
        {
            DisplayCatalogHandler displayCatalog = DisplayCatalogHandler.ProductionConfig();
            await displayCatalog.QueryDCATAsync("9wzdncrfj3tj");

            Assert.True(displayCatalog.IsFound);

            string xml = await FE3Handler.SyncUpdatesAsync(displayCatalog.ProductListing.Product.DisplaySkuAvailabilities[0].Sku.Properties.FulfillmentData.WuCategoryId);

            IList <string> RevisionIds  = new List <string>();
            IList <string> PackageNames = new List <string>();
            IList <string> UpdateIDs    = new List <string>();

            FE3Handler.ProcessUpdateIDs(xml, out RevisionIds, out PackageNames, out UpdateIDs);
            IList <Uri> FileUris = await FE3Handler.GetFileUrlsAsync(UpdateIDs, RevisionIds);
        }
Exemple #14
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}");
            };
        }
Exemple #15
0
        public async Task <string> Get(
            /*Mandatory get parameter*/ string query,
            /*Mandatory get parameter*/ string family,
            string Environment = "Production",
            string Market      = "US",
            string Lang        = "en",
            string Msatoken    = null)
        {
            Search searchrequest = new Search()
            {
                query        = query,
                devicefamily = (DeviceFamily)Enum.Parse(typeof(DeviceFamily), family, true),
                environment  = (DCatEndpoint)Enum.Parse(typeof(DCatEndpoint), Environment, true),
                lang         = (Lang)Enum.Parse(typeof(Lang), Lang, true),
                market       = (Market)Enum.Parse(typeof(Market), Market, true),
                msatoken     = Msatoken
            };
            DisplayCatalogHandler dcat = new DisplayCatalogHandler(searchrequest.environment, new Locale(searchrequest.market, searchrequest.lang, true));

            /* if the dcat search eventually takes an msa token
             * if (!string.IsNullOrWhiteSpace(searchrequest.msatoken))
             * {
             *  await dcat.SearchDCATAsync()
             * }
             * else
             * {
             *  await dcat.QueryDCATAsync(packagerequest.id, packagerequest.type);
             * }
             */
            List <Results> searchresults = new List <Results>();
            DCatSearch     result        = await dcat.SearchDCATAsync(searchrequest.query, searchrequest.devicefamily);

            foreach (Result res in result.Results)
            {
                foreach (Product prod in res.Products)
                {
                    searchresults.Add(new Results()
                    {
                        title     = prod.Title,
                        type      = prod.Type,
                        productid = prod.ProductId
                    });
                }
            }
            return(JsonConvert.SerializeObject(searchresults));
        }
        private async void InstallButton_Click(SplitButton sender, SplitButtonClickEventArgs 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.GetMainPackagesForProductAsync();

            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);
                }
            }

            InstallButton.IsEnabled = true;
        }
Exemple #17
0
        static async Task Main(string[] args)
        {
            Console.WriteLine($"StoreBot - {System.Reflection.Assembly.GetExecutingAssembly().GetName().Version}");
            Console.WriteLine("Connecting to Discord services....");
            DiscordSocketClient client = new DiscordSocketClient();

            settingsinstance = new Settings();
            await client.LoginAsync(TokenType.Bot, settingsinstance.AuthToken);

            await client.StartAsync();

            client.MessageReceived += MessageReceived;
            Console.WriteLine($"Connected to Discord services");
            await Utilities.Log($"Logged into Discord at {System.DateTime.Now}");

            await client.SetGameAsync("DisplayCatalog", null, ActivityType.Watching);

            dcat = new DisplayCatalogHandler(DCatEndpoint.Production, new Locale(Market.US, Lang.en, true));
            await Task.Delay(-1);
        }
Exemple #18
0
        public async Task GetPackagesForNetflix()
        {
            DisplayCatalogHandler displayCatalog = new DisplayCatalogHandler(DCatEndpoint.Production, new Locale(Market.US, Lang.en, true));
            await displayCatalog.QueryDCATAsync("9wzdncrfj3tj");

            Assert.True(displayCatalog.IsFound);

            string xml = await FE3Handler.SyncUpdatesAsync(displayCatalog.ProductListing.Product.DisplaySkuAvailabilities[0].Sku.Properties.FulfillmentData.WuCategoryId);

            IList <string> RevisionIds  = new List <string>();
            IList <string> PackageNames = new List <string>();
            IList <string> UpdateIDs    = new List <string>();

            FE3Handler.ProcessUpdateIDs(xml, out RevisionIds, out PackageNames, out UpdateIDs);
            IList <Uri> FileUris = await FE3Handler.GetFileUrlsAsync(UpdateIDs, RevisionIds);

            foreach (Uri fileuri in FileUris)
            {
                _output.WriteLine($"GetPackagesForNetflix: {fileuri}");
            }
        }
Exemple #19
0
        /// <summary>
        /// Enumerate content via search query
        /// </summary>
        /// <param name="dcatHandler"></param>
        /// <param name="query"></param>
        /// <param name="deviceFamily"></param>
        /// <returns></returns>
        public static async Task SearchAsync(DisplayCatalogHandler dcatHandler, string query, DeviceFamily deviceFamily)
        {
            try
            {
                DCatSearch results = await dcatHandler.SearchDCATAsync(query, deviceFamily);

                Console.WriteLine($"Search results (Count: {results.TotalResultCount}, Family: {deviceFamily})");

                foreach (Result res in results.Results)
                {
                    foreach (Product prod in res.Products)
                    {
                        Console.WriteLine($"{prod.Title} {prod.Type}: {prod.ProductId}");
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Exception while executing SearchAsync: {ex.Message}");
            }
        }
        public async Task <string> Get(
            /*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);
            }
            if (dcat.IsFound)
            {
                if (dcat.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
                {
                    dcat.ProductListing.Products = new List <Product>();
                    dcat.ProductListing.Products.Add(dcat.ProductListing.Product);
                }
                List <AlternateAppIDs> appinfo = new List <AlternateAppIDs>();
                foreach (AlternateId PID in dcat.ProductListing.Products[0].AlternateIds) //Dynamicly add any other ID(s) that might be present rather than doing a ton of null checks.
                {
                    appinfo.Add(new AlternateAppIDs()
                    {
                        IDType = PID.IdType,
                        Value  = PID.Value
                    });
                }
                appinfo.Add(new AlternateAppIDs()
                {
                    IDType = "ProductID",
                    Value  = dcat.ProductListing.Products[0].ProductId
                });
                try
                {
                    appinfo.Add(new AlternateAppIDs()
                    {
                        IDType = "PackageFamilyName",
                        Value  = dcat.ProductListing.Products[0].Properties.PackageFamilyName
                    });
                }
                catch (Exception ex) { Console.WriteLine(ex); };
                return(JsonConvert.SerializeObject(appinfo));
            }
            else
            {
                return("{\"error\":\"dcat not found\"}");
            }
        }
Exemple #21
0
        static async Task MessageReceived(SocketMessage message)
        {
            if (message.Content.StartsWith("$"))
            {
#if DEBUG
                await message.Channel.SendMessageAsync($"StoreBot is running in DEBUG mode. Output will be verbose.");
#endif
                switch (message.Content)
                {
                case "$DEV":
                    dcat = new DisplayCatalogHandler(DCatEndpoint.Dev, new Locale(Market.US, Lang.en, true));
                    await message.Channel.SendMessageAsync($"DCAT Endpoint was changed to {message.Content}");

                    break;

                case "$INT":
                    dcat = new DisplayCatalogHandler(DCatEndpoint.Int, new Locale(Market.US, Lang.en, true));
                    await message.Channel.SendMessageAsync($"DCAT Endpoint was changed to {message.Content}");

                    break;

                case "$PROD":
                    dcat = new DisplayCatalogHandler(DCatEndpoint.Production, new Locale(Market.US, Lang.en, true));
                    await message.Channel.SendMessageAsync($"DCAT Endpoint was changed to {message.Content}");

                    break;

                case "$XBOX":
                    dcat = new DisplayCatalogHandler(DCatEndpoint.Xbox, new Locale(Market.US, Lang.en, true));
                    await message.Channel.SendMessageAsync($"DCAT Endpoint was changed to {message.Content}");

                    break;
                }
                if (message.Content.Length != 13)
                {
                    return;
                }
                string ProductID = message.Content.Substring(1, 12);
                await dcat.QueryDCATAsync(ProductID);

                if (dcat.IsFound)
                {
                    await message.Channel.SendMessageAsync("Working....");
                    await BuildReply(dcat.ProductListing, message);
                }
                else
                {
                    await message.Channel.SendMessageAsync("No Product was Found.");
                }
            }
            else if (message.Content.StartsWith("*X")) //Search with Xbox Device Family
            {
                DisplayCatalogHandler dcathandler   = DisplayCatalogHandler.ProductionConfig();
                DCatSearch            SearchResults = await dcathandler.SearchDCATAsync(message.Content.Substring(2), DeviceFamily.Universal);

                int count = 0;
                foreach (Result R in SearchResults.Results)
                {
                    while (settingsinstance.NumberOfSearchResults >= count)
                    {
                        await message.Channel.SendMessageAsync(R.Products[0].Title);

                        count++;
                    }
                }
            }
            else if (message.Content.StartsWith("*D")) //Search with Desktop Device Family
            {
                DisplayCatalogHandler dcathandler   = DisplayCatalogHandler.ProductionConfig();
                DCatSearch            SearchResults = await dcathandler.SearchDCATAsync(message.Content.Substring(2), DeviceFamily.Desktop);

                int count = 0;
                foreach (Result R in SearchResults.Results)
                {
                    while (settingsinstance.NumberOfSearchResults >= count)
                    {
                        await message.Channel.SendMessageAsync(R.Products[0].Title);

                        count++;
                    }
                }
            }
        }
Exemple #22
0
        public async Task <string> Get(/*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);
            }
            Dictionary <string, string> productinfo = new Dictionary <string, string>();

            if (dcat.IsFound)
            {
                if (dcat.ProductListing.Product != null) //One day ill fix the mess that is the StoreLib JSON, one day.
                {
                    dcat.ProductListing.Products = new List <Product>();
                    dcat.ProductListing.Products.Add(dcat.ProductListing.Product);
                }
                if (dcat.ProductListing.Product.LocalizedProperties[0].ProductDescription.Length < 1023)
                {
                    productinfo.Add("Description:", dcat.ProductListing.Product.LocalizedProperties[0].ProductDescription);
                }
                else
                {
                    productinfo.Add("Description", dcat.ProductListing.Product.LocalizedProperties[0].ProductDescription.Substring(0, 1023));
                }
                productinfo.Add("Rating", $"{dcat.ProductListing.Product.MarketProperties[0].UsageData[0].AverageRating}");
                productinfo.Add("Last Modified", dcat.ProductListing.Product.MarketProperties[0].OriginalReleaseDate.ToString());
                productinfo.Add("Product Type", dcat.ProductListing.Product.ProductType);
                productinfo.Add("Is a Microsoft Listing", dcat.ProductListing.Product.IsMicrosoftProduct.ToString());
                if (dcat.ProductListing.Product.ValidationData != null)
                {
                    productinfo.Add("Validation Info", $"`{dcat.ProductListing.Product.ValidationData.RevisionId}`");
                }
                if (dcat.ProductListing.Product.SandboxID != null)
                {
                    productinfo.Add("SandBoxID", dcat.ProductListing.Product.SandboxID);
                }
                foreach (AlternateId PID in dcat.ProductListing.Product.AlternateIds) //Dynamicly add any other ID(s) that might be present rather than doing a ton of null checks.
                {
                    productinfo.Add($"{PID.IdType}", PID.Value);
                }
                if (dcat.ProductListing.Product.DisplaySkuAvailabilities[0].Sku.Properties.FulfillmentData != null)
                {
                    if (dcat.ProductListing.Product.DisplaySkuAvailabilities[0].Sku.Properties.Packages[0].KeyId != null)
                    {
                        productinfo.Add("EAppx Key ID", dcat.ProductListing.Product.DisplaySkuAvailabilities[0].Sku.Properties.Packages[0].KeyId);
                    }
                    productinfo.Add("WuCategoryID", dcat.ProductListing.Product.DisplaySkuAvailabilities[0].Sku.Properties.FulfillmentData.WuCategoryId);
                }
            }
            return(JsonConvert.SerializeObject(productinfo));
        }
        private async void Download_Click(object sender, RoutedEventArgs e)
        {
            InstallButton.IsEnabled = false;

            var gettingPackagesDialog = new ProgressDialog()
            {
                Title = ViewModel.Product.Title,
                Body  = "Fetching packages..."
            };
            await PackageHelper.DownloadPackage(ViewModel.Product,
                                                gettingPackagesCallback : product =>
            {
                gettingPackagesDialog.ShowAsync();
            },
                                                noPackagesCallback : async product =>
            {
                var noPackagesDialog = new ContentDialog()
                {
                    Title             = product.Title,
                    Content           = "No available packages for this product.",
                    PrimaryButtonText = "Ok"
                };
                await noPackagesDialog.ShowAsync();
            },
                                                packagesLoadedCallback : product =>
            {
                gettingPackagesDialog.Hide();
            },
                                                packageDownloadedCallback : async(product, details, file, toast) =>
            {
                var savePicker = new Windows.Storage.Pickers.FileSavePicker();
                savePicker.SuggestedStartLocation =
                    Windows.Storage.Pickers.PickerLocationId.Downloads;
                if (file.FileType.EndsWith("bundle"))
                {
                    savePicker.FileTypeChoices.Add("Windows App Bundle", new string[] { file.FileType });
                }
                else
                {
                    savePicker.FileTypeChoices.Add("Windows App Package", new string[] { file.FileType });
                }
                savePicker.SuggestedFileName = file.DisplayName;
                savePicker.SuggestedSaveFile = file;
                var userFile = await savePicker.PickSaveFileAsync();
                if (userFile != null)
                {
                    await file.MoveAndReplaceAsync(userFile);
                }
            });

            InstallButton.IsEnabled = true;
            return;

            var    culture   = CultureInfo.CurrentUICulture;
            string productId = ViewModel.Product.ProductId;



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

            var packs = await dcathandler.GetMainPackagesForProductAsync();

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

            gettingPackagesDialog.Hide();
            if (packs != null)// && packs.Count > 0)
            {
                var package = PackageHelper.GetLatestDesktopPackage(packs.ToList(), packageFamilyName, ViewModel.Product);
                if (package == null)
                {
                    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;
        }
        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 #25
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());
        }