Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
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));
        }
Exemplo n.º 3
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}");
            }
        }
Exemplo n.º 4
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++;
                    }
                }
            }
        }