-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGlobal.asax
86 lines (72 loc) · 2 KB
/
Global.asax
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
<%@ Application Language="C#" %>
<script runat="server">
private static int totalNumberOfUsers = 0;
private static int currentNumberOfUsers = 0;
private string statFile = "C:\\Inetpub\\wwwroot\\sdk\\statistics.txt";
private int ReadInteger(System.IO.StreamReader reader)
{
string line = reader.ReadLine();
if (line != null)
{
int value;
if (int.TryParse(line, out value))
return value;
}
return 0;
}
void Application_Start(object sender, EventArgs e)
{
if (System.IO.File.Exists(statFile))
{
using (System.IO.FileStream s = System.IO.File.OpenRead(statFile))
{
using (System.IO.StreamReader reader = new System.IO.StreamReader(s))
{
totalNumberOfUsers = ReadInteger(reader);
}
}
}
}
private void SaveStatistics()
{
using (System.IO.FileStream s = System.IO.File.OpenWrite(statFile))
{
using (System.IO.StreamWriter writer = new System.IO.StreamWriter(s))
{
writer.WriteLine(totalNumberOfUsers.ToString());
}
}
}
void Application_End(object sender, EventArgs e)
{
// Code that runs on application shutdown
}
void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
}
void Session_Start(object sender, EventArgs e)
{
totalNumberOfUsers += 1;
currentNumberOfUsers += 1;
SaveStatistics();
}
void Session_End(object sender, EventArgs e)
{
currentNumberOfUsers -= 1;
}
public static int TotalNumberOfUsers
{
get
{
return totalNumberOfUsers;
}
}
public static int CurrentNumberOfUsers
{
get
{
return currentNumberOfUsers;
}
}
</script>