Esempio n. 1
0
        public CarMaxVehicle LoadDetailCar(XmlNode node)
        {
            var newVehicle = new CarMaxVehicle();

            try
            {
                var apiUrlNode = node.SelectSingleNode("*[local-name()='links']/*[local-name()='resourcelink']/*[local-name()='href']");
                if (apiUrlNode == null)
                {
                    return(null);
                }
                newVehicle.CarMaxVehicleId = Convert.ToInt32(Path.GetFileName(apiUrlNode.InnerText));
                newVehicle.Url             = string.Format("https://www.carmax.com/cars/{0}", newVehicle.CarMaxVehicleId);
                newVehicle.Year            = Convert.ToInt32(node.SelectSingleNode("*[local-name()='year']").InnerText);
                newVehicle.Make            = node.SelectSingleNode("*[local-name()='make']").InnerText;
                newVehicle.Model           = node.SelectSingleNode("*[local-name()='model']").InnerText;
                newVehicle.Price           = Convert.ToInt32(node.SelectSingleNode("*[local-name()='price']").InnerText);
                newVehicle.Miles           = Convert.ToInt32(node.SelectSingleNode("*[local-name()='miles']").InnerText.Replace("K", "000"));
                newVehicle.ExteriorColor   = node.SelectSingleNode("*[local-name()='exteriorcolor']").InnerText;
                newVehicle.InteriorColor   = node.SelectSingleNode("*[local-name()='interiorcolor']").InnerText;
                newVehicle.Used            = node.SelectSingleNode("*[local-name()='isnew']").InnerText.Equals("false");
                newVehicle.FullPhotos      = node.SelectSingleNode("*[local-name()='photourl']").InnerText;
                newVehicle.ThumbnailPhotos = newVehicle.FullPhotos;
                newVehicle.Stock           = node.SelectSingleNode("*[local-name()='stocknumber']").InnerText;
                newVehicle.DriveTrain      = node.SelectSingleNode("*[local-name()='drivetrain']").InnerText;
                newVehicle.Transmission    = node.SelectSingleNode("*[local-name()='transmission']").InnerText;
                newVehicle.Vin             = node.SelectSingleNode("*[local-name()='vin']").InnerText;
                var carmaxStoreId = Convert.ToInt32(node.SelectSingleNode("*[local-name()='storeid']").InnerText);
                newVehicle.StoreId = (new VINMarketSqlHelper()).GetId("SELECT StoreId FROM CarMaxStore WHERE CarMaxStoreId = " + carmaxStoreId);

                newVehicle.UpdatedDate = DataCommonHelper.GetChicagoDateTime(DateTime.Now);
                newVehicle.CreatedDate = DataCommonHelper.GetChicagoDateTime(DateTime.Now);
            }
            catch (Exception ex)
            {
                throw;
            }

            return(newVehicle);
        }
Esempio n. 2
0
        private CarMaxStoreViewModel GetStoreDetail(XmlNode node)
        {
            try
            {
                var fullNameNode = node.SelectSingleNode(".//h4[@class='store-locator--result--name']/a");
                var fullName     = fullNameNode.InnerText.Trim();
                var url          = "https://www.carmax.com" + fullNameNode.Attributes["href"].Value;

                var name = node.SelectSingleNode("./div[@class='store-locator--result--header']") != null?node.SelectSingleNode("./div[@class='store-locator--result--header']").InnerText.TrimEnd() : fullName;

                var address  = node.SelectSingleNode(".//*[@data-react='GetDirectionsButton']/*[@data-scope='store']/*[@data-prop='Street']").InnerText;
                var city     = node.SelectSingleNode(".//*[@data-react='GetDirectionsButton']/*[@data-scope='store']/*[@data-prop='City']").InnerText;
                var stateStr = node.SelectSingleNode(".//*[@data-react='GetDirectionsButton']/*[@data-scope='store']/*[@data-prop='State']").InnerText;
                var zip      = Convert.ToInt32(node.SelectSingleNode(".//*[@data-react='GetDirectionsButton']/*[@data-scope='store']/*[@data-prop='ZipCode']").InnerText);
                var phone    = node.SelectSingleNode(".//span[@class='store-locator--result--phone unclickable']").InnerText.Trim();
                var id       = Convert.ToInt64(Path.GetFileName(url));

                var newStore = new CarMaxStoreViewModel()
                {
                    CarMaxStoreId = id,
                    Name          = name,
                    FullName      = fullName,
                    Url           = url,
                    Address       = address,
                    City          = city,
                    State         = stateStr,
                    ZipCode       = zip,
                    Phone         = phone,
                    CreatedDate   = DataCommonHelper.GetChicagoDateTime(DateTime.Now),
                    UpdatedDate   = DataCommonHelper.GetChicagoDateTime(DateTime.Now)
                };

                return(newStore);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Esempio n. 3
0
        public CarMaxVehicle LoadDetailCarNew(CarMaxVehicle newVehicle)
        {
            //imageUrl = https://img2.carmax.com/api/images/12702986
            var content     = WebHandler.DownloadContent("https://beta.carmax.com/cars/" + newVehicle.CarMaxVehicleId);
            var xmlDocument = WebHandler.DownloadDocument(content);
            var vinNode     = xmlDocument.SelectSingleNode("//*[@class='card-grid-section--action-bar-item'][2]/span[2]");

            if (vinNode == null)
            {
                return(null);
            }
            newVehicle.Vin = vinNode.InnerText.Trim();
            var infoNodes = xmlDocument.SelectNodes("//div[@class='card--text-block-list--row']");

            if (infoNodes != null)
            {
                foreach (XmlNode item in infoNodes)
                {
                    if (item.ChildNodes[1] == null || item.ChildNodes[3] == null)
                    {
                        continue;
                    }

                    var text  = item.ChildNodes[1].InnerText.Trim();
                    var value = item.ChildNodes[3].InnerText.Trim();
                    switch (text)
                    {
                    case "Drive":
                        newVehicle.DriveTrain = value;
                        break;

                    case "Transmission":
                        newVehicle.Transmission = value;
                        break;

                    case "Exterior":
                        newVehicle.ExteriorColor = value;
                        break;

                    case "Interior":
                        newVehicle.InteriorColor = value;
                        break;
                    }
                }
            }

            var featureNodes = xmlDocument.SelectNodes("//ul/li[@class='card-grid-section--item-list-element']");

            if (featureNodes != null)
            {
                var list = new List <string>();
                foreach (XmlNode item in featureNodes)
                {
                    list.Add(item.InnerText);
                }
                newVehicle.Features = string.Join(",", list);
            }

            var storeNode = xmlDocument.SelectSingleNode("//*[@id='qualifiers-global']");

            if (storeNode != null)
            {
                var jsonObj       = (JObject)JsonConvert.DeserializeObject(storeNode.Attributes["data-qualifiers"].Value);
                var carmaxStoreId = Convert.ToInt32(((JValue)jsonObj["StoreId"]).Value);
                newVehicle.StoreId = (new VINMarketSqlHelper()).GetId("SELECT StoreId FROM CarMaxStore WHERE CarMaxStoreId = " + carmaxStoreId);
            }

            var stockNode = xmlDocument.SelectSingleNode("//*[@class='card-grid-section--action-bar-item'][1]/span[2]");

            if (stockNode != null)
            {
                newVehicle.Stock = stockNode.InnerText.Trim();
            }
            var mpgCityNode = xmlDocument.SelectSingleNode("//*[@class='mpg']/*[@class='mpg--value']");

            if (mpgCityNode != null)
            {
                newVehicle.MPGCity = Convert.ToInt32(mpgCityNode.InnerText.Trim());
            }
            var mpgHighway = xmlDocument.SelectSingleNode("//*[@class='mpg'][2]/*[@class='mpg--value']");

            if (mpgHighway != null)
            {
                newVehicle.MPGHighway = Convert.ToInt32(mpgHighway.InnerText.Trim());
            }
            var priceNode = xmlDocument.SelectSingleNode("//*[@class='price-mileage--price-container']/*[@class='price-mileage--value']");

            if (priceNode != null)
            {
                newVehicle.Price = CommonHelper.RemoveSpecialCharactersAndReturnNumber(priceNode.InnerText.Trim());
            }
            var milesNode = xmlDocument.SelectSingleNode("//*[@class='price-mileage--mileage-container']/*[@class='price-mileage--value']");

            if (milesNode != null)
            {
                newVehicle.Miles = Convert.ToInt32(milesNode.InnerText.Trim().ToLower().Replace("k", "000").Replace("<", "").Replace(">", ""));
            }
            newVehicle.Used        = newVehicle.Miles > 1000;
            newVehicle.UpdatedDate = DataCommonHelper.GetChicagoDateTime(DateTime.Now);
            newVehicle.CreatedDate = DataCommonHelper.GetChicagoDateTime(DateTime.Now);

            return(newVehicle);
        }
Esempio n. 4
0
        public CarMaxVehicle LoadDetailCar(int year, string make, string model, string trim, long carId, string url)
        {
            var newVehicle = new CarMaxVehicle()
            {
                CarMaxVehicleId = carId, Year = year, Make = make, Model = model, Trim = trim, Url = url
            };

            try
            {
                var content     = WebHandler.DownloadContent(url);
                var xmlDocument = WebHandler.DownloadDocument(content);
                var vinNode     = xmlDocument.SelectSingleNode("//*[@class='vin']");
                if (vinNode == null)
                {
                    return(LoadDetailCarNew(newVehicle));
                }

                newVehicle.Vin   = vinNode.ChildNodes[1].Value.Trim();
                newVehicle.Price = CommonHelper.RemoveSpecialCharactersAndReturnNumber(xmlDocument.SelectSingleNode("//*[@class='sansser']/*").ChildNodes[0].Value.Trim());
                //var certifiedNode = xmlDocument.SelectSingleNode("//*[@class='info-container cqc_tombstone_pos']/*[last()]/*/*/*/*/*[last()-1]/*[last()]");
                //newVehicle.Certified = certifiedNode != null && certifiedNode.InnerText.Contains("CarMax Quality Certified");
                var infoNodes = xmlDocument.SelectNodes("//*[@class='info-container cqc_tombstone_pos']/*[last()]/*/*/*/*[last()]/*");
                if (infoNodes != null)
                {
                    foreach (XmlNode item in infoNodes)
                    {
                        if (!(item.Name.Equals("li")) || item.ChildNodes[1] == null)
                        {
                            continue;
                        }

                        var value = item.ChildNodes[1].Value;
                        switch (item.FirstChild.InnerText)
                        {
                        case "Miles":
                            newVehicle.Miles = value.Equals("New") ? 0 : Convert.ToInt32(value.ToLower().Replace("k", "000").Replace("<", "").Replace(">", ""));
                            newVehicle.Used  = !value.Equals("New");
                            break;

                        case "Drive":
                            newVehicle.DriveTrain = value;
                            break;

                        case "Transmission":
                            newVehicle.Transmission = value;
                            break;

                        case "Exterior":
                            newVehicle.ExteriorColor = value;
                            break;

                        case "Interior":
                            newVehicle.InteriorColor = value;
                            break;

                        case "EPA Mileage":
                            var tmp = value.Replace("MPG", "").Split('/');
                            newVehicle.MPGCity    = value.Equals("Not Available") ? 0 : Convert.ToInt32(tmp[0]);
                            newVehicle.MPGHighway = value.Equals("Not Available") ? 0 : Convert.ToInt32(tmp[1]);
                            break;

                        case "Stock #":
                            newVehicle.Stock = value;
                            break;

                        case "Rating":
                            newVehicle.Rating = Convert.ToDecimal(item.ChildNodes[1].InnerText.Replace("(", "").Replace(")", ""));
                            break;
                        }
                    }
                }

                var storeNode = xmlDocument.SelectSingleNode("//*[@id='qualifiers-global']");
                if (storeNode != null)
                {
                    var jsonObj       = (JObject)JsonConvert.DeserializeObject(storeNode.Attributes["data-qualifiers"].Value);
                    var carmaxStoreId = Convert.ToInt32(((JValue)jsonObj["StoreId"]).Value);
                    newVehicle.StoreId = (new VINMarketSqlHelper()).GetId("SELECT StoreId FROM CarMaxStore WHERE CarMaxStoreId = " + carmaxStoreId);
                }

                var features = xmlDocument.SelectNodes("//*[@class='features']/*[2]/*");
                if (features != null)
                {
                    var temp = (from XmlNode item in features select item.InnerText.Trim()).ToList();
                    newVehicle.Features = temp.Any() ? temp.Aggregate((a, b) => a + ',' + b) : string.Empty;
                }

                //var thumbnailImages = xmlDocument.SelectNodes("//*[@id='thumbs']/*");
                //var fullImages = xmlDocument.SelectNodes("//*[@id='photos']/*");
                //if (fullImages != null)
                //{
                //    var temp = (from XmlNode item in fullImages select item.Attributes["src"].Value).ToList();
                //    newVehicle.FullPhotos = temp.Any() ? temp.Aggregate((a, b) => a + ',' + b) : string.Empty;
                //    newVehicle.ThumbnailPhotos = newVehicle.FullPhotos;
                //}

                newVehicle.UpdatedDate = DataCommonHelper.GetChicagoDateTime(DateTime.Now);
                newVehicle.CreatedDate = DataCommonHelper.GetChicagoDateTime(DateTime.Now);
            }
            catch (Exception ex)
            {
                _logging.Error("CARMAX - LoadDetailVehicle", ex);
            }

            return(newVehicle);
        }