forked from WilliamSmithEdward/CMSSupervisorAutomation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMSSupervisorConnection2.vb
102 lines (61 loc) · 2.57 KB
/
CMSSupervisorConnection2.vb
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
Public Class CMSSupervisorConnection
Private _serverAddress As String
Private _acd As Integer
Private _userName As String
Private _password As String
Private _cvsApp As ACSUP.cvsApplication
Private _cvsConn As ACSCN.cvsConnection
Private _cvsSrv As ACSUPSRV.cvsServer
Public Sub New(ByVal serverAddress As String, ByVal acd As Integer, ByVal userName As String, ByVal password As String)
_serverAddress = serverAddress
_acd = acd
_userName = userName
_password = password
End Sub
Public Sub Connect()
_cvsApp = New ACSUP.cvsApplication
_cvsConn = New ACSCN.cvsConnection
_cvsSrv = New ACSUPSRV.cvsServer
_cvsApp.CreateServer(_userName, "", "", _serverAddress, False, "ENU", _cvsSrv, _cvsConn)
_cvsConn.Login(_userName, _password, _serverAddress, "ENU")
_cvsSrv.Reports.ACD = _acd
End Sub
Public Sub Disconnect()
_cvsConn.Logout()
_cvsConn.Disconnect()
System.Runtime.InteropServices.Marshal.ReleaseComObject(_cvsApp)
System.Runtime.InteropServices.Marshal.ReleaseComObject(_cvsConn)
System.Runtime.InteropServices.Marshal.ReleaseComObject(_cvsSrv)
_cvsApp = Nothing
_cvsConn = Nothing
_cvsSrv = Nothing
End Sub
Public Function ExecuteQuery(reportPath As String, reportParams As Dictionary(Of String, String), timeZone As String) As String
Dim strPath As String = Application.StartupPath
Dim rep As New ACSREP.cvsReport
Dim info As ACSCTLG.cvsReportInfo
If System.IO.File.Exists(strPath & "\export.txt") Then
System.IO.File.Delete(strPath & "\export.txt")
End If
info = _cvsSrv.Reports.Reports(reportPath)
_cvsSrv.Reports.CreateReport(info, rep)
If Not timeZone = "" Then
rep.TimeZone = timeZone
End If
For Each kvp As KeyValuePair(Of String, String) In reportParams
rep.SetProperty(kvp.Key, kvp.Value)
Next
rep.ExportData(strPath & "\export.txt", 44, 0, True, True, True)
rep.Quit()
If Not _cvsSrv.Interactive Then
For Each task As Object In _cvsSrv.ActiveTasks
_cvsSrv.ActiveTasks.Remove(task)
Next
End If
System.Runtime.InteropServices.Marshal.ReleaseComObject(rep)
System.Runtime.InteropServices.Marshal.ReleaseComObject(info)
rep = Nothing
info = Nothing
Return My.Computer.FileSystem.ReadAllText(strPath & "\export.txt")
End Function
End Class