private void HandleRequest(HttpListenerContext ctxt) { var settings = new XmlWriterSettings { // this is crucial to get rid of the BOM header, see https://stackoverflow.com/questions/1755958/how-can-i-remove-the-bom-from-xmltextwriter-using-c Encoding = new System.Text.UTF8Encoding(false), OmitXmlDeclaration = true, ConformanceLevel = ConformanceLevel.Fragment, CloseOutput = false, }; // decode command string url = ctxt.Request.RawUrl; int commandStart = url.IndexOf('/', 1) + 1; string command; if (commandStart != -1) { int commandEnd = url.IndexOf('?', commandStart); if (commandEnd == -1) { commandEnd = url.Length; } command = url.Substring(commandStart, commandEnd - commandStart); } else { command = "inspect"; } using (MemoryStream stream = new MemoryStream()) { using (var writer = XmlWriter.Create(stream, settings)) { var htmlWriter = new HtmlWriter(writer); try { writer.WriteStartElement("html"); writer.WriteStartElement("head"); WriteStyle(htmlWriter); writer.WriteEndElement(); writer.WriteStartElement("body"); switchStart: switch (command) { case "inspect": ExecuteInspect(htmlWriter, ctxt.Request.QueryString); break; default: command = "inspect"; goto switchStart; } writer.WriteEndElement(); writer.WriteEndElement(); } catch (Exception ex) { htmlWriter.Write(ex.Message); htmlWriter.Break(); using (htmlWriter.Tag("pre")) htmlWriter.Write(ex.StackTrace); writer.WriteFullEndElement(); } } stream.Flush(); ctxt.Response.ContentLength64 = stream.Length; stream.Position = 0; stream.WriteTo(ctxt.Response.OutputStream); } ctxt.Response.OutputStream.Close(); }
private void NamespaceLink(HtmlWriter writer, Namespace ns) { NamespaceLink(writer, ns, ns.FullName); }
private void AssemblyLink(HtmlWriter writer, Assembly assembly) { AssemblyLink(writer, assembly, assembly.Name); }
private void TypeLink(HtmlWriter writer, Type type) { TypeLink(writer, type, type.PrettyName()); }
private void FunctionLink(HtmlWriter writer, MethodBase method) { FunctionLink(writer, method, method.DeclaringType.Name + "." + method.Name); }
private void WriteAttributes(HtmlWriter writer, object[] attributes, bool stacked = true) { if (attributes.Length == 0) { return; } if (!stacked) { writer.Write("["); } for (int i = 0; i < attributes.Length; i++) { if (stacked) { writer.Write("["); } else if (i > 0) { writer.Write(" ,"); } var type = attributes[i].GetType(); TypeLink(writer, type); var properties = type.GetProperties(AllInstanceBindings); if (properties.Length > 0) { bool first = true; for (int j = 0; j < properties.Length; j++) { var prop = properties[j]; if (!prop.CanRead || prop.GetIndexParameters().Length > 0 || prop.Name == "TypeId") { continue; } if (!first) { writer.Write(", "); } else { writer.Write(" ( "); } first = false; writer.Write(prop.Name); writer.Write(" = "); var value = prop.GetValue(attributes[i], null); if (value == null) { writer.Write("null"); } else if (value is string) { writer.Write("\""); writer.Write((value as string)); writer.Write("\""); } } if (!first) { writer.Write(" ) "); } } if (stacked) { writer.Write("]"); writer.Break(); } } if (!stacked) { writer.Write("]"); } }
public static HtmlWriter.TagHandle ContainerFluid(this HtmlWriter writer) { return(writer.Tag("div", "class", "container-fluid")); }
public TagHandle(HtmlWriter writer, string tag) { m_Writer = writer; m_Tag = tag; }