WebAnswer GetHtmlAnswer() { HtmlPageBuilder html; if (Request != null) { html = new HtmlPageBuilder(Request); } else { html = new HtmlPageBuilder(); html.AddHeader(Properties.Resources.CaveWebServerHeaders); html.AddFooter($" <hr><address>{Server.ServerVersionString} Server at {NetTools.HostName}<br>© {Server.ServerCopyRight}</address>"); string link = "/"; html.Breadcrump.Add(new WebLink() { Link = link, Text = Server.Title }); } foreach (KeyValuePair <string, SerializerTable> t in tables) { SerializerTable table = t.Value; html.StartTable(table.Name, table.Layout); foreach (Row row in table.Rows) { html.WriteRow(row); } html.CloseTable(); } return(html.ToAnswer(lastMessage)); }
/// <summary>Adds result content rows.</summary> /// <param name="rows">The rows.</param> /// <param name="layout">The layout.</param> /// <param name="tableName">Name of the table.</param> public void AddRows(IEnumerable <Row> rows, RowLayout layout, string tableName = null) { if (tableName == null) { tableName = layout.Name; } if (!tables.TryGetValue(tableName, out SerializerTable result)) { tables[tableName] = result = new SerializerTable(layout, tableName); } foreach (Row row in rows) { result.AddRow(row); } }
/// <summary>Adds result content rows.</summary> /// <typeparam name="T"></typeparam> /// <param name="row">The row.</param> /// <param name="tableName">Name of the table.</param> public void AddStruct <T>(T row, string tableName = null) where T : struct { var layout = RowLayout.CreateTyped(typeof(T)); if (tableName == null) { tableName = layout.Name; } if (!tables.TryGetValue(tableName, out SerializerTable result)) { tables[tableName] = result = new SerializerTable(layout, tableName); } result.AddStruct(row); }
private WebAnswer GetPlainAnswer() { using (var ms = new MemoryStream()) { foreach (KeyValuePair <string, SerializerTable> t in tables) { SerializerTable table = t.Value; ms.WriteUtf8($"[Table: {table.Name}]\n"); var writer = new CSVWriter(ms); writer.SetLayout(table.Layout); writer.WriteRows(table.Rows); writer.Close(); ms.WriteUtf8($"#end table: {table.Name}\n\n"); } return(WebAnswer.Plain(Request, lastMessage, ms.ToArray())); } }
WebAnswer GetXmlAnswer() { XmlSerializer.Flags flags = 0; if (TransmitLayout) { flags |= XmlSerializer.Flags.WithLayout; } var xml = new XmlSerializer(Server.JsonVersion, flags); foreach (KeyValuePair <string, SerializerTable> t in tables) { SerializerTable table = t.Value; xml.Serialize(table.Name, table.Layout, table.Rows); } return(WebAnswer.Xml(Request, lastMessage, xml.ToString())); }
WebAnswer GetJsonAnswer() { JsonSerializer.Flags flags = 0; if (SkipMainObject) { flags |= JsonSerializer.Flags.SkipMainObject; } if (TransmitLayout) { flags |= JsonSerializer.Flags.WithLayout; } var json = new JsonSerializer(Server.JsonVersion, flags); foreach (KeyValuePair <string, SerializerTable> t in tables) { SerializerTable table = t.Value; json.Serialize(table.Name, table.Layout, table.Rows); } return(WebAnswer.Json(Request, lastMessage, json.ToString())); }