public bool Render(object o, string description, int depth, XhtmlTextWriter writer) { //there are two principal ways of rendering an object, // if it's an enumerable we render each object as a row in a table // if it's jut an object we render each property of the object as a row in a table if(!String.IsNullOrWhiteSpace(description)) { writer.RenderBeginTag(HtmlTextWriterTag.H3); writer.Write(description); writer.RenderEndTag(); writer.WriteLine(); } if (depth <= 0) return true; if (o is IEnumerable && !(o is String)) return RenderEnumerable((IEnumerable)o, depth, writer); else return RenderObject(o, depth, writer); }
/// <summary> /// Renders this instance. /// </summary> public void Render() { using (var html = new XhtmlTextWriter(this.Context.Writer)) { // messages html.AddAttribute(HtmlTextWriterAttribute.Class, "messages"); html.AddAttribute(HtmlTextWriterAttribute.Id, "message"); html.RenderBeginTag(HtmlTextWriterTag.Div); switch (this.Scope) { case MessageScope.Error: WriteMessage(html, "error", Errors.GenericMessage); break; case MessageScope.Warning: WriteMessage(html, "warning", Titles.Warning); break; default: WriteMessage(html, "success", Titles.Success); break; } // end messages html.RenderEndTag(); } }
public bool RenderEnumerable(IEnumerable enumerable, int depth, XhtmlTextWriter writer) { var elementType = GetElementTypeOfEnumerable(enumerable); if (elementType == null) return false; //get the members (fields and properties) var members = GetMembers(elementType); //write the headers and start the table writer.RenderBeginTag(HtmlTextWriterTag.Table); //if the element type is an element that needs to be rendered atomically we use a different method if(IsSimpleType(elementType)) { writer.RenderBeginTag(HtmlTextWriterTag.Tr); writer.RenderBeginTag(HtmlTextWriterTag.Th); writer.Write(elementType.Name); writer.RenderEndTag(); writer.RenderEndTag(); foreach (var element in enumerable) { writer.RenderBeginTag(HtmlTextWriterTag.Tr); writer.RenderBeginTag(HtmlTextWriterTag.Td); writer.Write(element.ToString()); writer.RenderEndTag(); writer.RenderEndTag(); } } else { writer.RenderBeginTag(HtmlTextWriterTag.Tr); foreach (var member in members) { writer.RenderBeginTag(HtmlTextWriterTag.Th); writer.Write(member.Name); writer.RenderEndTag(); } writer.RenderEndTag(); //tr writer.WriteLine(); //write all the members foreach (var element in enumerable) { writer.RenderBeginTag(HtmlTextWriterTag.Tr); foreach (var member in members) { writer.RenderBeginTag(HtmlTextWriterTag.Td); RenderMember(member, element, depth, writer); writer.RenderEndTag(); //td } writer.RenderEndTag(); //tr writer.WriteLine(); } } //end the table writer.RenderEndTag(); writer.WriteLine(); return true; }
public bool RenderObject(object o, int depth, XhtmlTextWriter writer) { var objectType = o.GetType(); if(IsSimpleType(objectType)) { writer.RenderBeginTag(HtmlTextWriterTag.P); writer.Write(o.ToString()); writer.RenderEndTag(); writer.WriteLine(); return true; } //get the members (fields and properties) var members = GetMembers(objectType); //create a two column table containing member and then value writer.RenderBeginTag(HtmlTextWriterTag.Table); //write a header containing the class name writer.RenderBeginTag(HtmlTextWriterTag.Tr); writer.AddAttribute(HtmlTextWriterAttribute.Colspan, "2"); writer.RenderBeginTag(HtmlTextWriterTag.Th); writer.Write(objectType.Name); writer.RenderEndTag(); //th writer.RenderEndTag(); //tr foreach (var member in members) { writer.RenderBeginTag(HtmlTextWriterTag.Tr); writer.AddAttribute(HtmlTextWriterAttribute.Class, "left"); writer.RenderBeginTag(HtmlTextWriterTag.Th); writer.Write(member.Name); writer.RenderEndTag(); //th writer.RenderBeginTag(HtmlTextWriterTag.Td); RenderMember(member, o, depth, writer); writer.RenderEndTag(); //td writer.RenderEndTag(); //tr } writer.RenderEndTag(); //table writer.WriteLine(); return true; }
private void Reformat() { // // Write out the HTML document lead. // StringWriter sw = new StringWriter(); XhtmlTextWriter htmlWriter = new XhtmlTextWriter(sw, " "); htmlWriter.WriteLine("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"); htmlWriter.AddAttribute("xmlns", "http://www.w3.org/1999/xhtml"); htmlWriter.RenderBeginTag(HtmlTextWriterTag.Html); htmlWriter.RenderBeginTag(HtmlTextWriterTag.Head); htmlWriter.RenderBeginTag(HtmlTextWriterTag.Title); htmlWriter.WriteEncodedText(Path.GetFileNameWithoutExtension(Mask.EmptyString(DocumentPath, _defaultFileName))); htmlWriter.RenderEndTag(); htmlWriter.AddAttribute(HtmlTextWriterAttribute.Type, "text/css"); htmlWriter.RenderBeginTag(HtmlTextWriterTag.Style); htmlWriter.Write(@"a:link{ color:#00c} body{ background:#fff; font-size:83%; font-family:arial,sans-serif} td, th{ font-size:100%} td{ border:solid 1px #aaa; padding:5px} table{ border-collapse:separate} h1{ font-size:x-large; margin-top:0px} h2{ font-size:large} h3{ font-size:medium} h4{ font-size:small} img{ border:0} pre{ margin-left:2em; padding:0.5em; border-left:3px solid #ccc}"); htmlWriter.RenderEndTag(/* style */); htmlWriter.RenderEndTag(/* head */); htmlWriter.RenderBeginTag(HtmlTextWriterTag.Body); // // Format the wiki into the HTML body. // new HtmlFormatter().Format(new WikiParser().Parse(new StringReader(_wikiBox.Text)), htmlWriter); // // Conclude the HTML document. // htmlWriter.RenderEndTag(/* body */); htmlWriter.RenderEndTag(/* html */); string html = sw.GetStringBuilder().ToString().Replace("\r", string.Empty); // // Update the WebBrowser with the HTML preview. // _webBrowser.AllowNavigation = true; _webBrowser.DocumentText = html; // // Update the RichTextBox with the HTML source and highlight // the markup. // _htmlBox.Clear(); _htmlBox.Text = html; HighlightMarkup(_htmlBox); // // The preview is now up to date with the wiki changes. // _wikiChanged = false; }