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 <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)); }
/// <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}"); } }
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++; } } } }
/// <summary> /// /// </summary> /// <param name="Query">The raw search query</param> /// <param name="DeviceFamily">The wanted DeviceFamily, only supported apps/games will be returned</param> /// <param name="SkipCount">The number of results to skip, only 100 products will be returned at once. A skip count of 100 will return products starting with the 101st result.</param> /// <returns></returns> public async Task <DCatSearch> SearchDCATAsync(string Query, DeviceFamily DeviceFamily, int SkipCount) { HttpResponseMessage httpResponse = new HttpResponseMessage(); HttpRequestMessage httpRequestMessage; switch (DeviceFamily) { case DeviceFamily.Desktop: httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, $"{Utilities.TypeHelpers.EnumToSearchUri(SelectedEndpoint)}{Query}&productFamilyNames=apps,games&platformDependencyName=Windows.Desktop"); httpResponse = await _httpClient.SendAsync(httpRequestMessage, new System.Threading.CancellationToken()); break; case DeviceFamily.Xbox: httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, $"{Utilities.TypeHelpers.EnumToSearchUri(SelectedEndpoint)}{Query}&productFamilyNames=apps,games&platformDependencyName=Windows.Xbox"); httpResponse = await _httpClient.SendAsync(httpRequestMessage, new System.Threading.CancellationToken()); break; case DeviceFamily.Universal: httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, $"{Utilities.TypeHelpers.EnumToSearchUri(SelectedEndpoint)}{Query}&productFamilyNames=apps,games&platformDependencyName=Windows.Universal"); httpResponse = await _httpClient.SendAsync(httpRequestMessage, new System.Threading.CancellationToken()); break; case DeviceFamily.Mobile: httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, $"{Utilities.TypeHelpers.EnumToSearchUri(SelectedEndpoint)}{Query}&productFamilyNames=apps,games&platformDependencyName=Windows.Mobile"); httpResponse = await _httpClient.SendAsync(httpRequestMessage, new System.Threading.CancellationToken()); break; case DeviceFamily.HoloLens: httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, $"{Utilities.TypeHelpers.EnumToSearchUri(SelectedEndpoint)}{Query}&productFamilyNames=apps,games&platformDependencyName=Windows.Holographic"); httpResponse = await _httpClient.SendAsync(httpRequestMessage, new System.Threading.CancellationToken()); break; case DeviceFamily.IotCore: httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, $"{Utilities.TypeHelpers.EnumToSearchUri(SelectedEndpoint)}{Query}&productFamilyNames=apps,games&platformDependencyName=Windows.Iot"); httpResponse = await _httpClient.SendAsync(httpRequestMessage, new System.Threading.CancellationToken()); break; case DeviceFamily.ServerCore: httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, $"{Utilities.TypeHelpers.EnumToSearchUri(SelectedEndpoint)}{Query}&productFamilyNames=apps,games&platformDependencyName=Windows.Server"); httpResponse = await _httpClient.SendAsync(httpRequestMessage, new System.Threading.CancellationToken()); break; case DeviceFamily.Andromeda: httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, $"{Utilities.TypeHelpers.EnumToSearchUri(SelectedEndpoint)}{Query}&productFamilyNames=apps,games&platformDependencyName=Windows.8828080"); httpResponse = await _httpClient.SendAsync(httpRequestMessage, new System.Threading.CancellationToken()); break; } if (httpResponse.IsSuccessStatusCode) { string content = await httpResponse.Content.ReadAsStringAsync(); Result = DisplayCatalogResult.Found; DCatSearch dcatSearch = DCatSearch.FromJson(content); return(dcatSearch); } else { throw new Exception($"Failed to search DisplayCatalog: {DeviceFamily.ToString()} Status Code: {httpResponse.StatusCode} Returned Data: {await httpResponse.Content.ReadAsStringAsync()}"); } }