This repository has been archived by the owner on Nov 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcAsyncRequests.cls
66 lines (57 loc) · 2.12 KB
/
cAsyncRequests.cls
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
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "cAsyncRequests"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
Event ResponseStart(Req As cAsyncRequest, ByVal Status As Long, ByVal ContentType As String)
Event ResponseDataAvailable(Req As cAsyncRequest, Data() As Byte)
Event ResponseFinished(Req As cAsyncRequest)
Event Error(Req As cAsyncRequest, ByVal ErrorNumber As Long, ByVal ErrorDescription As String)
Private mReqs As New Collection, mTimeout As Long
'centralized Event-Delegation
Friend Sub OnResponseStart(Req As cAsyncRequest, ByVal Status As Long, ByVal ContentType As String)
RaiseEvent ResponseStart(Req, Status, ContentType)
End Sub
Friend Sub OnResponseDataAvailable(Req As cAsyncRequest, Data() As Byte)
RaiseEvent ResponseDataAvailable(Req, Data)
End Sub
Friend Sub OnResponseFinished(Req As cAsyncRequest)
RaiseEvent ResponseFinished(Req)
End Sub
Friend Sub OnError(Req As cAsyncRequest, ByVal ErrorNumber As Long, ByVal ErrorDescription As String)
RaiseEvent Error(Req, ErrorNumber, ErrorDescription)
End Sub
Public Property Let Timeout(ByVal Milliseconds As Long)
mTimeout = Milliseconds
End Property
Public Function AddRequest(Key As String, Optional Timeout As Long = -1) As cAsyncRequest
If Timeout > -1 Then mTimeout = Timeout
mReqs.add New cAsyncRequest, Key
Set AddRequest = mReqs(Key)
AddRequest.Init Me, Key, mTimeout
End Function
Public Function RemoveRequest(ReqObjOrKey) As cAsyncRequest
If IsObject(ReqObjOrKey) Then mReqs.Remove ReqObjOrKey.Key Else mReqs.Remove ReqObjOrKey
End Function
Public Property Get RequestCount() As Long
RequestCount = mReqs.count
End Property
Public Property Get RequestItem(KeyOrOneBasedIndex) As cAsyncRequest
Set RequestItem = mReqs(KeyOrOneBasedIndex)
End Property
Public Sub Cleanup()
Dim Req As cAsyncRequest
For Each Req In mReqs
Req.http.Abort
Next
Set mReqs = Nothing
End Sub