public AdresseType ToAddressType(String addressString)
        {
            try
            {
                addressString = HttpUtility.UrlEncode(addressString, Encoding.UTF8);
                String urlString     = "http://dawa.aws.dk/adresser?q=" + addressString;
                var    url           = new Uri(urlString);
                var    responseBytes = new System.Net.WebClient().DownloadData(url);
                var    charset       = Encoding.UTF8;
                String response      = charset.GetString(responseBytes);

                JArray adresses = JArray.Parse(response);

                if (adresses.Count > 0)
                {
                    String streetName = null, houseNumber = null, floor = null, door = null, districtSubdivision = null, postCode = null, postDistrict = null;

                    streetName          = GetString(adresses[0], "adgangsadresse/vejstykke/navn");
                    houseNumber         = GetString(adresses[0], "adgangsadresse/husnr");
                    floor               = GetString(adresses[0], "etage");
                    door                = GetString(adresses[0], "dør");
                    districtSubdivision = GetString(adresses[0], "adgangsadresse/supplerendebynavn");
                    postCode            = GetString(adresses[0], "adgangsadresse/postnummer/nr");
                    postDistrict        = GetString(adresses[0], "adgangsadresse/postnummer/navn");

                    AdresseType      ret          = new AdresseType();
                    DanskAdresseType danskAdresse = new DanskAdresseType();
                    danskAdresse.PostDistriktTekst = postDistrict;
                    ret.Item = danskAdresse;

                    AddressCompleteType addressComplete = new AddressCompleteType();
                    danskAdresse.AddressComplete = addressComplete;

                    AddressAccessType addressAccess = new AddressAccessType();
                    addressAccess.StreetBuildingIdentifier = houseNumber;
                    addressComplete.AddressAccess          = addressAccess;

                    AddressPostalType addressPostal = new AddressPostalType();
                    addressPostal.StreetName      = streetName;
                    addressPostal.FloorIdentifier = floor;
                    addressPostal.SuiteIdentifier = door;
                    addressPostal.DistrictSubdivisionIdentifier = districtSubdivision;
                    addressPostal.PostCodeIdentifier            = postCode;
                    addressPostal.DistrictName    = postDistrict;
                    addressComplete.AddressPostal = addressPostal;

                    return(ret);
                }
            }
            catch (Exception ex)
            {
                cpreader.Logger.error(ex);
            }
            return(null);
        }
示例#2
0
        private AdresseType getAdresseType(IDanishAddress address)
        {
            String streetName = null, houseNumber = null, floor = null, door = null, districtSubdivision = null, postCode = null, postDistrict = null;

            streetName          = address.streetName();
            houseNumber         = address.streetBuilding();
            floor               = address.floor();
            door                = address.suite();
            districtSubdivision = address.districtSubdivision();
            postCode            = address.postCode();
            postDistrict        = address.postDistrikt();

            AdresseType ret = new AdresseType();

            DanskAdresseType danskAdresse = new DanskAdresseType();

            danskAdresse.PostDistriktTekst = postDistrict;
            ret.Item = danskAdresse;

            AddressCompleteType addressComplete = new AddressCompleteType();

            danskAdresse.AddressComplete = addressComplete;

            AddressAccessType addressAccess = new AddressAccessType();

            addressAccess.StreetBuildingIdentifier = houseNumber;
            addressComplete.AddressAccess          = addressAccess;

            AddressPostalType addressPostal = new AddressPostalType();

            addressPostal.StreetName      = streetName;
            addressPostal.FloorIdentifier = floor;
            addressPostal.SuiteIdentifier = door;
            addressPostal.DistrictSubdivisionIdentifier = districtSubdivision;
            addressPostal.PostCodeIdentifier            = postCode;
            addressPostal.DistrictName    = postDistrict;
            addressComplete.AddressPostal = addressPostal;

            return(ret);
        }
示例#3
0
        public static string ToAddressString(this AddressPostalType addr)
        {
            var parts = new string[] {
                addr.StreetName.TrimLeadingZeros(),
                addr.StreetBuildingIdentifier.TrimLeadingZeros(),
                addr.FloorIdentifier.TrimLeadingZeros(),
                addr.SuiteIdentifier.TrimLeadingZeros(),
                ",",
                addr.PostCodeIdentifier.TrimLeadingZeros(),
                addr.DistrictName.TrimLeadingZeros()
            };

            var ret = string.Join(" ",
                                  parts
                                  .Where(p => !string.IsNullOrEmpty(p))
                                  .ToArray()).Trim();

            if (ret.EndsWith(","))
            {
                ret = ret.Substring(0, ret.Length - 1).Trim();
            }

            return(ret);
        }