Ejemplo n.º 1
0
        /// <summary>
        /// Searches for geographical locations synchronously.
        /// </summary>
        /// <param name="searchString">String to search</param>
        /// <returns>List of location items matching the specified search string</returns>
        private List <LocationSearchItem> Search(string searchString)
        {
            List <LocationSearchItem> results = new List <LocationSearchItem>();

            if (searchString.Length == 0)
            {
                return(results);
            }


            var        stringPath  = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Data", "Cities.dat");
            FileStream _FileStream = File.OpenRead(stringPath);

            using (var fileReader = new StreamReader(_FileStream, Encoding.UTF8))
            {
                _LastSearchString = searchString;

                string line = null;
                try
                {
                    while ((line = fileReader.ReadLine()) != null && searchString.Equals(_LastSearchString))
                    {
                        string[] chunks = line.Split('\t');

                        var names = new List <string>();
                        names.Add(chunks[1]);
                        names.AddRange(chunks[3].Split(','));
                        var name = names.FirstOrDefault(s => s.Replace("\'", "").StartsWith(searchString, StringComparison.InvariantCultureIgnoreCase));
                        if (name != null)
                        {
                            double       latitude  = double.Parse(chunks[4], CultureInfo.InvariantCulture);
                            double       longitude = double.Parse(chunks[5], CultureInfo.InvariantCulture);
                            double       elevation = double.Parse(string.IsNullOrWhiteSpace(chunks[15]) ? "0" : chunks[15], CultureInfo.InvariantCulture);
                            TimeZoneItem timeZone  = TimeZones.FirstOrDefault(tz => tz.TimeZoneId.Equals(chunks[17], StringComparison.InvariantCultureIgnoreCase));

                            results.Add(new LocationSearchItem
                            {
                                Name     = name,
                                Country  = chunks[8],
                                Names    = string.Join(", ", names.Distinct().Except(new[] { name }).ToArray()),
                                Location = new CrdsGeographical(-longitude, latitude, timeZone.UtcOffset, elevation, timeZone.TimeZoneId, name)
                            });

                            if (results.Count == 10)
                            {
                                break;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                }

                return(results.OrderBy(r => r.Name).ToList());
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 ///     Retrieves the <see cref="TimeZone" /> object for the specified
 ///     <see>
 ///         <cref>TZID</cref>
 ///     </see>
 ///     (Time Zone Identifier).
 /// </summary>
 /// <param name="tzid">
 ///     A valid
 ///     <see>
 ///         <cref>TZID</cref>
 ///     </see>
 ///     object, or a valid
 ///     <see>
 ///         <cref>TZID</cref>
 ///     </see>
 ///     string.
 /// </param>
 /// <returns>
 ///     A <see cref="TimeZone" /> object for the
 ///     <see>
 ///         <cref>TZID</cref>
 ///     </see>
 ///     .
 /// </returns>
 public ITimeZone GetTimeZone(string tzid)
 {
     return(TimeZones.FirstOrDefault(tz => Equals(tz.TzId, tzid)));
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Retrieves the <see cref="ITimeZone" /> object for the specified
 /// <see cref="TZID"/> (Time Zone Identifier).
 /// </summary>
 /// <param name="tzid">A valid <see cref="TZID"/> object, or a valid <see cref="TZID"/> string.</param>
 /// <returns>A <see cref="TimeZone"/> object for the <see cref="TZID"/>.</returns>
 public ITimeZone GetTimeZone(string tzid)
 {
     return(TimeZones.FirstOrDefault(tz => object.Equals(tz.TZID, tzid)));
 }