-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGenerateHTMLStatusPage.cs
More file actions
86 lines (75 loc) · 2.94 KB
/
GenerateHTMLStatusPage.cs
File metadata and controls
86 lines (75 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace GenerateHTMLStatusPage
{
/// <summary>
/// Takes in a list of items and generates an HTML page that is stored
/// in the program's subdirectory.
/// </summary>
public sealed class ItemStatusPageGenerator
{
private static string Encode(string input)
{
StringBuilder sb = new StringBuilder(input);
sb.Replace("&", "&");
sb.Replace("<", "<");
sb.Replace(">", ">");
sb.Replace("\"", """);
sb.Replace("'", "'");
return sb.ToString();
}
public void Update(IEnumerable<Item> items)
{
if (!Directory.Exists("web"))
Directory.CreateDirectory("web");
using (StreamWriter op = new StreamWriter("web/item-status.html"))
{
op.WriteLine("<html>");
op.WriteLine(" <head>");
op.WriteLine(" <title>Item Status</title>");
op.WriteLine(" </head>");
op.WriteLine(" <body bgcolor=\"white\">");
op.WriteLine(" <h1>Item Status</h1>");
op.WriteLine(" <table width=\"100%\">");
op.WriteLine(" <tr>");
op.WriteLine(" <td bgcolor=\"black\"><font color=\"white\">Name</font></td><td bgcolor=\"black\"><font color=\"white\">Description</font></td><td bgcolor=\"black\"><font color=\"white\">Quantity</font></td>");
op.WriteLine(" </tr>");
foreach (var item in items)
{
op.Write(" <tr><td>");
op.Write(Encode(item.Name));
op.Write("</td><td>");
op.Write(Encode(item.Description));
op.Write("</td><td>");
op.Write(item.Quantity);
op.WriteLine("</td></tr>");
}
op.WriteLine(" <tr>");
op.WriteLine(" </table>");
op.WriteLine(" </body>");
op.WriteLine("</html>");
}
}
}
public class Item
{
public string Name { get; set; }
public string Description { get; set; }
public decimal Quantity { get; set; }
}
public static class Program
{
public static void Main()
{
var generator = new ItemStatusPageGenerator();
var items = new List<Item>() {
new Item() { Name = "A", Description = "Red A", Quantity = 2 },
new Item() { Name = "B", Description = "Green B", Quantity = 4 },
new Item() { Name = "C", Description = "Purple 'ish' C", Quantity = 8 },
new Item() { Name = "D", Description = "Teal & Orange D", Quantity = 16 },
};
generator.Update(items);
}
}
}