/// <summary> /// Constructor /// </summary> public HtmlComponentControl(IApplicationComponent component, ActiveTemplate template) { InitializeComponent(); _component = component; _template = template; #if DEBUG _webBrowser.IsWebBrowserContextMenuEnabled = true; #else _webBrowser.IsWebBrowserContextMenuEnabled = false; #endif _component.AllPropertiesChanged += AllPropertiesChangedEventHandler; this.Disposed += new EventHandler(DisposedEventHandler); ReloadPage(); }
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; } }