svnno****@sourc*****
svnno****@sourc*****
2010年 11月 25日 (木) 18:36:51 JST
Revision: 1114 http://sourceforge.jp/projects/tween/svn/view?view=rev&revision=1114 Author: syo68k Date: 2010-11-25 18:36:51 +0900 (Thu, 25 Nov 2010) Log Message: ----------- ・一部イベントのDataContractを定義 ・イベントをパースして認識するように(途中) Modified Paths: -------------- branches/UserStream/Tween/DataModel.vb branches/UserStream/Tween/Twitter.vb -------------- next part -------------- Modified: branches/UserStream/Tween/DataModel.vb =================================================================== --- branches/UserStream/Tween/DataModel.vb 2010-11-25 09:26:58 UTC (rev 1113) +++ branches/UserStream/Tween/DataModel.vb 2010-11-25 09:36:51 UTC (rev 1114) @@ -156,4 +156,29 @@ <DataMember(Name:="text")> Public text As String End Class + <DataContract()> _ + Public Class friendsevent + <DataMember(Name:="friends")> Public friends As Int64() + End Class + + <DataContract()> _ + Public Class deletedstatus + <DataMember(Name:="id")> Public id As Int64 + <DataMember(Name:="user_id")> Public user_id As Int64 + End Class + + <DataContract()> _ + Public Class deleteevent + <DataMember(Name:="event")> Public [event] As String + <DataMember(Name:="status")> Public status As deletedstatus + End Class + + <DataContract()> _ + Public Class eventdata + <DataMember(Name:="target")> Public target As user + <DataMember(Name:="target_object")> Public target_object As status + <DataMember(Name:="created_at")> Public created_at As String + <DataMember(Name:="event")> Public [event] As String + <DataMember(Name:="source")> Public source As user + End Class End Class Modified: branches/UserStream/Tween/Twitter.vb =================================================================== --- branches/UserStream/Tween/Twitter.vb 2010-11-25 09:26:58 UTC (rev 1113) +++ branches/UserStream/Tween/Twitter.vb 2010-11-25 09:36:51 UTC (rev 1114) @@ -2790,8 +2790,8 @@ End Sub Private EventNameTable() As String = { _ - "friends", _ - "target" + "favorite", _ + "unfavorite" } Private Sub UserStreamLoop() @@ -2813,18 +2813,35 @@ Dim idx2 As Integer = line.IndexOf(""":") If idx = 0 AndAlso idx2 > 0 Then Dim eventname As String = line.Substring(idx + 2, idx2 - 2) + If eventname.Equals("friends") Then + Debug.Print("friends") + Continue Do + ElseIf eventname.Equals("delete") Then + Debug.Print("delete") + Continue Do + ElseIf eventname.Equals("target") Then + Dim data As DataModel.eventdata + Debug.Print("Event") + Using stream As New MemoryStream() + Dim serializer As New DataContractJsonSerializer(GetType(DataModel.eventdata)) + res.Length = 0 + res.Append(line) + Dim buf As Byte() = Encoding.Unicode.GetBytes(res.ToString) + stream.Write(buf, offset:=0, count:=buf.Length) + stream.Seek(offset:=0, loc:=SeekOrigin.Begin) + data = DirectCast(serializer.ReadObject(stream), DataModel.eventdata) + End Using + Select Case Array.IndexOf(EventNameTable, data.event) + Case 0 ' favorite + Debug.Print("Event:favorite") + Case 1 ' unfavorite + Debug.Print("Event:unfavorite") + Case Else ' その他イベント + TraceOut("Unknown Event" + Environment.NewLine + line) + End Select + Continue Do + End If - Select Case Array.IndexOf(EventNameTable, eventname) - Case 0 ' friends - Debug.Print("friends") - Continue Do - Case 1 ' その他イベント - Debug.Print("Event") - TraceOut("Event" + Environment.NewLine + line) - Continue Do - Case Else - ' - End Select End If res.Length = 0 @@ -2864,4 +2881,6 @@ Public Event UserStreamStopped() Public Event UserStreamPaused() + Public Event UserStreamGetFriendsList() + End Class