Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
64 jtweddle 1
<%
2
' ------------------------------------------------------------------------------
3
Class clsProgress
4
' ------------------------------------------------------------------------------
5
	Public TotalBytes		' Number of bytes client sent to server
6
	Public BytesReceived	' Number of bytes received by server
7
	Public UploadStarted	' Time on server when upload started
8
	Public UploadCompleted	' Time on server when upload was completed
9
	Public LastActive		' Time on server when upload was last active
10
 
11
	Private FileName		' Name of temporary file holding progress information
12
	Private FSO				' File System Object
13
	Private Enabled			' Determines if progress class is enabled
14
' ------------------------------------------------------------------------------
15
	Public Function Load()
16
 
17
		' don't do anything if disabled
18
		If Not Enabled Then Exit Function
19
 
20
		Dim Data ' raw data about progress
21
		Dim Lines ' Array of lines within data
22
		Dim Line ' Individual line of name/value pair
23
		Dim Pair ' Property array containing name and value
24
 
25
		' Initialize default values
26
		TotalBytes = 0
27
		BytesReceived = 0
28
		UploadStarted = ""
29
		LastActive = ""
30
		UploadCompleted = ""
31
 
32
		' Retrieve information
33
		Data = ProgressData
34
 
35
		' If information is empty
36
		If Data = "" Then
37
 
38
			' Instruct caller that method failed
39
			Load = False
40
			Exit Function
41
 
42
		End If
43
 
44
		' Load session data, split into an array by
45
		' finding carriage returns
46
		Lines = Split(Data, vbCrLf)
47
 
48
		' Loop through each line
49
		For Each Line In Lines
50
 
51
			' parse loaded session
52
			' name=value
53
			Pair = Split(Line, "=", 2)
54
 
55
			' If pair has 2 indexes
56
			If UBound(Pair, 1) = 1 Then
57
 
58
				' Determine action based on first index
59
				' (attribute name)
60
				Select Case Pair(0)
61
					Case "TotalBytes"
62
						TotalBytes = CLng(Pair(1))
63
					Case "BytesReceived"
64
						BytesReceived = CLng(Pair(1))
65
					Case "UploadStarted"
66
						If IsDate(Pair(1)) Then
67
							UploadStarted = CDate(Pair(1))
68
						End If
69
					Case "LastActive"
70
						If IsDate(Pair(1)) Then
71
							LastActive = CDate(Pair(1))
72
						End If
73
					Case "UploadCompleted"
74
						If IsDate(Pair(1)) Then
75
							UploadCompleted = CDate(Pair(1))
76
						End If
77
				End Select
78
			End If
79
		Next
80
 
81
		' Return success
82
		Load = True
83
 
84
	End Function
85
' ------------------------------------------------------------------------------
86
	Public Sub Save()
87
 
88
		' don't do anything if disabled
89
		If Not Enabled Then Exit Sub
90
 
91
		Dim Data
92
 
93
		' save data into Info string
94
		Data = Data & "TotalBytes=" & TotalBytes & vbCrLf
95
		Data = Data & "BytesReceived=" & BytesReceived & vbCrLf
96
		Data = Data & "UploadStarted=" & UploadStarted & vbCrLf
97
		Data = Data & "LastActive=" & LastActive & vbCrLf
98
		Data = Data & "UploadCompleted=" & UploadCompleted & vbCrLf
99
 
100
		' save the information
101
		ProgressData = Data
102
 
103
	End Sub
104
' ------------------------------------------------------------------------------
105
	Private Sub Class_Initialize()
106
 
107
		' Declare FSO Constants
108
		Const WindowsFolder = 0
109
		Const SystemFolder = 1
110
		Const TemporaryFolder = 2
111
 
112
		Dim Folder
113
 
114
		' Only enable class if session ID was received
115
		Enabled = Not Request.QueryString("Session") = ""
116
 
117
		' Are we allowed to interact with FileSystemObject?
118
		If Not (FileSystemObjectEnabled Or FileSystemObjectEnabled = "") Then
119
			Enabled = False
120
		End If
121
 
122
		' don't do anything if disabled
123
		If Not Enabled Then Exit Sub
124
 
125
		' Instantiate File System Objec
126
		Set FSO = Server.CreateObject("Scripting.FileSystemObject")
127
 
128
		' Build path to information file in temporary folder
129
		Folder = FSO.GetSpecialFolder(TemporaryFolder).Path
130
 
131
		FileName ="AspUpload_" & Request.QueryString("Session") & ".tmp"
132
 
133
		FileName = Folder & "\" & FileName
134
 
135
	End Sub
136
' ------------------------------------------------------------------------------
137
	Private Sub Class_Terminate()
138
 
139
		' don't do anything if disabled
140
		If Not Enabled Then Exit Sub
141
 
142
		' Garbage Collection
143
		Set FSO = Nothing
144
 
145
	End Sub
146
' ------------------------------------------------------------------------------
147
	Private Property Get ProgressData()
148
 
149
		' don't do anything if disabled
150
		If Not Enabled Then Exit Property
151
 
152
		Dim File
153
 
154
		' If file does not yet exist, don't do anything
155
		If Not FSO.FileExists(FileName) Then Exit Property
156
 
157
		' Get the file
158
		Set File = FSO.OpenTextFile(FileName)
159
 
160
		' if the file has information
161
		If Not File.AtEndOfStream  Then
162
 
163
			' Read all the information
164
			ProgressData = File.ReadAll
165
 
166
		End If
167
 
168
		' Close the connection to the file
169
		File.Close
170
 
171
		' Garbage collection
172
		Set File = Nothing
173
 
174
	End Property
175
' ------------------------------------------------------------------------------
176
	Private Property Let ProgressData(ByRef information)
177
 
178
		' don't do anything if disabled
179
		If Not Enabled Then Exit Property
180
 
181
		' Declare Constants
182
		Const ForReading = 1
183
		Const ForWriting = 2
184
		Const ForAppending = 8
185
 
186
		Dim File
187
 
188
		' Open the text file
189
		'	* Create if it doesn't exist
190
		'	* Open for writing
191
		Set File = FSO.OpenTextFile(FileName, ForWriting, True)
192
 
193
		' Write the information to the file
194
		Call File.Write(information)
195
 
196
		' Close the connection to the file
197
		File.Close
198
 
199
		' Garbage collection
200
		Set File = Nothing
201
 
202
	End Property
203
' ------------------------------------------------------------------------------
204
End Class
205
' ------------------------------------------------------------------------------
206
%>