internal void ReloadPage() { Dictionary <string, object> context = new Dictionary <string, object>(); context["Component"] = _component; _cachedHtml = _template.Evaluate(context); if (this.Visible) { _webBrowser.DocumentText = _cachedHtml; } }
public void WriteHtml(TextWriter writer) { try { var request = WebRequest.Create(TemplateUrl); var response = (HttpWebResponse)request.GetResponse(); using (var s = response.GetResponseStream()) { // doubt that GetResponseStream ever returns null, but just in case if (s == null) { _job.SetError("No response stream available."); return; } using (var reader = new StreamReader(s, GetEncoding(response.CharacterSet))) { var template = new ActiveTemplate(reader); var html = template.Evaluate(_variables); writer.Write(html); } } } catch (WebException e) { // explicitly handle 404 to provide a helpful error message if (e.Status == WebExceptionStatus.ProtocolError && ((HttpWebResponse)e.Response).StatusCode == HttpStatusCode.NotFound) { _job.SetError(string.Format("The template {0} was not found (404).", TemplateUrl)); } else { _job.SetError(e.Message); } throw; } catch (Exception e) { _job.SetError(e.Message); throw; } }