所以在我試圖使一個CMS系統,利用雅虎通訊SDK。這個想法是讓自助機器人能夠引導客戶解決某些問題。會話通過兩種方法運行。一個腳本存在以迴應一般性迴應。在客戶收到的每條消息中,程序將查找certan關鍵字和問題,這些問題會觸發XML文件的響應。如果它找到一個它繼續與腳本。該計劃的工作,但需要付出代價。它是一個巨大的資源。在這個程序中,我有一個類來處理所有的yahoo messenger函數,比如登錄,註銷,接收和發送消息。我也有一堂課,我稱之爲對話。這樣可以保證消息來源的形式,發生的原因以及在腳本對話中的位置。在我的主要計劃中,我根據有多少不同的網站幫助會計師使用我的初始X客戶類。每次它收到一條消息時,它都會創建一個新的會話類,因爲它存在或它檢查現有會話並找到座標位置。它顯然也會對傳入消息中的關鍵字進行所有檢查。這是我用於接收消息的共享事件處理程序的代碼。我的問題是,有沒有辦法讓這個更有效率。資源和效率
Private Sub yahooclients_OnRec(ByVal sender As Object, ByVal buddy As String, ByVal message As String)
TotalRec = TotalRec + 1
Try
Dim c As YahooClient = CType(sender, YahooClient) 'Yahoo Client To Send Message From
showLog("From:" & buddy & " To:" & c.Account & " Message:" & message)
Dim msgSplit As String()
Dim retmsg As String
Dim smsg As String()
Dim n1 As XmlNode
Dim sran As New Random 'Random SPlit Message
Dim domran As New Random 'Random Domain ID
Dim Found1 As Boolean = False
Dim FoundIt As Integer = 0
Dim i As Integer = 0 'Keyword Counter
'Check Message For KeyWords By Splitting Each phrase by spaces
msgSplit = Split(message, " ")
For Each word In msgSplit
For Each value In KeywordInd
If value = word Then
n1 = m_nodelist.Item(i)
retmsg = n1.InnerText
GoTo ScrubMessage
End If
i = i + 1
Next
i = 0
Next
'Check For Conversations
If convos.Count = 0 Then
convos.Add(New Conversation(c.Account, buddy, 0))
retmsg = Script(0)
GoTo ScrubMessage
Else
For A As Integer = 0 To (convos.Count - 1)
If InStr(convos(A).TUser, c.Account) > 0 And InStr(convos(A).FUser, buddy) > 0 Then
Found1 = True
Exit For
End If
FoundIt = FoundIt + 1
Next
If Found1 = True Then
convos(FoundIt).SPosition = convos(FoundIt).SPosition + 1
'Send Next Position In Script
If convos(FoundIt).SPosition > (Script.Length - 1) Then
If convos(FoundIt).SPosition = Script.Length Then
TotalScript = TotalScript + 1
ToolStripStatusLabel10.Text = TotalScript
End If
Exit Sub
End If
retmsg = Script(convos(FoundIt).SPosition)
GoTo ScrubMessage
Else
convos.Add(New Conversation(c.Account, buddy, 0))
retmsg = Script(0)
GoTo ScrubMessage
End If
End If
ScrubMessage: 「去掉| SMSG =斯普利特(retmsg,「|」)
'Pull A Random Response
If smsg.Length > 1 Then
retmsg = smsg(sran.Next(0, (smsg.Length) - 1))
Else
retmsg = smsg(0)
End If
'Check For Domain Indicator
If InStr(retmsg, "%") > 0 Then
TotalLink = TotalLink + 1
End If
retmsg = Replace(retmsg, "%s", Domains(domran.Next(0, (Domains.Length - 1))))
If CheckBox2.Checked = True Then 'send Message With Font and Color
retmsg = "<font face=" & """" & fname & """" & ">" & "[#FF80C0m" & retmsg & "</font>"
End If
showLog(("Sending Message: " & retmsg & " To: " & buddy & " From: " & c.Account))
c.SendMessage(buddy, retmsg)
TotalSent = TotalSent + 1
ToolStripStatusLabel4.Text = TotalSent 'Updates Sent Counter
ToolStripStatusLabel6.Text = TotalRec 'Updates Rec Counter
ToolStripStatusLabel8.Text = TotalLink 'Updates Links counter
Catch ex As Exception
showLog(ex.ToString)
End Try
End Sub
程序變爲真的很多賬目沒有resonsive都在問的問題等
非常感謝提示! – 2011-01-13 21:24:50