Inheritance: IGeographicRegion
 private string ReportRegionData(GeographicRegion region)
 {
     return "Display Name: " + region.DisplayName + "\n" +
         "Native Name: " + region.NativeName + "\n" +
         "Currencies in use: " + string.Join(", ", region.CurrenciesInUse) + "\n" +
         "Codes: " + region.CodeTwoLetter + ", " + region.CodeThreeLetter + ", " + region.CodeThreeDigit + "\n\n";
 }
        private WebRequest CreateWebRequest(string productId)
        {
            var country = new GeographicRegion().CodeTwoLetter;
            var languages = string.Join(string.Empty, ApplicationLanguages.Languages.Select((x, i) =>
            {
                if (i == 1)
                {
                    return "_" + x;
                }
                if (i > 1)
                {
                    return "." + x;
                }

                return x;
            }));

            ////https://next-services.apps.microsoft.com/browse/{osVersion}.{osBuild}-{appModel}/{clientVersion}/{chromeLocale}_{localeList}/c/{country}/cp/{channelPartner}/Apps/{appId}

            var url = string.Format("https://next-services.apps.microsoft.com/browse/6.3.9600-0/776/{2}/c/{1}/cp/0/Apps/{0}",
                productId.TrimStart('{').TrimEnd('}'),
                country,
                languages);

            var request = WebRequest.Create(url);

            request.SetNoCacheHeaders();

            return request;
        }
        /// <summary>
        /// This is the click handler for the 'Display' button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Display_Click(object sender, RoutedEventArgs e)
        {
            // This scenario uses the Windows.Globalization.GeographicRegion class to
            // obtain the geographic region characteristics.

            // Stores results of the scenario
            StringBuilder results = new StringBuilder();

            // Display characteristics of user's geographic region.
            GeographicRegion userRegion = new GeographicRegion();
            results.AppendLine("User's region display name: " + userRegion.DisplayName);
            results.AppendLine("User's region native name: " + userRegion.NativeName);
            results.AppendLine("User's region currencies in use: " + string.Join(",", userRegion.CurrenciesInUse));
            results.AppendLine("User's region codes: " + userRegion.CodeTwoLetter + "," + userRegion.CodeThreeLetter + "," + userRegion.CodeThreeDigit);
            results.AppendLine();

            // Display characteristics of example region.
            GeographicRegion ruRegion = new GeographicRegion("RU");
            results.AppendLine("RU region display name: " + ruRegion.DisplayName);
            results.AppendLine("RU region native name: " + ruRegion.NativeName);
            results.AppendLine("RU region currencies in use: " + string.Join(",", ruRegion.CurrenciesInUse));
            results.AppendLine("RU region codes: " + ruRegion.CodeTwoLetter + "," + ruRegion.CodeThreeLetter + "," + ruRegion.CodeThreeDigit);

            // Display the results
            rootPage.NotifyUser(results.ToString(), NotifyType.StatusMessage);
        }
Exemplo n.º 4
0
        public void initialise()
        {
            // try to get countryCode from roamingSettings, if not there get from Windows API and save in roamingSettings
            if (roamingSettings.Values.ContainsKey("countryCode")) {
                countryCode = roamingSettings.Values["countryCode"].ToString();
            } else {
                GeographicRegion region = new GeographicRegion();
                string countryDetected = region.CodeTwoLetter;
                if (tvListingsAvailable(countryDetected)) {
                    roamingSettings.Values["countryCode"] = countryDetected;
                    countryCode = countryDetected;
                } else {
                    countryCode = "Not Supported";
                    throw new NoListingsAvailableException("No TV Listings for CountryCode detected from Windows", countryDetected);
                }
            }

            // same for this
            if (roamingSettings.Values.ContainsKey("locale")) {
                locale = roamingSettings.Values["locale"].ToString();
            } else {
                IReadOnlyList<string> languages = Windows.Globalization.ApplicationLanguages.Languages;
                locale = "NOT SET";
                foreach (string lang in languages) {
                    if (validLocale(lang)) {
                        roamingSettings.Values["locale"] = lang;
                        locale = lang;
                        break;
                    }
                }
                if (locale == "NOT SET") {
                    locale = "en-US";
                }
            }
        }
Exemplo n.º 5
0
 public static String ToShortDate(DateTime d)
 {
     if (userRegion == null)
     {
         userRegion = new GeographicRegion();
         userDateFormat = new Windows.Globalization.DateTimeFormatting.DateTimeFormatter("shortdate", new[] { userRegion.Code });
     }
     return userDateFormat.Format(d);
 }
        private void ShowResults()
        {
            // This scenario uses the Windows.Globalization.GeographicRegion class to
            // obtain the geographic region characteristics.
            var userGeoRegion = new GeographicRegion();

            // This obtains the geographic region characteristics by providing a country or region code.
            var exampleGeoRegion = new GeographicRegion("JP");

            // Display the results
            OutputTextBlock.Text = "User's Preferred Geographic Region\n" + ReportRegionData(userGeoRegion) +
                "Example Geographic Region by region/country code (JP)\n" + ReportRegionData(exampleGeoRegion);
        }
Exemplo n.º 7
0
 public static string GetLocale()
 {
     GeographicRegion userRegion = new GeographicRegion();
     string regionCode = userRegion.CodeTwoLetter;
     return regionCode;
 }
Exemplo n.º 8
0
 /// <summary>
 /// Fill the list with current day of week, and in descending order rest of the weekdays
 /// </summary>
 private void FillDateList()
 {
     GeographicRegion userRegion = new GeographicRegion();
     var userDateFormat = new Windows.Globalization.DateTimeFormatting.DateTimeFormatter( "shortdate", new[] { userRegion.Code } );
     for( int i = 0; i < 7; i++ )
     {
         var nameOfDay = System.Globalization.DateTimeFormatInfo.CurrentInfo.DayNames[ ( (int)DateTime.Now.DayOfWeek + 7 - i ) % 7 ];
         if( i == 0 )
         {
             nameOfDay += " " + _resourceLoader.GetString( "Today" );
         }
         DateTime itemDate = DateTime.Now.Date - TimeSpan.FromDays( i );
         _daySelectionList.Add( 
             new DaySelectionItem( 
                 nameOfDay + " " + userDateFormat.Format( itemDate ), 
                 itemDate ) );
     }
     // Add the option to show everything
     _daySelectionList.Add( new DaySelectionItem( _resourceLoader.GetString( "All" ), null ) );
 }