示例#1
0
        /// <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()}");
            }
        }