private static CalendarPreference[] GetCalendarPreferences()
        {
            if (options != null && !options.IncludeCalendarPreferences)
            {
                return(null);
            }

            List <XElement> calendarPreferenceElements = (from i in supplementalDataDocument.Elements("supplementalData")
                                                          .Elements("calendarPreferenceData").Elements("calendarPreference")
                                                          select i).ToList();

            if (calendarPreferenceElements.Count == 0)
            {
                return(null);
            }

            List <CalendarPreference> calendarPreferences = new List <CalendarPreference>();

            foreach (XElement calendarPreferenceElement in calendarPreferenceElements)
            {
                string regionIds = calendarPreferenceElement.Attribute("territories").Value.ToString();
                Progress("Adding calendar preference", regionIds);

                CalendarPreference calendarPreference = new CalendarPreference();
                calendarPreference.RegionIds = regionIds.Split(' ');

                string calendarTypes = calendarPreferenceElement.Attribute("ordering").Value.ToString();
                calendarPreference.CalendarTypes = calendarTypes.Split(' ');

                calendarPreferences.Add(calendarPreference);
                Progress("Added calendar preference", regionIds, ProgressEventType.Added, calendarPreference);
            }

            return(calendarPreferences.ToArray());
        }
Beispiel #2
0
        /// <summary>
        /// GetCalendarPreferenceIds gets the calendar preference ids for the region
        /// </summary>
        /// <param name="regionId">The Id of the region to get the calendar preference ids for</param>
        /// <returns>The calendar preference ids for the region</returns>
        public static string[] GetCalendarPreferenceIds(string regionId)
        {
            if (NCldr.CalendarPreferences == null)
            {
                return(null);
            }

            CalendarPreference calendarPreference = (from ms in NCldr.CalendarPreferences
                                                     where ms.RegionIds.Contains(regionId)
                                                     select ms).FirstOrDefault();

            if (calendarPreference != null)
            {
                // this region has a specific calendar preference
                return(calendarPreference.CalendarTypes);
            }

            // there are no specific calendar preferences for this region so default to the calendar preferences for the world ("001")
            return((from ms in NCldr.CalendarPreferences
                    where ms.RegionIds.Contains(NCldr.RegionIdForTheWorld)
                    select ms.CalendarTypes).FirstOrDefault());
        }