コード例 #1
0
        public async void SearchForBand()
        {
            Views.Shell.SetBusyVisibility(Visibility.Visible, "Searching");

            try
            {
                //Searching for a band with Bandsintown services
                BitArtistsService search = new BitArtistsService();
                BitArtist         artist = await search.GetArtistAsync(this.Value);

                if (artist != null)
                {
                    this.NavigationService.Navigate(typeof(Views.BandPage), artist);
                }
            }

            catch (ArgumentException)
            {
                //Catching bad argument input
                MessageDialog msgDialog = new MessageDialog("\"" + this.Value + "\" is not valid , please retry", "404 : Band not found:'(");
                await msgDialog.ShowAsync();
            }

            catch (Exception)
            {
                //Catching no service or notfound band
                MessageDialog msgDialog = new MessageDialog("No bands found for \"" + this.Value + "\" please retry... ", "404 : Band not found :'(");
                await msgDialog.ShowAsync();
            }
            finally {
                Views.Shell.SetBusyVisibility(Visibility.Collapsed);
            }
        }
コード例 #2
0
        public async Task <List <BitEvent> > GetEventsForArtistAsync(BitArtist query)
        {
            if (query == null)
            {
                throw new ArgumentNullException(nameof(query));
            }

            if (query.Name.IsBlank())
            {
                throw new ArgumentException("BandsInTown band name query could not be empty.", nameof(query));
            }

            //string queryEncoded = WebUtility.UrlEncode(query.Name);
            string queryEncoded = query.Name.Trim();
            string url          = string.Format("http://api.bandsintown.com/artists/{0}/events.json?api_version={1}&app_id={2}", queryEncoded, BIT_API_VERSION, APP_ID);

            Debug.WriteLine("GetEventsForArtistAsync>Request : " + url);

            string webresponse;

            using (HttpClient client = new HttpClient())
            {
                //client.DefaultRequestHeaders.TryAppendWithoutValidation("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10240");
                webresponse = await client.GetStringAsync(new Uri(url));

                Debug.WriteLine("GetEventsForArtistAsync>result : " + webresponse);
            }


            //TODO : Decompose
            return(JsonConvert.DeserializeObject <List <BitEvent> >(webresponse, new JsonSerializerSettings {
                Error = HandleDeserializationError
            }));
        }
コード例 #3
0
        public override void OnNavigatedTo(object parameter, NavigationMode mode, IDictionary <string, object> state)
        {
            if (state.Any())
            {
                // use cache value(s)
                if (state.ContainsKey(nameof(Name)))
                {
                    Name = state[nameof(Name)]?.ToString();
                }
                // clear any cache
                state.Clear();
            }
            else
            {
                // use navigation parameter
                //Name = parameter?.ToString();

                _Artist = (BitArtist)parameter;
                SearchBandEvents();
            }
        }