void tready_Tick(object sender, EventArgs e) { try { //stop the timer tready.Stop(); mshtml.IHTMLDocument2 docs2 = (mshtml.IHTMLDocument2)web.Document.DomDocument; mshtml.IHTMLDocument3 docs3 = (mshtml.IHTMLDocument3)web.Document.DomDocument; mshtml.IHTMLElement2 body2 = (mshtml.IHTMLElement2)docs2.body; mshtml.IHTMLElement2 root2 = (mshtml.IHTMLElement2)docs3.documentElement; // Determine dimensions for the image; we could add minWidth here // to ensure that we get closer to the minimal width (the width // computed might be a few pixels less than what we want). int width = Math.Max(body2.scrollWidth, root2.scrollWidth); int height = Math.Max(root2.scrollHeight, body2.scrollHeight); //get the size of the document's body Rectangle docRectangle = new Rectangle(0, 0, width, height); web.Width = docRectangle.Width; web.Height = docRectangle.Height; //if the imgsize is null, the size of the image will //be the same as the size of webbrowser object //otherwise set the image size to imgsize Rectangle imgRectangle; if (imgsize == null) { imgRectangle = docRectangle; } else { imgRectangle = new Rectangle() { Location = new Point(0, 0), Size = imgsize.Value } }; //create a bitmap object Bitmap bitmap = new Bitmap(imgRectangle.Width, imgRectangle.Height); //get the viewobject of the WebBrowser IViewObject ivo = web.Document.DomDocument as IViewObject; using (Graphics g = Graphics.FromImage(bitmap)) { //get the handle to the device context and draw IntPtr hdc = g.GetHdc(); ivo.Draw(1, -1, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, hdc, ref imgRectangle, ref docRectangle, IntPtr.Zero, 0); g.ReleaseHdc(hdc); } //invoke the HtmlImageCapture event bitmap.Save(fileName); bitmap.Dispose(); } catch { //System.Diagnostics.Process.GetCurrentProcess().Kill(); } if (HtmlImageCapture != null) { HtmlImageCapture(this, web.Url); } }
/// <summary> /// Метод модификации WebBrowser для отображения под WPF /// </summary> /// <param name="webbrowser"></param> private void ModifyWebBrowser(ref WebBrowser webbrowser) { htmlDoc = webbrowser.Document as mshtml.HTMLDocument; mshtml.IHTMLDocument2 doc2 = (mshtml.IHTMLDocument2)webbrowser.Document; mshtml.IHTMLDocument3 doc3 = (mshtml.IHTMLDocument3)webbrowser.Document; mshtml.IHTMLElement2 body2 = (mshtml.IHTMLElement2)doc2.body; mshtml.IHTMLElement2 root2 = (mshtml.IHTMLElement2)doc3.documentElement; HeightWebView = root2.scrollHeight; HeightWebFull = body2.scrollHeight; HeightWebMaximum = Math.Max(HeightWebView, HeightWebFull); dH = HeightWebMaximum / 20; }
public void GetOveCars2() { mshtml.IHTMLDocument3 doc3 = (mshtml.IHTMLDocument3) this.mainBrowser.Document; string html = doc3.documentElement.outerHTML; OveSearchResult2Scraper oveSearchResultScraper = new OveSearchResult2Scraper(html); oveSearchResultScraper.CarBinBidsScraped += new Action <List <OveCarBinBid> >(OveCarBinBidsScraped); Thread scraperThread = new Thread(new ThreadStart(oveSearchResultScraper.GetCars)) { IsBackground = true, Priority = ThreadPriority.Normal }; scraperThread.Start(); }
public void GetManheimCars() { mshtml.IHTMLDocument3 doc3 = (mshtml.IHTMLDocument3) this.mainBrowser.Document; string html = doc3.documentElement.outerHTML; ManheimSearchResultScraper manheimSearchResultScraper = new ManheimSearchResultScraper(html); manheimSearchResultScraper.CarInfoScraped += new Action <Dictionary <string, string> >(ManheimCarInfoScraped); Thread scraperThread = new Thread(new ThreadStart(manheimSearchResultScraper.GetCars)) { IsBackground = true, Priority = ThreadPriority.Normal }; scraperThread.Start(); }
public void loadGeofence(WebBrowser webBrowser, Geofence geofence) { if (webBrowser != null) { try { htmlDocument = (mshtml.IHTMLDocument3)webBrowser.Document; mshtml.IHTMLElementCollection collection = htmlDocument.getElementsByName("formGeofence"); foreach (mshtml.HTMLInputElement element in collection.item(name: "formGeofence")) { if (element.id == "geofenceId") { element.value = geofence.Id.ToString(); } if (element.id == "geofenceCoordinates") { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("["); foreach (Coordinate coordinate in geofence.getPoints()) { stringBuilder.Append("{\"Latitude\":\""); stringBuilder.Append(coordinate.latitude.ToString()); stringBuilder.Append("\",\"Longitude\":\""); stringBuilder.Append(coordinate.longitude.ToString()); stringBuilder.Append("\"},"); } stringBuilder.Remove(stringBuilder.Length - 1, 1); stringBuilder.Append("]"); element.value = stringBuilder.ToString(); } if (element.id == "geofenceName") { element.value = geofence.Name; } if (element.id == "geofenceSubmit") { mshtml.HTMLInputElement btnSubmit = element; btnSubmit.click(); } } } catch { } } }
public void loadPoi(WebBrowser webBrowser, Poi poi) { if (webBrowser != null) { htmlDocument = (mshtml.IHTMLDocument3)webBrowser.Document; mshtml.IHTMLElementCollection collection = htmlDocument.getElementsByName("formPoi"); foreach (mshtml.HTMLInputElement element in collection.item(name: "formPoi")) { if (element.id == "poiId") { element.value = poi.Id.ToString(); } if (element.id == "poiLatitude") { element.value = poi.Coordinate.latitude.ToString(); } if (element.id == "poiLongitude") { element.value = poi.Coordinate.longitude.ToString(); } if (element.id == "poiName") { element.value = poi.Name; } if (element.id == "poiDescription") { element.value = poi.Description; } if (element.id == "poiIcon") { element.value = poi.Image; } if (element.id == "poiSubmit") { mshtml.HTMLInputElement btnSubmit = element; btnSubmit.click(); } } } }
public void processCommand(WebBrowser webBrowser, MapCommand mapCommand) { if (webBrowser != null) { htmlDocument = (mshtml.IHTMLDocument3)webBrowser.Document; mshtml.IHTMLElementCollection collection = htmlDocument.getElementsByName("formCommand"); if (collection.item(name: "formCommand") == null) return; foreach (mshtml.HTMLInputElement element in collection.item(name: "formCommand")) { if (element.id == "commandId") { element.value = mapCommand.Id.ToString(); } if (element.id == "commandName") { element.value = mapCommand.Name; } if (element.id == "commandValue") { element.value = mapCommand.Value; } if (element.id == "commandSubmit") { mshtml.HTMLInputElement btnSubmit = element; btnSubmit.click(); } } } }
public void loadTracker(WebBrowser webBrowser, TrackerItem trackerItem, TrackerData trackerData, string displayMember) { if (webBrowser != null) { htmlDocument = (mshtml.IHTMLDocument3)webBrowser.Document; mshtml.IHTMLElementCollection collection = htmlDocument.getElementsByName("formTracker"); foreach (mshtml.HTMLInputElement element in collection.item(name: "formTracker")) { if (element.id == "trackerId") { element.value = trackerData.Tracker.Id.ToString(); } if (element.id == "trackerImei") { element.value = trackerData.Tracker.TrackerImei; } if (element.id == "trackerLabel") { if (displayMember == "VehicleRegistration") { element.value = trackerData.Tracker.VehicleRegistration; } else if (displayMember == "DriverName") { element.value = trackerData.Tracker.DriverName; } else if (displayMember == "VehicleModel") { element.value = trackerData.Tracker.VehicleModel; } else if (displayMember == "OwnerName") { element.value = trackerData.Tracker.OwnerName; } else if (displayMember == "TrackerImei") { element.value = trackerData.Tracker.TrackerImei; } else if (displayMember == "SimNumber") { element.value = trackerData.Tracker.SimNumber; } } if (trackerData.IsDataEmpty == false) { if (element.id == "trackerLatitude") { element.value = trackerData.Coordinate.latitude.ToString(); } if (element.id == "trackerLongitude") { element.value = trackerData.Coordinate.longitude.ToString(); } if (element.id == "trackerDegrees") { element.value = trackerData.Degrees.ToString(); } if (element.id == "trackerIcon") { element.value = trackerData.Tracker.ImageNumber.ToString(); } if (element.id == "trackerIconStatus") { if (trackerData.Speed > 0 && trackerData.ACC == true) { element.value = "driver"; } else if (trackerData.Speed == 0 && trackerData.ACC == false) { element.value = "stop"; } else if (trackerData.Speed == 0 && trackerData.ACC == true) { element.value = "idle"; } else if (trackerData.SOS == true) { element.value = "alarm"; } else { element.value = "lost"; } } if (element.id == "trackerIconAlert") { if (trackerData.Tracker.DateTimeExpired.CompareTo(DateTime.Now) <= 0 /*|| trackerItem.Tracker.VehicleRegistrationExpiry.CompareTo(DateTime.Now) <= 0*/) { element.value = "alarmExpiry"; } else if (trackerData.DateTime.Subtract(DateTime.Now).Hours > 1) { element.value = "alarmLostTracker"; } else if (trackerData.Speed > 0 && trackerData.ACC == false) { element.value = "alarmBreakDown"; } else if (trackerData.OverSpeed == true) { element.value = "alarmOverSpeed"; } else if (trackerData.GpsSatellites < 3) { element.value = "alarmLostSignalGps"; } else if (trackerData.GsmSignal < 5) { element.value = "alarmLostSignalGsm"; //} else if (trackerData.DateTime.Subtract(DateTime.Now) > (new TimeSpan(01, 00, 00))) { // element.value = "alarmLostTracker"; } else if ((trackerData.Mileage - trackerData.Tracker.MileageInitial) > trackerData.Tracker.MileageLimit) { element.value = "alarmMileageLimit"; } else if (trackerData.Geofence != null) { element.value = "alarmGeofence"; } else { element.value = "alarmOk!"; } } } if (element.id == "trackerIsEnabled") { element.value = trackerItem.IsChecked ? "1" : "0"; } if (element.id == "trackerSubmit") { mshtml.HTMLInputElement buttonSubmit = element; buttonSubmit.click(); } } } }