forked from cpe433-264/CPE433-64
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StatPlugin.cs
50 lines (46 loc) · 1.21 KB
/
StatPlugin.cs
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
using System;
using System.Collections.Generic;
using System.Text;
namespace DNWS
{
class StatPlugin : IPlugin
{
protected static Dictionary<String, int> statDictionary = null;
public StatPlugin()
{
if (statDictionary == null)
{
statDictionary = new Dictionary<String, int>();
}
}
public void PreProcessing(HTTPRequest request)
{
if (statDictionary.ContainsKey(request.Url))
{
statDictionary[request.Url] = (int)statDictionary[request.Url] + 1;
}
else
{
statDictionary[request.Url] = 1;
}
}
public HTTPResponse GetResponse(HTTPRequest request)
{
HTTPResponse response = null;
StringBuilder sb = new StringBuilder();
sb.Append("<html><body><h1>Stat:</h1>");
foreach (KeyValuePair<String, int> entry in statDictionary)
{
sb.Append(entry.Key + ": " + entry.Value.ToString() + "<br />");
}
sb.Append("</body></html>");
response = new HTTPResponse(200);
response.body = Encoding.UTF8.GetBytes(sb.ToString());
return response;
}
public HTTPResponse PostProcessing(HTTPResponse response)
{
throw new NotImplementedException();
}
}
}