public InterestCategoryCollection CollectCategories() { InterestCategoryCollection Categories = new InterestCategoryCollection(); try { using (var httpClient = new HttpClient()) { httpClient.Timeout = TimeSpan.FromSeconds(10); var responseMessage = httpClient.GetAsync( string.Format("{0}{1}", BeautifulTalkProtocolSet.ServerURIwithPort, BeautifulTalkProtocolSet.GetInterestsURI)).Result; if (responseMessage.IsSuccessStatusCode) { string strInterests = responseMessage.Content.ReadAsStringAsync().Result; JValue JValueInterests = JsonConvert.DeserializeObject <JValue>(strInterests); JArray JArrayInterests = JsonConvert.DeserializeObject <JArray>(JValueInterests.Value.ToString()); foreach (JObject JInterest in JArrayInterests) { var Interest = JsonConvert.DeserializeObject <InterestCategory>(JInterest.ToString()); Categories.Add(Interest); } } else { throw new ArgumentNullException("Get Interests failed."); } } } catch (FaultException serviceException) { throw serviceException; } catch (Exception unExpectedException) { throw unExpectedException; } return(Categories); }
//If interestView will be loaded, listbox will be focused by this method for follow Register step with Key(enter). //and collect interests from the server. private void ExecuteInitialLoadedCommand(UIElement targetElement) { if (null != targetElement) { targetElement.Focus(); } try { this.Categories = m_CollectCatagoriesService.CollectCategories(); } catch (FaultException serviceException) { this.CurrentMessage = "server is unavailable."; this.m_Logger.Log(serviceException.Message, Category.Exception, Priority.Medium); } catch (Exception unExpectedException) { this.CurrentMessage = "server is unavailable."; this.m_Logger.Log(unExpectedException.Message, Category.Exception, Priority.Medium); } }
public InterestCategoryCollection CollectCategories() { InterestCategoryCollection Categories = new InterestCategoryCollection(); Categories.Add(new InterestCategory("Art", "This is Art", ToBitmapImgConverter.LoadImage(@"/BeautifulTalk.Modules.Login;component/Resources/Images/base_art.png"))); Categories.Add(new InterestCategory("Automobile", "This is Automobile", ToBitmapImgConverter.LoadImage(@"/BeautifulTalk.Modules.Login;component/Resources/Images/base_automobile.png"))); Categories.Add(new InterestCategory("Building", "This is Building", ToBitmapImgConverter.LoadImage(@"/BeautifulTalk.Modules.Login;component/Resources/Images/base_building.png"))); Categories.Add(new InterestCategory("Cloth", "This is Cloth", ToBitmapImgConverter.LoadImage(@"/BeautifulTalk.Modules.Login;component/Resources/Images/base_cloth.png"))); Categories.Add(new InterestCategory("Dance", "This is Dance", ToBitmapImgConverter.LoadImage(@"/BeautifulTalk.Modules.Login;component/Resources/Images/base_dance.png"))); Categories.Add(new InterestCategory("Donation", "This is Donation", ToBitmapImgConverter.LoadImage(@"/BeautifulTalk.Modules.Login;component/Resources/Images/base_donation.png"))); Categories.Add(new InterestCategory("Food", "This is Food", ToBitmapImgConverter.LoadImage(@"/BeautifulTalk.Modules.Login;component/Resources/Images/base_food.png"))); Categories.Add(new InterestCategory("Gamble", "This is Gamble", ToBitmapImgConverter.LoadImage(@"/BeautifulTalk.Modules.Login;component/Resources/Images/base_gamble.png"))); Categories.Add(new InterestCategory("Mistery", "This is Mistery", ToBitmapImgConverter.LoadImage(@"/BeautifulTalk.Modules.Login;component/Resources/Images/base_mistery.png"))); Categories.Add(new InterestCategory("Movie", "This is Movie", ToBitmapImgConverter.LoadImage(@"/BeautifulTalk.Modules.Login;component/Resources/Images/base_movie.png"))); Categories.Add(new InterestCategory("Music", "This is Music", ToBitmapImgConverter.LoadImage(@"/BeautifulTalk.Modules.Login;component/Resources/Images/base_music.png"))); Categories.Add(new InterestCategory("News", "This is News", ToBitmapImgConverter.LoadImage(@"/BeautifulTalk.Modules.Login;component/Resources/Images/base_news.png"))); Categories.Add(new InterestCategory("Physics", "This is Physics", ToBitmapImgConverter.LoadImage(@"/BeautifulTalk.Modules.Login;component/Resources/Images/base_physics.png"))); Categories.Add(new InterestCategory("Plant", "This is Plant", ToBitmapImgConverter.LoadImage(@"/BeautifulTalk.Modules.Login;component/Resources/Images/base_plant.png"))); Categories.Add(new InterestCategory("Politics", "This is Politics", ToBitmapImgConverter.LoadImage(@"/BeautifulTalk.Modules.Login;component/Resources/Images/base_politics.png"))); Categories.Add(new InterestCategory("Reading", "This is Reading", ToBitmapImgConverter.LoadImage(@"/BeautifulTalk.Modules.Login;component/Resources/Images/base_reading.png"))); Categories.Add(new InterestCategory("Sports", "This is Sports", ToBitmapImgConverter.LoadImage(@"/BeautifulTalk.Modules.Login;component/Resources/Images/base_sports.png"))); Categories.Add(new InterestCategory("Toy", "This is Toy", ToBitmapImgConverter.LoadImage(@"/BeautifulTalk.Modules.Login;component/Resources/Images/base_toy.png"))); Categories.Add(new InterestCategory("Trip", "This is Trip", ToBitmapImgConverter.LoadImage(@"/BeautifulTalk.Modules.Login;component/Resources/Images/base_trip.png"))); return(Categories); }