private static TimeData GetTimeData()
        {
            if (options != null && !options.IncludeTimeData)
            {
                return(null);
            }

            XElement timeDataElement = (from i in supplementalDataDocument.Elements("supplementalData")
                                        .Elements("timeData")
                                        select i).FirstOrDefault();

            if (timeDataElement == null)
            {
                return(null);
            }

            Progress("Adding time data", String.Empty);

            TimeData timeData = new TimeData();

            List <XElement> hourElements = timeDataElement.Elements("hours").ToList();

            if (hourElements.Count > 0)
            {
                List <RegionHour> regionHours = new List <RegionHour>();
                foreach (XElement hourElement in hourElements)
                {
                    RegionHour regionMeasurementSystem = new RegionHour();
                    regionMeasurementSystem.Preferred = hourElement.Attribute("preferred").Value.ToString();
                    regionMeasurementSystem.Allowed   = hourElement.Attribute("allowed").Value.ToString().Split(' ');
                    regionMeasurementSystem.RegionIds = hourElement.Attribute("regions").Value.ToString().Split(' ');
                    regionHours.Add(regionMeasurementSystem);
                }

                timeData.Hours = regionHours.ToArray();
            }

            Progress("Added time data", string.Empty, ProgressEventType.Added, timeData);

            return(timeData);
        }
Beispiel #2
0
        /// <summary>
        /// GetHour gets the RegionHour for the region
        /// </summary>
        /// <param name="regionId">The Id of the region to get the RegionHour for</param>
        /// <returns>The RegionHour for the region</returns>
        public static RegionHour GetHour(string regionId)
        {
            if (NCldr.TimeData == null || NCldr.TimeData.Hours == null)
            {
                return(null);
            }

            RegionHour regionHour = (from h in NCldr.TimeData.Hours
                                     where h.RegionIds.Contains(regionId)
                                     select h).FirstOrDefault();

            if (regionHour != null)
            {
                // this region has a specific RegionHour
                return(regionHour);
            }

            // there is no specific RegionHour for this region so default to the RegionHour for the world ("001")
            return((from h in NCldr.TimeData.Hours
                    where h.RegionIds.Contains(NCldr.RegionIdForTheWorld)
                    select h).FirstOrDefault());
        }