protected override void BeforeClientNotification(RetrieverDoneArgs rda) { // A WMS server object is created here because doing so causes the // returned WMS capabilities description to be parsed. During that // parsing, schema or DTD URIs might be invoked by the parser, which // will cause additional http requests to be sent to the net. We // want all that to go on in the worker thread, so that the client // thread won't have to block waiting for them to occur in the UI // thread. rda.destinationObject = new Server(rda.DestinationFile); }
private void onContentReady(System.Object sender, RetrieverDoneArgs ea) { // This function is called on the UI thread when a message is sent // from the worker thread. It merely invokes any listeners and then // terminates the retrieval request. if (this.monitor.Enabled) { this.monitor.Stop(); } if (this.done != null) { this.done(this, ea); } this.endRequest(); }
private void monitorTick(System.Object sender, System.EventArgs ea) { if (this.state != RetrieverState.Retrieving) { return; } if (this.canceled) { this.endRequest(); return; } System.TimeSpan span = System.DateTime.Now - this.startTime; if (span > this.timeoutInterval) { this.endRequest(); if (this.done != null) { RetrieverDoneArgs pda = new RetrieverDoneArgs(this); pda.reason = RetrieverDoneArgs.CompletionReason.TimedOut; this.done(this, pda); } return; } span = System.DateTime.Now - this.previousProgressTime; if (span > this.progressInterval) { if (this.progress != null) { RetrieverProgressArgs pea = new RetrieverProgressArgs(this); this.progress(this, pea); } this.previousProgressTime = System.DateTime.Now; } }
private void sendMessageToUiThread(RetrieverDoneArgs rda) { this.owner.Invoke( new RetrieverDoneEventHandler(this.onContentReady), new object[] { System.Threading.Thread.CurrentThread, rda }); }
protected virtual void BeforeClientNotification(RetrieverDoneArgs rda) { return; // default implementation returns w/o doing anything. }
private void onRetrieval(System.IAsyncResult ar) { // This function is called by the System.Net.WebRequest class // on the *worker* thread, not the UI thread. System.Diagnostics.Debug.Assert(ar.IsCompleted); System.Net.WebResponse webResponse = null; try { webResponse = this.webRequest.EndGetResponse(ar); } catch (System.Net.WebException e) { if (e.Status == System.Net.WebExceptionStatus.RequestCanceled) { return; // the request was previously cancelled, a normal condition } else if (e.Status == System.Net.WebExceptionStatus.Success) { // ' Don't really understand this one. Why would an exception be thrown // if the request worked? Anyway, allow for it. System.Diagnostics.Debug.Assert(webResponse != null); } else { // Send the UI thread a message saying an error occurred. RetrieverDoneArgs erda = new RetrieverDoneArgs(this); erda.reason = RetrieverDoneArgs.CompletionReason.Error; erda.Message = e.Message; this.sendMessageToUiThread(erda); return; } } string suffixedDestination = Wms.Client.ExtensionMap.AddSuffixToPath(this.destination, webResponse.ContentType); try { System.IO.Stream rs = webResponse.GetResponseStream(); copyStreamToFile(webResponse.GetResponseStream(), suffixedDestination); } catch (System.Exception e) { // Send the UI thread a message saying an error occurred. RetrieverDoneArgs erda = new RetrieverDoneArgs(this); erda.reason = RetrieverDoneArgs.CompletionReason.Error; erda.Message = e.Message; this.sendMessageToUiThread(erda); return; } finally { webResponse.Close(); // closes the response stream } // Send the UI thread a message saying the file is ready. RetrieverDoneArgs rda = new RetrieverDoneArgs(this); rda.destinationFile = suffixedDestination; rda.contentLength = webResponse.ContentLength; rda.contentType = webResponse.ContentType; this.BeforeClientNotification(rda); this.sendMessageToUiThread(rda); }