-
Notifications
You must be signed in to change notification settings - Fork 0
/
clsProgress.asp
206 lines (155 loc) · 5.45 KB
/
clsProgress.asp
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<%
' ------------------------------------------------------------------------------
Class clsProgress
' ------------------------------------------------------------------------------
Public TotalBytes ' Number of bytes client sent to server
Public BytesReceived ' Number of bytes received by server
Public UploadStarted ' Time on server when upload started
Public UploadCompleted ' Time on server when upload was completed
Public LastActive ' Time on server when upload was last active
Private FileName ' Name of temporary file holding progress information
Private FSO ' File System Object
Private Enabled ' Determines if progress class is enabled
' ------------------------------------------------------------------------------
Public Function Load()
' don't do anything if disabled
If Not Enabled Then Exit Function
Dim Data ' raw data about progress
Dim Lines ' Array of lines within data
Dim Line ' Individual line of name/value pair
Dim Pair ' Property array containing name and value
' Initialize default values
TotalBytes = 0
BytesReceived = 0
UploadStarted = ""
LastActive = ""
UploadCompleted = ""
' Retrieve information
Data = ProgressData
' If information is empty
If Data = "" Then
' Instruct caller that method failed
Load = False
Exit Function
End If
' Load session data, split into an array by
' finding carriage returns
Lines = Split(Data, vbCrLf)
' Loop through each line
For Each Line In Lines
' parse loaded session
' name=value
Pair = Split(Line, "=", 2)
' If pair has 2 indexes
If UBound(Pair, 1) = 1 Then
' Determine action based on first index
' (attribute name)
Select Case Pair(0)
Case "TotalBytes"
TotalBytes = CLng(Pair(1))
Case "BytesReceived"
BytesReceived = CLng(Pair(1))
Case "UploadStarted"
If IsDate(Pair(1)) Then
UploadStarted = CDate(Pair(1))
End If
Case "LastActive"
If IsDate(Pair(1)) Then
LastActive = CDate(Pair(1))
End If
Case "UploadCompleted"
If IsDate(Pair(1)) Then
UploadCompleted = CDate(Pair(1))
End If
End Select
End If
Next
' Return success
Load = True
End Function
' ------------------------------------------------------------------------------
Public Sub Save()
' don't do anything if disabled
If Not Enabled Then Exit Sub
Dim Data
' save data into Info string
Data = Data & "TotalBytes=" & TotalBytes & vbCrLf
Data = Data & "BytesReceived=" & BytesReceived & vbCrLf
Data = Data & "UploadStarted=" & UploadStarted & vbCrLf
Data = Data & "LastActive=" & LastActive & vbCrLf
Data = Data & "UploadCompleted=" & UploadCompleted & vbCrLf
' save the information
ProgressData = Data
End Sub
' ------------------------------------------------------------------------------
Private Sub Class_Initialize()
' Declare FSO Constants
Const WindowsFolder = 0
Const SystemFolder = 1
Const TemporaryFolder = 2
Dim Folder
' Only enable class if session ID was received
Enabled = Not Request.QueryString("Session") = ""
' Are we allowed to interact with FileSystemObject?
If Not (FileSystemObjectEnabled Or FileSystemObjectEnabled = "") Then
Enabled = False
End If
' don't do anything if disabled
If Not Enabled Then Exit Sub
' Instantiate File System Objec
Set FSO = Server.CreateObject("Scripting.FileSystemObject")
' Build path to information file in temporary folder
Folder = FSO.GetSpecialFolder(TemporaryFolder).Path
FileName ="AspUpload_" & Request.QueryString("Session") & ".tmp"
FileName = Folder & "\" & FileName
End Sub
' ------------------------------------------------------------------------------
Private Sub Class_Terminate()
' don't do anything if disabled
If Not Enabled Then Exit Sub
' Garbage Collection
Set FSO = Nothing
End Sub
' ------------------------------------------------------------------------------
Private Property Get ProgressData()
' don't do anything if disabled
If Not Enabled Then Exit Property
Dim File
' If file does not yet exist, don't do anything
If Not FSO.FileExists(FileName) Then Exit Property
' Get the file
Set File = FSO.OpenTextFile(FileName)
' if the file has information
If Not File.AtEndOfStream Then
' Read all the information
ProgressData = File.ReadAll
End If
' Close the connection to the file
File.Close
' Garbage collection
Set File = Nothing
End Property
' ------------------------------------------------------------------------------
Private Property Let ProgressData(ByRef information)
' don't do anything if disabled
If Not Enabled Then Exit Property
' Declare Constants
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Dim File
' Open the text file
' * Create if it doesn't exist
' * Open for writing
Set File = FSO.OpenTextFile(FileName, ForWriting, True)
' Write the information to the file
Call File.Write(information)
' Close the connection to the file
File.Close
' Garbage collection
Set File = Nothing
End Property
' ------------------------------------------------------------------------------
End Class
' ------------------------------------------------------------------------------
%>