示例#1
0
        /// <summary>
        /// Does a high-level check of the format supplied and determines what type
        /// of location input was supplied.
        ///
        /// Formats are:
        /// 1. city                         - "Bronx"
        /// 2. city,state                   - "Bronx , New York"
        /// 3. city,state( abbreviation )   - "Bronx , NY"
        /// 4. city,country                 - "HomeTown , USA"
        /// 5. state                        - "New Jersey"
        /// 6. state abbreviation           - "NJ"
        /// 7. country                      - "Italy"
        /// the actuall parsing
        /// </summary>
        /// <param name="locationData">The location to parse. Can be any combination of
        /// inputs, check the summary above.</param>
        /// <returns></returns>
        private LocationLookUpResult InternalParse(string locationData)
        {
            CityLookUp    cityLookUp    = new CityLookUp(Cities.GetAll());
            StateLookUp   stateLookUp   = new StateLookUp(States.GetAll());
            CountryLookUp countryLookUp = new CountryLookUp(Countries.GetAll());

            try
            {
                bool isValidUSZipCode = IsUnitedStatesZipCode(locationData);
                bool containsComma    = isValidUSZipCode ? false : locationData.Contains(",");

                // United states Zip code format
                if (isValidUSZipCode)
                {
                    return(ParseUnitedStatesZipCode(locationData));
                }

                // City, ( State or Country )
                // Comma indicates search by city, <state> or <country>
                if (containsComma)
                {
                    return(LocationParser.ParseCityWithStateOrCountry(cityLookUp, stateLookUp, countryLookUp, locationData));
                }

                // Check for city, state, or country.
                // Start with narrowest search.
                // Check city.
                LocationLookUpResult result = LocationParser.ParseCity(cityLookUp, stateLookUp, countryLookUp, locationData);
                if (result != LocationLookUpResult.Empty && result.IsValid)
                {
                    return(result);
                }

                // Check State - 2nd most restrictive search.
                result = LocationParser.ParseState(stateLookUp, countryLookUp, locationData);
                if (result != LocationLookUpResult.Empty && result.IsValid)
                {
                    return(result);
                }

                // Check country - 3rd and final search criteria
                result = LocationParser.ParseCountry(countryLookUp, locationData);
                if (result != LocationLookUpResult.Empty && result.IsValid)
                {
                    return(result);
                }
            }
            catch (Exception ex)
            {
                // Some error during parsing.
                // Log the sucker into our system.
                Logger.Error("Error verifying search location", ex);
            }

            return(new LocationLookUpResult(LocationLookUpType.None, false, "Unable to determine location"));
        }
示例#2
0
        public static List <City> GetAll()
        {
            List <City> lstCities = new List <City>();
            DataTable   table     = Cities.GetAll();

            if (table != null && table.Rows.Count > 0)
            {
                foreach (DataRow myRow in table.Rows)
                {
                    City city = new City(Convert.ToInt32(myRow["Id"].ToString()), myRow["Name"].ToString());
                    lstCities.Add(city);
                }

                return(lstCities);
            }
            else
            {
                return(null);
            }
        }
示例#3
0
        public static ICity GetCityFromAddress(string address)
        {
            if (string.IsNullOrWhiteSpace(address))
            {
                return(null);
            }

            var pattern = string.Format(@"(?i:{0}\s(?<cityName>[а-я][а-я-\s\.]+))", Constants.City.AddressTypesMask);
            var match   = System.Text.RegularExpressions.Regex.Match(address, pattern);

            var cityName = match.Groups["cityName"].Value;
            var city     = string.Format("{0} {1}", Constants.City.CityMask, cityName);
            var locality = string.Format("{0} {1}", Constants.City.LocalityMask, cityName);

            return(!match.Success
        ? null
        : Cities.GetAll().FirstOrDefault(c =>
                                         c.Name.ToLower() == city.ToLower() || c.Name.ToLower() == cityName ||
                                         c.Name.ToLower() == locality.ToLower()));
        }
示例#4
0
 public override IQueryable <City> GetAll()
 {
     return(Cities.GetAll());
 }