Esempio n. 1
0
        public static async Task <Model.SearchCollection> GetSearch(string keyword, uint start = 0)
        {
            string url = string.Format("search/subject/{0}?max_results=25&start={1}&type=2", keyword, start);

            using (HttpResponseMessage response = await APIclient.GetAsync(Uri.EscapeUriString(url)))
            {
                try
                {
                    response.EnsureSuccessStatusCode();
                    string response_body = await response.Content.ReadAsStringAsync();

                    Model.SearchCollection search_collection = JsonConvert.DeserializeObject <Model.SearchCollection>(response_body);
                    return(search_collection);
                }
                catch (HttpRequestException http_exception)
                {
                    if (response.StatusCode == HttpStatusCode.NotFound)
                    {
                        throw new WebException(http_exception.Message);
                    }
                    else
                    {
                        throw new AuthorizationException(response.StatusCode.ToString());
                    }
                }
                catch (WebException)
                {
                    throw;
                }
                catch (JsonReaderException json_reader_exception)
                {
                    throw new EmptySearchException(json_reader_exception.Message);
                }
            }
        }
Esempio n. 2
0
 private async void SearchButtonClick(object sender, RoutedEventArgs e)
 {
     subject_list = new List <Model.Collection>();
     Model.SearchCollection search_collection = new Model.SearchCollection();
     try
     {
         search_collection = await Retry.Do(() => ApiHelper.GetSearch(KeywordTextBox.Text), TimeSpan.FromSeconds(3));
     }
     catch (WebException web_exception)
     {
         Console.WriteLine(web_exception.Message);
     }
     catch (AuthorizationException authorization_exception)
     {
         Console.WriteLine(authorization_exception.Message);
     }
     catch (EmptySearchException empty_search_exception)
     {
         Console.WriteLine(empty_search_exception.Message);
         return;
     }
     foreach (var s in search_collection.list)
     {
         subject_list.Add(new Model.Collection(s));
     }
     SubjectListControl.SwitchList(ref subject_list);
 }