|
Rank: Newbie Groups: Member
Joined: 3/21/2015 Posts: 8
|
Hi
I'm trying to invoke an array of elements , which works well , but only download the last
this is the code
private void button1_Click(object sender, EventArgs e) {
win = m_WebView.GetDOMWindow(); int Inicio = 0; Element[] links = win.document.getElementsByName("BtnDescarga"); int count = links.Length; for (int i = 0; i < count; i++) //Count = 60 {
string xHTML = links[i].outerHTML; string Argumento = ""; Inicio = 0; if (Indice(ref Inicio, xHTML, ref Argumento) != -1) //get args { if (i == 1) // Used to check arguments, (changing the value 1 by 2, or 5 or X), if I erase this line it downloads the 60th, but always it invokes all elements { object[] param = { (Object)Argumento, (Object)"Recuperacion" }; links[i].InvokeFunction("click", param); } } } }
this is the NewWindow event:
void WebView_NewWindow(object sender, NewWindowEventArgs e) { e.Accepted = false; EO.WebBrowser.WebView webView = (EO.WebBrowser.WebView)sender; webView.Url = e.TargetUrl; }
The next event comes only once
void WebView_BeforeDownload(object sender, BeforeDownloadEventArgs e) { e.ShowDialog = false; e.FilePath = "D:\\Tnt\\Xml\\" + Path.GetFileName(e.FilePath); e.ShowDialog = false; }
|
|
Rank: Newbie Groups: Member
Joined: 3/21/2015 Posts: 8
|
I 'm programming with eo.webbrowser trial version and according to http://www.essentialobjects.com/forum/postst8859_Which-are-the-trial-limitation-of-EO-Browser.aspx , may be the cause of the download?
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,196
|
Hi,
This depends on what your click is trying to do. If your click handler submits or navigate to another page, then there will only be ONE request per window. This is because each window is always paired with a single request/response cycle. Consider the following sequence of events:
1. The window loads a page; 2. You click a link in the page that navigates to another page; 3. The window generates a request A that starts loading the other page, before it receives the contents from the new page, contents of the old page are still on the screen; 4. You click another link in the page that initiates another request B;
At step 4 two things can happen depending on the timing:
1. Request A in step 3 is canceled. Request B in step 4 proceeds, -- OR -- 2. Request B in step 4 is ignored thus allowing request A in step 3 to proceed;
In either case, you will only get one surviving request per window.
The "standard" way to get around this limitation is to use iframes. For example, if you use JavaScript to create an iframe and set the new iframe's src to the download Url, that iframe will start the download. Since each iframe has its own window object, so it can start its own request without canceling other pending requests. This allows you to start multiple downloads at the same time.
Lastly, please keep in mind that by default Chrome has a limit on how many pending request per host (I believe the default is 6). So if you tries to download more files at the same time from the same server than the limit value, additional download won't start.
Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 3/21/2015 Posts: 8
|
Hi,
The click don´t handler submits, it's a callback. I debuged line by line and WOW all files downloaded. So I modify the code:
private void btnDescarga_Click(object sender, EventArgs e) { EO.WebBrowser.DOM.Window win = new EO.WebBrowser.DOM.Window(); win = m_WebView.GetDOMWindow(); int Inicio = 0;
Element[] links = win.document.getElementsByName("BtnDescarga"); int count = links.Length; pb.Maximum = count; pb.Value = 0; pb.Step = 1; Listo.Visible = false;
for (int i = 0; i < count; i++) { string xHTML = links[i].outerHTML; string Argumento = ""; Inicio = 0; if (Indice(ref Inicio, xHTML, ref Argumento) != -1) //get args { Thread.Sleep(500); //Added object[] param = { (Object)Argumento, (Object)"Recuperacion" }; links[i].InvokeFunction("click", param); Thread.Sleep(500); //Added Application.DoEvents(); //Added } pb.PerformStep(); } Listo.Visible = true; pb.Value = 0; }
And now download 55
Is there any way to wait until then download is complete?
Thank's
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,196
|
Hi,
You can handle the WebView's DownloadCompleted event. This event is fired when a download is complete. The WebView does not provide any built-in method for you to wait for this event, however you can write a loop to do so. Inside the loop make sure you call WebView.DoEvents() (not Application.DoEvents).
Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 3/21/2015 Posts: 8
|
Thank's
It works fine with WebView.DoEvents(1500)
|
|