Esempio n. 1
0
 /// <summary>Checks whether the given address is a valid address (either full or partial).</summary>
 public static bool IsValid(AddressStruct a) {
    if (a == null) return false;
    if (a.CountryCode.IsEmpty()) return false;
    if (a.CityName.IsEmpty()) return a.StreetName.IsEmpty() && a.HouseNumber.IsEmpty();
    if (a.StreetName.IsEmpty()) return a.HouseNumber.IsEmpty();
    // skipping StateCode and ZipCode (see comments in MemberwiseEquals)
    return true;
 }
Esempio n. 2
0
 /// <summary>Compares two addresses for equality, member-by-member.</summary>
 public static bool MemberwiseEquals(AddressStruct a1, AddressStruct a2) {
    if (Object.ReferenceEquals(a1, a2)) return true;
    if (a1 == null || a2 == null) return false;
    Func<string, string, bool> notequal = (s1, s2) => !(s1.IsEmpty() ? s2.IsEmpty() : s1 == s2);
    if (notequal(a1.CountryCode, a2.CountryCode)) return false;
    // skip StateCode check (not relevant for now)
    // skip ZipCode check (not all addresses have zip code)
    if (notequal(a1.CityName, a2.CityName)) return false;
    if (notequal(a1.StreetName, a2.StreetName)) return false;
    if (notequal(a1.HouseNumber, a2.HouseNumber)) return false;
    return true;
 }
Esempio n. 3
0
      //TODO: Replace by proper method for localized address formatting
      private static string _formatPrimaryAddress(AddressStruct address) {
         if (address == null) return String.Empty;

         var countryCode = address.CountryCode;
         var cityName = address.CityName;
         var cityAddress = cityName;
         var zipCode = address.ZipCode ?? address.PostalCode;
         if (zipCode.NotEmpty()) {
            if (countryCode == "DK") {
               cityAddress = zipCode + " " + cityAddress;
            } else {
               cityAddress += " (" + zipCode + ")";
            }
         }

         var streetName = address.StreetName;
         var houseNumber = address.HouseNumber;
         var streetAddress = streetName;
         if (streetAddress.NotEmpty() && houseNumber.NotEmpty()) {
            if (countryCode == "IL" || countryCode == "DK") {
               streetAddress = streetAddress + " " + houseNumber;
            } else {
               streetAddress = houseNumber + " " + streetAddress;
            }
         }

         var hasStreet = streetAddress.NotEmpty();
         var hasCity = cityAddress.NotEmpty();

         var result = String.Empty;
         if (hasStreet) {
            result = streetAddress;
         }
         if (hasCity) {
            result += (hasStreet ? ", " + cityAddress : cityAddress);
         }

         return result;
      }
Esempio n. 4
0
 private static Contact _getAddress(A.Address address, Operator opco, ContactType type) {
    if (address == null || opco == null) return null;
    var addr = new AddressStruct {
       CityName = address.city,
       CountryCode = opco.CountryCode,
       HouseNumber = address.streetNumber,
       PostalCode = address.postcode,
       StreetName = address.streetName,
       ZipCode = address.postcode
    };
    return new Contact { Type = type, Value = _formatPrimaryAddress(addr) };
 }
Esempio n. 5
0
 /// <summary>Converts an <see cref="AddressStruct"/> object to closest matching <see cref="AddressPart"/>.</summary>
 public static AddressPart ToAddressPart(AddressStruct address) {
    if (address == null || address.CountryCode.IsEmpty()) return AddressPart.None;
    if (address.CityName.IsEmpty()) return AddressPart.Country;
    if (address.StreetName.IsEmpty()) return AddressPart.City;
    if (address.HouseNumber.IsEmpty()) return AddressPart.Street;
    return AddressPart.House;
 }
Esempio n. 6
0
 /// <summary>Converts an <see cref="AddressStruct"/> object to an <see cref="Address"/> primitive.</summary>
 public static Address ToAddress(AddressStruct address) {
    return new Address(address);
 }
Esempio n. 7
0
 /// <summary>Converts an <see cref="AddressStruct"/> object to closest matching <see cref="PoiType"/>.</summary>
 public static PoiType ToPoiType(AddressStruct address) {
    if (address == null || address.CountryCode.IsEmpty()) return PoiTypes.Undefined;
    if (address.CityName.IsEmpty()) return PoiTypes.Country;
    if (address.StreetName.IsEmpty()) return PoiTypes.City;
    if (address.HouseNumber.IsEmpty()) return PoiTypes.Street;
    return PoiTypes.House;
 }
Esempio n. 8
0
 public static IEnumerable<Site> GetMockupSites(string file) {
    var root = Path.Combine(Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName), @"Mockup");
    var lines = File.ReadAllLines(Path.Combine(root, file));
    //we not handle versions now
    var sites = new List<Site>();
    foreach (var line in lines) {
       var site = line.Split('\t');
       if (site.Length >= 10) {
          var id = BplIdentity.Get(site[0]);
          var name = site[1];
          var type = 1;
          int.TryParse(site[2], out type);
          var country = site[3];
          var city = site[4];
          var street = site[5];
          var house = site[6];
          var zip = site[7];
          var addr = new AddressStruct {
             CountryCode = country,
             CityName = city,
             StreetName = street,
             HouseNumber = house,
             ZipCode = zip,
          };
          var lon = 0d;
          double.TryParse(site[8], out lon);
          var lat = 0d;
          double.TryParse(site[9], out lat);
          var c = new Coordinate(new Angle(lat), new Angle(lon));
          var s = default(Site);
          switch (type) {
             case 1:
             case 4:
                s = new ParkingSite {
                   Id = id,
                   Name = name,
                   Position = c,
                   Address = addr
                }; break;
             case 2: s = new CustomerSite {
                Id = id,
                Name = name,
                Position = c,
                Address = addr
             }; break;
             case 8:
             case 16: s = new HomeSite {
                Id = id,
                Name = name,
                Position = c,
                Address = addr
             }; break;
             case 32: s = new BXStation {
                Id = id,
                Name = name,
                Position = c,
                Address = addr
             }; break;
             default: s = new UserDefinedSite {
                Id = id,
                Name = name,
                Position = c,
                Address = addr
             }; break; //1 is unknown
          }
          if (site.Length >= 11 && site[10].Contains(":")) {
             //loc name
             s.LocalizedName = _getLocStr(site[10].RemoveAll("\""));
          }
          if (site.Length >= 12 && site[11].Contains(":")) {
             s.LocalizedAddress = _getLocStr(site[11].RemoveAll("\""));
          }
          sites.Add(s);
       }
    }
    return sites;
 }