Blame | Last modification | View Log | RSS feed
<%' ------------------------------------------------------------------------------Class clsProgress' ------------------------------------------------------------------------------Public TotalBytes ' Number of bytes client sent to serverPublic BytesReceived ' Number of bytes received by serverPublic UploadStarted ' Time on server when upload startedPublic UploadCompleted ' Time on server when upload was completedPublic LastActive ' Time on server when upload was last activePrivate FileName ' Name of temporary file holding progress informationPrivate FSO ' File System ObjectPrivate Enabled ' Determines if progress class is enabled' ------------------------------------------------------------------------------Public Function Load()' don't do anything if disabledIf Not Enabled Then Exit FunctionDim Data ' raw data about progressDim Lines ' Array of lines within dataDim Line ' Individual line of name/value pairDim Pair ' Property array containing name and value' Initialize default valuesTotalBytes = 0BytesReceived = 0UploadStarted = ""LastActive = ""UploadCompleted = ""' Retrieve informationData = ProgressData' If information is emptyIf Data = "" Then' Instruct caller that method failedLoad = FalseExit FunctionEnd If' Load session data, split into an array by' finding carriage returnsLines = Split(Data, vbCrLf)' Loop through each lineFor Each Line In Lines' parse loaded session' name=valuePair = Split(Line, "=", 2)' If pair has 2 indexesIf 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)) ThenUploadStarted = CDate(Pair(1))End IfCase "LastActive"If IsDate(Pair(1)) ThenLastActive = CDate(Pair(1))End IfCase "UploadCompleted"If IsDate(Pair(1)) ThenUploadCompleted = CDate(Pair(1))End IfEnd SelectEnd IfNext' Return successLoad = TrueEnd Function' ------------------------------------------------------------------------------Public Sub Save()' don't do anything if disabledIf Not Enabled Then Exit SubDim Data' save data into Info stringData = Data & "TotalBytes=" & TotalBytes & vbCrLfData = Data & "BytesReceived=" & BytesReceived & vbCrLfData = Data & "UploadStarted=" & UploadStarted & vbCrLfData = Data & "LastActive=" & LastActive & vbCrLfData = Data & "UploadCompleted=" & UploadCompleted & vbCrLf' save the informationProgressData = DataEnd Sub' ------------------------------------------------------------------------------Private Sub Class_Initialize()' Declare FSO ConstantsConst WindowsFolder = 0Const SystemFolder = 1Const TemporaryFolder = 2Dim Folder' Only enable class if session ID was receivedEnabled = Not Request.QueryString("Session") = ""' Are we allowed to interact with FileSystemObject?If Not (FileSystemObjectEnabled Or FileSystemObjectEnabled = "") ThenEnabled = FalseEnd If' don't do anything if disabledIf Not Enabled Then Exit Sub' Instantiate File System ObjecSet FSO = Server.CreateObject("Scripting.FileSystemObject")' Build path to information file in temporary folderFolder = FSO.GetSpecialFolder(TemporaryFolder).PathFileName ="AspUpload_" & Request.QueryString("Session") & ".tmp"FileName = Folder & "\" & FileNameEnd Sub' ------------------------------------------------------------------------------Private Sub Class_Terminate()' don't do anything if disabledIf Not Enabled Then Exit Sub' Garbage CollectionSet FSO = NothingEnd Sub' ------------------------------------------------------------------------------Private Property Get ProgressData()' don't do anything if disabledIf Not Enabled Then Exit PropertyDim File' If file does not yet exist, don't do anythingIf Not FSO.FileExists(FileName) Then Exit Property' Get the fileSet File = FSO.OpenTextFile(FileName)' if the file has informationIf Not File.AtEndOfStream Then' Read all the informationProgressData = File.ReadAllEnd If' Close the connection to the fileFile.Close' Garbage collectionSet File = NothingEnd Property' ------------------------------------------------------------------------------Private Property Let ProgressData(ByRef information)' don't do anything if disabledIf Not Enabled Then Exit Property' Declare ConstantsConst ForReading = 1Const ForWriting = 2Const ForAppending = 8Dim File' Open the text file' * Create if it doesn't exist' * Open for writingSet File = FSO.OpenTextFile(FileName, ForWriting, True)' Write the information to the fileCall File.Write(information)' Close the connection to the fileFile.Close' Garbage collectionSet File = NothingEnd Property' ------------------------------------------------------------------------------End Class' ------------------------------------------------------------------------------%>