Snippets
Created by
Mihamina Rakotomandimby
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 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 | Imports TCX.Configuration
Imports TCX.PBXAPI
Imports System.Text
Imports System.IO
Imports _3cx_listen_event_version2.traitement
Public Class Form1
' Private Declare Function GetKeyValueA Lib "kernel32.dll" Alias "GetPrivateProfileStringA" (ByVal strSection As String, ByVal strKeyName As String, ByVal strNull As String, ByVal RetVal As StringBuilder, ByVal nSize As Integer, ByVal strFileName As String) As Integer
'Public Delegate Sub UpdateConnectDlg(ByVal newConn As Integer)
'Dim _activeConnDict As Dictionary(Of Integer, ActiveConnection)
'Dim _queueConnDict As Dictionary(Of Integer, ActiveConnection)
'Dim _stopUpdates As Boolean
'#Region "Phone"
Public ResultArray As New ArrayList
Public trd As System.Threading.Thread
Public trd1 As System.Threading.Thread
Public flag_abort As Boolean = False
Public list_ivr As New List(Of String) ' list des identifiants des IVR
Public list_extension As New List(Of String) 'list des files d'attentes créer
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
InitializeComponent()
'Try
' PhoneSystem.ApplicationName = "tantelycx"
' ' Dim ps As PhoneSystem = PhoneSystem.Root
' 'Dim regKeyAppRoot As RegistryKey
' 'If (IntPtr.Size = 4) Then
' ' regKeyAppRoot = Registry.LocalMachine.OpenSubKey("SOFTWARE\\3CX\\PhoneSystem")
' 'Else
' ' regKeyAppRoot = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Wow6432Node\\3CX\\PhoneSystem")
' 'End If
' 'Dim _appPath As String = Application.StartupPath
' 'Dim filePath As String = _appPath & "Bin\3CXPhoneSystem.ini"
' 'Dim value As String = GetKeyValue("ConfService", "ConfPort", filePath)
' 'Dim port As Int32 = 0
' 'If Not String.IsNullOrEmpty(value) Then
' ' Int32.TryParse(value.Trim, port)
' ' PhoneSystem.CfgServerPort = port
' 'End If
' 'value = GetKeyValue("ConfService", "confUser", filePath)
' 'If Not String.IsNullOrEmpty(value) Then
' ' PhoneSystem.CfgServerUser = value
' 'End If
' 'value = GetKeyValue("ConfService", "confPass", filePath)
' 'If Not String.IsNullOrEmpty(value) Then
' ' PhoneSystem.CfgServerPassword = value
' 'End If
' PhoneSystem.CfgServerHost = "127.0.0.1"
' PhoneSystem.CfgServerPort = 5485
' PhoneSystem.CfgServerUser = "cfguser_default"
' PhoneSystem.CfgServerPassword = "omcsrshzpb"
' Dim check As Integer = 0
' Dim configSrvConn As Boolean = False
' Do
' Try
' configSrvConn = PhoneSystem.Root.Connected
' Catch ex As Exception
' Console.WriteLine("not connected " & ex.Message)
' Threading.Thread.Sleep(10000)
' check = check + 1
' End Try
' If configSrvConn Or check > 3 Then Exit Do
' Loop
' Dim tenantArr As Tenant
' tenantArr = PhoneSystem.Root.GetTenant
' Dim dnArr() As DN = PhoneSystem.Root.GetDN
' 'Dim connArr() As ActiveConnection
' Dim DnRegistered As New ArrayList
' Dim NoOfActiveConn As Int16 = 0
' Dim DnConnArr As New ArrayList
' For Each dn As DN In dnArr
' ' If dn.IsRegistered Then Console.WriteLine(dn.ID & " is connected")
' If dn.GetType.ToString = "TCX.Configuration.Extension" Then
' DnRegistered.Add(dn.Number)
' Dim ext As Extension
' ext = dn
' Console.WriteLine("number" & dn.Number.ToString)
' 'Console.Write("userstatus:" & dn.GetPropertyByName("ConnectionStatus").ToString)
' End If
' 'For Each dn1 In dn.GetActiveConnections
' ' If dn.GetType.ToString = "TCX.Configuration.Extension" Then
' ' Dim ExtNo As String = ""
' ' ExtNo = dn1.DN.Number
' ' Dim status = dn1.Status
' ' DnConnArr.Add(ExtNo & " - " & status)
' ' End If
' 'Next
' Next
' Dim FreeExt As New ArrayList
' FreeExt = CompareArrays(DnRegistered, DnConnArr)
' For l = 0 To FreeExt.Count - 1
' MsgBox(FreeExt.Item(l).ToString)
' Next
'Catch ex As Exception
' Console.WriteLine("error:" & ex.Message)
' MessageBox.Show(String.Format("{0} {1}", ex.Message, ex.StackTrace))
'End Try
'flag_abort = False
'If Not connect_phonesystem() Then
' MsgBox("Phonesystem does not connected")
' Exit Sub
'End If
'File.AppendAllText("log_1.txt", "Parametres" & vbCrLf)
'For Each p In PhoneSystem.Root.GetParameters
' File.AppendAllText("log_1.txt", p.ToString & vbCrLf)
'Next
'File.AppendAllText("log_1.txt", "codecs" & vbCrLf)
'For Each c In PhoneSystem.Root.GetCodecs
' File.AppendAllText("log_1.txt", c.ToString & vbCrLf)
'Next
'File.AppendAllText("log_1.txt", "Conditions" & vbCrLf)
'For Each r In PhoneSystem.Root.GetRuleConditions
' File.AppendAllText("log_1.txt", r.ToString & vbCrLf)
'Next
'File.AppendAllText("log_1.txt", "RuleHours" & vbCrLf)
'For Each rh In PhoneSystem.Root.GetRuleHourTypes
' File.AppendAllText("log_1.txt", rh.ToString & vbCrLf)
'Next
'File.AppendAllText("log_1.txt", "RuleCalltype" & vbCrLf)
'For Each rl In PhoneSystem.Root.GetRuleCallTypes
' File.AppendAllText("log_1.txt", rl.ToString & vbCrLf)
'Next
'File.AppendAllText("log_1.txt", "GetTenants" & vbCrLf)
'For Each t As Tenant In PhoneSystem.Root.GetTenants()
' For Each Ivr1 As IVR In t.GetIVRs()
' File.AppendAllText("log_1.txt", Ivr1.Name & vbCrLf)
' File.AppendAllText("log_1.txt", Ivr1.Number & vbCrLf)
' File.AppendAllText("log_1.txt", Ivr1.PromptFilename & vbCrLf)
' File.AppendAllText("log_1.txt", Ivr1.Timeout & vbCrLf)
' File.AppendAllText("log_1.txt", Ivr1.TimeoutForwardType.ToString() & vbCrLf)
' Next
'Next
'MsgBox("ok")
'If Not connect_phonesystem() Then
' MsgBox("Not connecter")
' Return
'End If
''Dim dnArr() As DN = PhoneSystem.Root.GetDN
''Dim p() As DNProperty
''For Each DN In dnArr
'' If DN.GetType.ToString = "TCX.Configuration.Extension" Then
'' p = DN.GetProperties
'' End If
'' Exit For
''Next
''Stop
If Not connect_phonesystem() Then
MsgBox("Phonesystem does not connected")
Exit Sub
End
End If
get_all_extension_ivr()
trd = New Threading.Thread(AddressOf getStatistiques)
trd.Start()
trd1 = New Threading.Thread(AddressOf getstatus)
trd1.Start()
End Sub
Function connect_phonesystem() As Boolean
'Try
PhoneSystem.ApplicationName = "CallViewer"
'' Dim ps As PhoneSystem = PhoneSystem.Root
'Dim regKeyAppRoot As RegistryKey
'If (IntPtr.Size = 4) Then
' regKeyAppRoot = Registry.LocalMachine.OpenSubKey("SOFTWARE\\3CX\\PhoneSystem")
'Else
' regKeyAppRoot = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Wow6432Node\\3CX\\PhoneSystem")
'End If
'Dim _appPath As String = CType(regKeyAppRoot.GetValue("AppPath"), String)
'Dim filePath As String = Path.Combine(_appPath, "Bin\3CXPhoneSystem.ini")
'Dim value As String = GetKeyValue("ConfService", "ConfPort", filePath)
'Dim port As Int32 = 0
'If Not String.IsNullOrEmpty(value) Then
' Int32.TryParse(value.Trim, port)
' PhoneSystem.CfgServerPort = port
'End If
'value = GetKeyValue("ConfService", "confUser", filePath)
'If Not String.IsNullOrEmpty(value) Then
' PhoneSystem.CfgServerUser = value
'End If
'value = GetKeyValue("ConfService", "confPass", filePath)
'If Not String.IsNullOrEmpty(value) Then
' PhoneSystem.CfgServerPassword = value
' End If
PhoneSystem.CfgServerHost = "127.0.0.1"
PhoneSystem.CfgServerPort = 5485
PhoneSystem.CfgServerUser = "cfguser_default"
PhoneSystem.CfgServerPassword = "igf7wt9o2ed56u"
Dim check As Integer = 0
Dim configSrvConn As Boolean = False
Do
Try
configSrvConn = PhoneSystem.Root.Connected()
Catch ex As Exception
Console.WriteLine("not connected " & ex.Message)
Threading.Thread.Sleep(10000)
check = check + 1
End Try
If configSrvConn Or check > 3 Then Exit Do
Loop
Return configSrvConn
End Function
Sub get_all_extension_ivr()
Dim dnArr() As DN = PhoneSystem.Root.GetDN
Dim s As String
For Each d In dnArr
Try
s = d.ToString
Catch ex As Exception
s = "vide"
End Try
File.AppendAllText("liste_des_dn.txt", d.Number & " - " & d.GetType.ToString & vbCrLf & s & vbCrLf)
Next
list_extension = (From a In dnArr.ToList Where a.GetType.ToString = "TCX.Configuration.Extension" Select a.Number).ToList
list_ivr = (From a In dnArr.ToList Where a.GetType.ToString = "TCX.Configuration.IVR" Select a.Number).ToList
End Sub
Sub getstatus()
Dim dnArr() As DN = PhoneSystem.Root.GetDN
Dim stype As String = ""
Dim ac() As ActiveConnection
Try
Do
For Each d In dnArr
stype = d.GetType.ToString
If stype = "TCX.Configuration.Extension" And d.Number = "00001" Then
Dim ext As Extension = d
ext.CurrentProfile.CustomMessage = "en visio"
File.WriteAllText("status_" & ext.Number & ".txt", ext.CurrentProfile.Name)
ac = d.GetActiveConnections
If ac.Count = 0 Then
' fermeko lay appel izay mitondra an le extension iny soit ivr; soit file d'attente soit extension
proceed.fermer_appel(d)
End If
ElseIf stype = "TCX.Configuration.IVR" Or stype = "TCX.Configuration.Queue" Then
proceed.fermer_appel(d)
End If
Next
System.Threading.Thread.Sleep(10)
Loop
Catch ex As Exception
File.WriteAllText("error.txt", "getstatus:" & ex.Message)
End Try
End Sub
Sub getStatistiques()
' Dim tenantArr As Tenant
'tenantArr = PhoneSystem.Root.GetTenant
Dim aa As MyListener = New MyListener(Nothing)
AddHandler PhoneSystem.Root.Updated, New NotificationEventHandler(AddressOf aa.ps_Updated)
AddHandler PhoneSystem.Root.Inserted, New NotificationEventHandler(AddressOf aa.ps_Inserted)
AddHandler PhoneSystem.Root.Deleted, New NotificationEventHandler(AddressOf aa.ps_Deleted)
Console.WriteLine("------------------------------")
' For Each t In aa.oTraitement.list_log
'Console.WriteLine(t.ToString)
' Next
Dim DnRegistered As New ArrayList
Dim NoOfActiveConn As Int16 = 0
Dim DnConnArr As New ArrayList
Dim ilistener As Integer = 0
'Do
' 'If flag_abort Then Exit Do
' For Each dn As DN In dnArr
' If dn.GetType.ToString = "TCX.Configuration.IVR" Then
' If dn.IsRegistered Then
' Dim t1 As Extension = dn
' Dim ac() As ActiveConnection = dn.GetActiveConnections()
' If ac.Length > 0 Then
' Try
' For Each a In ac
' 'Console.WriteLine("call_id" & a.CallID)
' 'Console.WriteLine(a.InternalParty)
' 'Console.WriteLine(a.IsInbound)
' 'Console.WriteLine(a.IsOutbound)
' 'Console.WriteLine(a.LastChangeStatus)
' 'Console.WriteLine(a.ExternalParty)
' 'File.AppendAllText("log.txt", Now & ":" & dn.Number & ": " & a.Status.ToString & vbCrLf
' ' )
' 'File.AppendAllText("log.txt", Now & ":" & dn.Number & ": " & a.CallID.ToString & vbCrLf
' ' )
' 'File.AppendAllText("log.txt", Now & ":" & dn.Number & ": " & a.CallConnectionID.ToString & vbCrLf
' ' )
' 'File.AppendAllText("log.txt", Now & ":" & dn.Number & ": " & a.ExternalParty.ToString & vbCrLf
' ' )
' 'File.AppendAllText("log.txt", Now & ":" & dn.Number & ": " & a.InternalParty.ToString & vbCrLf
' ' )
' 'File.AppendAllText("log.txt", Now & ":" & dn.Number & ": " & a.IsInbound.ToString & vbCrLf)
' 'File.AppendAllText("log.txt", Now & ":" & dn.Number & ": " & a.IsOutbound.ToString & vbCrLf)
' 'File.AppendAllText("log.txt", Now & ":" & dn.Number & ": " & a.LastChangeStatus.ToString & vbCrLf
' ' )
' Dim d As DN = a.OriginatedBy
' Next
' Catch ex As Exception
' End Try
' ' File.AppendAllText("log.txt", Now & ":" & dn.Number & " connecté et en communication" & vbCrLf)
' Else
' ' File.AppendAllText("log.txt", Now & ":" & dn.Number & " connecté et libre" & vbCrLf)
' End If
' Else
' ' File.AppendAllText("log.txt", Now & ":" & dn.Number & " is not connected" & vbCrLf)
' End If
' End If
' Next
' ilistener = ilistener + 1
' ' Threading.Thread.Sleep(2000)
' ' File.AppendAllText("log.txt", "---------------------------------------------" & vbCrLf)
' 'If ilistener > 100 Then Exit Do
'Loop
'PhoneSystem.Root.Disconnect()
End Sub
Function CompareArrays(ByVal FistArray As ArrayList, ByVal SecondArray As ArrayList) As ArrayList
'Dim ResultArray As New ArrayList
Dim sItem As String
If SecondArray.Count = 0 Then
ResultArray = FistArray
Return ResultArray
End If
For Each sItem In FistArray
If Not SecondArray.Contains(Trim(sItem)) Then
ResultArray.Add(sItem)
End If
Next
Return ResultArray
End Function
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
trd.Abort()
PhoneSystem.Root.Disconnect()
flag_abort = True
End
End
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
'File.AppendAllText("log_1.txt", "Parametres" & vbCrLf)
'For Each p In PhoneSystem.Root.GetParameters
' File.AppendAllText("log_1.txt", p.ToString & vbCrLf)
'Next
'File.AppendAllText("log_1.txt", "codecs" & vbCrLf)
'For Each c In PhoneSystem.Root.GetCodecs
' File.AppendAllText("log_1.txt", c.ToString & vbCrLf)
'Next
'File.AppendAllText("log_1.txt", "Conditions" & vbCrLf)
'For Each r In PhoneSystem.Root.GetRuleConditions
' File.AppendAllText("log_1.txt", r.ToString & vbCrLf)
'Next
'File.AppendAllText("log_1.txt", "RuleHours" & vbCrLf)
'For Each rh In PhoneSystem.Root.GetRuleHourTypes
' File.AppendAllText("log_1.txt", rh.ToString & vbCrLf)
'Next
'File.AppendAllText("log_1.txt", "RuleCalltype" & vbCrLf)
'For Each rl In PhoneSystem.Root.GetRuleCallTypes
' File.AppendAllText("log_1.txt", rl.ToString & vbCrLf)
'Next
'File.AppendAllText("log_1.txt", "GetTenants" & vbCrLf)
'For Each t As Tenant In PhoneSystem.Root.GetTenants()
' For Each Ivr1 As IVR In t.GetIVRs()
' File.AppendAllText("log_1.txt", Ivr1.Name & vbCrLf)
' File.AppendAllText("log_1.txt", Ivr1.Number & vbCrLf)
' File.AppendAllText("log_1.txt", Ivr1.PromptFilename & vbCrLf)
' File.AppendAllText("log_1.txt", Ivr1.Timeout & vbCrLf)
' File.AppendAllText("log_1.txt", Ivr1.TimeoutForwardType.ToString() & vbCrLf)
' Next
'Next
'MsgBox("ok")
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
End Sub
Private Sub Form1_FormClosed(sender As Object, e As FormClosedEventArgs) Handles MyBase.FormClosed
trd.Abort()
trd1.Abort()
PhoneSystem.Root.Disconnect()
flag_abort = True
File.AppendAllText("log.txt", vbCrLf & "Fermeture Programme" & vbCrLf)
End
End Sub
End Class
|
Comments (0)
You can clone a snippet to your computer for local editing. Learn more.