Example #1
0
        private static Store ParseDocument(IXPathNavigable pageSource)
        {
            Store result = new Store();

            // alternate method:
            // 1. get all tds
            // 2. find one that contains text
            // 3. go to parent table
            // 4. get child trs
            XPathNavigator navigator = pageSource.CreateNavigator();
            XPathNodeIterator nodes = navigator.Select("//table[@id='infoWindow']//tr");
            //HtmlNodeCollection tableRowCollection = pageSource.DocumentNode.SelectNodes("//table[@id='infoWindow']//tr");
            //List<string> trimmedStringsx = new List<string>();
            List<string> trimmedStrings = new List<string>();

            //foreach (HtmlNode tableRow in tableRowCollection)
            //{
            //    string noHtml = HtmlEntity.DeEntitize(tableRow.InnerText.Trim());
            //    // Eliminate the empty lines
            //    //if (!String.IsNullOrEmpty(noHtml))
            //    //{
            //    trimmedStringsx.Add(noHtml);
            //    //}
            //}

            foreach (XPathNavigator node in nodes)
            {
                trimmedStrings.Add(HtmlEntity.DeEntitize(node.Value.Trim()));
            }

            result.StoreNumber = ExtractStoreNumber(trimmedStrings);
            result.AddressLine = ExtractStreetAddress(trimmedStrings);
            result.City = ExtractCity(trimmedStrings);
            result.TelephoneNumber = ExtractTelephoneNumber(trimmedStrings);

            XPathNavigator directionsLinkNode = navigator.SelectSingleNode("//input[@id='directionsLink']");
            result.Latitude = ExtractLatitude(directionsLinkNode);
            result.Longitude = ExtractLongitude(directionsLinkNode);
            if (!result.Latitude.HasValue || result.Latitude == 0 || !result.Longitude.HasValue || result.Longitude == 0)
            {
                //var location = geolocationService.GeoLocate(new GeoLocation.BusinessEntities.Address()
                //{
                //    AddressLine = result.AddressLine,
                //    Locality = result.City,
                //    AdminDistrict = "Ontario", 
                //    CountryRegion="Canada"
                //});

                //result.Latitude = location.Latitude;
                //result.Longitude = location.Longitude;
            }

            return result;
        }
Example #2
0
        // GET api/stores
        public async Task<IEnumerable<Store>> Get()
        {
            List<Store> result = new List<Store>();
            TextInfo textInfo = CultureInfo.CurrentCulture.TextInfo;
            var pageXml = await this.pageRetrieverFactory.StoreListPageRetriever.RetrievePageXml(String.Empty);
            var query = from s in pageXml.Element("storeSearchResponse").Element("stores").Elements("store") select s;
            foreach (var item in query)
            {
                Store currentStore = new Store();
                currentStore.StoreNumber= Convert.ToInt32(item.Element("locationNumber").Value.Trim());
                currentStore.AddressLine = item.Element("locationAddress1").Value.Trim();
                currentStore.AddressLine = textInfo.ToTitleCase(currentStore.AddressLine.ToLower(CultureInfo.CurrentCulture));
                currentStore.City = ExtractCityName(item.Element("locationCityName").Value.Trim());
                currentStore.TelephoneNumber = String.Format("({0}) {1}", item.Element("phoneAreaCode").Value.Trim(), item.Element("phoneNumber1").Value.Trim());
                currentStore.Latitude = Convert.ToDecimal(item.Element("latitude").Value.Trim());
                currentStore.Longitude = Convert.ToDecimal(item.Element("longitude").Value.Trim());
                result.Add(currentStore);
            }

            return result;
        }