/// <summary> /// Validates the country code got from phone region settings. /// </summary> /// <param name="sender">Validate Device Country button</param> /// <param name="e">Event arguments</param> private void ValidateDeviceCountry(object sender, RoutedEventArgs e) { this.ValidateDeviceCountryButton.IsEnabled = false; string countryCode = RegionInfo.CurrentRegion.TwoLetterISORegionName.ToLower(); CountryResolver resolver = new CountryResolver(ApiKeys.AppId); resolver.CheckAvailability( (Response<bool> response) => { Dispatcher.BeginInvoke(() => { if (response.Result) { MessageBox.Show("Hooray! Nokia Music is available in " + RegionInfo.CurrentRegion.DisplayName + "!"); } else { if (response.Error != null) { MessageBox.Show(response.Error.Message); } else { MessageBox.Show("Sorry, Nokia Music is not available in your region - you won't be able to use the API features."); } countryCode = null; } EnableCountrySpecificApiButtons(countryCode); App.SaveCountryCode(countryCode); this.ValidateDeviceCountryButton.IsEnabled = true; }); }, countryCode); }
/// <summary> /// Checks the availability of Nokia Music in a locale. /// Initializes Nokia Music API if it is available. /// </summary> /// <param name="twoLetterCountryCode">An ISO 3166-2 country code</param> private void InitializeNokiaMusicApi(string twoLetterCountryCode) { if (resolver == null) { resolver = new CountryResolver(MusicApi.MUSIC_EXPLORER_APP_ID); } if (twoLetterCountryCode != null) { resolver.CheckAvailability((Response<bool> response) => { Deployment.Current.Dispatcher.BeginInvoke(() => { if (!response.Result) { MessageBox.Show("Sorry, Nokia Music is not available in this locale."); twoLetterCountryCode = null; } }); }, twoLetterCountryCode.ToLower()); } // If country code is null, phone region settings are used App.MusicApi.Initialize(twoLetterCountryCode); // Make initial requests to fill models App.MusicApi.GetArtistInfoForLocalAudio(); App.MusicApi.GetNewReleases(); App.MusicApi.GetTopArtists(); App.MusicApi.GetGenres(); App.MusicApi.GetMixGroups(); }
/// <summary> /// Validates the country code got from phone region settings. /// </summary> /// <param name="sender">Validate Device Country button</param> /// <param name="e">Event arguments</param> private async void ValidateDeviceCountry(object sender, RoutedEventArgs e) { this.ValidateDeviceCountryButton.IsEnabled = false; string countryCode = RegionInfo.CurrentRegion.TwoLetterISORegionName.ToLower(); CountryResolver resolver = new CountryResolver(ApiKeys.ClientId); string message = null; try { bool available = await resolver.CheckAvailabilityAsync(countryCode); if (available) { message = "Hooray! Nokia MixRadio is available in " + RegionInfo.CurrentRegion.DisplayName + "!"; } else { message = "Sorry, Nokia MixRadio is not available in your region - you won't be able to use the API features."; countryCode = null; } } catch (Exception ex) { message = ex.Message; countryCode = null; } MessageBox.Show(message); this.EnableCountrySpecificApiButtons(countryCode); App.SaveCountryCode(countryCode); this.ValidateDeviceCountryButton.IsEnabled = true; }