public void BeforeEach() { subject = new RouteAdapter(); AddressLocation origin = new AddressLocation() { address = new Address(){ street = "Avenida Jabaquara", houseNumber = "100" }, point = new MapLinkConnector.MaplinkV3_AddressFinder.Point(){ x = -46.6405497, y = -23.6267322 } }; AddressLocation destination = new AddressLocation() { address = new Address(){ street = "Avenida Jabaquara", houseNumber = "1000" }, point = new MapLinkConnector.MaplinkV3_AddressFinder.Point() { x = -46.6374321, y = -23.6146506 } }; locations = new List<AddressLocation>(); locations.Add(origin); locations.Add(destination); }
/// <summary> /// Get list of cantones /// </summary> /// <param name="addressLocationList"></param> /// <param name="addressLocationProvincia"></param> /// <param name="initDataBaseValue"></param> /// <returns>List of cantones</returns> private List <AddressLocation> GetListOfCatonByProvincia(List <AddressLocation> addressLocationList, List <AddressLocation> addressLocationProvincia, ref int initDataBaseValue) { var cantonList = new List <AddressLocation>(); foreach (AddressLocation addressLocation in addressLocationList) { if ((cantonList.Where(a => (a.CantonId == addressLocation.CantonId) && (a.ProvinciaId == addressLocation.ProvinciaId)).Count()) == 0) { var currentAddressLocation = new AddressLocation() { ProvinciaId = addressLocation.ProvinciaId, CantonId = addressLocation.CantonId, CantonDescription = addressLocation.CantonDescription, DataBaseId = initDataBaseValue, TypeId = Utilities.Constants.TipoUbicacion.Canton, CountryCode = Utilities.Constants.COUNTRY_CODE }; cantonList.Add(currentAddressLocation); initDataBaseValue++; } } foreach (AddressLocation address in addressLocationProvincia) { foreach (AddressLocation canton in cantonList) { if (canton.ProvinciaId == address.ProvinciaId) { canton.DataBaseParentId = address.DataBaseId; } } } return(cantonList); }
public async Task <BoligsidenHouseDetails> GetHouseDetailsAsync(AddressLocation address) { var houseId = await GetHouseId(address); var doc = await $"https://www.boligsiden.dk/salg/{houseId}" .GetHtmlAsync().ConfigureAwait(false); var detailsJson = doc.DocumentNode .SelectNodes("//script") .FirstOrDefault(x => x.ChildNodes.Count == 1 && x.ChildNodes[0].InnerHtml.TrimStart().StartsWith("bs.page.initPropertyPresentation")) .InnerHtml .Trim() .MatchRegex(@"^bs\.page\.initPropertyPresentation\((?<obj>.*)\);$") .Groups["obj"] .Value; var detailsObj = JToken.Parse(detailsJson); var prop = detailsObj["property"]; var periodDays = prop.GetInt32("salesPeriod"); var periodTotalDays = prop.GetNullableInt32("salesPeriodTotal"); var location = prop["mapPosition"]["latLng"]; var coordinates = new GeoLocation(location.Value <double>("lat"), location.Value <double>("lng")); return(new BoligsidenHouseDetails( houseId, TimeSpan.FromDays(periodDays), periodTotalDays.HasValue ? TimeSpan.FromDays(periodTotalDays.Value) : (TimeSpan?)null, coordinates )); }
public async Task <List <Shop> > GetShops(GeoLocation location, IEnumerable <string> dealerIds) { var shopQuery = $"{_root}/stores" .SetQueryParam("r_lat", location.Latitude) .SetQueryParam("r_lng", location.Longitude); if (dealerIds?.Any() ?? false) { shopQuery = shopQuery.SetQueryParam("dealer_ids", string.Join(",", dealerIds)); } var shops = await shopQuery .SetQueryParam("order_by", "distance") .WithHeader("X-Token", _sessionToken) .WithHeader("X-Signature", GetSignature()) .GetJsonListAsync() .ConfigureAwait(false); return(shops.Select(x => { return new Shop( x.branding.name, AddressLocation.Parse(x.street, $"{x.zip_code} {x.city}") ); }).ToList()); }
public async Task <DawaAddress[]> SearchForHouse(AddressLocation address) { var response = await $"https://dawa.aws.dk/adgangsadresser/autocomplete" .SetQueryParam("q", GetParameter(address)) .GetJsonAsync <AddressElement[]>(); return(response.Select(a => a.Address).ToArray()); }
public async Task <AddressLocation> GetAddress(HtmlDocument document) { var adrNode = document.DocumentNode.SelectSingleNode("//div[@class='name']/h1"); var adr = adrNode.ChildNodes[0].DecodedInnerHtml().Trim().Trim(',').Trim(); var codeCity = adrNode.ChildNodes[1].DecodedInnerHtml().Trim().Trim(',').Trim(); return(AddressLocation.Parse(adr, codeCity)); }
public async Task <AddressLocation> GetAddress(HtmlDocument document) { var adrString = document.DocumentNode .SelectSingleNode("//section[@class='title-band']/div/div/h1") .DecodedInnerHtml() .Trim(); adrString = Regex.Replace(adrString, " +", " "); return(AddressLocation.Parse(adrString)); }
/// <summary> /// Read the file with the localization /// </summar> /// <returns>List of file lines</returns> public List <AddressLocation> GetAddressLocationFromFile() { Console.WriteLine("Start reading the file"); var addressLocationList = new List <AddressLocation>(); try { #region Read File string currentDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); StreamReader streamreader = new StreamReader(currentDirectory + Utilities.Constants.LOCALIZATION_FILE); char[] delimiter = new char[] { Utilities.Constants.TAB_SYMBOL }; #endregion #region Read file lines while (streamreader.Peek() > 0) { var fileLine = streamreader.ReadLine().Split(delimiter); if (fileLine.Length == Utilities.Constants.TOTAL_OF_COLUMNS) { var addressLocationLine = new AddressLocation() { ProvinciaId = Convert.ToInt32(fileLine[0]), ProvinciaDescription = fileLine[1], CantonId = Convert.ToInt32(fileLine[2]), CantonDescription = fileLine[3], DistritoId = Convert.ToInt32(fileLine[4]), DistritoDescription = fileLine[5], BarrioId = Convert.ToInt32(fileLine[6]), BarrioDescription = fileLine[7] }; //Console.WriteLine(addressLocationLine.ToString()); addressLocationList.Add(addressLocationLine); } } #endregion } catch (Exception ex) { if (ex.InnerException != null) { Console.WriteLine(ex.InnerException); } if (ex.Message != null) { Console.WriteLine(ex.Message); } if (ex.StackTrace != null) { Console.WriteLine(ex.StackTrace); } } Console.WriteLine("Finish reading the file"); return(addressLocationList); }
/// <summary> /// Get the address for the given location. /// </summary> /// <param name="location"></param> /// <returns></returns> public VAddress GetAddress(AddressLocation location) { foreach (VAddress adr in GetAddressList()) { if (adr.Location == location) { return(adr); } } return(null); }
/// <summary> /// /// </summary> /// <param name="loc"></param> /// <returns></returns> public Address GetAddress(AddressLocation loc) { foreach (Address adr in GetAddresses()) { if (adr.Location == loc) { return(adr); } } return(null); }
public Address(AddressLocation loc, string extra, string street, string locality, string region, string postalcode, string country, bool prefered) : this() { Location = loc; ExtraAddress = extra; Street = street; Locality = locality; Region = region; PostalCode = postalcode; Country = country; IsPrefered = prefered; }
public async Task <AddressLocation> GetAddress(HtmlDocument document) { var titleText = document.DocumentNode .SelectSingleNode("//title") .DecodedInnerHtml() .Trim() .MatchRegex(@"^(.*) \| Thorkild-Kristensen$") .Groups[1].Value; return(AddressLocation.Parse(titleText)); }
private static string GetParameter(AddressLocation location) { if (location.Town != null) { return($"{location.Street}, {location.Town}, {location.PostalCode} {location.City}"); } else { return($"{location.Street}, {location.PostalCode} {location.City}"); } }
private static string GetParameter(AddressLocation address) { if (address.Town != null) { return($"{address.Street}, {address.Town}, {address.PostalCode} {address.City}"); } else { return($"{address.Street}, {address.PostalCode} {address.City}"); } }
public async Task <AddressLocation> GetAddress(HtmlDocument document) { var addressH1 = document.DocumentNode .SelectSingleNode("//div[@class='information']//h1") .InnerHtml .Split(new string[] { "<br>" }, StringSplitOptions.None) .Select(x => x.DecodeHtml().Trim()) .ToArray(); var adr = string.Join(", ", addressH1.Take(addressH1.Length - 1)); return(AddressLocation.Parse(adr, addressH1[addressH1.Length - 1])); }
public async Task <AddressLocation> GetAddress(HtmlDocument document) { var adr = document.DocumentNode.SelectSingleNode("//div[@class='mpdiv1']/h2[1]").DecodedInnerHtml(); var cityMatch = document.DocumentNode .SelectSingleNode("//div[@class='mpdiv1']/p[2]") .DecodedInnerHtml() .MatchRegex(@"^(?<zip>\d+), *(?<name>[^ ].*[^ ]) *•"); var postalCode = int.Parse(cityMatch.Groups["zip"].Value); var city = cityMatch.Groups["name"].Value; return(AddressLocation.Parse(adr, $"{postalCode} {city}")); }
public async Task <AddressLocation> GetAddress(HtmlDocument document) { var address = document.DocumentNode .SelectSingleNode("//strong[@class='case-info__property__info__main__title__address']") .DecodedInnerHtml() .Trim(); var cityStr = document.DocumentNode .SelectSingleNode("//em[@class='case-info__property__info__main__title__location']") .DecodedInnerHtml() .Trim(); return(AddressLocation.Parse(address, cityStr)); }
public async Task <AddressLocation> GetAddress(HtmlDocument document) { var adr1 = document.DocumentNode.SelectSingleNode("//div[@class='single-sidebar-title']").DecodedInnerHtml().Trim(); var adr2 = document.DocumentNode.SelectSingleNode("//div[@class='single-sidebar-subtitle']").DecodedInnerHtml().Trim(); var sb = new StringBuilder(adr1 + ", " + adr2); for (int i = 0; i < sb.Length; i++) { if (char.IsWhiteSpace(sb[i])) { sb[i] = ' '; } } return(AddressLocation.Parse(sb.ToString())); }
/// <summary> /// Get list of barrios /// </summary> /// <param name="addressLocationList"></param> /// <param name="addressLocationDistrito"></param> /// <param name="initDataBaseValue"></param> /// <returns>List of barrios</returns> private List <AddressLocation> GetListOfBarrioByDistrito(List <AddressLocation> addressLocationList, List <AddressLocation> addressLocationDistrito, ref int initDataBaseValue) { var barrioList = new List <AddressLocation>(); foreach (AddressLocation addressLocation in addressLocationList) { if ((barrioList.Where(a => (a.BarrioId == addressLocation.BarrioId) && (a.DistritoId == addressLocation.DistritoId) && (a.CantonId == addressLocation.CantonId) && (a.ProvinciaId == addressLocation.ProvinciaId)).Count()) == 0) { var currentAddressLocation = new AddressLocation() { ProvinciaId = addressLocation.ProvinciaId, CantonId = addressLocation.CantonId, DistritoId = addressLocation.DistritoId, BarrioId = addressLocation.BarrioId, BarrioDescription = addressLocation.BarrioDescription, DataBaseId = initDataBaseValue, TypeId = Utilities.Constants.TipoUbicacion.Barrio, CountryCode = Utilities.Constants.COUNTRY_CODE }; barrioList.Add(currentAddressLocation); initDataBaseValue++; } } foreach (AddressLocation address in addressLocationDistrito) { foreach (AddressLocation barrio in barrioList) { if ((barrio.ProvinciaId == address.ProvinciaId) && (barrio.CantonId == address.CantonId) && (barrio.DistritoId == address.DistritoId)) { barrio.DataBaseParentId = address.DataBaseId; } } } return(barrioList); }
/// <summary> /// Get list of provincias /// </summary> /// <param name="addressLocationList"></param> /// <param name="initDataBaseValue"></param> /// <returns>List of provincias</returns> private List <AddressLocation> GetListOfProvincia(List <AddressLocation> addressLocationList, ref int initDataBaseValue) { var provinciaList = new List <AddressLocation>(); foreach (AddressLocation addressLocation in addressLocationList) { if ((provinciaList.Where(a => a.ProvinciaId == addressLocation.ProvinciaId).Count()) == 0) { var currentAddressLocation = new AddressLocation() { ProvinciaId = addressLocation.ProvinciaId, ProvinciaDescription = addressLocation.ProvinciaDescription, DataBaseId = initDataBaseValue, TypeId = Utilities.Constants.TipoUbicacion.Provincia, CountryCode = Utilities.Constants.COUNTRY_CODE }; provinciaList.Add(currentAddressLocation); initDataBaseValue++; } } return(provinciaList); }
private async Task <int> GetHouseId(AddressLocation location) { string addressQuery; if (location.Town != null) { addressQuery = $"{location.Street}, {location.Town}, {location.PostalCode} {location.City}"; } else { addressQuery = $"{location.Street}, {location.PostalCode} {location.City}"; } var response = await $"https://www.boligsiden.dk/propertysearch/savequicksearch?query={addressQuery}&itemTypes=100|200|300|400|500|600|700|800|900&completionType=8&itemType=Property" .GetJsonAsync <JToken>(); if (response["type"].Value <string>() == "SUGGESTIONLIST" && location.Town != null) { return(await GetHouseId(new AddressLocation(location.Street, location.PostalCode, location.City))); } if (response["url"] == null) { throw new Exception("No url property in Boligsiden response"); } var url = response.Value <string>("url"); var match = Regex.Match(url, @"/salg/(?<id>\d+)"); if (!match.Success) { throw new Exception("No house id could be extracted from Boligsiden url: " + url); } return(int.Parse(match.Groups["id"].Value)); }
public static Task <Distance> GetDistance(this IGoogleDirectionsRepository repository, GeoLocation origin, AddressLocation destination) => repository.GetDistance(GetParameter(origin), GetParameter(destination));
/// <summary> /// /// </summary> /// <param name="loc"></param> /// <returns></returns> public Address GetAddress(AddressLocation loc) { foreach (Address adr in GetAddresses()) { if (adr.Location == loc) return adr; } return null; }