Exemple #1
0
        private WC.IE OpenVehicleInfoWindow(WC.TableCellCollection tdsInput)
        {
            Func <WC.TableCellCollection, WC.IE> f = (tds) => {
                var link   = tds[2].Links.First();
                var target = link.GetAttributeValue("target");
                link.SetAttributeValue("target", _vehicleInfoTargetName);
                link.Click();
                try {
                    vehicleInfoIE = WC.IE.AttachTo <WC.IE>(WC.Find.ByTitle(t => {
                        return(t.StartsWith("Manheim - PowerSearch"));
                    }));
                } catch { }
                if (vehicleInfoIE == null || vehicleInfoIE.Title == "Manheim - PowerSearch - Search Results")
                {
                    try {
                        vehicleInfoIE = WC.IE.AttachTo <WC.IE>(WC.Find.ByTitle(t => {
                            return(t == "Manheim - PowerSearch - Search Results");
                        }));
                        if (vehicleInfoIE != null)
                        {
                            var vehicle_detail_row = vehicleInfoIE.TableRow(WC.Find.ByClass("vehicle_detail_row "));
                            if (vehicle_detail_row.Exists)
                            {
                                var link1 = vehicle_detail_row.Link("vehicleDetailsLink_0");
                                if (link1 != null)
                                {
                                    link1.Click();
                                    try {
                                        return(WC.IE.AttachTo <WC.IE>(WC.Find.ByTitle(t => {
                                            return t == "Manheim - PowerSearch - Vehicle Details";
                                        })));
                                    } catch { }
                                }
                            }
                            Log = new Exception("VehicleInfo window not found.");
                        }
                    } catch { }
                }
                return(vehicleInfoIE);
            };

            if (Application.Current.Dispatcher.CheckAccess())
            {
                return(f(tdsInput));
            }
            var d = Application.Current.Dispatcher.BeginInvoke(f, tdsInput);

            d.Wait(TimeSpan.FromSeconds(30));
            return(d.Result as WC.IE);
        }
Exemple #2
0
        private static void AddPreSale(Model.ManheimEntities manheimModel, Model.Auction auctionEntity, DateTime saleDate, WC.TableCellCollection tds, string vin, WC.IE vehicleInfoIE)
        {
            var rightContent = vehicleInfoIE.Div("rightContent");

            #region Vehicle

            #region Grade
            var grade      = 0.0;
            var lastColumn = rightContent.Div(WC.Find.ByClass("lastColumn"));
            if (lastColumn.Exists)
            {
                var gradeLink = lastColumn.Link(WC.Find.ByText(new Regex("Grade")));
                if (gradeLink.Exists)
                {
                    double.TryParse(Regex.Replace(gradeLink.Text, @"[^\d.]", ""), out grade);
                }
            }
            #endregion


            var mmrElement = vehicleInfoIE.Link("mmrHover");
            int mmrPrice   = 0;
            if (mmrElement.Exists)
            {
                int.TryParse(mmrElement.Text, NumberStyles.AllowThousands | NumberStyles.AllowCurrencySymbol, NumberFormatInfo.CurrentInfo, out mmrPrice);
            }
            var div   = vehicleInfoIE.Div(new Regex("vdpTab_detail-1"));
            var table = div.Tables.First();
            if (table != null)
            {
                var vehicleEntity = manheimModel.Vehicles.SingleOrDefault(v => v.VIN == vin);
                if (vehicleEntity == null)
                {
                    vehicleEntity       = SetVehicle(table);
                    vehicleEntity.Grade = grade;
                    manheimModel.Vehicles.Add(vehicleEntity);
                }
                else
                {
                    UpdateVehicle(vehicleEntity, table);
                }
                vehicleEntity.MMR = mmrPrice;
                manheimModel.SaveChanges();
                #endregion

                #region Seller
                var sellerElement = rightContent.Div(WC.Find.ByClass("firstColumn")).ElementWithTag("li", WC.Find.First());
                var sellerName    = sellerElement.Exists ? sellerElement.Text : "";
                var sellerEntity  = manheimModel.Sellers.SingleOrDefault(s => s.Name == sellerName);
                if (sellerEntity == null)
                {
                    sellerEntity = new Model.Seller()
                    {
                        Name = sellerName
                    };
                    manheimModel.Sellers.Add(sellerEntity);
                    manheimModel.SaveChanges();
                }
                #endregion

                #region PreSale
                var preSale = new Model.PreSale()
                {
                    Ln       = int.Parse(tds[0].Text.Split('-')[0]),
                    Run      = int.Parse(tds[0].Text.Split('-')[1]),
                    SaleDate = saleDate
                };
                lock (auctionEntity) {
                    preSale.Vehicle = vehicleEntity;
                    preSale.Auction = auctionEntity;
                    preSale.Seller  = sellerEntity;
                    manheimModel.PreSales.Add(preSale);
                }
                #endregion
                manheimModel.SaveChanges();
            }
        }